GPIO Configuration on booting

Post Reply
manas7891
Posts: 46
Joined: Thu Dec 28, 2023 5:14 pm
languages_spoken: english
ODROIDs: Odroid M1
Has thanked: 22 times
Been thanked: 1 time
Contact:

GPIO Configuration on booting

Post by manas7891 »

I am developing an android app in Odroid M1. The app also features to work on GPIO pins. Initilaly I configured the GPIO pins using Android Debug Bridge (adb), and it seems to work. But once I restart the device no more the pins work. It seems it is loosing the GPIO initialization. As I explore more, I came to know that each time the device restarts, I need to reconfigure the GPIO pins. How can I automatically configure the GPIO pins while booting?

User avatar
tobetter
Posts: 13216
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 1014 times
Been thanked: 2301 times
Contact:

Re: GPIO Configuration on booting

Post by tobetter »

How many pins and which pins are you willing to configure? And after configuring them how are you using them?

manas7891
Posts: 46
Joined: Thu Dec 28, 2023 5:14 pm
languages_spoken: english
ODROIDs: Odroid M1
Has thanked: 22 times
Been thanked: 1 time
Contact:

Re: GPIO Configuration on booting

Post by manas7891 »

I am using GPIO Pin #120, 118, 119, 121; these corresponds to pin no 12, 16, 18, and 22 respectively. Apart from that pin no. 20 is used as GND Pin and Pin No. 17 is used as PWR. I am using them in Pull-Up configurations. After configuring I use them to interact with my buttons in my app. That means they should be able to interact with the buttons similar to touch in the UI layout.

User avatar
mctom
Posts: 4135
Joined: Wed Nov 11, 2020 4:44 am
languages_spoken: english, polski
ODROIDs: XU4, M1, H3+, SP3, N2L, M1S, N2
Location: Gdańsk, Poland
Has thanked: 609 times
Been thanked: 829 times
Contact:

Re: GPIO Configuration on booting

Post by mctom »

So you're using them as inputs with pull-ups. All GPIO are configured as inputs by default, as this is the safest state for surrounding electronics.

The most straightforward solution is to add external pull-up resistors to each pin - this will always work. Internal pull-ups aren't any better and resistors are worth much less than 1 second of your life.
Punk ain't no religious cult, punk means thinking for yourself!
OpenUPS
PiStackMon

Luke.go
Posts: 838
Joined: Mon May 30, 2016 1:55 pm
languages_spoken: english
Has thanked: 160 times
Been thanked: 145 times
Contact:

Re: GPIO Configuration on booting

Post by Luke.go »

you can use android things api to control the GPIO pins.

And, as motioned by @mctom, you can add external pull-up resistors.

manas7891
Posts: 46
Joined: Thu Dec 28, 2023 5:14 pm
languages_spoken: english
ODROIDs: Odroid M1
Has thanked: 22 times
Been thanked: 1 time
Contact:

Re: GPIO Configuration on booting

Post by manas7891 »

Thanks for the solutions, I already have external resistors for the pull up configurations. The issue is I want to keep the pull-up configurations which I have set using ADB. These configurations however get reset when I reboot my device. They need to to initialized again while booting. Is there any solution for it.

User avatar
tobetter
Posts: 13216
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 1014 times
Been thanked: 2301 times
Contact:

Re: GPIO Configuration on booting

Post by tobetter »

manas7891 wrote:
Thu May 09, 2024 4:51 pm
Thanks for the solutions, I already have external resistors for the pull up configurations. The issue is I want to keep the pull-up configurations which I have set using ADB. These configurations however get reset when I reboot my device. They need to to initialized again while booting. Is there any solution for it.
I am wondering why you need pull-up configuration if you have external resistors?
What command did you run to set the pull up configuration?

User avatar
mctom
Posts: 4135
Joined: Wed Nov 11, 2020 4:44 am
languages_spoken: english, polski
ODROIDs: XU4, M1, H3+, SP3, N2L, M1S, N2
Location: Gdańsk, Poland
Has thanked: 609 times
Been thanked: 829 times
Contact:

Re: GPIO Configuration on booting

Post by mctom »

In case this is what you may be thinking, you don't need to configure GPIO to be "aware" of external pull-up resistors.
Punk ain't no religious cult, punk means thinking for yourself!
OpenUPS
PiStackMon

manas7891
Posts: 46
Joined: Thu Dec 28, 2023 5:14 pm
languages_spoken: english
ODROIDs: Odroid M1
Has thanked: 22 times
Been thanked: 1 time
Contact:

Re: GPIO Configuration on booting

Post by manas7891 »

May be i need to explain what is my requirement;
1. I am developing an app in android, on my Odrdoid M1 Device. The android Version is 11
2. I want to configure the hardware buttons (Using GPIO)
3. I am using the pins as stated before
4. to configure the pins as input pins, I first initialized using ADB
5. I got some success, but when I restart the device, the configuration gets reset and for that I need to initialize the GPIO pins again, which is not a feasible process.
6. I wish that I could set the configurations of the hardware pins permanently.
Let me show you how I configured the pins in adb shell:

odroidm1:/ # echo 120 > /sys/class/gpio/export
odroidm1:/ # echo "in" > /sys/class/gpio/gpio120/direction
odroidm1:/ # echo 1 > /sys/class/gpio/gpio120/active_low

Hope I could explain the situation. Thanks

User avatar
tobetter
Posts: 13216
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 1014 times
Been thanked: 2301 times
Contact:

Re: GPIO Configuration on booting

Post by tobetter »

manas7891 wrote:
Fri May 10, 2024 10:40 am
May be i need to explain what is my requirement;
1. I am developing an app in android, on my Odrdoid M1 Device. The android Version is 11
2. I want to configure the hardware buttons (Using GPIO)
3. I am using the pins as stated before
4. to configure the pins as input pins, I first initialized using ADB
5. I got some success, but when I restart the device, the configuration gets reset and for that I need to initialize the GPIO pins again, which is not a feasible process.
6. I wish that I could set the configurations of the hardware pins permanently.
Let me show you how I configured the pins in adb shell:

odroidm1:/ # echo 120 > /sys/class/gpio/export
odroidm1:/ # echo "in" > /sys/class/gpio/gpio120/direction
odroidm1:/ # echo 1 > /sys/class/gpio/gpio120/active_low

Hope I could explain the situation. Thanks
Are you going to use the buttons as key inputs like Up/Left/Right/Down and so on? Or are you willing to make to any keys other than keyboards and want to recognise the keys in your app directly?

If you want to make them run as a keyboard or keypad, why don't you add a device tree for GPIO keypad? There is an example for ODROID-N2/C4, but can apply to ODROID-M1 as well after modifying some of them in the code.
https://wiki.odroid.com/common/applicat ... s[]=keypad
Also there is another thread similar,
viewtopic.php?f=180&t=45095&start=50

If you wiling to use the buttons not like a keyboard, you can use Android Things and can identify each buttons in your application.
viewtopic.php?f=178&t=37101
These users thanked the author tobetter for the post:
manas7891 (Fri May 10, 2024 1:32 pm)

Luke.go
Posts: 838
Joined: Mon May 30, 2016 1:55 pm
languages_spoken: english
Has thanked: 160 times
Been thanked: 145 times
Contact:

Re: GPIO Configuration on booting

Post by Luke.go »

I think this example help you. https://github.com/odroidThings/contrib ... utton.java

You can use the Button class or apply this method to your apps. :)
Or customize it a little to fit your request.
These users thanked the author Luke.go for the post:
manas7891 (Fri May 10, 2024 2:47 pm)

manas7891
Posts: 46
Joined: Thu Dec 28, 2023 5:14 pm
languages_spoken: english
ODROIDs: Odroid M1
Has thanked: 22 times
Been thanked: 1 time
Contact:

Re: GPIO Configuration on booting

Post by manas7891 »

tobetter wrote:
Fri May 10, 2024 10:53 am
manas7891 wrote:
Fri May 10, 2024 10:40 am
May be i need to explain what is my requirement;
1. I am developing an app in android, on my Odrdoid M1 Device. The android Version is 11
2. I want to configure the hardware buttons (Using GPIO)
3. I am using the pins as stated before
4. to configure the pins as input pins, I first initialized using ADB
5. I got some success, but when I restart the device, the configuration gets reset and for that I need to initialize the GPIO pins again, which is not a feasible process.
6. I wish that I could set the configurations of the hardware pins permanently.
Let me show you how I configured the pins in adb shell:

odroidm1:/ # echo 120 > /sys/class/gpio/export
odroidm1:/ # echo "in" > /sys/class/gpio/gpio120/direction
odroidm1:/ # echo 1 > /sys/class/gpio/gpio120/active_low

Hope I could explain the situation. Thanks
Are you going to use the buttons as key inputs like Up/Left/Right/Down and so on? Or are you willing to make to any keys other than keyboards and want to recognise the keys in your app directly?

If you want to make them run as a keyboard or keypad, why don't you add a device tree for GPIO keypad? There is an example for ODROID-N2/C4, but can apply to ODROID-M1 as well after modifying some of them in the code.
https://wiki.odroid.com/common/applicat ... s[]=keypad
Also there is another thread similar,
viewtopic.php?f=180&t=45095&start=50

If you wiling to use the buttons not like a keyboard, you can use Android Things and can identify each buttons in your application.
viewtopic.php?f=178&t=37101
Thank you for your reply and suggestions. I will try the solutions you have provided. I want to use them as dedicated keys for my app. They have nothing to do with other apps. Since, I am using the Odroid device for specific app development. So I will be trying Android of things as suggested.

User avatar
tobetter
Posts: 13216
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 1014 times
Been thanked: 2301 times
Contact:

Re: GPIO Configuration on booting

Post by tobetter »

manas7891 wrote:
Fri May 10, 2024 1:44 pm
tobetter wrote:
Fri May 10, 2024 10:53 am
Are you going to use the buttons as key inputs like Up/Left/Right/Down and so on? Or are you willing to make to any keys other than keyboards and want to recognise the keys in your app directly?

If you want to make them run as a keyboard or keypad, why don't you add a device tree for GPIO keypad? There is an example for ODROID-N2/C4, but can apply to ODROID-M1 as well after modifying some of them in the code.
https://wiki.odroid.com/common/applicat ... s[]=keypad
Also there is another thread similar,
viewtopic.php?f=180&t=45095&start=50

If you wiling to use the buttons not like a keyboard, you can use Android Things and can identify each buttons in your application.
viewtopic.php?f=178&t=37101
Thank you for your reply and suggestions. I will try the solutions you have provided. I want to use them as dedicated keys for my app. They have nothing to do with other apps. Since, I am using the Odroid device for specific app development. So I will be trying Android of things as suggested.
Sure, @Luke.go is the most expert about AndroidThings for ODROID. So please refer to the code that is provided by him to use class Button and please keep posting your questions here then you will have more supports. Using the class Button will let you allow the buttons in your application only.
These users thanked the author tobetter for the post:
manas7891 (Fri May 10, 2024 2:48 pm)

Post Reply

Return to “Android”

Who is online

Users browsing this forum: No registered users and 1 guest