Jump to content

Recommended Posts

Posted

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

9968480900_1577182384_thumb.jpg

Thanks in advance.

:)

 

 

 

Posted
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

 

Posted

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?

 

 

Snap69.jpg

Posted
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)

Posted

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

 

Snap70.jpg

Posted
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...

Posted

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 ?

 

 

Snap72.jpg

Posted

Hello

thank`s for reply

Looks not work.

pls check screen below

echo 37 > /sys/class/gpio/unexport

 

 

obraz.png

Posted
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 ...

Posted

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

 

Snap69.jpg

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines