changed from a normal RGB led to neopixel ws2812b

py3
Gunstick 2015-05-02 01:58:10 +02:00
parent 06f1e1ae6a
commit d2c4ef06a6
4 changed files with 114 additions and 70 deletions

View File

@ -4,15 +4,21 @@ the button has an RGB led to show status
how to install how to install
============== ==============
# login as user pi
sudo apt-get install unclutter xdotool git-core screen imagemagick
cd ~
git clone https://github.com/syn2cat/doorbuzz.git
put into /etc/rc.local the following line: put into /etc/rc.local the following line:
su pi -c '/home/pi/buzzctrl.sh' & su pi -c '/home/pi/doorbuzz/buzzctrl.sh' &
sudo vi /etc/xdg/lxsession/LXDE/autostart sudo vi /etc/xdg/lxsession/LXDE/autostart
remove screensaver remove screensaver
sudo apt-get install unclutter xdotool git-core screen imagemagick cd ~
git clone git://git.drogon.net/wiringPi git clone git://git.drogon.net/wiringPi
cd wiringPi cd wiringPi
./build ./build
cd ~
mkdir -p /home/pi/.config/lxsession/LXDE/ mkdir -p /home/pi/.config/lxsession/LXDE/
cat > /home/pi/.config/lxsession/LXDE/autostart <<"EOF" cat > /home/pi/.config/lxsession/LXDE/autostart <<"EOF"
@ -20,9 +26,18 @@ cat > /home/pi/.config/lxsession/LXDE/autostart <<"EOF"
@xset -dpms @xset -dpms
@xset s noblank @xset s noblank
@unclutter -display :0 -noevents -grab @unclutter -display :0 -noevents -grab
@./videoplayer.sh @./doorbuzz/videoplayer.sh
EOF EOF
https://learn.adafruit.com/neopixels-on-raspberry-pi/software
sudo apt-get install build-essential python-dev git scons swig
git clone https://github.com/jgarff/rpi_ws281x.git
cd rpi_ws281x
scons
cd python
sudo python setup.py install
cd doorbuzz
connect the button and LED to pins as shown in buzzctrl.sh connect the button and LED to pins as shown in buzzctrl.sh
create a file "secret.txt" containing the http://user:pass@10.1.1.xx part of the URL create a file "secret.txt" containing the http://user:pass@10.1.1.xx part of the URL

View File

@ -1,57 +1,38 @@
#!/bin/bash #!/bin/bash
# led is not neopixel, so use the python lib for that
BUTTONPIN=25 BUTTONPIN=25
REDLEDPIN=23 SHOWLEDPRG="sudo python /home/pi/doorbuzz/setneocolor.py"
GREENLEDPIN=18
BLUELEDPIN=24
BUZZERURL="$(cat "$(dirname "$0")"/secret.txt)/state.xml?relay1State=2&pulseTime1=5" BUZZERURL="$(cat "$(dirname "$0")"/secret.txt)/state.xml?relay1State=2&pulseTime1=5"
BUZZERSTATUSURL="$(cat "$(dirname "$0")"/secret.txt)/state.xml" BUZZERSTATUSURL="$(cat "$(dirname "$0")"/secret.txt)/state.xml"
ATTENUATION=4
# file secret.txt should contain username:password # file secret.txt should contain username:password
# install by putting into /etc/rc.local # install by putting into /etc/rc.local
# su pi -c '/home/pi/buzzctrl.sh' & # su pi -c '/home/pi/doorbuzz/buzzctrl.sh' &
echo "Initializing hardware" echo "Initializing hardware"
# the button # the button
gpio -g mode $BUTTONPIN up gpio -g mode $BUTTONPIN up
gpio -g mode $BUTTONPIN in gpio -g mode $BUTTONPIN in
# R
gpio -g mode $REDLEDPIN out
# G
gpio -g mode $GREENLEDPIN out
# B
gpio -g mode $BLUELEDPIN out
pulseon() { pulseon() {
pin=$1 red=$1
value=0 green=$2
valueinc=64 blue=$3
gpio -g mode $pin pwm $SHOWLEDPRG pulse $((red/ATTENUATION)) $((green/ATTENUATION)) $((blue/ATTENUATION)) </dev/null >/dev/null 2>&1 &
while true echo $!
do
gpio -g pwm $pin $value
value=$((value+valueinc))
if [ $value -gt 1023 ] || [ $value -lt 0 ]
then
valueinc=$((0-valueinc))
value=$((value+valueinc))
fi
sleep 0.2
done
} }
pulseoff() { pulseoff() {
pin=$1 if [ $(ps -edf | grep pulse | grep "$1"|wc -l) -gt 0 ]
kill $2 then
gpio -g mode $pin out sudo kill "$1"
gpio -g write $pin 0 fi
} }
ledcolor() { ledcolor() {
red=$1 red=$1
green=$2 green=$2
blue=$3 blue=$3
gpio -g write $REDLEDPIN $red $SHOWLEDPRG set $((red/ATTENUATION)) $((green/ATTENUATION)) $((blue/ATTENUATION))
gpio -g write $GREENLEDPIN $green
gpio -g write $BLUELEDPIN $blue
} }
declare -a morse declare -a morse
morse[0]="-----" morse[0]="-----"
@ -69,68 +50,54 @@ morseled() {
echo $message echo $message
msglen=${#message} msglen=${#message}
pos=0 pos=0
morsecode=""
while [ $pos -lt $msglen ] while [ $pos -lt $msglen ]
do do
morsecode=${morse[${message:${pos}:1}]} morsecode="$morsecode ${morse[${message:${pos}:1}]}"
pos=$((pos+1)) pos=$((pos+1))
echo $morsecode echo $morsecode
morselen=${#morsecode}
morsepos=0
while [ $morsepos -lt $morselen ]
do
ledcolor $2 $3 $4
#echo "c($morsepos)=${morsecode:${morsepos}:1}"
if [ "${morsecode:${morsepos}:1}" = "." ]
then
#echo "."
sleep 0.1
else
#echo "-"
sleep 0.2
fi
ledcolor 0 0 0
sleep 0.1
morsepos=$((morsepos+1))
done
sleep 0.2
echo
done done
red=$2
green=$3
blue=$4
$SHOWLEDPRG morse $((red/ATTENUATION)) $((green/ATTENUATION)) $((blue/ATTENUATION)) "$morsecode"
echo
} }
echo "morsing IP" echo "morsing IP"
ledcolor 1 1 1 ledcolor 255 255 255
sleep 3 sleep 3
ledcolor 0 0 0 ledcolor 0 0 0
sleep 1 sleep 1
morseled "$(hostname -I|awk -F. '{sub(" ","",$NF);printf $NF}')" 1 0 0 morseled "$(hostname -I|awk -F. '{sub(" ","",$NF);printf $NF}')" 255 0 0
ledcolor 1 1 1 ledcolor 255 255 255
sleep 1 sleep 1
echo "Main loop" echo "Main loop"
while true while true
do do
ledcolor 0 1 1 ledcolor 0 255 255
pulseon $GREENLEDPIN & pulsepid=$(pulseon 0 0 255 )
pulsepid=$! trap "pulseoff $pulsepid;ledcolor 0 0 0;exit" 1 2 3
trap "pulseoff $GREENLEDPIN $pulsepid;ledcolor 0 0 0;exit" 1 2 3
gpio -g wfi $BUTTONPIN falling gpio -g wfi $BUTTONPIN falling
while [ $(gpio -g read $BUTTONPIN) != 0 ] while [ $(gpio -g read $BUTTONPIN) != 0 ]
do do
gpio -g wfi $BUTTONPIN falling gpio -g wfi $BUTTONPIN falling
done done
pulseoff $GREENLEDPIN $pulsepid pulseoff $pulsepid
ledcolor 0 1 1 ledcolor 0 255 255
echo "Pushiii" echo "Pushiii"
wget -O - -S --timeout=1 --tries=1 "$BUZZERURL" 2>&1 wget -O - -S --timeout=1 --tries=1 "$BUZZERURL" 2>&1
ret=$? ret=$?
if [ $ret -ne 0 ] if [ $ret -ne 0 ]
then then
morseled "$ret" 1 0 0 morseled "$ret" 255 0 0
else else
while wget -O - --timeout=1 --tries=1 $BUZZERSTATUSURL|grep '<relay1state>1</relay1state>' while wget -O - --timeout=1 --tries=1 $BUZZERSTATUSURL|grep '<relay1state>1</relay1state>'
do do
ledcolor 0 1 0 ledcolor 0 255 0
sleep 0.9 sleep 0.9
ledcolor 0 1 1 ledcolor 0 255 255
sleep 0.1 sleep 0.1
done done
fi fi

62
setneocolor.py Executable file
View File

@ -0,0 +1,62 @@
#!/usr/bin/python
# sets color of first neo pixel
from __future__ import division
import time
import sys
from math import *
from neopixel import *
# LED strip configuration:
LED_COUNT = 1 # Number of LED pixels.
LED_PIN = 18 # GPIO pin connected to the pixels (must support PWM!).
LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz)
LED_DMA = 5 # DMA channel to use for generating signal (try 5)
LED_BRIGHTNESS = 100 # Set to 0 for darkest and 255 for brightest
LED_INVERT = False # True to invert the signal (when using NPN transistor level shift)
# Main program logic follows:
if __name__ == '__main__':
# Create NeoPixel object with appropriate configuration.
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS)
# Intialize the library (must be called once before other functions).
strip.begin()
r=int(sys.argv[2])
g=int(sys.argv[3])
b=int(sys.argv[4])
if(sys.argv[1] == "set"):
print "Color set to: ",r,g,b
strip.setPixelColor(0, Color(r,g,b))
strip.show()
if(sys.argv[1] == "morse"):
print "Morsing with: ",r,g,b
speed=10
morsecode=sys.argv[5]
for c in morsecode:
if c==".":
strip.setPixelColor(0, Color(r,g,b))
strip.show()
time.sleep(0.2)
strip.setPixelColor(0, Color(0,0,0))
strip.show()
time.sleep(0.2)
if c=="-":
strip.setPixelColor(0, Color(r,g,b))
strip.show()
time.sleep(0.7)
strip.setPixelColor(0, Color(0,0,0))
strip.show()
time.sleep(0.2)
if c==" ":
strip.setPixelColor(0, Color(0,0,0))
strip.show()
time.sleep(1)
if(sys.argv[1] == "pulse"):
print "Pulsing with: ",r,g,b
pulsewidth=50
while True:
for i in range(pulsewidth):
trigo=sin(i/pulsewidth*pi)
strip.setPixelColor(0, Color(int(r*trigo),int(g*trigo),int(b*trigo)))
strip.show()
time.sleep(50/1000.0)

View File

@ -13,7 +13,7 @@ do
then # test on false, so in case of network fail, it defaults to playing then # test on false, so in case of network fail, it defaults to playing
sleep 60 sleep 60
else else
ls *mp4 | ls ~/*mp4 |
while read video while read video
do do
omxplayer "$video" </dev/null omxplayer "$video" </dev/null