How to address Neopixels from Serial window?

In the process of trying to understand what data to send to Neopixels to control them and we are not understanding what bytes to send to turn on and off RGB colors.

Here is example code on Arduino: A simple Arduino program which uses Adafruit's NeoPixel library to relay serial-level RGB data to a series of WS2811-compatible LED modules attached to an output pin. The use of Adafurit's library requires double buffering in the serial-receive code, reducing the number of LEDs that can be driven with a single Arduino. It's possible that code could be upgraded to avoid this limitation, but it wasn't an issue with the number of LEDs that I was driving with the code (256). IMPORTANT NOTE: When sending data to this program, NEVER SEND MORE THAN 63 BYTES AT A TIME. Doing so will crash the arduino and confuse the USB Serial driver on your computer. Send blocks of up to 63 bytes and wait for a few microseconds before sending more (calling your language's flush() method works well). · GitHub

// include the neo pixel library
#include <Adafruit_NeoPixel.h>

// The number of LEDs being driven. This dictates how much data is expected in each frame read from the serial port.
static const int NUM_LEDS = 256;

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_RGB     Pixels are wired for RGB bitstream
//   NEO_GRB     Pixels are wired for GRB bitstream
//   NEO_KHZ400  400 KHz bitstream (e.g. FLORA pixels)
//   NEO_KHZ800  800 KHz bitstream (e.g. High Density LED strip)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(
  NUM_LEDS,             // Number of pixels in strip
  12,                   // Pin number (most are valid)
  NEO_GRB + NEO_KHZ800  //  pixel type flags, add together as needed:
                        //   NEO_RGB     Pixels are wired for RGB bitstream
                        //   NEO_GRB     Pixels are wired for GRB bitstream
                        //   NEO_KHZ400  400 KHz bitstream (e.g. Old FLORA pixels)
                        //   NEO_KHZ800  800 KHz bitstream (e.g. New FLORA pixels and most WS2811 strips)
);

// Buffer used to read LED data from Serial.
// TODO: Direct access to the Adafruit_NeoPixel buffer would cut memory usage in half
char colorValues[NUM_LEDS*3];

void setup() {
  // Init the NeoPixel library and turn off all the LEDs
  strip.begin();
  strip.show();
  
  // Do a quick test/demo to show that things are working
  for (int i=0; i<60; i++) { flashAll(strip.Color((i%20)*2,i%30,i%60)); delay(10); }

  // Initialize the buffer to all black
  memset(colorValues, 0, sizeof(colorValues));

  // Initialize serial and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for port to be ready
  }
  
  // Tell the computer that we're ready for data
  Serial.println("READY");
}


void loop() {
  while (true) {
    int bufferPos = 0;
    
    // Read the data for each pixel
    while (bufferPos < NUM_LEDS*3) {
      int color = Serial.read();
      if (color >= 0) {
        colorValues[bufferPos++] = color;
      }
    }
    
    // Feed the data to the NeoPixel library
    for(int i=0; i<NUM_LEDS; i++) {
      int d = i*3;
      uint32_t c = strip.Color(colorValues[d], colorValues[d+1], colorValues[d+2]);
      strip.setPixelColor(i, c);
    }
    
    // update the strip
    strip.show();
    
    // Clear up the serial buffer
    while (Serial.available() > 0) Serial.read();
    
    // Let the sender know we're ready for more data
    Serial.println("READY");
  }
}

void flashAll(uint32_t color) {
  // Do a quick test/demo to show that things are working
  for (int i=0; i < NUM_LEDS; i++) {
    strip.setPixelColor(i, color);
  }
  strip.show();
}

I am assuming that we need to send 3 color values (0-255) for every LED so for 1 Neopixel, we need to send "255 0 0" to turn on the RED LED (assuming RGB is the color order) and "0 0 0" to turn it off.

However upon uploading the sketch and trying to enter these commands directly into the Serial Monitor, we get different results (which also dramatically change based on if "no line ending" or "newline" is selected in the bottom). No matter what we send, we cannot seem to turn off the LED with just 0's.

Can anyone shed some light on how to input bytes into the Serial Monitor to control just the R, G, B or turn off the LED entirely? Or is it not possible with Serial Monitor and we need to send serial from a different program?

Thank you.

The serial monitor will only send single ASCII characters, so it you want to receive a value something like 255 then the serial monitor sends 2 then 5 then 5, what is more it sends them as ASCII characters. So you have to receive them one at a time, convert from ASCII to a number and then assemble those potentially three numbers into one value. Use the delimiter ( commas ) to see how many places of decimal numbers you are dealing with.

or turn off the LED entirely?

You simply set the R G B values to zero to do this.

Thank you, very helpful info! I still got a little bit lost at how to do this part?

Grumpy_Mike:
convert from ASCII to a number and then assemble those potentially three numbers into one value. Use the delimiter ( commas ) to see how many places of decimal numbers you are dealing with.

You keep referring to receiving, which I am a little lost about. Do you mean the Arduino receives from the computer's serial monitor but when I type a character in serial monitor, it is trying to send the ascii (i.e. 2 = alt-50) ? If so, how would I simply send a "255" value into Arduino in serial monitor typing window?

but when I type a character in serial monitor, it is trying to send the ascii (i.e. 2 = alt-50) ?

Sorry I don't deal in decimal, it is far too hard. Use hex and the bit patterns are so much more clear.
When you type 2 it sends 0x32, type 5 and it sends 0x35.
To convert this into a number simply AND the number with 0x0F.

number = receivedChar & 0x0F;

If so, how would I simply send a "255" value into Arduino in serial monitor typing window?

You can't do it easily, you have to assemble the number. Assume you have received three characters in variables r1,r2 and r3 and you have checked that they are in the range 0x30 to 0x39. Then:-

number = (r1 & 0x0F) * 100 + (r2 & 0x0F) * 10 + (r3 & 0x0F)

will assemble the number.

For more information see:- Serial Input Basics - updated - Introductory Tutorials - Arduino Forum

Thanks again Mike. Alas I am not sure what to do with your information because I am not able to write a sketch from scratch. I am using a visual programming software called Vuo to generate RGB pixel values and am hoping someone can point me in the direction of good code to use. Probably beyond the scope of these community forums however...

I think your problem is that you are not describing what you want to do.
Please read the how to use this forum sticky post, it will tell you how to ask questions.

What is this Vuo? Please supply a link.
What do you want to do with the numbers it produces?
How many LEDs are you playing with?
Have you run the AdaFruit examples?

If you are doing anything unusual or unique you will not find pew written code, you have to write it yourself or get someone else to write it for you. If the latter post in the gigs and collaboration section and say how much you are willing to pay.

Maybe read serial input basics to get ideas.