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.


test1.h (25.2 KB)