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.
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
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.
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.
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
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.
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?
===============================================
Software Serial Buffer Expansion
The change for software serial ports require a simple modification of the file:
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.