djmcg Posted December 24, 2019 Posted December 24, 2019 Hello Ones again I`m would like to connect 1 LED to GPIO and make it blink . I try to find tutorial on Wen but for OPI Win it`s not work (duo to lack tutorial for this models) Could You help me wrote simple code to make LED start blinking? With program included in Armbian to steering GPIO for my OPI Thanks in advance.
martinayotte Posted December 24, 2019 Posted December 24, 2019 3 hours ago, djmcg said: Could You help me wrote simple code to make LED start blinking? Although some will say that way is almost deprecated, the simplest way is to use /sys/class/gpio ! Here is a small bash script that toggle the green LED of OPiWin which is on PH11/GPIO235 : #!/bin/bash echo 235 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio235/direction while true; do echo 0 > /sys/class/gpio/gpio235/value sleep 0.25 echo 1 > /sys/class/gpio/gpio235/value sleep 0.25 done 1
djmcg Posted December 24, 2019 Author Posted December 24, 2019 Could You advice how to run this script? I have desktop wersion. Should I paste those code to any program like "Geany" and run somehow?
martinayotte Posted December 24, 2019 Posted December 24, 2019 18 minutes ago, djmcg said: Could You advice how to run this script? Yes, you can use "geany" or any other editor, paste the above code, save it as something like "led-flash.sh", make it executable using "chmod a+rx led-flash.sh" and run it from a shell using "./led-flash.sh". (BTW, use the BCM numbers as the gpio numbers)
djmcg Posted December 24, 2019 Author Posted December 24, 2019 Hi I`m update the code #!/bin/bash echo 37 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio37/direction while true; do echo 0 > /sys/class/gpio/gpio37/value sleep 0.25 echo 1 > /sys/class/gpio/gpio37/value sleep 0.25 done But I have error from terminal
martinayotte Posted December 24, 2019 Posted December 24, 2019 8 minutes ago, djmcg said: I have error from terminal This error looks like you've saved the file as a DOS format with CRLF instead of Unix format with CR only, that why the error mentioned "^M" at the end of /bin/bash...
djmcg Posted December 24, 2019 Author Posted December 24, 2019 I use Pluma right now to save It works but occurred error and when I stop (Ctrl+C) from time to time led is shine (see screen sometime stop at 1 or 0 ) it`s any possible to clean it ?
martinayotte Posted December 24, 2019 Posted December 24, 2019 1 hour ago, djmcg said: it`s any possible to clean it ? Clean up can be done by doing "echo 37 > /sys/class/gpio/unexport".
djmcg Posted December 25, 2019 Author Posted December 25, 2019 Hello thank`s for reply Looks not work. pls check screen below echo 37 > /sys/class/gpio/unexport
martinayotte Posted December 25, 2019 Posted December 25, 2019 4 hours ago, djmcg said: Looks not work. Maybe some other apps has been using this gpio before running the script ? Check the output of "cat /sys/kernel/debug/gpio" ! Also, check if same strange behaviour occur after a reboot, doing export/unexport should be coherent ...
djmcg Posted December 25, 2019 Author Posted December 25, 2019 After reboot is fine. However I forgot mentioned I`m update script #!/bin/bash echo 37 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio37/direction echo 38 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio38/direction echo 39 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio39/direction echo 101 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio101/direction echo 36 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio36/direction while true; do #led1 echo 1 > /sys/class/gpio/gpio37/value sleep 0.25 echo 0 > /sys/class/gpio/gpio37/value sleep 0.01 #Led2 echo 1 > /sys/class/gpio/gpio38/value sleep 0.25 echo 0 > /sys/class/gpio/gpio38/value sleep 0.01 # led3 echo 1 > /sys/class/gpio/gpio39/value sleep 0.25 echo 0 > /sys/class/gpio/gpio39/value sleep 0.01 #led4 echo 1 > /sys/class/gpio/gpio101/value sleep 0.25 echo 0 > /sys/class/gpio/gpio101/value sleep 0.01 #led5 echo 1 > /sys/class/gpio/gpio36/value sleep 0.25 echo 0 > /sys/class/gpio/gpio36/value sleep 0.01 #led4 echo 1 > /sys/class/gpio/gpio101/value sleep 0.25 echo 0 > /sys/class/gpio/gpio101/value sleep 0.01 # led3 echo 1 > /sys/class/gpio/gpio39/value sleep 0.25 echo 0 > /sys/class/gpio/gpio39/value sleep 0.01 #Led2 echo 1 > /sys/class/gpio/gpio38/value sleep 0.25 echo 0 > /sys/class/gpio/gpio38/value sleep 0.01 done Those command works echo 0 > /sys/class/gpio/gpio37/value
Recommended Posts