1 1
djmcg

Orange PI Win - Blink LED -

Recommended Posts

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.

:)

 

 

 

Share this post


Link to post
Share on other sites
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

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Hello

thank`s for reply

Looks not work.

pls check screen below

echo 37 > /sys/class/gpio/unexport

 

 

obraz.png

Share this post


Link to post
Share on other sites
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 ...

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
1 1