1

I am a newbie to arduino programming. I wish to send big strings which are in range of 100 to 1000 characters to my arduino uno. I saw that arduino cannot read more than 63 characters at a time.

The strings can be received in parts (~40 characters) which will be processed by my program and few minutes later they will get deleted. Then another ~40 characters will be received and the process continues till all the characters are received.

Can you please help me with this. If the question is not clear, you're free to ask in the comments. Thanks in advance :-)

6
  • 1
    Running 1000 bytes through the serial port will take quite some time: the bytes are sent one after the other. Your Arduino should just process each byte as it receives it. Commented Jun 15, 2016 at 14:34
  • Do you have any code yet?
    – Dave X
    Commented Jun 15, 2016 at 16:22
  • @EdgarBonet The bytes are commands to be executed by the machine. So processing might take long
    – dark32
    Commented Jun 16, 2016 at 8:08
  • @DaveX Do you mean the code for serial communication?
    – dark32
    Commented Jun 16, 2016 at 8:08
  • @dark32 I mean have you got any semi-working code to show what issue you are having. From the Q, it seems you can process about 40 bytes per few minutes, and you seek to buffer 2-25 commands worth of data within the Arduino. There's code in 3D printers that processes megabytes worth of serial commands on-the-fly at command-execution speed by using buffering and handshaking on the sending end. They rely on a state machine to assemble a command and its parameters from a serial stream, and don't pull data out of the the buffer until they are ready for it.
    – Dave X
    Commented Jun 16, 2016 at 15:40

1 Answer 1

2

I saw that arduino cannot read more than 63 characters at a time.

Not strictly true. The Arduino core HardwareSerial library has a 64 byte buffer, so it can only buffer up to 64 characters. If your sketch is reading the characters from the buffer whilst you are sending the characters from your PC then that limit is irrelevant. As long as you are reading the characters as fast as they are coming in.

Serial is actually quite slow (on the scale of things) and unless you're doing silly things like using delay() or long blocking loops, then reading the data fast enough is not that big a problem. If you do need more time the simplest way is just to slow down the serial data somewhat - i.e., use a lower baud rate. The slower you send the data the longer you get between each character arrives to do things.

For strings the size you are on about you are probably best off processing the data on the fly rather than storing it all then post-processing it - simply because the Arduino doesn't have much RAM, so storing large strings isn't always an option.

4
  • I do believe that it's possible to change the size of the buffer though. Which may be neccesary if only a high baudrate is possible, on a device where the execution of the messages takes longer than the receiving. In all other cases, your answer will do (:
    – aaa
    Commented Jun 15, 2016 at 15:38
  • @Paul Yes, you can always hack the core to increase the SERIAL_BUFFER_SIZE from 64 to something bigger - at the cost of more wasted RAM...
    – Majenko
    Commented Jun 15, 2016 at 15:40
  • But you'll avoid having to copy it from one buffer to another, in order to be able to receive one message at once. But indeed, if possible, another way of fixing it may be preferable
    – aaa
    Commented Jun 15, 2016 at 16:04
  • @Paul: For that, you would have to make the RX buffer public, and you would need to be ready to deal with the message not being contiguous, because it's a ring buffer. Commented Jun 16, 2016 at 11:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.