As mentioned in my previous blog on Dragonboard 410C GPIO I was planning to use the libsoc library from Jack Mitch. I though I'd installed this correctly but when I tried to access it from Python it was refusing to import the library. Re-reading the GPIO blog article from 96boards I'd not compiled this correctly. So I tried that again and this time was successful.
./configure --enable-python --enable-board=dragonboard410c make sudo make install sudo ldconfig /usr/local/lib
As the Dragonboard uses 1.8v logic levels, I used a simple MOSFET based level shifter module.
One channel was connected to my HC-SR501 Passive IR module, the other connected to the three pins of a RGB Led.
I had some issues getting the libsoc code to work, which turned out that I'd forgotten to "request" the GPIOs. Once I'd added that in, it is straightforward to flash an output on GPIO-B.
from time import sleep from libsoc import gpio from libsoc import GPIO # GPIO.set_debug(True) gpio_out = gpio.GPIO(GPIO.gpio_id("GPIO-B"), gpio.DIRECTION_OUTPUT) with gpio.request_gpios(gpio_out): while True: gpio_out.set_high() sleep(1) gpio_out.set_low() sleep(1)
In the process of investigating my issues I discovered libsoc_zero. If you've used GPIO_Zero on the Pi, it's very similar. You'll see that it just adds a little more abstraction in the form of LEDs and Buttons.
from libsoc_zero.GPIO import LED from time import sleep gpio_red = LED('GPIO-B') while (True): gpio_red.on() sleep(0.5) gpio_red.off() sleep(0.5)
The next example lights the RED led when the sensor detects movement. I noticed that whilst doing this that the output from the IR module appears to float when there is nothing detected so I added a pull down resistor to the output pin and the circuit became a lot more predictable.
from libsoc_zero.GPIO import Button from libsoc_zero.GPIO import LED from time import sleep sensor = Button('GPIO-A') gpio_red = LED('GPIO-B') gpio_red.off() sleep(2) while True: if sensor.is_pressed(): gpio_red.on() sleep(0.5) else: gpio_red.off() sleep(0.5)
I've also been looking at boxing up the project. Normally I'd build this on strip board but as I'm a little short on time, I think it will likely stay on the breadboard. The webcam cable is quite long so I'll see if I can safely shorten that.