[UNO] SerialPassthrough works but then turns into garbage

Hi,

I want to interface with a device that has a serial port (Phillips Hue Bridge).
I was hoping to use the Arduino Uno as a serial passthrough device to communicate with my computer (OSX).

It kind of works, and when booting the Hue, I can see plaintext, but it seems to get increasingly more garbled, and after maybe 20-30 lines it turns into full garbage.

I’m using the following code:

#include <SoftwareSerial.h>

SoftwareSerial hue(2, 3); // RX, TX

void setup() {
  Serial.begin(115200);
  hue.begin(115200);
}

void loop() {
  // One direction for now
  if (hue.available()) {
    Serial.write(hue.read());
  }
}

I’m connecting to the Arduino Uno’s serial port like this:

screen /dev/cu.usbmodem1441101 115200

Potentially I’m making a really dumb mistake, or maybe software serial just isn’t good enough?

I hope you are enjoying this, you will learn a lot by the time you have it working. As a FYI software serial can only work in simplex mode, transmit or receive but not concurrently. Try taking your software serial down to 9600 baud, that should help some. By taking a SWAG I think you are over running the software serial because of background interrupts, such as the timers and the debug port that is sending data to the console. I have had problems with some Arduino's software serial not working properly at 115,200 baud but fine at 9600. Many of the Arduinos use a resonator rather then a crystal, this will typically add timing error to the serial interfaces.

Thanks for your response!

I watched a video where it said the baud rate should be 115200, so that's what I picked.
What determines the baud rate? Can I choose that freely, or is that determined by the device I'm connecting to (the Hue)?

I tried lowering the baud rate, but then I didn't get any cleartext anymore...

Actually I just want to connect some serial console to the Hue device, and I couldn't think of a better way to do that then using the Arduino as a bridge. Maybe I should just buy a USB-to-serial cable instead...

dietervdw:
What determines the baud rate? Can I choose that freely, or is that determined by the device I'm connecting to (the Hue)?

The baudrate needs to be agreed on by both side. Serial is an asynchronous protocol. That means there is no clock signal that tells the receiver when the data (each bit) is valid. The receiver knows when the bits start coming because the signal stays on a fixed level before (mostly High). But then it guesses when the next bit will be valid. Because the clocks are not the same on both ends there will be an error over time. With lower bit rates the chance of error tends to get smaller. After each byte serial stops and waits for a little while before sending the next.

dietervdw:
I tried lowering the baud rate, but then I didn't get any cleartext anymore...

Because you only changed on one side.

dietervdw:
Actually I just want to connect some serial console to the Hue device, and I couldn't think of a better way to do that then using the Arduino as a bridge. Maybe I should just buy a USB-to-serial cable instead...

Just write a sketch that does not write to serial and connect the Hue TX and RX to the Arduino TX and RX. There is a second ATmega chip on the UNO that is a USB-to-Serial bridge. Check the schematic of the board in the store under DOCUMENTATION. This way the Arduino will just loop and your Hue can talk to the Serial Monitor.

https://store.arduino.cc/arduino-uno-rev3

Klaus_K:
The baudrate needs to be agreed on by both side.

I don’t think I can control the baudrate of the Phillips Hue right? I guess that’s just whatever it is programmed to be?

Klaus_K:
Just write a sketch that does not write to serial and connect the Hue TX and RX to the Arduino TX and RX. There is a second ATmega chip on the UNO that is a USB-to-Serial bridge. Check the schematic of the board in the store under DOCUMENTATION. This way the Arduino will just loop and your Hue can talk to the Serial Monitor.

This feels like a golden tip, thanks!
I assumed I couldn’t use the TX and RX pins on the Arduino because it would interfere with the working of the Arduino, but if I understand it correctly I can just completely bypass the Arduino and just use the USB-to-serial part to do the communication? That sounds like exactly what I need, will try!

Update: works like a charm! Thank you so much! :smiley:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.