Chip9$ input output on XIO ports

Da raspibo.

This tutorial shows how to read the value of a button or turn a led on and off.

Chip9$ has a PCF8574A i2c port expander. It drives the ports named XIO-P0 to XIO-P7 (pin 13 to 20 on U14).

It is possible to use these ports from the shell command line.

# cd /sys/class/gpio/
# ls
export       gpiochip0    gpiochip408  unexport

gpiochip408 is the PCF8574A expander. port numbered in the range 0-407 are GPIO of the AllWinner A13 SoC. Read carefully the manual and Chip schematics prior to use them.

The ports provided by the expander are the following:

port   export#  pin
XIO-P0   408    13
XIO-P1   409    14
XIO-P2   410    15
XIO-P3   411    16
XIO-P4   412    17
XIO-P5   413    18
XIO-P6   414    19
XIO-P7   415    20

First experiment: read a gpio input (e.g. a button)

Activate the XIO-P0 port:

 # echo 408 > export

This generates a virtual dir gopio408:

 # ls
 export       gpio408      gpiochip0    gpiochip408  unexport
 # ls gpio408
 active_low  direction   power       uevent
 device      edge        subsystem   value

There is a pullup to the input:

 # cat gpio408/value


Now, use a 10Kohm resistor to connect the pin 13 of U14 to ground (for example pin 1 of U14) (it works using a jumper, too. The resistor is for safety. It is more unlikely to damage the Chip toy.)

 # cat gpio408/value

As you may guess, without the resistor or jumper the value returns 1. In this way it is possible to read input from buttons. Remember to deactivate the port:

 # echo 408 > unexport

Second experiment: write a gpio output (e.g. turn on/off a led diode)

Now let us use the same gpio for output. We can activate the port as before:

 # echo 408 > export

remove the jumper of the previous experiment! and define the port as output:

 # echo out > gpio408/direction

Connect a led diode in series with a suitable resistor(*) between pin 13 of U14 and +3.3V (pin 5 of U13). The led anode must be towards +3.3v. (*) In my tests I use 1Kohm resistors. The led is not very bright at 3.3V but it is safe to use the same "tool" at 5V too.

(pin 13 of U14) ---/\/\/\/\-----|<|----- (pin 5 of U13)

If everything is okay the led should be on.


Now write 1 to the value:

 # echo 1 > gpio408/value

And the led will turn off. Obviously, to turn the led back on:

 # echo 0 > gpio408/value 

The values are reversed because the expander ports are like open collector connections.

At the end remember to deactivate the port:

 # echo in > gpio408/direction 
 # echo 408 > unexport
Strumenti personali