3

This is really a two part question. I have an ESP8266 hooked up to USB. I have connected my LED strip (WS2812B LEDs) to the RX port, so I can control them individually and so on. I realised WiFi is a bit slow and will eventually crash the ESP8266 if I send enough requests, which is why I want to give serial a go.

  1. If I open up the serial monitor, how do I send something to it, such as a color or 100 colors in one command? I'd assume Serial.read() inside a Serial.write() would display whatever I type in, but it doesn't do that. I can Serial.write() inside a loop, and it will display that.
  2. Is something like this even possible? I'm looking for a way to send a lot of information (could be 100 colors (1 per LED)) as fast as possible. Speed is the key here.

Software serial is an option as well, as long as it's faster than WiFi.

  • what are the LEDs saying that you need to listen to them? ;) do you need RX? – dandavis Mar 27 '17 at 8:56
  • Are you suing the NodeMCU eLua-based firmware or the ESP8266 Arduino Core? – Edgar Bonet Mar 28 '17 at 8:32
  • @EdgarBonet Arduino :) – MortenMoulder Mar 28 '17 at 17:01
5

Regarding “I have connected my LED strip (WS2812B LEDs) to the RX port”: If you connect an LED strip to the RX pin, there's a good chance you won't be able to read serial data reliably on that pin, and may have trouble loading new sketches. It makes sense to connect the LEDs to some pin other than RX.

Regarding “If I open up the serial monitor, how do I send something to it”: Ordinarily, one uses the serial monitor to receive data from an attached MCU or to send data to the MCU. (An MCU is a microcontroller – eg an Arduino or ESP8266.) In the sketch on the MCU, use Serial.write() to send binary data to the monitor, and Serial.print() to send text and formatted numbers to the monitor.

If you want to send serial data rapidly from your host computer to the MCU, write a C or Python (etc) program that opens a serial port, marshals the data, and sends it. In the sketch on the MCU, use Serial.available to test if characters are available to read, and Serial.read to read a character. For faster transmission, you can send binary data instead of ASCII, but would need to read up on that before attempting it.

For fast data transmission, aim for either high data rates or strong data compression. For example, you might make up a protocol that only sends colors for pixels that are going to change; or might have high-level commands that tell the MCU how to generate a set of data, via color end points, step rates, and numbers of steps.

In general, wifi data rates are somewhat higher than serial data rates. If that is not what you are experiencing, perhaps review the article Found a way to upload data VERY fast by wifi from github.com/esp8266.


Edit 1: Regarding “Nothing is displayed in the serial monitor” [from code like if (Serial.available()) { Serial.write(Serial.read()); }]: I'm assuming that the sketch in use has a setup() routine containing a Serial.begin(somedatarate) statement, with the same data rate selected in the serial monitor as in the Serial.begin() statement. I'm also assuming the sketch has a loop() routine containing the if (Serial.available()) { Serial.write(Serial.read()); } code.

I'm also assuming the sketch was properly downloaded, and then the serial monitor was opened, using the USB-serial port the ESP8266 is attached to, and then you typed some text into the text entry box of the serial monitor and pressed or clicked Enter to send the text to the ESP8266, with a proper setting for the end-of-line character.

If all those assumptions are correct, but nothing shows up in reply to the text you send, then it seems likely some hardware or software issue is occurring. For example, when the Serial data structure is set up (when the sketch begins running) it might be selecting an incorrect Rx pin. Or something may be loading down the Rx pin. To find out if either of those is the case, use an oscilloscope (if you have one) to look at what's arriving at different ESP8266 pins when you send text from the serial monitor. If no scope, connect a 5K-10KΩ resistor to an LED and use that as a logic probe. One end of the resistor connects to a probe; the other end goes to the LED anode; and the LED cathode is grounded. Test if that's working by touching the probe to +3.3V. When the probe appears to be working ok, use it to check for brief flashes of data at different Rx pins on the ESP8266 when you send data from the serial monitor. If no data gets to the ESP8266, it can't echo it. (Note, I'm not sure how your NodeMCU ESP8266 handles serial-via-USB data; my notion that serial data should be visible on some Rx pin might be wrong.)

If it appears data is getting to some pin but isn't showing up as available, you might try opening software serial on that pin. Some examples appear in code in a serial monitor note at github.com/esp8266. I don't know enough about NodeMCU / ESP8266 to say what to do if probing and software serial don't help.

  • Thanks a lot for the reply! I am using NeoPixelBus which automatically sends the data to the LED strip through the RX pin (because I use NeoEsp8266Dma800KbpsMethod and couldn't get any other to work). In my void loop(void){} function, I can write if (Serial.available()) { Serial.write(Serial.read()); } right? If I then input something into the Arduino IDE serial monitor (like 0xff0000) it should write that in the monitor right after, right? Because that doesn't seem to work. – MortenMoulder Mar 27 '17 at 9:30
  • “Doesn't seem to work” is what symptoms? No LEDs lighting up? No serial monitor output at all? Wrong monitor output? If the latter also try Serial.print(Serial.read());. Note, I'm assuming RX is pin D3. You might put LED strips on several pins at once, eg D2 as well as D3, while trying to find a Neo Esp method that works. Perhaps detach LED strips while trying out Serial comms – James Waldby - jwpat7 Mar 27 '17 at 19:04
  • "Doesn't seem to work" meaning nothing it displayed in the serial monitor. The LED strip is hooked up to GPIO03/RXD0. Check out this image (bottom right) – MortenMoulder Mar 27 '17 at 19:57
  • I added some paragraphs in Edit 1 that might help, but I don't really know what the problem is due to. – James Waldby - jwpat7 Mar 27 '17 at 22:13
  • Thanks a lot for the reply! As far as I remember, I had to remove all the serial commands from my Arduino code before I could get the LED strip to work (in the first place). It's really bugging me why it won't work properly. Do you happen to have any kind of guide I can follow (that you know works), which allows me to enter something like 0xff0000 into the serial monitor console and read it straight back in the console? Not even a guide, just some code that works on the ESP8266. – MortenMoulder Mar 28 '17 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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