I am trying to make a moving message board using an Arduino Uno, HC-05 Bluetooth module and DMD board. Sending message to the DMD through the Bluetooth module can only give a not more than 62 character message. I need help in what to do to get up to 200 or more. Thanks.
-
5You need to read the serial data before the buffer fills up. Do not use the serial's buffer in place of your own.– MajenkoCommented May 31, 2018 at 21:52
-
What about reading the serial buffer into a ring buffer larger that 64 bytes?– PhillyNJCommented Jun 1, 2018 at 1:37
-
I got to access the HardwareSerial through program files> arduino, till i got to it, but find it hard to implement a change, am a newbie in this stuff.– DanielCommented Jun 1, 2018 at 11:15
-
The point is, that you don't really have a good reason to modify the HardwareSerial library. You are a beginner, so start with using the library correctly by constantly reading the bytes from the internal buffer to your own big buffer in your code. You do not need to modify the library for this– chrislCommented Jun 2, 2018 at 7:33
2 Answers
First: There is no such concept of a message on the Serial bus, unless you implement it yourself. On hardware level only individual bytes are transmitted, and you don't even know, when each byte will be transmitted exactly. Since there are only individual bytes in the first place, there is no limitation on how many bytes can be transmitted.
Yes, the Serial
library has a limited buffer of 64 bytes, but as Majenko wrote it is not intended for buffering all bytes for one of your messages. It should only buffer the bytes, until the main sketch can read them from the buffer. On reading the bytes will be removed from the buffer, leasing buffer space for new characters.
The buffer size of the Serial
library can be increased by changing the numbers in HardwareSerial.h
in the following lines
#define SERIAL_TX_BUFFER_SIZE 64
#define SERIAL_RX_BUFFER_SIZE 64
But this is not really the solution to your problem. When first filling the buffer and then read the whole message you just arbitrarly constrain yourself to a insufficient solution.
Instead of waiting for all the messages bytes (and finally filling up the buffer) you should steadily check, if new bytes are available and then load them into your own buffer. You can use a delimiter byte to mark the end of a message, mostly "\n" (newline character) is used for this. Copy the bytes into your own buffer, until you read the delimiter byte. Then use the message as a whole for your application. Don't forget to clear your buffer afterwards.
The examples for the Serial
library, especially the SerialEvent
example show how to do this in your code.
-
2It gets even worse. There's no concept of a message in a serial line, but there often is in an application. Further, a serial link proxied over Bluetooth will be bunched into packets and tend to arrive in bursts. But those bursts often won't align with the boundaries between application messages! Commented Jun 1, 2018 at 4:30
The software from the transmitter can break the text you want to send into pieces of 62 characters in length and send them one by one. The receiver will save the most recent piece in a String and join it with a another String which will be storing the whole message. If you don't mind it being a little bit slower, then this is the solution for you