Hi,
hooking up Arduino to a terminal using RS232 Shield, when the terminal sends data over to Arduino, it always stop at 240 plus, seems to me the Serial buffer not enough to receive more than that? despite the reading as follow:
void loop() {
if (Serial.available()) {
int c = Serial.read();
}
}
how to receive data more than the serial buffer size? Thanks,
and then print it so you can check what's going on.
Serial.println(freeMemory());
When one uses an ethernet shield and the string library, memory usage can get out of hand pretty quickly, so you could be running out on unexpectedly. You should allow a couple of hundred bytes of leftover memory for transient things that happen or you will get random, unexplained failures.
You can get MemoryFree from the playground, I put it in everything I do these days. Saved my projects several times now.
This way, you can cross this item off the list of possible problems.
venngomez:
the program is quite simple, should not be using too much RAM, btw, the board is Arduino Duemilanove
Oh really? Prove me wrong...
BTW: claiming something doesn't work and posting code THAT DOESN'T SHOW the problem right away stinks! Consider yourself slapped around the head with a wet fish - numerous times.
The ATmega328 has a tiny amount of RAM, 2k, you don't want ever to concatenate strings in memory like this. Your computer may has millions of times more RAM than a microcontroller and virtual memory too...
RAM size is an issue in my old code, thanks for all those helping a newbie like me here. to eliminate this, I use a SD card to store the result, following is the new code, but it still gets only part of the data expected from the terminal, probably around 140 or a little more, looks like the serial buffer overflow? will following help:
void loop()
{
if (Serial.available()) {
int c = Serial.read();
if (c < 32) {
myFile.print(c, HEX);
myFile.print("="); // just for debugging
}
else {
myFile.print((char)c);
myFile.print("-"); // for debugging
}
}
if (!done && millis() > 60000) { // let's close the file after one min
digitalWrite(13, HIGH);
myFile.flush();
myFile.close();
done = 1;
zoomkat:
The data sheet for the chip used on your arduino should specify the buffer size of the built in serial port. I think I heard that it is 128 bytes.
Right, surprisingly Mikal Hart's NewSoftSerial works in this case, it has a buffer of 64 bytes. now I got the complete data from the terminal.
you are absolutely right! did not notice that, that's really wrong. actually i can't use Serial.println in that case as it is already connected to the terminal.
Doesn't this disable the SD before you finish the file?
______
Rob
Hi Rob,
Can you give some more tips on this? quite new to this Arduino, I close the file after one min of running the app for debugging purpose, the reading of data from terminal takes less than a second.
I've not used SD cards or that library but normally with an SPI device you raise SS (pin 13 in your case) after you have finished with the device.
That code looks like you deselect the card then close the file. If closing the file involves accessing the SD card I don't see how that can work.
OTOH if the .flush() and .close() functions lower pin 13 then it will work, but in that case there's no point you doing anything with that pin, just let the library handle it.
I see, it's a newbie's code:) my first few days in Arduino, i used it to turn a light high to signify the end of a process for debugging as well, not knowing it will cause a problem to SD. after switching my serial lib to NewsoftwareSerial, everything seems running perfectly, I can have two serial devices, one connecting to terminal, another for monitoring, thanks to everybody who answer my questions.