Arduino and Neopixel: Controlling with App

Hi,
I programmed my own Android app to control my neopixels. I have installed a HC-05 Bluetooth module to receive the data that I send from the app.

What works?
The connection is established, data can be sent.

What does not work?
RGB color data are not displayed correctly, although I saw via the serial monitor that the respective values ​​were received.

Java code of the app:

void SendRGB() {
 if (btSocket != null) {
 //sendSignal("" + (65536 * red.getProgress() + 256 * green.getProgress() + blue.getProgress()));

 String redValue = String.format("%03d", red.getProgress());
 String greenValue = String.format("%03d", green.getProgress());
 String blueValue = String.format("%03d", blue.getProgress());

 String signal = redValue + greenValue + blueValue;

 sendSignal("s" + signal);
 }
}

This code takes 3 values ​​from the respective red, green and blue regulator in my app. Its values ​​are between 0 and 255. What is finally sent looks like this:

Example:
Red: 100
Green: 1
Blue: 40

signal = 100001040

sendSignal = s100001040

Arduino Code: (Comments are made for you in the code)

#include <Adafruit_NeoPixel.h>

#include <SoftwareSerial.h>

int LED_COUNT = 5;//60;

int redValue = 0;
int greenValue = 0;
int blueValue = 0;

bool power = true;

Adafruit_NeoPixel strip(LED_COUNT, 6, NEO_GRB + NEO_KHZ800);

void setup() {
  //Serial.begin(38400);
  Serial.begin(9600);
  
  //strip.fill(strip.Color(255, 255, 255), 0, LED_COUNT);
  strip.begin();
}

void loop(){
  char received[10];
  
  if (Serial.available() > 0) {
    int i = 0;
    while (Serial.available() > 0) {
      received[i] = Serial.read();
      Serial.write(received[i]); //<-------- This is a proof for me that it receives the data correctly. I've seen it in the Serial Monitor
      
      i++;
    }
    
    if (received[0] == 's') { //<-------- This if statement works also fine, because if I click the send button in my App it shows a color but not the color that would show when I mix those 3 values.
         redValue = (received[1] << 16) + (received[2] << 8) + received[3]; //<------- Bit shifting here to get (like the example) 100 from single chars (1 0 0)
         greenValue = (received[4] << 16) + (received[5] << 8) + received[6]; //<------- Here doing the same
         blueValue = (received[7] << 16) + (received[8] << 8) + received[9]; //<------- and here also

         strip.fill(strip.Color(redValue, greenValue, blueValue), 0, LED_COUNT);

      }
      strip.show();
   }
}

In my opinion completely understandable, but it doesn't work. I have already tried a direct 32bit color integer. Unfortunately, that didn't work either ...

Thank you in advance for your suggestions.

Regards,
Colin

         redValue = (received[1] - '0') * 100 + (received[2] - '0') * 10 + received[3] -'0';

PaulRB:

         redValue = (received[1] - '0') * 100 + (received[2] - '0') * 10 + received[3] -'0';

Hi, thanks for your hint. I also saw that bit shifting is not what I want here. I tested it but now the strip shows the same color no matter what color code I am sending... I tried it without the - '0' part, but that had the same result. It is a white with a little bit of blue.

Err... there is no data connection in your photo?

PaulRB:
Err... there is no data connection in your photo?

yes, this is because I only hold the cable in place if I test it. This is a test strip with only 5 neopixel connected to a battery.

I forgot to say +1 karma for using code tags, and posting a photo.

Have you tried running the "strandtest" example sketch that came with the neopixel library?

If that works (when you are holding the cable), I suggest printing redValue, greenValue, blueValue to serial monitor in your sketch.

PaulRB:
I forgot to say +1 karma for using code tags, and posting a photo.

Have you tried running the "strandtest" example sketch that came with the neopixel library?

If that works (when you are holding the cable), I suggest printing redValue, greenValue, blueValue to serial monitor in your sketch.

Thank you :slight_smile:
So I got new results. I've printed the redValue. It says 6965 everytime. Regardless what I've send wit my app :o :confused:

redValue says 6965
greenValue says 8812
blueValue says 5639

Try this change:

if (Serial.available() >= 10) {