def test_setmode(self):
     rpi_gpio = Mock()
     adapter = GPIO.RPiGPIOAdapter(rpi_gpio, mode=rpi_gpio.BCM)
     rpi_gpio.setmode.assert_called_with(rpi_gpio.BCM)
     adapter = GPIO.RPiGPIOAdapter(rpi_gpio, mode=rpi_gpio.BOARD)
     rpi_gpio.setmode.assert_called_with(rpi_gpio.BOARD)
     adapter = GPIO.RPiGPIOAdapter(rpi_gpio)
     rpi_gpio.setmode.assert_called_with(rpi_gpio.BCM)
 def test_output(self):
     rpi_gpio = Mock()
     adapter = GPIO.RPiGPIOAdapter(rpi_gpio)
     adapter.output(1, True)
     rpi_gpio.output.assert_called_with(1, True)
     adapter.output(1, False)
     rpi_gpio.output.assert_called_with(1, False)
 def test_input(self):
     rpi_gpio = Mock()
     adapter = GPIO.RPiGPIOAdapter(rpi_gpio)
     rpi_gpio.input = Mock(return_value=True)
     val = adapter.input(1)
     self.assertTrue(val)
     rpi_gpio.input.assert_called_with(1)
 def test_setup(self):
     rpi_gpio = Mock()
     adapter = GPIO.RPiGPIOAdapter(rpi_gpio)
     adapter.setup(1, GPIO.OUT)
     rpi_gpio.setup.assert_called_with(1, rpi_gpio.OUT, pull_up_down=rpi_gpio.PUD_OFF)
     adapter.setup(1, GPIO.IN)
     rpi_gpio.setup.assert_called_with(1, rpi_gpio.IN, pull_up_down=rpi_gpio.PUD_OFF)
     adapter.setup(1, GPIO.IN, GPIO.PUD_DOWN)
     rpi_gpio.setup.assert_called_with(1, rpi_gpio.IN, pull_up_down=rpi_gpio.PUD_DOWN)
     adapter.setup(1, GPIO.IN, GPIO.PUD_UP)
     rpi_gpio.setup.assert_called_with(1, rpi_gpio.IN, pull_up_down=rpi_gpio.PUD_UP)
Example #5
0
    def __init__(self,
                 clk=None,
                 cs=None,
                 do=None,
                 units="c",
                 spi=None,
                 gpio=None):

        self._spi = None
        self.units = units
        # Handle hardware SPI
        if spi is not None:
            self._spi = spi
        elif clk is not None and cs is not None and do is not None:
            if gpio is None:
                gpio = GPIO.RPiGPIOAdapter(RPi.GPIO)
            self._spi = SPI.BitBang(gpio, clk, None, do, cs)
        else:
            raise ValueError('Must specify either spi')
        self._spi.set_clock_hz(5000000)
        self._spi.set_mode(0)
        self._spi.set_bit_order(SPI.MSBFIRST)
Example #6
0
def get_platform_gpio_for_pi(**keywords):
    import RPi.GPIO
    return GPIO.RPiGPIOAdapter(RPi.GPIO, **keywords)
 def test_add_event_detect(self):
     rpi_gpio = Mock()
     adapter = GPIO.RPiGPIOAdapter(rpi_gpio)
     adapter.add_event_detect(1, GPIO.RISING)
     rpi_gpio.add_event_detect.assert_called_with(1, rpi_gpio.RISING)
 def test_wait_for_edge(self):
     rpi_gpio = Mock()
     adapter = GPIO.RPiGPIOAdapter(rpi_gpio)
     adapter.wait_for_edge(1, GPIO.FALLING)
     rpi_gpio.wait_for_edge.assert_called_with(1, rpi_gpio.FALLING)
 def test_event_detected(self):
     rpi_gpio = Mock()
     adapter = GPIO.RPiGPIOAdapter(rpi_gpio)
     adapter.event_detected(1)
     rpi_gpio.event_detected.assert_called_with(1)
 def test_add_event_callback(self):
     rpi_gpio = Mock()
     adapter = GPIO.RPiGPIOAdapter(rpi_gpio)
     adapter.add_event_callback(1, callback=self.test_add_event_callback)
     rpi_gpio.add_event_callback.assert_called_with(
         1, self.test_add_event_callback)
 def test_remove_event_detect(self):
     rpi_gpio = Mock()
     adapter = GPIO.RPiGPIOAdapter(rpi_gpio)
     adapter.remove_event_detect(1)
     rpi_gpio.remove_event_detect.assert_called_with(1)
# Raspberry Pi GPIO configuration.
DC = 24
RST = 25
SPI_PORT = 0
SPI_DEVICE = 0
backlight = 3
UV = 2
SPEED_HZ = 4000000

# Create TFT LCD display object.
disp = TFT.ST7735(DC,
                  rst=RST,
                  spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=SPEED_HZ))

#Initialize Digital Output pins
GPIOcontroller = GPIO.RPiGPIOAdapter(RPi.GPIO, mode=RPi.GPIO.BCM)
GPIOcontroller.setup(pin=UV, mode=GPIO.OUT)
GPIOcontroller.setup(pin=backlight, mode=GPIO.OUT)
GPIOcontroller.output(UV, GPIO.LOW)
GPIOcontroller.output(backlight, GPIO.LOW)

# Initialize ST7735 display and variables used in its operation
WIDTH = 128
HEIGHT = 160
x0 = 40
y0 = 60
calibrationWidth = 50
calibrationHeight = 50
exposure_time = 10
default_diam = 1.0
current_diam = default_diam
Example #13
0
# It is recommended to use a software SPI connection with 4 digital GPIO pins.

# Configuration for a Raspberry Pi:
CS   = 8
MOSI = 7
MISO = 18
SCLK = 22

# Configuration for a BeagleBone Black:
# CS   = 'P8_7'
# MOSI = 'P8_8'
# MISO = 'P8_9'
# SCLK = 'P8_10'

# Create an instance of the PN532 class.
pn532 = PN532.PN532(cs=CS, sclk=SCLK, mosi=MOSI, miso=MISO,gpio = GPIO.RPiGPIOAdapter(RPi.GPIO,RPi.GPIO.BOARD))

# Call begin to initialize communication with the PN532.  Must be done before
# any other calls to the PN532!
pn532.begin()

# Get the firmware version from the chip and print(it out.)
ic, ver, rev, support = pn532.get_firmware_version()
print('Found PN532 with firmware version: {0}.{1}'.format(ver, rev))

# Configure PN532 to communicate with MiFare cards.
pn532.SAM_configuration()

# Main loop to detect cards and read a block.
print('Waiting for MiFare card...')
while True:
Example #14
0
    SCAN_TIMEOUT = float(sys.argv[1])

if len(sys.argv) > 2:
    CS = int(sys.argv[2])
    MOSI = int(sys.argv[3])
    MISO = int(sys.argv[4])
    SCLK = int(sys.argv[5])

time.sleep(2)

# initialize pn532 python
pn532 = PN532.PN532(cs=CS,
                    sclk=SCLK,
                    mosi=MOSI,
                    miso=MISO,
                    gpio=GPIO.RPiGPIOAdapter(RPi.GPIO, RPi.GPIO.BOARD))

# begin pn532 operations
pn532.begin()

print json.dumps({'message': 'Initialized', 'code': 1})

# Get the firmware version from the chip and print(it out.)
ic, ver, rev, support = pn532.get_firmware_version()
print json.dumps({
    'message': 'Firmware Version',
    'code': 3,
    'data': {
        'ic': ic,
        'ver': ver,
        'rev': rev,