0

I am trying to set up an LED-strip of 30 RGB LEDs (model WS2801). The strip is connected to an Arduino Uno and an external power supply and the goal is to send colors to the arduino using PySerial which are then shown on the LED strip.

I have been trying to wrap my head around the communications, which I am having a hard time with, especially due to the loose typing of python.

I wrote some code that generates smooth color transitions and got the strip to actually show a fairly smooth color transition, unfortunately the colors are the wrong ones.

Now I am guessing something overflows somewhere, especially since colors such as 0xFF0000 (red) show as a yellow tone, which indicates that on top of red some green gets added as well.

The Python code using pySerial:

@classmethod
def set_lights(self: RGBHardware, colors: List[int]) -> None:
    for i in range(len(colors)):
        rgb = color_to_rgb(colors[i])
        self.arduino.write(chr(76).encode()) # 'L'
        self.arduino.write(chr(i).encode())
        self.arduino.write(chr(rgb[0]).encode())
        self.arduino.write(chr(rgb[1]).encode())
        self.arduino.write(chr(rgb[2]).encode())
    self.arduino.write(chr(90).encode()) # 'Z'

@classmethod
def turn_on(self) -> None:
    self.arduino = serial.Serial('/dev/ttyACM0', 115200)
    if self.arduino.isOpen:
        self.arduino.close()
    self.arduino.open()
    pass

The code running on the Arduino Uno:

void setup() {
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000L)
  clock_prescale_set(clock_div_1); // Enable 16 MHz on Trinket
#endif

  Serial.begin(115200);
  strip.begin();
  // Update LED contents, to start they are all 'off'
  strip.show();
}

void loop() {
   while (Serial.available()) {
        uint8_t serial = Serial.read();
        if (serial == 'Z') {
            strip.show();
        } else if (serial == 'L') {
            int i = getNextInput();
            int r = getNextInput();
            int g = getNextInput();
            int b = getNextInput();
            strip.setPixelColor(i, Color(r,g,b));
        }
   }
}

uint8_t getNextInput() {
  while(!Serial.available()); // wait for a character
  return Serial.read();
}

I am having the strong feeling I am just missing a miniscule detail and it is quite frustrating.

Any help would be greatly appreciated!

EDIT: So I recorded some data and pasted the results below. I found that always not the whole LED-strip was updated and none of it with the correct color. Once even the character "Z" seemed to go missing (that causes the strip to fully refresh) so no color was showing at all.

What I also forgot to mention earlier was that I am using Celery in Python to do the light switching as a background task.

To record the results I used

print("i, R,G,B: " + str(i) + ", " + str(rgb[0]) + "," + str(rgb[1]) + "," + str(rgb[2])) to print the data in python and

Serial.println("i, R,G,B: " + String(i) + ", " + String(r) + "," + String(g) + "," + String(b)); to do the same on the Arduino.

Sending color red from Python:

[2018-07-23 16:13:57,121: WARNING/ForkPoolWorker-7] i, R,G,B: 0, 255,0,0
[2018-07-23 16:13:57,122: WARNING/ForkPoolWorker-7] i, R,G,B: 1, 255,0,0
[2018-07-23 16:13:57,123: WARNING/ForkPoolWorker-7] i, R,G,B: 2, 255,0,0
[2018-07-23 16:13:57,125: WARNING/ForkPoolWorker-7] i, R,G,B: 3, 255,0,0
[2018-07-23 16:13:57,126: WARNING/ForkPoolWorker-7] i, R,G,B: 4, 255,0,0
[2018-07-23 16:13:57,127: WARNING/ForkPoolWorker-7] i, R,G,B: 5, 255,0,0
[2018-07-23 16:13:57,127: WARNING/ForkPoolWorker-7] i, R,G,B: 6, 255,0,0
[2018-07-23 16:13:57,128: WARNING/ForkPoolWorker-7] i, R,G,B: 7, 255,0,0
[2018-07-23 16:13:57,129: WARNING/ForkPoolWorker-7] i, R,G,B: 8, 255,0,0
[2018-07-23 16:13:57,129: WARNING/ForkPoolWorker-7] i, R,G,B: 9, 255,0,0
[2018-07-23 16:13:57,131: WARNING/ForkPoolWorker-7] i, R,G,B: 10, 255,0,0
[2018-07-23 16:13:57,132: WARNING/ForkPoolWorker-7] i, R,G,B: 11, 255,0,0
[2018-07-23 16:13:57,132: WARNING/ForkPoolWorker-7] i, R,G,B: 12, 255,0,0
[2018-07-23 16:13:57,133: WARNING/ForkPoolWorker-7] i, R,G,B: 13, 255,0,0
[2018-07-23 16:13:57,134: WARNING/ForkPoolWorker-7] i, R,G,B: 14, 255,0,0
[2018-07-23 16:13:57,136: WARNING/ForkPoolWorker-7] i, R,G,B: 15, 255,0,0
[2018-07-23 16:13:57,137: WARNING/ForkPoolWorker-7] i, R,G,B: 16, 255,0,0
[2018-07-23 16:13:57,139: WARNING/ForkPoolWorker-7] i, R,G,B: 17, 255,0,0
[2018-07-23 16:13:57,140: WARNING/ForkPoolWorker-7] i, R,G,B: 18, 255,0,0
[2018-07-23 16:13:57,141: WARNING/ForkPoolWorker-7] i, R,G,B: 19, 255,0,0
[2018-07-23 16:13:57,142: WARNING/ForkPoolWorker-7] i, R,G,B: 20, 255,0,0
[2018-07-23 16:13:57,144: WARNING/ForkPoolWorker-7] i, R,G,B: 21, 255,0,0
[2018-07-23 16:13:57,145: WARNING/ForkPoolWorker-7] i, R,G,B: 22, 255,0,0
[2018-07-23 16:13:57,146: WARNING/ForkPoolWorker-7] i, R,G,B: 23, 255,0,0
[2018-07-23 16:13:57,147: WARNING/ForkPoolWorker-7] i, R,G,B: 24, 255,0,0
[2018-07-23 16:13:57,148: WARNING/ForkPoolWorker-7] i, R,G,B: 25, 255,0,0
[2018-07-23 16:13:57,149: WARNING/ForkPoolWorker-7] i, R,G,B: 26, 255,0,0
[2018-07-23 16:13:57,150: WARNING/ForkPoolWorker-7] i, R,G,B: 27, 255,0,0
[2018-07-23 16:13:57,151: WARNING/ForkPoolWorker-7] i, R,G,B: 28, 255,0,0
[2018-07-23 16:13:57,151: WARNING/ForkPoolWorker-7] i, R,G,B: 29, 255,0,0

Received color red on the arduino:

i, R,G,B: 0, 195,191,0
i, R,G,B: 1, 195,191,0
i, R,G,B: 2, 195,191,0
i, R,G,B: 3, 195,191,0
i, R,G,B: 4, 195,191,0
i, R,G,B: 5, 195,191,0
i, R,G,B: 6, 195,191,0
i, R,G,B: 7, 195,191,0
i, R,G,B: 8, 195,191,0
i, R,G,B: 9, 195,191,0
i, R,G,B: 10, 195,191,0
i, R,G,B: 11, 195,191,0
i, R,G,B: 12, 195,191,0
i, R,G,B: 13, 195,191,0
i, R,G,B: 14, 195,191,0
i, R,G,B: 15, 195,191,0
i, R,G,B: 16, 195,191,0
i, R,G,B: 17, 195,191,0
i, R,G,B: 18, 195,191,0
i, R,G,B: 19, 195,191,0
i, R,G,B: 20, 195,191,0
i, R,G,B: 21, 195,191,0
i, R,G,B: 22, 195,191,0
i, R,G,B: 23, 195,191,0
i, R,G,B: 24, 195,191,0
i, R,G,B: 25, 195,191,0
i, R,G,B: 26, 76,27,195

Sending color green from Python:

[2018-07-23 16:22:34,374: WARNING/ForkPoolWorker-8] i, R,G,B: 0, 0,255,0
[2018-07-23 16:22:34,376: WARNING/ForkPoolWorker-8] i, R,G,B: 1, 0,255,0
[2018-07-23 16:22:34,377: WARNING/ForkPoolWorker-8] i, R,G,B: 2, 0,255,0
[2018-07-23 16:22:34,378: WARNING/ForkPoolWorker-8] i, R,G,B: 3, 0,255,0
[2018-07-23 16:22:34,380: WARNING/ForkPoolWorker-8] i, R,G,B: 4, 0,255,0
[2018-07-23 16:22:34,381: WARNING/ForkPoolWorker-8] i, R,G,B: 5, 0,255,0
[2018-07-23 16:22:34,382: WARNING/ForkPoolWorker-8] i, R,G,B: 6, 0,255,0
[2018-07-23 16:22:34,383: WARNING/ForkPoolWorker-8] i, R,G,B: 7, 0,255,0
[2018-07-23 16:22:34,384: WARNING/ForkPoolWorker-8] i, R,G,B: 8, 0,255,0
[2018-07-23 16:22:34,385: WARNING/ForkPoolWorker-8] i, R,G,B: 9, 0,255,0
[2018-07-23 16:22:34,386: WARNING/ForkPoolWorker-8] i, R,G,B: 10, 0,255,0
[2018-07-23 16:22:34,387: WARNING/ForkPoolWorker-8] i, R,G,B: 11, 0,255,0
[2018-07-23 16:22:34,387: WARNING/ForkPoolWorker-8] i, R,G,B: 12, 0,255,0
[2018-07-23 16:22:34,388: WARNING/ForkPoolWorker-8] i, R,G,B: 13, 0,255,0
[2018-07-23 16:22:34,389: WARNING/ForkPoolWorker-8] i, R,G,B: 14, 0,255,0
[2018-07-23 16:22:34,389: WARNING/ForkPoolWorker-8] i, R,G,B: 15, 0,255,0
[2018-07-23 16:22:34,390: WARNING/ForkPoolWorker-8] i, R,G,B: 16, 0,255,0
[2018-07-23 16:22:34,390: WARNING/ForkPoolWorker-8] i, R,G,B: 17, 0,255,0
[2018-07-23 16:22:34,391: WARNING/ForkPoolWorker-8] i, R,G,B: 18, 0,255,0
[2018-07-23 16:22:34,392: WARNING/ForkPoolWorker-8] i, R,G,B: 19, 0,255,0
[2018-07-23 16:22:34,393: WARNING/ForkPoolWorker-8] i, R,G,B: 20, 0,255,0
[2018-07-23 16:22:34,393: WARNING/ForkPoolWorker-8] i, R,G,B: 21, 0,255,0
[2018-07-23 16:22:34,394: WARNING/ForkPoolWorker-8] i, R,G,B: 22, 0,255,0
[2018-07-23 16:22:34,395: WARNING/ForkPoolWorker-8] i, R,G,B: 23, 0,255,0
[2018-07-23 16:22:34,395: WARNING/ForkPoolWorker-8] i, R,G,B: 24, 0,255,0
[2018-07-23 16:22:34,396: WARNING/ForkPoolWorker-8] i, R,G,B: 25, 0,255,0
[2018-07-23 16:22:34,397: WARNING/ForkPoolWorker-8] i, R,G,B: 26, 0,255,0
[2018-07-23 16:22:34,398: WARNING/ForkPoolWorker-8] i, R,G,B: 27, 0,255,0
[2018-07-23 16:22:34,398: WARNING/ForkPoolWorker-8] i, R,G,B: 28, 0,255,0
[2018-07-23 16:22:34,399: WARNING/ForkPoolWorker-8] i, R,G,B: 29, 0,255,0

Received color green on the Arduino:

i, R,G,B: 0, 0,195,191
i, R,G,B: 1, 0,195,191
i, R,G,B: 2, 0,195,191
i, R,G,B: 3, 0,195,191
i, R,G,B: 4, 0,195,191
i, R,G,B: 5, 0,195,191
i, R,G,B: 6, 0,195,191
i, R,G,B: 7, 0,195,191
i, R,G,B: 8, 0,195,191
i, R,G,B: 9, 0,195,191
i, R,G,B: 10, 0,195,191
i, R,G,B: 11, 0,195,191
i, R,G,B: 12, 0,195,191
i, R,G,B: 13, 0,195,191
i, R,G,B: 14, 0,195,191
i, R,G,B: 15, 0,195,191
i, R,G,B: 16, 0,195,191
i, R,G,B: 17, 0,195,191
i, R,G,B: 18, 0,195,191
i, R,G,B: 19, 0,195,191
i, R,G,B: 20, 0,195,191
i, R,G,B: 21, 0,195,191
i, R,G,B: 22, 0,195,191
i, R,G,B: 23, 0,195,191
i, R,G,B: 24, 0,195,191
i, R,G,B: 25, 0,195,191
i, R,G,B: 26, 76,28,0

Sending color blue from Python:

[2018-07-23 16:26:52,416: WARNING/ForkPoolWorker-2] i, R,G,B: 0, 0,0,255
[2018-07-23 16:26:52,416: WARNING/ForkPoolWorker-2] i, R,G,B: 1, 0,0,255
[2018-07-23 16:26:52,417: WARNING/ForkPoolWorker-2] i, R,G,B: 2, 0,0,255
[2018-07-23 16:26:52,417: WARNING/ForkPoolWorker-2] i, R,G,B: 3, 0,0,255
[2018-07-23 16:26:52,418: WARNING/ForkPoolWorker-2] i, R,G,B: 4, 0,0,255
[2018-07-23 16:26:52,418: WARNING/ForkPoolWorker-2] i, R,G,B: 5, 0,0,255
[2018-07-23 16:26:52,419: WARNING/ForkPoolWorker-2] i, R,G,B: 6, 0,0,255
[2018-07-23 16:26:52,419: WARNING/ForkPoolWorker-2] i, R,G,B: 7, 0,0,255
[2018-07-23 16:26:52,420: WARNING/ForkPoolWorker-2] i, R,G,B: 8, 0,0,255
[2018-07-23 16:26:52,420: WARNING/ForkPoolWorker-2] i, R,G,B: 9, 0,0,255
[2018-07-23 16:26:52,421: WARNING/ForkPoolWorker-2] i, R,G,B: 10, 0,0,255
[2018-07-23 16:26:52,421: WARNING/ForkPoolWorker-2] i, R,G,B: 11, 0,0,255
[2018-07-23 16:26:52,422: WARNING/ForkPoolWorker-2] i, R,G,B: 12, 0,0,255
[2018-07-23 16:26:52,422: WARNING/ForkPoolWorker-2] i, R,G,B: 13, 0,0,255
[2018-07-23 16:26:52,423: WARNING/ForkPoolWorker-2] i, R,G,B: 14, 0,0,255
[2018-07-23 16:26:52,423: WARNING/ForkPoolWorker-2] i, R,G,B: 15, 0,0,255
[2018-07-23 16:26:52,424: WARNING/ForkPoolWorker-2] i, R,G,B: 16, 0,0,255
[2018-07-23 16:26:52,424: WARNING/ForkPoolWorker-2] i, R,G,B: 17, 0,0,255
[2018-07-23 16:26:52,425: WARNING/ForkPoolWorker-2] i, R,G,B: 18, 0,0,255
[2018-07-23 16:26:52,426: WARNING/ForkPoolWorker-2] i, R,G,B: 19, 0,0,255
[2018-07-23 16:26:52,427: WARNING/ForkPoolWorker-2] i, R,G,B: 20, 0,0,255
[2018-07-23 16:26:52,427: WARNING/ForkPoolWorker-2] i, R,G,B: 21, 0,0,255
[2018-07-23 16:26:52,428: WARNING/ForkPoolWorker-2] i, R,G,B: 22, 0,0,255
[2018-07-23 16:26:52,428: WARNING/ForkPoolWorker-2] i, R,G,B: 23, 0,0,255
[2018-07-23 16:26:52,429: WARNING/ForkPoolWorker-2] i, R,G,B: 24, 0,0,255
[2018-07-23 16:26:52,429: WARNING/ForkPoolWorker-2] i, R,G,B: 25, 0,0,255
[2018-07-23 16:26:52,430: WARNING/ForkPoolWorker-2] i, R,G,B: 26, 0,0,255
[2018-07-23 16:26:52,430: WARNING/ForkPoolWorker-2] i, R,G,B: 27, 0,0,255
[2018-07-23 16:26:52,431: WARNING/ForkPoolWorker-2] i, R,G,B: 28, 0,0,255
[2018-07-23 16:26:52,431: WARNING/ForkPoolWorker-2] i, R,G,B: 29, 0,0,255

Received color blue on the Arduino:

i, R,G,B: 0, 0,0,195
i, R,G,B: 1, 0,0,195
i, R,G,B: 2, 0,0,195
i, R,G,B: 3, 0,0,195
i, R,G,B: 4, 0,0,195
i, R,G,B: 5, 0,0,195
i, R,G,B: 6, 0,0,195
i, R,G,B: 7, 0,0,195
i, R,G,B: 8, 0,0,195
i, R,G,B: 9, 0,0,195
i, R,G,B: 10, 0,0,195
i, R,G,B: 11, 0,0,195
i, R,G,B: 12, 0,0,195
i, R,G,B: 13, 0,0,195
i, R,G,B: 14, 0,0,195
i, R,G,B: 15, 0,0,195
i, R,G,B: 16, 0,0,195
i, R,G,B: 17, 0,0,195
i, R,G,B: 18, 0,0,195
i, R,G,B: 20, 0,0,195
i, R,G,B: 23, 191,76,26

Sending color orange from Python:

[2018-07-23 16:29:20,725: WARNING/ForkPoolWorker-9] i, R,G,B: 0, 255,128,0
[2018-07-23 16:29:20,726: WARNING/ForkPoolWorker-9] i, R,G,B: 1, 255,128,0
[2018-07-23 16:29:20,727: WARNING/ForkPoolWorker-9] i, R,G,B: 2, 255,128,0
[2018-07-23 16:29:20,728: WARNING/ForkPoolWorker-9] i, R,G,B: 3, 255,128,0
[2018-07-23 16:29:20,729: WARNING/ForkPoolWorker-9] i, R,G,B: 4, 255,128,0
[2018-07-23 16:29:20,731: WARNING/ForkPoolWorker-9] i, R,G,B: 5, 255,128,0
[2018-07-23 16:29:20,732: WARNING/ForkPoolWorker-9] i, R,G,B: 6, 255,128,0
[2018-07-23 16:29:20,733: WARNING/ForkPoolWorker-9] i, R,G,B: 7, 255,128,0
[2018-07-23 16:29:20,734: WARNING/ForkPoolWorker-9] i, R,G,B: 8, 255,128,0
[2018-07-23 16:29:20,735: WARNING/ForkPoolWorker-9] i, R,G,B: 9, 255,128,0
[2018-07-23 16:29:20,736: WARNING/ForkPoolWorker-9] i, R,G,B: 10, 255,128,0
[2018-07-23 16:29:20,737: WARNING/ForkPoolWorker-9] i, R,G,B: 11, 255,128,0
[2018-07-23 16:29:20,738: WARNING/ForkPoolWorker-9] i, R,G,B: 12, 255,128,0
[2018-07-23 16:29:20,739: WARNING/ForkPoolWorker-9] i, R,G,B: 13, 255,128,0
[2018-07-23 16:29:20,740: WARNING/ForkPoolWorker-9] i, R,G,B: 14, 255,128,0
[2018-07-23 16:29:20,741: WARNING/ForkPoolWorker-9] i, R,G,B: 15, 255,128,0
[2018-07-23 16:29:20,742: WARNING/ForkPoolWorker-9] i, R,G,B: 16, 255,128,0
[2018-07-23 16:29:20,743: WARNING/ForkPoolWorker-9] i, R,G,B: 17, 255,128,0
[2018-07-23 16:29:20,744: WARNING/ForkPoolWorker-9] i, R,G,B: 18, 255,128,0
[2018-07-23 16:29:20,744: WARNING/ForkPoolWorker-9] i, R,G,B: 19, 255,128,0
[2018-07-23 16:29:20,745: WARNING/ForkPoolWorker-9] i, R,G,B: 20, 255,128,0
[2018-07-23 16:29:20,746: WARNING/ForkPoolWorker-9] i, R,G,B: 21, 255,128,0
[2018-07-23 16:29:20,747: WARNING/ForkPoolWorker-9] i, R,G,B: 22, 255,128,0
[2018-07-23 16:29:20,747: WARNING/ForkPoolWorker-9] i, R,G,B: 23, 255,128,0
[2018-07-23 16:29:20,749: WARNING/ForkPoolWorker-9] i, R,G,B: 24, 255,128,0
[2018-07-23 16:29:20,750: WARNING/ForkPoolWorker-9] i, R,G,B: 25, 255,128,0
[2018-07-23 16:29:20,750: WARNING/ForkPoolWorker-9] i, R,G,B: 26, 255,128,0
[2018-07-23 16:29:20,751: WARNING/ForkPoolWorker-9] i, R,G,B: 27, 255,128,0
[2018-07-23 16:29:20,752: WARNING/ForkPoolWorker-9] i, R,G,B: 28, 255,128,0
[2018-07-23 16:29:20,752: WARNING/ForkPoolWorker-9] i, R,G,B: 29, 255,128,0

Received color orange on the Arduino:

i, R,G,B: 0, 195,191,194
i, R,G,B: 1, 195,191,194
i, R,G,B: 2, 195,191,194
i, R,G,B: 3, 195,191,194
i, R,G,B: 4, 195,191,194
i, R,G,B: 5, 195,191,194
i, R,G,B: 6, 195,191,194
i, R,G,B: 7, 195,191,194
i, R,G,B: 8, 195,191,194
i, R,G,B: 9, 195,191,194
i, R,G,B: 10, 195,191,194
i, R,G,B: 11, 195,191,194
i, R,G,B: 12, 195,191,194
i, R,G,B: 13, 195,191,194
i, R,G,B: 14, 195,191,194
i, R,G,B: 15, 195,191,194
i, R,G,B: 16, 195,191,194
i, R,G,B: 17, 195,191,194
i, R,G,B: 18, 195,191,194
i, R,G,B: 19, 195,191,194
i, R,G,B: 76, 23,195,191
i, R,G,B: 194, 128,0,76

Received color orange on the Arduino (again):

i, R,G,B: 0, 195,191,194
i, R,G,B: 1, 195,191,194
i, R,G,B: 2, 195,191,194
i, R,G,B: 3, 195,191,194
i, R,G,B: 4, 195,191,194
i, R,G,B: 5, 195,191,194
i, R,G,B: 6, 195,191,194
i, R,G,B: 7, 195,191,194
i, R,G,B: 8, 195,191,194
i, R,G,B: 9, 195,191,194
i, R,G,B: 10, 195,191,194
i, R,G,B: 11, 195,191,194
i, R,G,B: 12, 195,191,194
i, R,G,B: 13, 195,191,194
i, R,G,B: 14, 195,191,194
i, R,G,B: 15, 195,191,194
i, R,G,B: 16, 195,191,194
i, R,G,B: 17, 195,191,194
i, R,G,B: 18, 195,191,194
i, R,G,B: 128, 0,76,24
i, R,G,B: 27, 195,191,194

Another Edit: What is also interesting is that the main color (e.g. when I send red most of the LEDs are yellow) stays the same every time I tried. But the amount of LEDs that gets passed differs with each try. The same goes for the last one or two LEDs the Arduino receives. Their colors and indexes are all over the place.

10
  • generates smooth color transitions .... do not send transitions ..... send discrete colors to the whole string 0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00 ... etc ...............document the resulting color ...... check color value on the web .... html-color-codes.com ................ update your question with results
    – jsotola
    Jul 22, 2018 at 18:01
  • Red and green produce yellow. I think you are seeing cyan 0x00FFFF. It kind of looks like the bits are inverted.
    – Gerben
    Jul 22, 2018 at 19:39
  • @jsotola I added some sample data, maybe you could take a look again?
    – flntzr
    Jul 23, 2018 at 16:38
  • @Gerben That was a mistake on my end, red actually show up as yellow on the strip.
    – flntzr
    Jul 23, 2018 at 16:50
  • 1
    Try using a lower baudrate and see if the problem persists.
    – Gerben
    Jul 23, 2018 at 16:53

1 Answer 1

1

This

...
  self.arduino.write(chr(76).encode()) # 'L'
  self.arduino.write(chr(i).encode())
  self.arduino.write(chr(rgb[0]).encode())
  self.arduino.write(chr(rgb[1]).encode())
  self.arduino.write(chr(rgb[2]).encode())
self.arduino.write(chr(90).encode()) # 'Z'
...

should be spelled:

  self.arduino.write(b'L')
  self.arduino.write(i.to_bytes(1,'big'))
  self.arduino.write(bytes(rgb))
self.arduino.write(b'Z')

It is much more readable this way; you could refactor even further:

  sout = b'L' + i.to_bytes(1,'big') + bytes(rgb)
  self.arduino.write(sout)
self.arduino.write(b'Z')

Your also wasting effort here:

Serial.println("i, R,G,B: " + String(i) + ", " + String(r) + "," + String(g) + "," + String(b));

This should be said more like this:

Serial.print(i);
Serial.print(", ");
Serial.print(r);
Serial.print(", ");
Serial.print(g);
Serial.print(", ");
Serial.println(b);

This eliminates three temporary String objects you were creating with String().

The rest of the code looks like it should work so you should try trouble shooting, you could:

  • Lower the baud rate till it works
  • Try 9600 baud and increase it until it stops working
  • Try the a serial sample program, make sure the serial portion is working correctly first
  • Write your own minimal test program, make sure the serial is working correctly at first.
1
  • Thank you very much, this worked perfectly. And you are completely right about the String concatenation, I wasn't really paying attention to performance, due to those values just being printed for debugging.
    – flntzr
    Jul 23, 2018 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.