OPIO
Pat Beirne edited this page 2 years ago

OPIO

The RaspberryPi and OrangePi environment uses an app simply called gpio to control the GPIO pins. The original verion was written by Gordon Henderson as part of his WiringPi project and has been ported to work on most of the OrangePi series boards. But there is no (commonly available) version for the OrangePi-i96. Rather than port it, I decided to rewrite it in Python3. To be safe, it has a new name: opio. It operates very similarly to the original gpio program, with fewer features. The repository for opio is here

With opio you can:

  • examine the current state of all the GPIO pins involved in the 40 pin connector
  • change mode and direction on each pin
  • change the value (0V/3V) on each pin

opio is written in Python3, which is available on the stock Linux distribution for both the i96 and 2G-IOT boards. This of course makes it a bit slow, taking about 500ms to do anything.

The term mode is whether a pin is a GPIO or being used as its alternate function, and whether it's an input or output. The term value means 1/0, an on these pins, that means 2.8V or 0V.

Usage
  opio [-d] mode <n> [in | out | alt]
  opio [-d] read <n>
  opio [-d] write <n> <value>
  opio [-2] [readall | readallx | exports | leds]

For the first 3 forms of the command, the number is the linux-gpio number, ranging from 0 to 127. [0..31 is portA, 32..63 is portB, 64......67 is portD and 96..127 is portC]

The first version sets the mode for a pin. If the mode is 'in' or 'out', the pin is set to GPIO mode and the 'export' is created. If the mode is set to 'alt', the pin is set to its alt-function mode (like i2c or uart) and the 'export' is deleted. You can use the -d option to prevent the export from being created or deleted.

The second version simply reads value of the pin and returns '1' or '0'. If the pin is an 'out' pin, the last value written will be returned.

The third version writes a '1' or a '0' to the pin. If the pin is in mode 'in' or 'alt', this command will have no effect.

As a convenience, the read and write commands will automatically set the mode on the GPIO pin and create an export. So, generally, the mode command is only required if you wish to change a pin back to its `alt' function.

The 'readall' returns a chart very similar to the chart created by gpio readall original gpio program. This includes the gpio number, the i96 bus name, the pins alternate function, the current mode and value.

The 'readallx' returns a chart with extra information, such as the RDA pin assignments. The 'exports' command lists which pins have existing exports in the /sys/class/gpio folder. and the 'leds' command lists the state of the LED's on board. [Note: the LEDs start up in an odd state and the 'leds' command will not relect the correct state until the LEDs have been manipulated]