OdroidC1 - change pin state at startup and shutdown [SOLVED]

Moderators: odroid, mdrjr

OdroidC1 - change pin state at startup and shutdown [SOLVED]

Unread postby sbigler » Mon Mar 26, 2018 11:03 pm

Dear Sir,
On my Odroid-C1, I would like to set pin <gpiox.109> to level high when starting up (the soonest as possible). And set this same pin to low level at the end of the shutting down process (the latest).

The following three commands work perfectly from terminal:
gpio mode 13 out
gpio write 13 1
gpio write 13 0

I think the best way is to create 2 short bash scripts containing the needed commands.
But I am confused about where to save those 2 scripts to make sure they run at startup and when shutting down. Also how to invoke them?

Would anyone give me some hints about it?
Thx in advance for helping,
Stephane
Last edited by sbigler on Wed Mar 28, 2018 4:41 pm, edited 1 time in total.
sbigler
 
Posts: 34
Joined: Thu Jul 31, 2014 10:53 pm
languages_spoken: english
ODROIDs: odroid-u3 / odroid-c1 / odroid-c1+

Re: Odroid C1 - change pin state at startup and shutdown

Unread postby odroid » Tue Mar 27, 2018 9:58 am

Add the commands in "/etc/rc.local" and let me know the result.
The commands should be placed on just before "exit 0".
User avatar
odroid
Site Admin
 
Posts: 29098
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID

Re: Odroid C1 - change pin state at startup and shutdown

Unread postby sbigler » Tue Mar 27, 2018 4:04 pm

Thx Odroid,

Your solution works well when booting. I added the following in /etc/rc.local to have a nice HIGH level on desired pin:
Code: Select all
/usr/local/bin/gpio mode 13 out
/usr/local/bin/gpio write 13 1



Any idea on what script should be edited in order to run the following command at the end of shutting down process?
Code: Select all
/usr/local/bin/gpio write 13 0


Thx,
Stephane
sbigler
 
Posts: 34
Joined: Thu Jul 31, 2014 10:53 pm
languages_spoken: english
ODROIDs: odroid-u3 / odroid-c1 / odroid-c1+

Re: Odroid C1 - change pin state at startup and shutdown

Unread postby odroid » Tue Mar 27, 2018 4:57 pm

How do you shutdown the system normally?
Do you run "poweroff" command on the terminal?
Or press the Power icon on the Mate Desktop?
User avatar
odroid
Site Admin
 
Posts: 29098
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID

Re: Odroid C1 - change pin state at startup and shutdown

Unread postby sbigler » Tue Mar 27, 2018 5:00 pm

I press power icon on low right corner of desktop.

But I insist on the fact that I need the pin staying high level to the latest. I mean the pin should be set low level at the very end of the shutdown process.
sbigler
 
Posts: 34
Joined: Thu Jul 31, 2014 10:53 pm
languages_spoken: english
ODROIDs: odroid-u3 / odroid-c1 / odroid-c1+

Re: Odroid C1 - change pin state at startup and shutdown

Unread postby meveric » Tue Mar 27, 2018 5:22 pm

in the past you could simply put a script under /etc/init.d/ that has a start and a stop commad
update-rc.d created symlinks for booting and shutdown of the system.
While this should still work now systemd is more widely used.
You'll find similar files under /etc/systemd/system the service files here have a ExecStart and ExecStop entries which allow you to run different scripts for starting and stopping as well.
Donate to support my work on the ODROID GameStation Turbo Image for U2/U3 XU3/XU4 X2 X C1 as well as many other releases.
Check out the Games and Emulators section to find some of my work or check the files in my repository to find the software i build for ODROIDs.
If you want to add my repository to your image read my HOWTO integrate my repo into your image.
User avatar
meveric
 
Posts: 9448
Joined: Mon Feb 25, 2013 2:41 pm
languages_spoken: german, english
ODROIDs: X2, U2, U3, XU-Lite, XU3, XU3-Lite, C1, XU4, C2, C1+, XU4Q, HC1, N1, Go

Re: Odroid C1 - change pin state at startup and shutdown

Unread postby sbigler » Tue Mar 27, 2018 5:50 pm

ok, thx. I will investigate systemd and come back.
sbigler
 
Posts: 34
Joined: Thu Jul 31, 2014 10:53 pm
languages_spoken: english
ODROIDs: odroid-u3 / odroid-c1 / odroid-c1+

Re: Odroid C1 - change pin state at startup and shutdown

Unread postby sbigler » Wed Mar 28, 2018 4:37 pm

Apparently systemd is not running on 14.04. So I changed my mind and successfully used init.d and run levels ;)

Here is the step by step procedure to run myscript at shutdown in case someone else is interested:

    - create the script /etc/init.d/myscript to be run at shutdown (for reminder I just wanna set output #13 to low level):
    Code: Select all
    #!/bin/bash
    /usr/local/bin/gpio write 13 0
    exit 0

    - make it executable:
    Code: Select all
    chmod + x /etc/init.d/myscript

    - make the symbolic link to the right run level (rc0.d) by using the command update-rc.d (do not forget the dot at the end...):
    Code: Select all
    update-rc.d myscript start 19 0 .

    - check the new link:
    Code: Select all
    ll /etc/rc0.d/myscript
    lrwxrwxrwx 1 root root 19 Mar /etc/rc0.d/S19myscript -> ../init.d/myscript


tada :D
sbigler
 
Posts: 34
Joined: Thu Jul 31, 2014 10:53 pm
languages_spoken: english
ODROIDs: odroid-u3 / odroid-c1 / odroid-c1+

Re: OdroidC1 - change pin state at startup and shutdown [SOL

Unread postby odroid » Wed Mar 28, 2018 9:23 pm

Good to hear your found a good solution. :)
Thank you for sharing the solution.
User avatar
odroid
Site Admin
 
Posts: 29098
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID


Return to General Chat

Who is online

Users browsing this forum: No registered users and 2 guests