Detect GPIO pins on boot and make decision accordingly

Hello There,
I want to connect a 3 state switch to my Jetson Nano 2gb, and based in its state I want to either boot in Gui mode and run an application, boot in tty1 mode and run another app or boot normally without running anything.
How can I achieve this?
Is there a way to monitor the GPIO pins on boot and make decisions accordingly?

Thanks in advance!

See the online Jetson Linux Developer Guide, as you can see, u-boot sources is public available. you may have customization to control GPIOs, please also check developer guide, U-Boot Customization for reference,

Thanks for the reply,
I don’t want to sound ignorant, but I’ve spent several hours searching in vain, since I do not know what I am actually searching for.
Can you give me any leads?

I am thinking about placing an ‘if’ clause in a boot file, which in turn checks state of the switch and makes the decision. Is there any system file where I can do so?
Any help would be appreciated.

None of your usecase needs to be done in the bootloader.

The difference between GUI mode and “tty console” are just whether the system runs the desktop GUI or not.
Both cases are already in kernel.

You can use sysfs to monitor the GUI first. Search gpio sysfs to know how to monitor gpio.

And search some keywords like systemd over the Internet for automatic tool.

Again, you don’t need to touch any “boot file”.

1 Like

Thank you for your help,
I was able to set up a service that runs on startup, which in turn runs a shell script that does the required monitoring and starts the system in the suitable “mode”.


echo 15 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio15/direction
pin15=$(cat /sys/class/gpio/gpio15/value)

echo 13 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio13/direction
pin13=$(cat /sys/class/gpio/gpio13/value)

echo 19 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio19/direction
pin19=$(cat /sys/class/gpio/gpio19/value)
echo $pin13
echo $pin15
echo $pin19

if [ $pin15 -eq 1 ] 
then #Run application in 1 mode
echo 'APPLICATION is running in 1 mode'
python3 /home/user/

elif [ $pin13 -eq 1 ] #Run application in 2 mode
echo 'APPLICATION is running in 2 mode'
systemctl start gdm3.service
python3 /home/tekno-h/

elif [ $pin19 -eq 1 ] #Run application in 3 mode
echo 'APPLICATION is running in 3 mode'
systemctl start gdm3.service 

However I have a small problem, one of my applications requires a gui to display a camera output on the screen, and although the system starts the graphical interface, it stays stuck on the login window, I tried following this thread but it did not work:
[Auto login jetson nano 2gb - #14 by swapnilgtm1998]
Any ideas ?
Thanks again

The exact problem is that the auto-login isn’t working, although the settings show that the password prompt is disabled. @WayneWWW

Which auto login? The desktop GUI? or the console?

@WayneWWW Both are not working…

The console one does not support auto-login. Not sure about your GUI case.
Have you set the disable in the system setting through GUI?

Actually, I am mostly concerned to auto login in the GUI case.
Yes, when I navigate to users and groups in the settings it displays:
“Password: Not asked on login”

Have you configured that one under “Display setting”?

I configured it through:
“Preferences”->“Users and Groups”->“Password”->Change->“Don’t ask for password on login”->“OK”

Ok, so I think I know what is causing the problem,in the case where the GUI is required, after the system boots and the service runs the shell script I was starting the gui session through: “systemctl start gdm3.service” and I was always asked to login through using the password. So I reset “systemctl set-default” and I am no longer asked for a password after booting in GUI.
However, I am back to my original problem, if I set the system to normally start in gui mode how can I ask it to go to console (something like “systemctl start gdm3.service” but for console) ?
and also, even though I am no longer prompt to enter a password, I am not able to display the camera output on the screen after start up(“cannot open display”), any ideas?
one more thing, if don’t have a display connected and I start a gui session, will that add the display load on the system, computationally speaking ?

You can disable gdm3 service and it can make it enter console.

I don’t know what kind of camera framework you are using. export DISPLAY=:0 is required for argus camera case.

Also, to make this env work, the Xserver is needed. Which means gdm3 is needed. Our graphic driver supports to have no monitor connected case. You can use devkit to check it. For example, gdm3 is still running even when you have no monitor connected.

My problem is that when I start a gdm3 gui session using “systemctl start gdm3.service” auto login doesn’t work, and when I am in the normal gui session using “systemctl stop gdm3.service” doesn’t work.
I found that using Ctrl+ALT+F3 gets me to console mode, is there a command that can also do that ?
As for the framework used, I am running a python application which displays some output to the screen using Opencv ("cv2.imshow). Is there no way I can get this application to display its output on the screen after startup without Xserver?

Also, In the case where no monitor is connected, will the graphic driver still be rendering the display ?
Sorry if my English isn’t great…

“systemctl stop gdm3.service” doesn’t work.

You mean it didn’t go into console?

Also, In the case where no monitor is connected, will the graphic driver still be rendering the display ?

The app that uses GPU to do the work will still run. But no monitor means no display.

Correct, the system will not enter console mode if it is not initiated through gdm3.service

Please also run this after you disable gdm3.

sudo loginctl terminate-seat seat0

Running :
“sudo systemctl stop gdm3.service” and/ or “sudo systemctl disable gdm3.service”
followed by :
“sudo loginctl terminate-seat seat0”
took me back to the login screen in gui mode.