I'm using the Serial Monitor as a way of pasting programs to a language interpreter (uLisp).
On boards like the Arduino Micro based on the ATmega32U4 the serial hangs up if I try to paste a block of text with more than a small number of characters (about 384). I can reproduce this effect using a simple test program:
void setup() {
Serial.begin(9600);
}
int count = 0;
void loop() {
if (count%64 == 0) {
Serial.println();
Serial.print(count);
Serial.write(' ');
}
while (!Serial.available());
Serial.write(Serial.read());
count++;
}
This doesn't happen on other boards, such as the Arduino Uno or Arduino Mega 2560, so it isn't simply that I'm filling the serial buffer.
OK, in that case you will have to be a little clearer in your description.
I have tested your code (with my modification) on a Leonardo and can not reproduce the problem. All characters (I've tested sending up to roughly 2500 characters) correctly display.
Just in case: Be aware that your while(!Serial.available()); will block the code if no data is available but that should be the case on e.g. an Uno as well.
void setup()
{
Serial.begin(250000);
while (!Serial);
Serial.println("Ready");
}
int count = 0;
void loop()
{
if (count % 64 == 0)
{
Serial.println();
Serial.print(count);
Serial.write(' ');
}
while (!Serial.available());
Serial.write(Serial.read());
count++;
}
I just had a similar issue with a Micro (ATmega32U4) and reading your post gave me an idea on trying smaller text, it worked, then I thought it could be a buffer issue, so I created a small loop and printed from 1 to 100 character long on one single line, one Serial.println(), and to my surprise, they all went through, so I got back to my original Sketch and now it works...
That's all I can share since my problem is gone. No matter how many times I plug it in and load the Sketch, it always works now and I can not reproduce the problem anymore...
From discussing this problem on another forum I believe it may only affect the Arduino IDE on the Mac. I can't test this because I don't have a PC.
Please could someone with a Mac confirm they can reproduce my problem.
I have also confirmed that I get the same problem with the Arduino MKRZero, using the same test program (see my first post in this topic), except there the limit is 1024 characters.
The Arduino Zero (Programming Port) doesn't have the problem.
johnsondavies:
if I try to paste a block of text with more than a small number of characters (about 384). I can reproduce this effect using a simple test program:
I am assuming you are pasting data into the serial monitor to send it to the Arduino?
The Serial Input Buffer is 64 bytes long so 384 characters is a LOT of data.
My wild quess is that you are overwhelming the 32u4 because it sends data at the full USB speed and ignores the baud rate - so the effective baud rate may be well over 1,000,000.
Your code would need to clear the serial input buffer very smartly to keep up with that.
And, as you seem to be resending the received characters you are probably choking the serial output buffer also.
Try sending less than 64 bytes at a time and see does the problem go away?
And to identify if it is the re-sending that is causing the problem try receiving the full message before sending it back
@johnsondavies
Have you tried another terminal program instead of Serial Monitor. No idea what is available for Mac (maybe minicom is already installed).
It might be the IDE but can also be the driver.
@Robin2
Tested with a Leonardo on a PC and it has no problems at 250000 or 9600 baud. One line of 2500 characters; no CR/LF. Output below with code from reply #3. There should be 10 As, 10 Bs etc if one removes the word ready (and yes, I did count them ).
I'm more or less aware of that. From previous experiences, I thought that the baud rates did not have have to match, but that did not work at the first attempt this time
sterretje:
From previous experiences, I thought that the baud rates did not have have to match, but that did not work at the first attempt this time
Sorry. I did not mean to imply that they did not have to match - I have never tested that. But my experience is that it runs at the same (high) speed regardless of the setting. And, almost certainly, I was doing my testing with a Python program rather than the Serial monitor.
You did not imply that I did some testing in the past and thought that they did not have to match; this time however it did not work with different baudrates, so I must have been mistaken.