Arduino Micro baud rate for Serial through USB [SOLVED]

Hello

I have problems with sending serial data through the USB with the correct baud rate with an Arduino Micro.

Background:
I'm trying to send data through the USB port to a Hatteland Screen/PC running Windows 10. Hatteland is using their SCOM protocol with 9600 baud rate.

This is my code:

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  delay(1000);
  // generate some test data
  data = data ^ 0xFF; // Toggle between 0x00 and 0xFF
  // Create BZZ message
  createBZZMessage(data, BZZ_str);
  for (int i = 0; i < 9; i++) {
    Serial.write(BZZ_str[i]);
  }
  delay(500);
}

void createBZZMessage(uint8_t data, uint8_t *destiantion) {
  uint8_t ATTN = 0x07;
  uint8_t ADDR = 0xFF;
  uint8_t CMD[] = {0x42, 0x5A, 0x5A}; //BZZ
  uint8_t LEN = 0x01;
  uint8_t IHCHK;
  uint8_t DATA;
  uint8_t IDCHK;

  // calculate checksum(s)
  IDCHK = ~data;
  IHCHK = ~((ATTN + ADDR + CMD[0] + CMD[1] + CMD[2] + LEN) % 255) + 1;

  destiantion[0] = ATTN;
  destiantion[1] = ADDR;
  destiantion[2] = CMD[0];
  destiantion[3] = CMD[1];
  destiantion[4] = CMD[2];
  destiantion[5] = LEN;
  destiantion[6] = IHCHK;
  destiantion[7] = data;
  destiantion[8] = IDCHK;
}

I have tried the exact same code on an UNO and it works without any problems. So I know that the code is correct. So I'm suspicious if it could be the baud rate.

Strange behaviour:
When I use RealTerm I can read the data from the Micro regardless what baud rate I'm setting in RealTerm. On the UNO I can only read the data at the correct baud rate (9600).

Why can I sniff the data no matter what baud rate I set and could that be a part of the problem I'm having?
Is there any way to only send at 9600?

Apologies

PS
I'm quite new to programming and Arduinos. I've tried searching for someone with a similar problem to me but I might not have used the correct search terms so forgive me if it's already been answered.

For boards with native USB (like your Micro), the baudrate is irrelevant.

Which problem?

One possible pitfall for boards with native USB is that you have to wait till a communication channel is opened; that happens e.g. when RealTerm opens the port.

To make sure that you don't send data before the communication channel is open, add while(!Serial) to setup()

void setup()
{
  Serial.begin(9600);
  // wait till communication channel opens
  while(!Serial);
}

This is not because of the USB connection, but because of the 'classical' UART serial connection between the 328P processor and the serial-USB converter on the UNO board.
The Micro has a native USB hardware, so there is no such UART connection.

Aha, that might explain why the code is working on the UNO but not on the Micro.

Is there a way to go around this? To get the native USB act like an UART serial connection?

I will search the forum as well to see if someone have tried something similar. I'll post the solution if I can find it.

You still have not said what your problem is.

It acts like a serial connection.

Assuming that while(!Serial) did not help you: your Micro has a UART on pins 0 and 1; add a TTL-to-USB converter (e.g. https://www.sparkfun.com/products/9716).

1 Like

Sorry for the delay, I've been trying your suggestion and looking to see if I've done anything else wrong. But I have not made any progress yet.

I am new to this, I will try to formulate my problem correctly.
Let's see if I succeed:

Short version:
My code for sending data to a Hatteland PC monitor works with UNO but the same code does not work on Micro.

Long verstion:

I am trying to send the data from Arduino Micro to a Hatteland PC monitor (HD16T30) via USB.
The Hatteland has it's own serial protocol SCOM and the baud rate should be 9600.
When I upload my code to a UNO everything is working correctly. Hatteland receives the data and can read it (I am sending data to make a buzzer toggle on and off).
The problem is that the same code does not work with Arduino Micro.
I was suspecting that it had something to do with the baud rate.

I am also using RealTerm to sniff the data.
On the UNO I need to set the baud rate to 9600 to capture the data.
But when I sniff the data on the Micro I can set the baud rate at any rate and it does not matter. I can read the data anyway,
(feels like I'm not doing a good job explaining my problem)

The Hatteland seems to be an intelligent device. It might be that it does not have a driver for the Micro.

Can you see on the Hatteland if devices connected to the USB port are recognised?

First off, thank you for helping me.

The Hatteland is running Windows 10. I have used the Micro to program a joystick-mouse with the help of HID library and it is working fine. Is that a sign that I have the right driver or is it different from sending serial data?

When i just run the code I've posted I can see the Micro as a COM port and use RealTerm on Hatteland to sniff the signal. I can see all the data (no matter what baud rate I set in RealTerm).

I migh be hung up on the baud rate but that's the difference I can pick up between the UNO and Micro when I use Real Term. I think that if I can send the data with a baud rate of 9600 to Hatteland it should recognize the signal as SCOM (like it does on the UNO).

I'm not sure, a little outside my league; but I think it's not an indication of the correct driver. Below screenshot of a Arduino Micro in Device Manager.

Do you have a normal PC? Can you check your code on there?

One comment in the user manual:

The SCOM port is COM1; do you have anything connected to COM2?

I've had a look at the driver and I tried updating them inside the properties window but it said I had the latest ones. The file version is 10.0.17763 (WinBuild 160101.0800). I also tried a Windows Update but no luck so far.

I have tried just having the Arduino connected after a restart but still nothing. I tried different ports as well.

As I've mentioned before I think it is strange that everything works great with Arduino UNO but not with Arduino Micro (with the exact same code I've posted in the beginning). It might be like MicroBahner says: The Micro has a native USB hardware, so there is no such UART connection.

I might have to read up on the difference. I'll see if I can comprehend anything from Atmels datasheet for 32U4. Or if there is something with how a hardware USB sends the data in comparison with UART.

I have a connection that might be able to temporarily help me write a code to collect the data from the com that the micro is using (like RealTerm). Then I can send that data to COM1. But it feels like a bad workaround :upside_down_face:

That's far outside my area of expertise.

Is my understanding correct that you have RealTerm running on the Hatteland and that that works? If so, I would contact Hatteland about the issue. As I mentioned in post #5, there is a real UART on pins 0 and 1; just needs a TTL-to-USB converter.

You can abuse your Uno for that.

  1. Keep the Uno in reset with a piece of wire between the reset pin and GND.
  2. Connect the Uno's TX to the Micro's TX, Uno's RX to Micro's RX and GND to GND.
  3. Modify your sketch to use Serial1 and upload to the Micro.

Uno should obviously be connected to a USB port on the Hatteland.

I have been in contact with Hatteland and I've gotten some help but I think I have a little bit of a special case so I'm guessing they don't want to put too much resources my way.

Yes, I have RealTerm running on the Hatteland and I can get the exact data I want. But the Hatteland software I'm using can only interpret the UNO and not Micro. I've asked for a different software from Hatteland but I haven't gotten any respons yet. So I think my next option is to have a programmer make a Serial Bridge software that can take the data from the Micro and send it as a SCOM to COM1 on the Hatteland.

From the little knowledge I have i would guess it all comes down to the data sent either though UART (UNO) or as USB (Micro). And, all though, RealTerm can read it. The Hatteland software can not.

I will contact Hatteland if I find a solution so they might make an update to their software. And if I find a solution that will help someone with another project I will post it here.

I want to thank you so much for helping me out in the process.

Mean while I found this:

The whole concept of Baud Rate with USB communication is completely meaningless. There is no such thing as "baud rate" over USB.

You don't need somebody to make a serial bridge.

I've provided a temporary solution in post #11 using your Uno and a permanent one in post #5 using a converter.

Thank you
I wanted to use your solution in post#5. I think it's a great option but I'm working with another person I can't persuade. I told him "connect one cable = solution;" but all I got was "does not compute". :wink: (I think he doesn't want to use any other physical port on the Hatteland or add a cable to carry the UART signal)

Jokes aside, for anyone reading this looking for information I would recommend the solution in post #5.

And, again, thank you for your help!

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