GPIO LED blinker using SYSFS on the Rock64
#1
   

In the above pic I'm blinking an LED at physical pin(16) of the Rock64, GPIO3_A5, on the PI-2 bus;

... to use the sysfs method of setting the pin on|off one must first calculate the gpio# using the following:

( bank_num  * 32 )  + ( pad_name * 8 ) + pad_num

where pad names = {A:0, B:1, C:2, D:3}

In the above example the bank_num is 3 , pad_name is 0*8,  and the pad_num is 5 ,  so:
 ( 3 * 32 ) + ( 0 * 8 ) + 5  =  101

The following steps are used to set the gpio pin on|off:

1) sudo -i
2) echo 101 > /sys/class/gpio/export
3) echo out > /sys/class/gpio/gpio101/direction
4) echo 1 > /sys/class/gpio/gpio101/value          <--ON
5) echo 0 > /sys/class/gpio/gpio101/value          <--OFF

The following codes will blink gpio101 at pin(16), GPIO3_A5:  blinker.sh and sysled.sh are closely related scripts. The former is a controlled loop, and the latter is a forever running loop;  both are useful. Compare the two script and notice that they are almost identical.

blinker.sh

Code:
#!/bin/sh

echo $1 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio$1/direction

COUNTER=0
while [ $COUNTER -lt $2 ]; do
   echo 1 > /sys/class/gpio/gpio$1/value
   sleep .35
   echo 0 > /sys/class/gpio/gpio$1/value
   sleep .65
   COUNTER=$(($COUNTER+1))
done

echo $1 > /sys/class/gpio/unexport

To run blinker enter two parameters;  the first the gpio#, and the second the number of times you want it to blink!

sudo  ./blinker.sh  101  7

(will blink gpio101 seven times)


sysled.sh

Code:
#!/bin/sh

echo $1  > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio$1/direction

COUNTER=0
while [ $COUNTER -lt 10 ]; do
   echo 1 > /sys/class/gpio/gpio$1/value
   sleep .35
   echo 0 > /sys/class/gpio/gpio$1/value
   sleep .65
done


To run sysled: 

sudo  -b  ./sysled.sh  101

(will strobe gpio101 forever)

( remember to cd into the working directory where you place the script   )
( also, don't forget to make the script executable: chmod 0754 sysled.sh )

   

In the pic above I have attached the grey wire at ground pin(14),  and the orange wire at pin(16).

The anode of the LED is attached at the orange wire, and the cathode of the LED is attached to the grey wire through the ballast resistor , which is 330 ohms. The LED is a low power (5-7ma) 3mm standard LED.

I have so far tested the blue pins ( see chart ) and the green pins.  DO NOT use the blue pins if you're using the micro SD card !  If you're booting from the eMMC module (as I am) then the blue pins and most of the green pins are available to you;
marcushh777    Cool

please join us for a chat @  irc.pine64.xyz:6667   or ssl  irc.pine64.xyz:6697

( I regret that I am not able to respond to personal messages;  let's meet on irc! )


Messages In This Thread
GPIO LED blinker using SYSFS on the Rock64 - by MarkHaysHarris777 - 07-06-2017, 03:41 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Rock64 No Audio @ Debian 12 dmitrymyadzelets 2 290 04-08-2024, 06:47 AM
Last Post: dmitrymyadzelets
  OpenWRT on the Rock64 CanadianBacon 14 8,364 04-03-2024, 08:48 AM
Last Post: helpmerock
  Rock64 bricked shawwwn 7 5,703 03-17-2024, 12:22 PM
Last Post: dmitrymyadzelets
  Rock64 won't boot luminosity7 10 4,165 03-16-2024, 08:33 AM
Last Post: dmitrymyadzelets
  Rock64 doesn't boot dstallmo 1 337 03-16-2024, 08:29 AM
Last Post: dmitrymyadzelets
  How well does Rock64 deal with HDR and Atmos on Kodi? drvlikhell 3 1,897 04-29-2023, 04:24 AM
Last Post: newestssd
  Rock64 board not working, no HDMI no Ethernet. EDited 3 3,539 01-17-2023, 02:31 PM
Last Post: Flagtrax
  ROCK64 v3 can it boot from USB? Tsagualsa 4 2,117 11-29-2022, 11:31 AM
Last Post: Macgyver
  rock64 v3 spiflash Macgyver 0 763 11-28-2022, 02:18 PM
Last Post: Macgyver
  my rock64 dosen't work rookie_267 0 960 10-07-2022, 07:50 PM
Last Post: rookie_267

Forum Jump:


Users browsing this thread: 2 Guest(s)