UNO Q Serial Monitor, strange output

Experienced strange output in a complex motor controller sketch. So I wrote the following sketch to see what happens. Same garbled output.

#include "Arduino_RouterBridge.h"
int a = 0;
int b = 1;

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

void loop() {
  // put your main code here, to run repeatedly:
  Monitor.print("a = ");
  Monitor.println(a);
  Monitor.print("b = ");
  Monitor.println(b);  
  Monitor.print("a + b = ");
  Monitor.println(a+b);  
  a += 1;
  b += 1;
  delay(1000);
}

Screenshot Output in AppLab:


Screenshot Output in Arduino IDE:

Any idea, what's wrong

If you upload your sketch by Arduino IDE, output will be perfect

Unfortunately not, see screenshot above. Did you use Serial.println()?

Why not Bridge.begin(); code?

Message/data from MCU goes to MPU through router bridge and then goes to Console>>python over the USB-C/USB-A connector.

I wanted to port a more complex sketch for motor controller from Uno to Uno Q.
This is only a test for calculations and output in the Serial Monitor.
Bridge.begin() alone did not change the situation with wrong end of line commands.
I will try data relay to Python and output in the shell later.

And I will try SBC mode.

Follow SSS (start with Small Step) Strategy to see success!

Hi @legoexpert2011. I think you are encountering this bug:

The developers are working on a fix:

If you have a GitHub account, you can subscribe to that thread to get notifications of any new developments related to this subject:

Thanks, I subscribed

I also had lots of issues with printing out results. Here is what worked for me:

void setup() {
  Monitor.begin();
  delay(1000);

}

Give Monitor a chance to get its act together.

Get rid of the println’s since they don’t appear to work.

Use this instead:

    Monitor.print("******************\n");
    Monitor.flush();

Get rid of all ambiguity to avoid shuffling outputs as follows: Compose your string, then print it out.

    String tm_out = "Elapsed time = " + tm_elt + "\n end loop\n";
    Monitor.print(tm_out);

instead of something like:

Monitor.print("Elapsed time = ")
Monitor.println(tm_elt)
Monitor.println(" end loop")

Good luck.

Thanks for your support.
Unfortunately, the line feed with "\n" did not work. See photo

And here the code snippet:

  printout = "Code = " + String(code) + "\n";
  Monitor.print(printout);
  delay(500);
  Monitor.flush();
  int forward = int(code/1000);
  printout = "forward = " + String(forward) + "\n";
  Monitor.print(printout);
  delay(500);
  Monitor.flush();
  int curve = int((code-1000*forward)/10);
  printout = "curve = " + String(curve) + "\n";
  Monitor.print(printout);
  delay(500);
  Monitor.flush();
  int button =  int((code-1000*forward) - 10* curve);
  printout = "button = " + String(button) + "\n";
  Monitor.print(printout);
  delay(500);
  Monitor.flush();

The good thing is: all this is preliminary code. Overall objective is a remote control of a robot car, where a 5-digit-code must be split into 3 components for "forward", "curve" and "button". I could see that this works properly.

Thanks again.

The C-code for Linefeed/Newline character is '\n' and NOT "\n".

Does not make a difference. Neither as part of the string concatenation nor as stand-alone print statement.
Conclusion: FIFO and line feed are not yet working properly.

curious,
what happens if you replace all the '\n' with '\r' ??
Monitor.print("loop\r");// seems to work..
~q

Much better. Thank you. :slightly_smiling_face:
However, FIFO still has some hick-ups (random). See ScreenShot.


"Code - forward - curve - button" is one block per iteration.

watch out for any println's..
seems like \n blows it up??
~q

void Code(int code)   {
  printout = "Code = " + String(code) + '\r';
  Monitor.print(printout);
  delay(300);
  int forward = int(code/1000);
  printout = "forward = " + String(forward) + '\r';
  Monitor.print(printout);
  delay(300);
  int curve = int((code-1000*forward)/10);
  printout = "curve = " + String(curve) + '\r';
  Monitor.print(printout);
  delay(300);
  int button =  int((code-1000*forward) - 10* curve);
  printout = "button = " + String(button) + '\r';
  Monitor.print(printout);
  delay(300);
  printout = "\r";
  Monitor.print(printout);
  delay(300);
}

Now, this part is excellent. Printout as expected, Code seperated in its components.
No println(), an empty line produced with
printout = "\r";
Monitor.print(printout);

But here, the code stems from the Python program through the Bridge. The overall objective is a remote control with HC-12 (433MHz). That's another issue.

Thanks

sorry can't help with the python..
but i would try ending the lines with carriage returns, like we are printing..
i'm sure it's being worked on..
~q

If anyone is curious..
I've been looking real hard at this for few days now..
println calls monitor write twice not necessarily a newline issue..
1st call we get the string..
the next call has 2 chars, i haven't bothered to check i'm sure it's just a newline and carriage return..
i think i'm starting to get my bridge to a stable state..
i would like to override println and see if I can get that to just one call to write??
my write is tight, blocking with the mutex, current code is loose..
need more testing time myself..
my test sketch..

#include <Arduino_RouterBridge.h>

void setup() {
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);
  Monitor.begin();
}

void loop() {
  static unsigned long count = 1;
  Monitor.println("Start of loop..");
  Monitor.print("Loop:"); Monitor.println(count);
  count++;
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);
  Monitor.println("End of loop");
}

results thus far..
orig bridge on left, modified on right..

sorry.. ~q

I've determined it's probably somewhere else..
Quite easy to see add a k_msleep(10) to the top of monitor write..
After taking out my debug prints, it went sideways..
If I insert a 10ms delay, added it to the end before releasing mutex then it all got better..
Was my first test to try this morning, installed orig code and added the delay..
added it to the top..
cleaned it right up..
println does try to clobber with two quick punches..
the other end not fast enough??
or we need a sequence added..
just another episode of as the code compiles..
src.zip (11.3 KB)

sorry.. ~q