Brenton just shared a new content in Guides > Guides: "GlowBit Stick 1x8 - Python and MicroPython Guide"
Read more
HI. I have a project where I need two Glowbit strips (or possible glowbit ,matrix) and I want to control the strips separately, possibly different colours, different led selections, etc. I read on the document and looked at the tutorial and wasnât totally clear. I have both a Raspberry pi 4 and a Raspberry pi zero. On these do I use either GPIO18 or GPIO12? Can I use any other pins if I wanted to control more devices?
Thanks
Hi John,
Our Glowbit gear can be chained together just like the individual WS2812s can!
Youâd only need one IO pin if you were to chain together modules Dout
to Din
Let us know if you have any more questions
-James
Thanks. If I chain them together can I still individually address the LEDs on each of the Glowbit strips so, for example I could set the first strip to all green and the second strip to all read, then change just the colour of Leds on the second strip?
Hi John,
Thatâs correct. Itâd appear as one long strip so-to-speak, so you can address any of the LEDs individually
-James
Many thanks for the quick responses. I have ordered some devices to play with.
Furthering this discussion as i dont see anywhere else suitable. I purchased a bunch of these glowbit sticks. Using the end pads and cable in between each glowstick, i connected them up, but only the first stick worked. I am using on arduino via an esp32, the sketch set for 16 leds. No matter how i try and configure, i just cant get the daisy chaining to work. Any ideas please?
Hi Martin, Welcome to the forum!
Could you post a photo of how youâve got everything hooked up, with a focus on the connections between the sticks?
Could you also post the code that youâre using? Three backticks (```) either side of your code will format it properly on our forum.
Weâll take a look and hopefully get you back on track!
-James
Please see the attached photo of 2x glowbit sticks wire together.
I previously tried this with another brand stick but could only ever get the first stick working, hence changing to the glowbit sticks. I can change the the sticks around and still only the first one works.
This is the sketch i use.
//Library needs to be included
#include "Adafruit_NeoPixel.h"
// Set the pin that is connected to the D0 on the Neopixel string
#define PIN 4
// change to the number of neopixels in your string
#define NUMPIXELS 16//
// see Adafruit strandtest example for more information on possible values.
//sets up an Object called "pixels" that our instructions will be sent to
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(9600);
Serial.println("NeoPixel_MultiColourFadeInOutTwinklev1");
//This line starts by initialising "pixels"
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
//now set various values starting at 0 to 15 for a 16 pixel string
//Used as a test to make sure connection is correct.
pixels.setPixelColor(0, pixels.Color(0, 50, 0));//green
pixels.setPixelColor(1, pixels.Color(50, 0, 0)); //red
pixels.setPixelColor(2, pixels.Color(15, 50, 50)); //Blue
pixels.setPixelColor(3, pixels.Color(50, 50, 25)); //yellow
pixels.setPixelColor(4, pixels.Color(100, 100, 100));//white
pixels.setPixelColor(5, pixels.Color(50, 0, 50));//purple
pixels.setPixelColor(6, pixels.Color(50, 25, 25)); //pink
pixels.setPixelColor(7, pixels.Color(255, 255, 255)); //bright white
//Nothing changes until this line is sent
pixels.show(); // Send the updated pixel colors to the hardware.
delay(3000);//wait 3 seconds before starting the show
//prepare for system
pixels.clear(); // Set all pixel colors to 'off'
pixels.show();
}
unsigned long myNeoTimers[16];//array that holds millis() timer info for each neopixel
//Multi dimensional Array to hold all the data for the system
//see http://www.digitaltown.co.uk/lesson11Arrays.php for tutorial
//[lightState][lightDir][R][G][B],
//[lightState] 0-255 0 = off, 255 fully lit; controls the current brightness state...increasing or decreasing
//[lightDir] 0 = decreasing, 1 = increasing tells system if the light is increasing or decreasing
//[R][G][B] = the target RGB state
int myNeoSettings[16][5];
//const variables to make the code more readable when dealing with the array
const int lightState = 0;
const int lightDir = 1;
const int myRed = 2;
const int myGreen = 3;
const int myBlue = 4;
void loop() {
int q;
for (q = 0; q <8; q++) {
if (millis() > myNeoTimers[q]) {
if(myNeoSettings[q][0] < 0){//light is out so ready to start a new cycle
//first select a colour for this neopixel
//this gives a white/yellow/blue effect
//add extra case statements and increase random max to add more fixed colours
switch(random(4)){
case 1://Yellow
myNeoSettings[q][myRed] = 50;
myNeoSettings[q][myGreen] = 50;
myNeoSettings[q][myBlue] = 25;
break;
case 2://Blue
myNeoSettings[q][myRed] = 15;
myNeoSettings[q][myGreen] = 50;
myNeoSettings[q][myBlue] = 50;
break;
case 3://Pink
myNeoSettings[q][myRed] = 50;
myNeoSettings[q][myGreen] = 25;
myNeoSettings[q][myBlue] = 25;
break;
default://white
myNeoSettings[q][myRed] = 100;
myNeoSettings[q][myGreen] = 100;
myNeoSettings[q][myBlue] = 100;
break;
}
//This will select random colours
/*
myNeoSettings[q][myRed] = random(256);
myNeoSettings[q][myGreen] = random(256);
myNeoSettings[q][myBlue] = random(256);
*/
myNeoSettings[q][lightDir] = 1;//as light is out we want it to increase in brightness
myNeoSettings[q][lightState] = 1;//give the light a brightness value
}
if(myNeoSettings[q][0] == 256){//light maxxed so needs to start to turn off
myNeoSettings[q][lightDir] = 0; //tell system this pixel will be getting dimmer
myNeoSettings[q][lightState] = 255;//give the light a brightness value
}
//this section deals with setting the led brightness value and resetting the millis timer
//get the correct values for the RGB and set the neopixel to is.
pixels.setPixelColor(q, colourState(myNeoSettings[q][myRed],myNeoSettings[q][lightState]), colourState(myNeoSettings[q][myGreen],myNeoSettings[q][lightState]), colourState(myNeoSettings[q][myBlue],myNeoSettings[q][lightState]));
pixels.show();
//increase or decrease the lightState depending if getting brighte or dimmer.
if(myNeoSettings[q][lightDir] > 0){//getting brighter
myNeoSettings[q][lightState]++;
}else{//dimming
myNeoSettings[q][lightState]--;
}
if(myNeoSettings[q][lightState] < 0 || myNeoSettings[q][lightState] > 255){
//at max state so longer value
myNeoTimers[q] = millis() + random(200, 1500);//0.2 - 4 seconds
}else{//increasing or decreasing in value so short value
myNeoTimers[q] = millis() + random(20);//0 - 20 milliseconds
}
}
}
}
//this function works out what the individual RGB values should be depending on what stage it is in dimming/lighting
int colourState(int pixelMax,int pixelBrightness){
int returnBrightness;
//to keep values positive
returnBrightness = pixelMax * 100;
//because the value is stored as an int anything beynd the decimal point will be automatically removed.
//see http://www.digitaltown.co.uk/lesson6bitsandbytes.php for more info.
returnBrightness = (returnBrightness/255) * pixelBrightness;
returnBrightness = returnBrightness/100;
return returnBrightness;
}
Hi @Martin203062 - it looks like your loops are stopping at 8, eg the first for-loop in your main loop()
is defined as follows and contains the âmagic-numberâ 8:
for (q = 0; q <8; q++) {
// your loop code...
}
This will only set colours for the first 8 LEDs in the strip, no matter how long the strip is.
Perhaps try changing it to the following, where NUM_PIXELS
has already been defined as 16
for (q = 0; q < NUMPIXELS ; q++) {
// your loop code...
}
Now, no matter how long your strip is defined, the loop will always set every LED.
Thanks Michael, i will try that.
@Martin203062 Itâs alive!
Happy making!
@johnr As a second style of response to your initial question, you should be able to control separate Glowbit sticks if you initialise them as
stick1 = glowbit.stick()
stick2 =glowbit.stick(pin = 19)
This should make stick1 and stick2 separately controllable, given that you connect the Din pin for stick1 to GPIO18 and stick2 to GPIO19. Then just issue appropriate commands to stick1 and/or stick2 appropriately.
This is the background plan for a project I am building, where there will be Glowbit sticks on 18, a neopixel string on 19 and some 3watt RGB Leds (neopixel style) on 20 âŚ
ArrrgH!
And trying that code style doesnt seem to work âŚ
with the second line commented out - stick1 works
import glowbit
stick1 = glowbit.stick()
# stick2 = glowbit.stick(pin = 19)
but with both lines active
import glowbit
stick1 = glowbit.stick()
stick2 = glowbit.stick(pin = 19)
stick1 fails to operate - but stick2 works fine âŚ
There seems to be something within the glowbit library that allows the âcreationâ of only one glowbit object at a time.
Note: trying this sort of in isolation as i only have one off stick connected to pin18
Any one got some guidance ?? Otherwise I am in for a bunch of fuggly programming to keep Sticks and neopixel string logically separated
Hi Murray,
Which platform are you using the GlowBIt library on? On the Raspberry Pi Pico the data signals are generated with a PIO state machine and only one GlowBit object can use a given state machine.
Thankfully the Pico contains 8 state machines, the âsm=â keyword argument can be used to specify which state machine to use, with number 0 being used by default.
Try:
stick1 = glowbit.stick()
stick2 = glowbit.stick(pin = 19, sm=1)
AHAH!
And the solution appears to be setting the Pico statemachine number into the initialisation call
import glowbit
stick1 = glowbit.stick() # uses default pin=18, sm=0
stick2 = glowbit.stick(pin=19, sm=1) # use another pin and state machine !!!
stick1 runs as expected ,and waiting for additional sticks etc to finally âproveâ the code.
Sorta makes sense when you think about what one is expecting the Pico to do âŚ
Hi @Brenton - thanks, I think we collided with our answers. The penny dropped when I looked into the glowbit.py library and saw the default sm=0 parameter
Hi Brenton.
i have a RP2040 with the waveshare 10DOF IMU and some 1x8 glowbits.
i want to make a roll/pitch indicator with a 1x8 stick for roll and a 1x8 stick for pitch.
i have started by using the glowbit library/module and upython. i have used the graph1d function to get the positive pitch to work on 4 of the bits for the first 8degrees (ledâs 0-3 @ 2deg per led).
I want to use bits 0-3 for positive angle and bits 7-4 for negative angle.
i have looked at the ânewGraph1d()â to map the bit 7-4 as a separate graph but with my limited knowledge am no sure how to go about doing this. any hints?
oh this is quite cool - following along cause I finally got around to hooking these cuties up!
I also wanted to control 2 sticks individually or rather a little more precisely.
But had already jumped the gun and soldered them in a linear format (eg din out to inâŚ) doh!
So I thought this canât be too hardâŚIt must be able to be done in code and Iâm really pleased to say it is possible so popping this in in case anyone finds it useful:
stick = glowbit.stick(numLEDs=8)
stick2 =glowbit.stick(numLEDs=8)
#rainbow currently all
for index in range(8):
c = stick.wheel(36*index)
stick.pixelSet(index, c)
stick2.pixelSet(index, c)
stick.pixelsShow()
stick2.pixelsShow()```