My Schematic

download schematic

Support

Senin, 07 Oktober 2013

Bitbanging Radxa Rock gpios

This post assumes you're using the latest Linux kernel from here on your Radxa Rock RK3188 board.

As you may already know, by looking at the openly available Radxa Rock schematics, this board has many GPIOs accessible through two expansion headers (along with other buses like LCD, SPI, I2C, etc.) as well as three user LEDs.

In this brief post I'll explain how to access any of these GPIOs to read/write its value. I've chosen one of the user LEDs to easily see the results of our actions.


By checking the schematics, it is easy to see there is a Red LED connected to GPIO0_B7 (gpio 175), an active low Green LED at GPIO0_B4 (gpio 172), and another active low Yellow LED at GPIO0_B6 (gpio 174).

How do I know the gpio number from the pin name? Relatively easy, look for your pin name here, and calculate the gpio number by taking into account that GPIO_BASE = 160 and NUM_GROUP = 32.


In this example we will toggle the Green LED on and off by following these commands in a Terminal within Linux in your Radxa (or through ssh to the board):

#become root
su root
#tell Linux we want to have access to gpio pin 172
echo 172 > /sys/class/gpio/export
#set it as an output pin (though we will be able to readback its value)
echo "out" > /sys/class/gpio/gpio172/direction
#set its value to 1 (turn off led)
echo 1 > /sys/class/gpio/gpio172/value
#set its value to 0 (turn on led)
echo 0 > /sys/class/gpio/gpio172/value
#in any case read the pin value
cat /sys/class/gpio/gpio172/value

Now, I'll be figuring out how to communicate with SPI and I2C devices hooked to the RR's expansion headers.




Tidak ada komentar:

Posting Komentar