07-06-2017, 03:41 AM
(This post was last modified: 07-07-2017, 02:03 AM by MarkHaysHarris777.)
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
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! )
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! )