Need help with colour display on Dotstar LED strip

Hello,

I am working on creating a POV Globe display like this. I'm using the Dotstar LED strip to display the images. I want to be able to use any image on the display and have created the following python script to convert an image into a header file with an array of the RGB value for the image. The script is below:

from PIL import Image

img = Image.open("simpletest.jpg", "r")
img = img.convert("RGB")

h, w = img.size
pixels = list(img.getdata())

name = "Simpletest.png"
outfile = "testfile.h"
with open(outfile, "w+") as outf:
   
    outf.write(f"const static uint8_t {name}[] = {{\n")
    for pixel in pixels:
        r, g, b = pixel
        outf.write(f"{b}, {g}, {r},\n")
    outf.write("};\n")
    print(f"Saved header to {outfile}")

It gives me a header file which I then import into the Arduino IDE and use the code there to display the image. I was testing my image display code, just to see that my logic worked and displayed the appropriate colors and I used a test image that just has black and white colors in it (attached the image with the post). However, when I ran the code (with delays so I could view the colors being displayed), there were times when I would see colors other than just black and white. Here is the code I used to test my logic:

#include <Adafruit_DotStar.h>
#include <SPI.h>
#include "images/test1.h"

#define NUMPIXELS 144 // Number of LEDs in strip we use
#define DATAPIN    2
#define CLOCKPIN   3
Adafruit_DotStar strip = Adafruit_DotStar(
 NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BRG);

#define BRIGHTNESS 10

//Set all LEDs to a specific color
void setAll(uint32_t color) {
  for (int i = 0; i < NUMPIXELS; i++) {
    strip.setPixelColor(i, color);
  }
  strip.show();
}

void setColoumns(int x){
  int led = 0;
  int numpix = 144;
  for(int i = numpix*x*3; i < numpix*x*3 + numpix*3; i+=3){
    uint8_t b =  pixels[i];
    uint8_t r =  pixels[i+2];
    uint8_t g =  pixels[i+1];
    uint32_t color = 0x000000 ; //GRB
  
    color = color | (g << 16) ;
    color = color | (r << 8) ;
    color = color | b ;

    strip.setPixelColor(led, color);
    led++;
    Serial.println(led);
  }
  strip.show();
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  strip.begin();
  strip.show();
  strip.setBrightness(BRIGHTNESS);
  strip.setPixelColor(4, 0xFF0000);
  strip.show();
  delay(1000);
}

void loop() {
  // put your main code here, to run repeatedly:

  setAll(0x00FF00);
  delay(500);
  setAll(0x000000);
  delay(200);
  
  for (int i =0; i < 72; i++){
    setColoumns(i);
    delay(1000);
    //Use the line below to see when a new coloumn is being displayed
    //setAll(0xFFFF00);
    //delay(500);
    
  }
  
  setAll(0xFF0000);
  delay(500);

}

I'm unsure of what is going wrong here and I would greatly appreciate your help with figuring out why I'm seeing colors being displayed other than black and white even though the picture only contains black and white colors.

Edit: Uploaded the file I'm using to get the colors in the Arduino code.

Simpletest.png

Simpletest.png

test1.h (25.2 KB)

Have You verified that the first conversion gives correct data in the file?

If the issue is a seemingly random twinkling of lights from the strip, when the strip has been told to display 'black', is, what I have found to be, a power supply issue.

My solution was to use a separate regulator to just supply the strips, of course connect the commons together.

@Railroader, I did have a look at the file and it gives me a list of three-tuples like (255,255,255). There are black areas as well which are (0,0,0). However, there are other parts that have (4,4,4) or (233,233,233), which is a lighter white color from what I've managed to find. I've uploaded a file that has some of the conversions in it which the code gives me to the original post if you want to look at it more. I did go through it and I cannot see any part of it which should result in a blue or pink or yellow color but I'm seeing those colors being shown, especially after the black parts of the image start getting displayed.

@Idahowalker, I'll have a look into trying to get a separate power supply for the LED strip. Currently, it is being powered from the Arduino Mega for the 5 V but I have a power bank which I'll try and connect to it.

educiono:
Currently, it is being powered from the Arduino Mega for the 5 V but I have a power bank which I'll try and connect to it.

How many amps does each LED on your strip want? How many amps does the Mega supply?

Idahowalker:
How many amps does each LED on your strip want? How many amps does the Mega supply?

I'm using 144 LEDs on the strip. It has a max power usage of 43 watts (8.6 Amps at 5 Volts) - gotten from the adafruit website. The max output of a Mega pin os 40mA. So it seems I should try an external power supply to make sure the power supply is not an issue. I'll update on if this fixes the issue.

educiono:
I'm using 144 LEDs on the strip. It has a max power usage of 43 watts (8.6 Amps at 5 Volts) - gotten from the adafruit website. The max output of a Mega pin os 40mA. So it seems I should try an external power supply to make sure the power supply is not an issue. I'll update on if this fixes the issue.

Excellent deduction. +1.

Common blunder - mistaking an Arduino for something resembling a "power supply".

Note that even if you are parsimonious about how many LEDs you illuminate at one time, and with what brightness, presuming the "Dotstar" LEDs are functionally similar to the NeoPixels, a 144 LED strip will draw about 150 mA when completely dark.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.