Monday, October 7, 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.




12 comments:

  1. Hi,

    Thanks by the excellent tutorials. It's same to read Radxa analog pins, right?

    Thanks,
    Alvaro

    ReplyDelete
    Replies
    1. I got stuck at the SPI pins, what analog pins do you mean?

      Delete
    2. Hi Galland, i also fighting with GPIO and SPI, let's combine our efforts.

      Delete
  2. Hi,

    In the specifications: Extend header - 80 pins including GPIO, I2C, SPI, Line in, USB 2.0, PWM, ADC, LCD, GPS etc

    and in Radxa Rock schematics there are some pins labeled _A0, _A1,... wich usually means to analog pins.
    GPIO1_A0/UART0_RX
    GPIO1_A1/UART0_TX
    GPIO1_A2/UART0_CTS
    GPIO1_A3
    ...

    I d'like to connect some analog sensors (like a LDR).

    Thanks a lot,
    Alvaro 

    ReplyDelete
    Replies
    1. Oh, I didn't notice the ADC mention, must find them :)
      However I don't think they are the GPIO1_A* since that's just the port naming (there are also GPIO_B*, GPIO_C*, ...).

      Delete
  3. Could the libraries from Raspberry Pi GPIO controls be adapted to this ?
    The RPi has a nice Python module for this which makes it really easy.

    Do you happen to know if the inner-workings of such libs are using the same methods of writing to a file or is there a lower level access to GPIO and such ?

    ReplyDelete
  4. Hi,
    I want to access the analog pin J8/33 ad0 but can find how to do it. Can you help me?

    Thanks. Regards.

    ReplyDelete
  5. Hi,

    Have you any example/tutorial how to connect a SPI device?

    Thanks a lot,
    Alvaro

    ReplyDelete
    Replies
    1. Just to add, I want connect a nRF24L01+, or other devices, without the use of an arduino.

      Delete
  6. Hi Galland,
    Did you figure out with SPI?

    ReplyDelete
  7. Hello guys... I wonder why the public/community has to figure out the GPIOs and its functions. Why there isn't the RR board maker come to simplify this trivial issues + giving some (at least) simple examples on each ports (SPI, I2c, UART, etc) ? I have seen these repeated efforts from time to time on various other boards alike. Where are the board makers support on this common issues which surely become the interest of the board purchasers?

    ReplyDelete
  8. Hi,i was told by tom cubie the board maker founder,that there will be an ide and comand set and AT comands for this board,it was supposed to be on a dvd of some sort with examples etc,maybe its still being made,just look around for the rock chip development ide and software etc,and look for the pdf datasheet for the rockchip,just putting ideas out there,it should be verry same as r pi i would think.

    ReplyDelete

Note: Only a member of this blog may post a comment.