Raspberry Pi - KeirRice/PolarTable GitHub Wiki
I'm using the now discontinued Raspberry Pi 1 - Model B. It's running an ARM CPU at 700MHz and using a broadcom BCM2835 SoC.
For the operating system, I'm using Raspbian GNU/Linux 8.0 (jessie)
- Never sink more than 16 mA on a pin.
- Never draw more than 2 mA on a pin.
https://www.circuits.dk/everything-about-raspberry-gpio/
It was a lot more fiddly than I expected to get access to the GPIO pins. By default, everything is locked down.
I was able to get pigpio to read values, but I couldn't write or set any pullup states. It was throwing this error
pigpio.error: 'no permission to update GPIO'
We need to create a new user group and set the correct permissions before we can use them.
Check your settings and see if you have everything enabled you want.
sudo raspi-config
Create a new user group
sudo groupadd gpio
Add your user (in the example "pi") to the group
sudo usermod -aG gpio pi
Set the owner and permissions for the GPIO accessor paths.
sudo chgrp gpio /sys/class/gpio/export
sudo chgrp gpio /sys/class/gpio/unexport
sudo chmod 775 /sys/class/gpio/export
sudo chmod 775 /sys/class/gpio/unexport
For each pin you need access to (in the example "4"), you need to 'export' it.
Note: We are using the broadcom pin numbers not the physical header numbers.1
echo "4" > /sys/class/gpio/export
Create or edit.
/lib/udev/rules.d/60-python-pifacecommon.rules
/lib/udev/rules.d/60-python3-pifacecommon.rules
KERNEL=="spidev*", GROUP="spi", MODE="0660"
SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c 'chown -R root:gpio /sys/class/gpio && chmod -R 770 /sys/class/gpio; chown -R root:gpio /sys/devices/virtual/gpio && chmod -R 770 /sys/devices/virtual/gpio; chown -R root:gpio /sys/devices/platform/soc/*.gpio/gpio && chmod -R 770 /sys/devices/platform/soc/*.gpio/gpio'"
Restart the device and you should be okay to go.
Create or edit2
/etc/udev/rules.d/91-gpio.rules
SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /sys/class/gpio/export /sys/class/gpio/unexport ; chmod 220 /sys/class/gpio/export /sys/class/gpio/unexport'"
SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value ; chmod 660 /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value'"
Reload the rule with
sudo udevadm test --action=add /class/gpio
raspi-gpio
List a bunch of info about the state of the GPIO.
sudo raspi-gpio get
sudo apt-get install raspi-gpio
pigpio
A deamon for working with GPIO in python. Also comes with a command line util pigs
.
http://abyz.me.uk/rpi/pigpio/
sudo apt install pigpio
sudo systemctl enable pigpiod
sudo systemctl start pigpiod
import pigpio
pin = 4
pi = pigpio.pi() # exit script if no connection to daemon
if not pi.connected:
raise RuntimeError('No Connection')
pi.set_mode(pin, pigpio.OUTPUT)
pi.set_pull_up_down(pin, pigpio.PUD_OFF)
x = pi.read(pin)
value = not x
pi.write(pin, value)
RPi.GPIO
Nice python module for accessing GPIO. Is a bit limited when it comes to callback options.
https://pypi.org/project/RPi.GPIO/
sudo apt-get install python-rpi.gpio
import RPi.GPIO as GPIO
pin = 4
GPIO.setup(pin, GPIO.OUT, GPIO.PUD_OFF)
x = GPIO.input(pin)
value = not x
GPIO.output(pin, value)
The BCM2835 has hardware support for I2C in both Master and Slave modes. Unfortunately the early model Raspberry Pi models only take advantage of the Master mode. 3 4
Even if the hardware was connected there are also limitations at the kernel layer of Raspbian.5
The options for my project are to:
-
Redesign the system so the Arduino is in slave mode.
This would stop the Arduino from directly talking to the SX5109 board.
-
Redesign the system to support multi-master mode.
This would force the Arduino to be swapping between Master and Slave mode. More complex and would likely require another signal line between Arduino and Pi to manage the swaps.
-
Use another protocol like SPI.
Requires at least three additional connections between Arduino and Pi. We are also already using the SPI hardware on the Arduino side.
-
Write our own bit bashed I2C slave mode communication using a pair of GPIO pins.
How hard could it be...
1: https://www.raspberrypi.org/forums/viewtopic.php?p=806830&sid=f1a15faefbbbba6d22d8988e9ef24f0b#p806830
2: https://www.raspberrypi.org/forums/viewtopic.php?p=734582&sid=392942c6e6ca05012380b4230e70e9d3#p734582
3: https://elinux.org/RPi_BCM2835_GPIOs
4: https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=44482
5: https://www.raspberrypi.org/forums/viewtopic.php?t=87804