Page 1 of 1

Definitive Easy Mode to access (3xGPIO and UART)

Unread postPosted: Thu May 15, 2014 10:37 am
by mdrjr
Nice images -> https://drive.google.com/folderview?id= ... sp=sharing

There are 3 GPIO's (1.8V Logic Level) on U3 that you can use.

GPIO199, GPIO200 and GPIO204

To enable those GPIO's

Code: Select all
cdroot@odroid:~# cd /sys/class/gpio/
root@odroid:/sys/class/gpio# echo 199 > export
root@odroid:/sys/class/gpio# echo 200 > export
root@odroid:/sys/class/gpio# echo 204 > export



How to flash an LED (red colored) on the GPIO.
Note: The LED must be a RED one since red are the leds that requires less voltage to operate.
Connect an LED like this -> https://drive.google.com/file/d/0B54WDu ... sp=sharing
TIP: The bigger lead of the LED is the positive and the smaller is the Negative(Ground).

This code will setup the GPIO.
Code: Select all
cd /sys/class/gpio
echo 204 > export
cd gpio204
echo out > direction


Flash the LED:
Code: Select all
while true; do
echo 0 > value
sleep 1
echo 1 > value
sleep 1
done


The code above is a infinite loop that will flash the LED.. explained:
Code: Select all
while true; do # while true is true, do this:
echo 0 > value # turn off the led
sleep 1 # wait 1 sec
echo 1 > value # turn on the led
sleep 1 # wait 1 sec
done # we are done here


Performance notes:
Toggling the GPIO from shell with a infinite loop. I could measure 10kHz on the scope.
Poking the /sys nodes with a C program I could get 250kHz (source: https://docs.google.com/document/d/17SQ ... sp=sharing)

You can use mlinuxguy Gpio example to get ~2.4Mhz out of it.
https://github.com/mlinuxguy/odpygpio

Re: Definitive Easy Mode to access (3xGPIO and UART)

Unread postPosted: Thu May 15, 2014 1:30 pm
by Digimaster
Thank you mdrjr for the complete guide for gpio! Nice pictures!

Here is a simple extra logic for powerful device control (relay switch) http://forum.odroid.com/viewtopic.php?f=80&t=3570&start=20#p33362
I'm also going to make a simple logic for dry switch input to 1,8v logic.

Re: Definitive Easy Mode to access (3xGPIO and UART)

Unread postPosted: Thu May 15, 2014 1:46 pm
by memeka
Don't you need to disable bitbanging driver?

Re: Definitive Easy Mode to access (3xGPIO and UART)

Unread postPosted: Thu May 15, 2014 6:08 pm
by odroid
With the latest kernel update, the I2C driver is not loaded automatically.

So the i2c-gpio-custom module should be loaded manually if you need the I2C.

Re: Definitive Easy Mode to access (3xGPIO and UART)

Unread postPosted: Fri May 16, 2014 4:24 am
by sert00
great 3ad!so usefull,thanks

Re: Definitive Easy Mode to access (3xGPIO and UART)

Unread postPosted: Mon Jul 07, 2014 11:54 am
by Respectech
When I try to open two of the ports, I get errors:

root@odroid:/sys/class/gpio# echo 199 > export
bash: echo: write error: Device or resource busy
root@odroid:/sys/class/gpio# echo 200 > export
bash: echo: write error: Device or resource busy

but 204 works. I've tried it directly after a reboot. Any ideas why?

Re: Definitive Easy Mode to access (3xGPIO and UART)

Unread postPosted: Mon Jul 07, 2014 12:27 pm
by odroid
Update the kernel first!

Re: Definitive Easy Mode to access (3xGPIO and UART)

Unread postPosted: Mon Jul 07, 2014 1:33 pm
by Respectech
OK. For anybody who wants to know, the information on how to update the kernel is in mdrjr's signature: viewtopic.php?f=29&t=1516

I upgraded the kernel and rebooted the ODROID-U3, and now I am able to access pins 199 and 200. However, I am not able to access the GPIO pins on the IO Board:

odroid@odroid:/sys/class/gpio$ echo 304 > export
bash: echo: write error: No such device

Re: Definitive Easy Mode to access (3xGPIO and UART)

Unread postPosted: Mon Jul 07, 2014 2:37 pm
by odroid
As we described in the above post... you should do "sudo modprobe i2c-gpio-custom".

Re: Definitive Easy Mode to access (3xGPIO and UART)

Unread postPosted: Mon Jul 07, 2014 3:49 pm
by Respectech
Thanks for the additional information and help!

In addition to the above (updating the kernel), here is the exact sequence of events I needed to do to get past the "No such device" message when exporting a pin on the IO Board, and to be able to turn pin P17 on and off:

odroid@odroid:/sys/class/gpio$ sudo su
root@odroid:/sys/class/gpio# modprobe gpio-pca953x
root@odroid:/sys/class/gpio# modprobe i2c-gpio-custom bus0=4,200,199
root@odroid:/sys/class/gpio# echo tca6416 0x20 > /sys/devices/platform/i2c-gpio.4/i2c-4/new_device
root@odroid:/sys/class/gpio# echo 304 > export
root@odroid:/sys/class/gpio# cd gpio304
root@odroid:/sys/class/gpio/gpio304# echo out > direction
root@odroid:/sys/class/gpio/gpio304# echo 1 > value ;Turns on the pin
root@odroid:/sys/class/gpio/gpio304# echo 0 > value ;Turns off the pin

Re: Definitive Easy Mode to access (3xGPIO and UART)

Unread postPosted: Mon Jul 07, 2014 7:27 pm
by odroid
Thank you for the confirmation.
Your comprehensive instruction will be very helpful for other people! ;)

Re: Definitive Easy Mode to access (3xGPIO and UART)

Unread postPosted: Wed Sep 24, 2014 3:31 am
by omegatek
Can I use the 5V PSU? Specifically, I would like to be able to turn the 5V on and off or is it always on? Is there a way use the 5v to power something else but be able to toggle power to it through software?

Re: Definitive Easy Mode to access (3xGPIO and UART)

Unread postPosted: Wed Sep 24, 2014 3:34 am
by mdrjr
5V there is always on.
You can use one GPIO to trigger a transistor that will allow pass the 5V :)

Re: Definitive Easy Mode to access (3xGPIO and UART)

Unread postPosted: Thu Sep 25, 2014 11:35 am
by omegatek
Ah, great idea. Thank you!

Re: Definitive Easy Mode to access (3xGPIO and UART)

Unread postPosted: Thu Jan 08, 2015 11:36 am
by KC7NOA
is this still the easy way .. on a X2 too ?

Re: Definitive Easy Mode to access (3xGPIO and UART)

Unread postPosted: Thu Jan 08, 2015 12:24 pm
by odroid
KC7NOA wrote:is this still the easy way .. on a X2 too ?

Yes, if you have the same Kernel.

Re: Definitive Easy Mode to access (3xGPIO and UART)

Unread postPosted: Thu Jan 08, 2015 2:28 pm
by KC7NOA
i dont think so ... iv just got the latest of mdrjr script pulls ...

Re: Definitive Easy Mode to access (3xGPIO and UART)

Unread postPosted: Thu Jan 08, 2015 5:20 pm
by odroid
Did you check the pin-out difference between X2 and U3?
Tell me what you tried...

Re: Definitive Easy Mode to access (3xGPIO and UART)

Unread postPosted: Fri Jan 09, 2015 4:35 am
by KC7NOA
its way different ... X2 has alot more....

i was wondering if the process would work for the X2 ... or is there a more up to date way to use the gpio's on a X2 ....

iv also sent linuxguy a pm .. no response yet ...

edit ---- missed you asking what iv done --

nothing yet .. i need to decide on level conversion .... i want to control relays mostly .. and a few digital, one being I2C ... but i think i would need to port some smooth tuneing firmware to be used in conjunction with the I2C`....

Re: Definitive Easy Mode to access (3xGPIO and UART)

Unread postPosted: Thu Jan 15, 2015 2:15 pm
by KC7NOA
Guess odpygpio will work with the current kernel ....

Re: Definitive Easy Mode to access (3xGPIO and UART)

Unread postPosted: Thu Jan 15, 2015 2:19 pm
by odroid
Toggle the same GPIO pins(GPIO199, GPIO200 and GPIO204) on your board.
You need to compare the pin-map on U3 with your X2.

Re: Definitive Easy Mode to access (3xGPIO and UART)

Unread postPosted: Fri Feb 13, 2015 2:17 am
by uy0ll
You can use mlinuxguy Gpio example to get ~2.4Mhz out of it.
https://github.com/mlinuxguy/odpygpio

Maps the GPIO pin to the sysfs only support OdroidXU, X2, not U3. How to use library for GPIO199, GPIO200 and GPIO204 on U3 board?