How to select baud rate for Serial.begin() at different wire.setClock()?

Hello,

My understanding is that Serial.begin() is for serial terminal communication between Arduino and computer, while wire.setClock() is for communication between Arduino and sensor device.

There are many data transmissions between Arduino and sensor device. only the final result is needed to pass to the serial monitor. For example, for a 4-channel sensor device, it required a lot of write/read transmission for a Arduino to get a channel data, especially for high resolution data channel, e.g. a 32-bit resolution, it needs 4 write/read to get one channel 32-bit data, and 16 write/read are required to get all 4-channel data, however, only the final 4-ch data needs to be passed to serial terminal, and the final 4-channel data can also be combined into a string, only the single string needs to be passed to the serial monitor, as a result, the serial monitor needs a lot slower baud rate for such a case. The lower the baud rate the safer the data transfer via USB port.

Can some one let me know what is the best baud rate for the Serial.begin() if the wire.set Clock is at 100 kHz?

Or how to calculate the required lowest baud rate?

I just need to pass a string with combined final data of 40-digit long at approximately 50 times per second to the serial monitor.

Thanks,
Gu

Make the Serial rate as fast as you can whilst ensuring reliable serial communication. The IDE allows for up to 2,000,000 baud if the device being communicated with can use it and if the wiring is suitable

Like Bob said. Serial.prints can block if the Tx buffer fills up see my tutorial on
Arduino Serial I/O for the Real World

Thank you. I will go through your tutorial.
Gu

Usually, text formatted data is sent to serial monitor, so 40 digits = 40 characters.

40 characters * 50 times per second * 8 10 bits per character = 1,600 20,000 bits per second or 1,600 20,000 baud.

As mentioned above, 2,000,000 baud is possible if the wiring is good enough. That's 1000 100 times faster than you need. I normally use 115,200 baud, which works with almost any wiring. That's over 100 5 times faster than you need.

You are worrying about something that's not really very important in practice.

Thank you, PaulRB,

Is there a number of bytes limit for a single Serial.print() for Arduino Uno?

Gu

There is an internal buffer of 64 bytes. If you exceed that, Serial.print becomes a blocking function.

@PaulRB , it's 16,000 bits :wink:

Hi drmpf,
It is a nice tutorial link. Thank you for your effort.

Is the number 66 in the createBuffer function an added buffer or a created buffer separately?

createBufferedOutput(output, 66, DROP_UNTIL_EMPTY);

Arduino Uno has 64 bytes buffer, as an added buffer of 66, it should make up a total 130 bytes. however, as a created buffer separately, the total should be 66 bytes for use.

Could you please clarify it?

Gu

The buffered output 66 byte buffer is in addition to the default TX 63 byte buffer on UNO to give a total ~130 (less a few bytes set aside for ~~ buffer full marks)
Due to some 'fancy' coding, writing to buffered out writes through first to the hardware TX buffer until that fills up, and only then buffers the rest in buffered output
You can use
output.getSize()
to get the combined size of buffered output and hardware TX buffering

And, each character is 10 bits, not 8, as each serial character contains a start bit, and a stop bit, in addition to the 8 data bits.

Oops! Thanks for that. Post corrected. Could not find an icon for marking text as strike through, though.

If you mean this then the current advice is to put ~~ each side of the text to get the effect. One day we may get an icon to do it

I knew that, Ray, but was keeping it simple and trying to indicate to the OP that the baud rates suggested are orders of magnitude faster than would be required. Unfortunately my mental arithmetic failed me and I was an order of magnitude out! Very embarrassing.

Ah, thanks!

Thank you, drmpf

I found another way of expending serial buffer on web "Internet of Home Things » Expanding Arduino Serial Port Buffer Size" and like to repost the important part here below between the two ======= . I checked the two folders and did find SoftwareSerial.h and HardwareSerial.h . Probably this is the easiest way of doing it.

In the IDE1.18.13, the hardwareSerial.h has following code, there are two places defining Rx and Tx buffers. I am not an experienced person in C/C++, Could you please have a look to see how to modify them?

#if !defined(SERIAL_TX_BUFFER_SIZE)
#if ((RAMEND - RAMSTART) < 1023)
#define SERIAL_TX_BUFFER_SIZE 16
#else
#define SERIAL_TX_BUFFER_SIZE 64
#endif
#endif
#if !defined(SERIAL_RX_BUFFER_SIZE)
#if ((RAMEND - RAMSTART) < 1023)
#define SERIAL_RX_BUFFER_SIZE 16
#else
#define SERIAL_RX_BUFFER_SIZE 64
#endif
#endif
#if (SERIAL_TX_BUFFER_SIZE>256)
typedef uint16_t tx_buffer_index_t;
#else
typedef uint8_t tx_buffer_index_t;
#endif
#if (SERIAL_RX_BUFFER_SIZE>256)
typedef uint16_t rx_buffer_index_t;
#else
typedef uint8_t rx_buffer_index_t;
#endif

===============================================
Software Serial Buffer Expansion
The change for software serial ports require a simple modification of the file:

\hardware\arduino\avr\libraries\SoftwareSerial\SoftwareSerial.h

Change:

__#define _SS_MAX_RX_BUFF 64 // RX buffer size

To:

__#define _SS_MAX_RX_BUFF 256 // RX buffer size

Hardware Serial Buffer Expansion
The change for hardware serial ports require a simple modification of the file:

\hardware\arduino\avr\cores\arduino\HardwareSerial.h

Change:

__#define SERIAL_TX_BUFFER_SIZE 64
__#define SERIAL_RX_BUFFER_SIZE 64

To:

__#define SERIAL_TX_BUFFER_SIZE 256
__#define SERIAL_RX_BUFFER_SIZE 256

====================================

Sure also works and is simpler, but changes the buffer size and memory usage for all your sketches, not just the current one, and can still block when it fills up. You also loose the changes next time you update Arduino versions.

My code is for just the current sketch, can be configured to never block, or to block if you wish, and outputs ~~ to let you know when some output has been dropped to avoid blocking.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.