I need to control a relay with GPIO, anyone knows how to set a GPIO?
hello damingwang,
here show the steps to control gpio pin with the console commands.
taking to control gpio123 for example.
switch to gpio directory with root user
cd /sys/class/gpio/
Generate gpio123 name
echo 123 > export
Enable the gpio
echo out > direction && echo 1 > value
Thanks, Jerry. But when I try to find GPIO map in /sys/class/gpio, it turns out āpermission deniedā, I already do
āsudo suā in count nvidia. How can I check them.
hello damingwang,
may i know which gpio pin you would like to control manually?
thanks
[quote=āJerryChangā]
hello damingwang,
may i know which gpio pin you would like to control manually?
thanks
After I get the permission, I can successfully change a IO status.Using the example IO in doc:" PLATFORM ADAPTATION AND
BRING-UP GUIDE", now I am going to control CAN1_STBY (GPIO3_PAA.06), but I donāt understand the pin number calculate formula for now.
Thanks a lot!
Using this table: NVIDIA Jetson TX2 J21 Header Pinout - JetsonHacks
I would like to make J21 Header pins 31, 33, and 37 outputs, so I tried echoing 398, 389, and 388 to export and I also get āpermission deniedā. Any help would be great!
Use āsudoā (you need to be root). E.g.:
sudo echo 123 > /sys/class/gpio/export
Or stay sudo by using a root shell:
sudo -s
cd /sys/class/gpio/
echo 123 > export
echo out > direction && echo 1 > value
exit
Thank you very much - works but a follow on question - I tried all of the GPIO pins on the J21 header and only found two that work āout of the boxā - pin 18 (gpio481) and pin 29 (gpio398).
Any reason why the same procedure doesnāt work for pins 31, 33, and 37 (gpio298, gpi389, and gpio 388) ?
Thanks for the fast reply!
As the name goes, āGPIOā is āgeneralāā¦those pins can have multiple uses. You have to configure the pin for what you wantā¦which could imply removing something else using that pin. I have not looked at the particular pins, but perhaps the question should not be whether they work out of the boxā¦they doā¦the question is one of what configuration is required based on what is already using the pin?
I have not looked at the particular pins, someone else may be able to answer. If you show the specific error from a specific command someone is more likely to see what is going on.
I canāt even get gpio481 and gpio398 to light up. Thereās no power on the pin even though the kernel thinks there should be, based on /sys/kernel/debug/gpio (excerpted):
GPIOs 320-511, platform/2200000.gpio, tegra-gpio
gpio-398 ( | sysfs ) out hi
Iām using the latest stock firmware. Maybe I need to have compiled my own kernel with the right GPIO parameters?
Also, I know my test LED works since connecting it to power/ground on the same header works fine.
Any suggestions? Starting to think about working around using a USB-GPIO breakout :(
I tested J21 pin 18 and it does seem suspicious.
J21 pin 18 maps to MDM_WAKE_AP (which has a 1.8V on SoC side, but goes through a level shifter on J21). This touches the M.2 slot. Do you have anything in the M.2? Or any drivers for hardware which might go in the M.2?
There does seem to be some bug related to this. For reference, I am using R28.1. For GPIO 481 these two directories may be relevant (481 must be exported first for this to show up):
/sys/devices/2200000.gpio/gpio/gpio481/
/sys/class/gpio/gpio481/
ā¦in theory these are the same due to symbolic links.
For everything below Iām using sudo.
Start with a fresh cold boot. Go to ā/sys/class/gpio/ā and export 481, then cd to ā/sys/devices/2200000.gpio/gpio/gpio481/ā. āecho out > directionā. If you ācat directionā it will say out.
If I then measure pin 18 voltage I get 0 volts (which matches āvalueā being ā0ā at the start). If I then echo ā1ā to āvalueā the voltage goes up to 1.56V.
Mostly when I āecho 0 > valueā the āvalueā register shows ā0ā, but actual pin voltage does not drop. Sometimes it does. Keep doing this repeatedly on the command line (assumes already exported and direction out) while monitoring pin 18 voltage:
cd /sys/class/gpio/gpio481
echo 1 > value ; cat value
echo 0 > value ; cat value
This seems to imply something is not seeing the change on echo to value to 0, but it seems changing value to 1 always works. Getting back to ā0ā seems to require a cold boot (warm boot wonāt reset itā¦this seems wrong since reboot goes back to āinā and not exported). dmesg does not say anything.
It is possible the device tree is related to this (I have not looked), but it seems odd that if the device tree is causing an issue that sometimes the echo to value works on the pin, but not always (and in fact echo 0 rarely works on actual pin voltage)ā¦but echo followed by cat of value always says it succeeded.
If I echo āinā to direction, then the pin voltage remains at 1.56V. I donāt think this should happen unless there is something else going on.
Are there current patches needed for J21 pin 18 to function as regular GPIO as export of 481?
borism - I am using jetsonhacks and built my kernel on the TX2 - after doing āgetkernelsourcesā the menu config device tree comes up and I used the defaults. I pulled jetsonhacks from git and am using HEAD which is the 28.1 release/tag. The one thing I did is add SPI and got the loopback test to work - I donāt think that would make a difference. You could try pulling the latest from git and see if it works. Hope this helps!
ā¦ and these were the 2 most useful articles so far:
C++ code to toggle GPIOs (works for me when I compile it into my source)
https://devtalk.nvidia.com/default/topic/1020887/jetson-tx2/how-to-configure-a-gpio-on-tx2-/?offset=8#5213286
and this Chart with gpio pin numbers:
contactjuggle - thatās very interesting. A few days ago, I had a bunch of GPIOs working fine. (I have a TX2, sometimes itās plugged into an Nvidia Reference board, sometimes itās plugged into an Auvidea J106, and sometimes itās plugged into an Auvidea J120. Everything was working as expected.)
Then, it the last day or two, I got SPI (/dev/spidev*) working. And now my GPIOs donāt work anymore. Iāve gone back to my old kernels and my old .dtbs, but it still doesnāt work. ā¦ very strangeā¦
Ah, sometimes my gpiochip shows up as gpiochip320, but sometimes it shows up as gpiochip488. I guess I need to be more careful with my device treesā¦ I seem to have my GPIOs working againā¦
we can see the J21 Pin18 is gpio481 Sysfs GPIO.
we check the Pin is GPIO3_PY.01
how to get the gpio{Number}, is there some formula ?
GPIO03_PY.01 ====>gpio481
Thanks
You get the GPIO name from the pinmux xls spreadsheet. (In this case, itās GPIO3_PY.01)
On a running Jetson system, you can look inside /sys/class/gpio/ and see the "gpiochip"s in your system. You should see a /sys/class/gpio/gpiochip320, which is the main GPIO controller on the TX2. The number, 320, is the starting gpio number for that chip.
Each letter group controls 8 gpios. In the kernel source code, look up the letter code in:
kernel-4.4/include/dt-bindings/gpio/tegra186-gpio.h
ā¦ in that file, we can see that the āYā is the 20th group of 8. Then add the final ā01ā.
So:
320 + 8*20 + 1 = 481
hello wuyankun1986,
please refer to the documentation,
[Release 28.1 Development Guide]-> [PDF Documents]-> [Tegra Linux Driver Package TX2 Adaptation Guide]
and check the āGPIO changesā session in page 7.
thanks
@JerryChang spin.interrupt
Thanks for your reply. I get it! ^.^
could you tell me the gpiochip{number}, the number is 320, why is 320 ?
I had an error: direction permission denied while trying to to these steps and I found a solution to it here are the steps :
1)$ sudu su //to be the root
2)cd /sys/class/gpio/ //to go to the gpio directory
3)echo 481 > export //to export gpio481 as an example
4)cd /sys/class/gpio//gpio481
5) echo out > direction ; cat direction //the first part is to set the direction to output and the second part to read the value after writing it to make sure (n.b cat command use to read the content of a file)
6)echo 1 > value ; cat value //to set the value to 1.