60 LED ring does not respond

Hello :slight_smile:

I am desperate for help, so I can finally understand where my mistake is!

My project consists of an Arduino Uno board with a scale (HX711) and an LED ring with 60 LEDs 60 LED 172mm Ring - WS2812B 5050 RGB LED with Integrated Drivers (Adaf ‚ÄĒ Cool Components). The ring is attached to the top of a bowl which stands on a scale. Now, I want the LED ring to light up to map the current weight as part of the desired weight (e.g. if 100 of 200 grams are in the bowl, half the ring should be lit). I am using the Pololu library for the LED ring and HX711.h for the scale. The scale part works fine. However, the resulting LEDs never light up!

I posted the code below with a big comment in the line from which nothing seems to be executed. Any help or advice is appreciated enormously!

Another question: Does anyone know how to dim the LEDs using the Pololu library?

Thank you very much in advance!!! :slight_smile:
And please let me know if this message is lacking relevant information.

All the best & stay healthy!

//---------------------Libraries--------------------------

#include "HX711.h"
#include "PololuLedStrip.h"

//--------------------PINs-------------------------------
#define DOUT  3
#define CLK  2
HX711 scale;
float calibration_factor = 360000; 

PololuLedStrip <7> ledStrip;
#define LED_COUNT 60
rgb_color colors[LED_COUNT];

int w;  //desired weight for current ingredient
int cw; //current weight on scale 


//----------------------Setup---------------------------
void setup () {
  Serial.begin(9600);
  scale.begin(DOUT, CLK);
  scale.set_scale(calibration_factor); 
  scale.tare(); 
  Serial.println("Setup executed");   

}

//----------------------Loop-----------------------------------
void loop () {
  
  //defining the colours for each single LED (unelegant, I know ;)  )
  sc_colors();
  
  
  //int a = scale.get_units()*500;
  float a = scale.get_units()*500;
  Serial.print("Reading: ");
  Serial.print(a); 
  Serial.println(" grams");
  delay(1000);
  
  w = 200;
   
  // as long as weight doesn't indicate that all ingredients (together 800 grams) are added
  while (a < 800) {                                
    cw = scale.get_units()*500;
    Serial.println("While/if loop is executed");  
    Serial.println(cw);                        
    /*Serial.print(cw, 1);            
    Serial.print(" grams");
    Serial.println(); 
    delay(1000);
    */
    
    if (cw < 200) {               
      //to asure that the percentage of LEDs lit corresponds to the percentage of desired weight reached 
      int pp = map(cw, 0,w,0,60);  
      Serial.println(pp);         //to check correctness
      delay(1000);

      //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      // FROM HERE ONWARDS IT DOESN'T DO ANYTHING --> the LED ring is never lit at all (but the code works on itself)
      for (int i; i < pp; i++)    
      { 
        ledStrip.write(colors, i);
        delay(1000);
      }
    }
     
    while (int e = 0 < 3) {
      for (int j; j < LED_COUNT; j++)
      { 
        colors[j] = {140, 230 , 100};  
        ledStrip.write(colors, j);     // I just want this line to fill the whole neopixel green.        
        delay(1000);
        colors[j] = {0, 0 , 0}; 
        ledStrip.write(colors, j);     // I just want this line to fill the whole neopixel green.        
        delay(1000);
      }
      e++;
    }
  }
}
        
 

/////////////FUNCTIONS///////////

int sc_colors(){
  colors[0] = {160, 60, 210};
  colors[1] = {170, 60, 210};
  colors[2] = {185, 70, 205};
  colors[3] = {195, 80, 200};
  colors[4] = {205, 90, 195};
  colors[5] = {215, 100, 190};
  colors[6] = {225, 100, 185};
  colors[7] = {235, 100, 180};
  colors[8] = {245, 100, 180};
  colors[9] = {255, 100, 180};
  colors[10] = {255, 90, 175};
  colors[11] = {255, 80, 170};
  colors[12] = {255, 70, 165};
  colors[13] = {255, 60, 160};
  colors[14] = {255, 50, 155};
  colors[15] = {255, 40, 150};
  colors[16] = {255, 30, 145};
  colors[17] = {255, 20, 70};
  colors[18] = {255, 10, 50};
  colors[19] = {255, 8, 20};
  colors[20] = {255, 6, 10};
  colors[21] = {255, 4, 5};
  colors[22] = {255, 0, 0};
  colors[23] = {255, 5, 0};
  colors[24] = {255, 10, 0};
  colors[25] = {255, 20, 0};
  colors[26] = {255, 35, 0};
  colors[27] = {255, 50, 0};
  colors[28] = {255, 60, 0};
  colors[29] = {255, 70, 0};
  colors[30] = {255, 80, 0};
  colors[31] = {255, 90, 0};
  colors[32] = {255, 100, 0};
  colors[33] = {255, 110, 0};
  colors[34] = {255, 115, 0};
  colors[35] = {255, 120, 0};
  colors[36] = {255, 125, 0};
  colors[37] = {255, 130, 0};
  colors[38] = {255, 135, 0};
  colors[39] = {255, 140, 0};
  colors[40] = {255, 145, 0};
  colors[41] = {255, 150, 0};
  colors[42] = {255, 155, 0};
  colors[43] = {255, 160, 0};
  colors[44] = {245, 165, 0};
  colors[45] = {230, 170, 0};
  colors[46] = {225, 175, 0};
  colors[47] = {210, 180, 0};
  colors[48] = {195, 185, 0};
  colors[49] = {180, 195, 0};
  colors[50] = {165, 205, 0};
  colors[51] = {155, 215, 0};
  colors[52] = {145, 220, 0};
  colors[53] = {140, 230, 0};
  colors[54] = {135, 240, 0};
  colors[55] = {130, 245, 0};
  colors[56] = {125, 250, 0};
  colors[57] = {110, 255, 0};
  colors[58] = {90, 255, 0};
  colors[59] = {70, 255, 0};
  colors[60] = {50, 255, 0};
 }

OK, just a few tips to help here.

You need to go and read the forum instructions so that you can go back and modify your original post (not re-post it) - using the ‚ÄúMore ‚Üí Modify‚ÄĚ option below the right hand corner of your post - to mark up your code as such using the ‚Äú</>‚ÄĚ icon in the posting window. Just highlight each section of code (or output if you need to post that) from the IDE and click the icon.

In fact, the IDE itself has a ‚Äúcopy for forum‚ÄĚ link to put these markings on a highlighted block for you so you then just paste it here in a posting window. But even before doing that, don‚Äôt forget to use the ‚ÄúAuto-Format‚ÄĚ (Ctrl-T) option first to make it easy to read. If you do not post it as ‚Äúcode‚ÄĚ it can easily be quite garbled and is always more difficult to read due to the font.

It is inappropriate to attach it as a ‚Äú.ino‚ÄĚ file unless it is clearly too long to include in the post proper. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And even that would also assume they are using a PC and have the IDE running on that PC.

Also tidy up your blank space. Do use blank lines, but only single blanks between complete functional blocks.

Thank you for the guidance. I changed the format, I hope it is better now.
Do you have any more suggestions? :slight_smile:

Have you tried some of the example sketches that came with the Pololu library, to check that the LEDs are connected and working correctly?

while (int e = 0 < 3)

What was the intention of this line?

I'm not sure you have understood how to use the Pololu library, in particular, how ledStrip.write() should be used. Studdy the example sketches and compare how ledStrip.write() is used compared to your code. Your code uses ledStrip.write() inside loops. The example sketches use ledStrip.write() only after a loop has finished. ledStrip.write() is equivalent to strip.show() in the AdaFruit and FastLED libraries.

PaulRB:
Have you tried some of the example sketches that came with the Pololu library, to check that the LEDs are connected and working correctly?

Yes, I did and they work.

PaulRB:

while (int e = 0 < 3)

What was the intention of this line?

Here, I try to make the whole circle blink for three times in green, shutting it off in between.

PaulRB:
I’m not sure you have understood how to use the Pololu library, in particular, how ledStrip.write() should be used. Studdy the example sketches and compare how ledStrip.write() is used compared to your code. Your code uses ledStrip.write() inside loops. The example sketches use ledStrip.write() only after a loop has finished. ledStrip.write() is equivalent to strip.show() in the AdaFruit and FastLED libraries.

Yes, I am not a big fan either :smiley: Do you think it is worth to try this with the Adafruit library? I tried before and failed, but I guess I learned a lot since. The Pololu library just seems a bit clumsy to be honest, not as flexible. I might try and keep you posted!

Here, I try to make the whole circle blink for three times in green, shutting it off in between.

And did it work?

You declare a variable then set it to zero and then check to see if it is less than 3. You will always get the same result because each time it is checked you start off with a new variable called e. This will be a different variable to the variable you called e the last time you executed the code in the brackets.

Please post a link to the Polulu library; is it GitHub - pololu/pololu-led-strip-arduino: Arduino library for addressable RGB LED strips from Pololu?

For addressable led strips, I suspect that most of us use either FastLed or Adafruit's neoPixel library ( and some use their own :wink: )

Hello :slight_smile:

Thank you for your answers!

The library I used was this one GitHub - pololu/pololu-led-strip-arduino: Arduino library for addressable RGB LED strips from Pololu, but I struggled quite a lot with it.

Therefore, I tried it with Adafruit. I integrated your feedback and the basic mechanism works now. Thank you very much! I should have given up Pololu from the start :D. So far, the following thing works:

The percentage of lit LEDs on the ring corresponds to the weight on the scale (the current weight/ desired weight). After the desired weight is reached, the ring blinks three times in green. However, it is a bit unsteady and not perfectly smooth. Maybe you have some advice here? That would be super helpful!

Another thing is the rainbow: I had to let go of the colour changing of the 60 LEDs. I’d love to integrate it again, but it seems really complicated. The perfect colour would be (with a smooth transfer):

first 15 LEDs: red
15 to 30: orange
30 to 45: yellow
45 to 60: green

I guess this really is a mathematical riddle. I’d love to solve it, but I have too much time pressure. If anyone is up for it, please let me know :stuck_out_tongue:

My code is:

//---------------------Libraries--------------------------

#include "HX711.h"
#include <Adafruit_NeoPixel.h>

//--------------------PINs-------------------------------
#define DOUT  3
#define CLK  2
HX711 scale;

#define PIN 7
#define LED_COUNT 60
Adafruit_NeoPixel pixels(LED_COUNT, PIN, NEO_RGB + NEO_KHZ800); // evtl. NEO_GRB

int w;  //desired weight for current ingredient
int cw; //current weight on scale 

int pp;
float calibration_factor = 360000; 



//----------------------Setup---------------------------
void setup () {
  Serial.begin(9600);
  scale.begin(DOUT, CLK);
  scale.set_scale(calibration_factor); 
  scale.tare(); 
  Serial.println("Scale setup executed");     

  pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
  pixels.setBrightness(10);
  pixels.show(); // Initialize all pixels to 'off'
  Serial.println("Pixel setup executed");     

}

//----------------------Loop-----------------------------------
void loop () {

  pixels.clear(); // Set all pixel colors to 'off"
  

  //Just to check that scale works:
  Serial.print("Reading: ");
  Serial.print(scale.get_units()*500); 
  Serial.println(" grams");
  delay(1000);
  
  //first 300 grams flour
  w = 300;

  // as long as weight doesn't indicate that enough ingredient is added, 
  // weigh current weight and transfer (cw/w) it to percentage of neopixels lit
  while (scale.get_units()*500 < w) {    
    cw = scale.get_units()*500;
        
    //to asure that the percentage of LEDs lit corresponds to the percentage of desired weight reached 
    int pp = map(cw,0,w,0,60);  
    Serial.println(pp);         //to check correctness
    
    uint16_t j;
    for(j=0; j<256; j++) {
      int colour[] = {200,200,200};
      pixels.fill(colour, 0, pp);
    /*//introduces LEDs
    uint16_t i, j;
    for(j=0; j<256; j++) {
    for(i=0; i<pp; i++) {
      pixels.setPixelColor(i, Wheel((i+j) & 255));
    }
    */
    pixels.show();
    delay(10);
    pixels.clear();
    }
  }

  //if while loop stops (more than 200grams), ring is filled green and turned off (3 times)
  colorWipe(3000);
  colorWipe(3000);
  colorWipe(3000);
} 
    

  

       

        
        
 

/////////////FUNCTIONS///////////
// Fill the dots one after the other with a color, then turn off
void colorWipe(uint8_t wait) {
  for(uint16_t i=0; i<pixels.numPixels(); i++) {
    pixels.setPixelColor(i, pixels.Color(150, 0, 0));
    pixels.show();
  }
  delay(wait);
  pixels.clear();
  delay(wait);
}       
        

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    int pp = map(cw, 0,w,0,60);  
    for(i=0; i<pp; i++) {
      pixels.setPixelColor(i, Wheel((i+j) & 255));
    }
    pixels.show();
    delay(wait);
  }
}


// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 255) {
    return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

I'd love to integrate it again, but it seems really complicated.

No it is very simple. Use the colour wheel function you find in the examples, you put in an angle denoted by the variable h and you get out an RGB colour for that angle.
Just go from an angle of zero (red) and step through until you reach the angle you are displaying setting the colour as you go.