Skip to content

Commit 87dea7e

Browse files
authored
neopixel ring test script - raspberry pi + arduino nano + usb connection
neopixel ring test script - raspberry pi + arduino nano + usb connection
1 parent 293d5bf commit 87dea7e

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#########################################
2+
# NeoPixel.py
3+
# more info @: http://myrobotlab.org/service/NeoPixel
4+
#########################################
5+
6+
#http://myrobotlab.org/service/NeoPixel
7+
#Submitted by calamity on Fri, 07/29/2016 - 15:39
8+
#The Neo Pixel are chainable, addressable leds hardware that can be controlled using only one signal wire.
9+
#The NeoPixel service allow you to connect and control an Neo Pixel hardware connected to an Arduino with MRL
10+
11+
#Setup:
12+
#The NeoPixel hardware can connect to any pins on the arduino board, including analog pins
13+
#Note: Neopicel hardware can draw a lot of power (60mA for each pixels at full brightness).
14+
#If you are running big NeoPixel hardware, you should power it with external power source instead of the Arduino.
15+
16+
17+
# virtual = True
18+
#port = "COM3"
19+
port = "/dev/ttyUSB0"
20+
# optional but recommended neopixel connected on a dedicated arduino
21+
rxtxPort = "Serial2"
22+
23+
# start optional virtual arduino service, used for internal test
24+
if ('virtual' in globals() and virtual):
25+
virtualArduino = Runtime.start("virtualArduino", "VirtualArduino")
26+
virtualArduino.connect(port)
27+
# end used for internal test
28+
29+
#Starting Arduino Service
30+
arduino = Runtime.start("arduino","Arduino")
31+
arduino.setBoardNano() #or setBoardMega() or arduino.setBoardUno() or .setBoardNano()
32+
arduino.connect(port)
33+
34+
#Starting NeoPixel Service
35+
neopixel = Runtime.start("neopixel","NeoPixel")
36+
neopixel.attach(arduino, 2, 24)
37+
38+
#neopixel.attach(arduino, pin, number of pixel)
39+
#if ('virtual' in globals() and virtual):
40+
# #Attach Neopixel to main arduino
41+
# neopixel.attach(arduino, 2, 24)
42+
#else:
43+
# #Starting optional RX/TX connected slave arduino and Attach Neopixel to slave arduino
44+
# arduinoNano = Runtime.start("arduinoNano","Arduino")
45+
# arduinoNano.setBoardNano() #or arduino.setBoardUno()
46+
# arduinoNano.connect(arduino,rxtxPort)
47+
# neopixel.attach(arduinoNano, 2, 24)
48+
49+
50+
#Animations;
51+
#"Color Wipe"
52+
#"Larson Scanner"
53+
#"Theater Chase"
54+
#"Theater Chase Rainbow"
55+
#"Rainbow"
56+
#"Rainbow Cycle"
57+
#"Flash Random"
58+
#"Ironman"
59+
60+
#speed: 1-65535 1=full speed, 2=2x slower than 1, 10=10x slower than 1
61+
#starting a animation
62+
#neopixel.setAnimation("Animation Name", red, green, blue, speed)
63+
#neopixel.setAnimation("Theater Chase", 255, 0, 0, 1) #running Theater Chase with color red at full speed
64+
65+
def lightupthering():
66+
neopixel.setAnimation("Theater Chase Rainbow", 0, 0, 255, 1) #running Theater Chase with color red at full speed
67+
sleep(10)
68+
neopixel.animationStop()
69+
neopixel.setAnimation("Color Wipe", 0, 0, 255, 1) #running Theater Chase with color red at full speed
70+
sleep(10)
71+
neopixel.animationStop()
72+
neopixel.setAnimation("Larson Scanner", 0, 0, 255, 1) #running Theater Chase with color red at full speed
73+
sleep(10)
74+
neopixel.animationStop()
75+
neopixel.setAnimation("Theater Chase", 0, 0, 255, 1) #running Theater Chase with color red at full speed
76+
sleep(10)
77+
neopixel.animationStop()
78+
neopixel.setAnimation("Rainbow", 0, 0, 255, 1) #running Theater Chase with color red at full speed
79+
sleep(10)
80+
neopixel.animationStop()
81+
neopixel.setAnimation("Rainbow Cycle", 0, 0, 255, 1) #running Theater Chase with color red at full speed
82+
sleep(10)
83+
neopixel.animationStop()
84+
neopixel.setAnimation("Flash Random", 0, 0, 255, 1) #running Theater Chase with color red at full speed
85+
sleep(10)
86+
neopixel.animationStop()
87+
neopixel.setAnimation("Ironman", 0, 0, 255, 1) #running Theater Chase with color red at full speed
88+
sleep(10)
89+
neopixel.animationStop()
90+
91+
#run an animation with python script
92+
#turn off all the pixels
93+
for pixel in range (1,neopixel.numPixel + 1):
94+
neopixel.setPixel(pixel, 0, 0, 0) #setPixel(pixel, red, green, blue)
95+
neopixel.writeMatrix() #send the pixel data to the Neopixel hardware
96+
97+
for loop in range(0,10): #do 10 loop
98+
for pixel in range(1, neopixel.numPixel +1):
99+
neopixel.setPixel(pixel, 255, 0, 0) #set the pixel to red
100+
neopixel.writeMatrix()
101+
sleep(0.03) #give a bit of delay before next step
102+
neopixel.setPixel(pixel, 0, 0, 0) #turn off the pixel
103+
neopixel.writeMatrix()
104+
105+
for pixel in range (1,neopixel.numPixel + 1):
106+
neopixel.setPixel(pixel, 0, 0, 0) #setPixel(pixel, red, green, blue)
107+
neopixel.writeMatrix() #send the pixel data to the Neopixel hardware
108+
109+
for loop in range(0,10): #do 10 loop
110+
for pixel in range(1, neopixel.numPixel +1):
111+
neopixel.setPixel(pixel, 0, 255, 0) #set the pixel to green
112+
neopixel.writeMatrix()
113+
sleep(0.03) #give a bit of delay before next step
114+
neopixel.setPixel(pixel, 0, 0, 0) #turn off the pixel
115+
neopixel.writeMatrix()
116+
117+
for pixel in range (1,neopixel.numPixel + 1):
118+
neopixel.setPixel(pixel, 0, 0, 0) #setPixel(pixel, red, green, blue)
119+
neopixel.writeMatrix() #send the pixel data to the Neopixel hardware
120+
121+
122+
for loop in range(0,10): #do 10 loop
123+
for pixel in range(1, neopixel.numPixel +1):
124+
neopixel.setPixel(pixel, 0, 0, 255) #set the pixel to blue
125+
neopixel.writeMatrix()
126+
sleep(0.03) #give a bit of delay before next step
127+
neopixel.setPixel(pixel, 0, 0, 0) #turn off the pixel
128+
neopixel.writeMatrix()
129+
130+
for loop in range(0,5):
131+
print ("loop "+str(loop))
132+
lightupthering()

0 commit comments

Comments
 (0)