2

I was trying to evaluate the speed of communication between pc and Arduino, using this code in Arduino:

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println("Ciao Arduino");
}

and this in Python:

import time, serial

arduino = serial.Serial('/dev/cu.usbmodem1421', 250000)

time.sleep(3)
count = 0
start = time.time()
while True:
   a = arduino.readline()
   print a
   count = count+1
   time1 = time.time()
   if time1-start >1 :
      print "--" + str(count)
      print a
      count = 0
      start=time1

Wich print out how many readline() he managed to do to evaluate the speed in further project. And I realized two things:

  1. The program is working even with different baudrate
  2. and with correct baudrate(For ex. 300-300 or 250000-25000) the baudrate is irrelevant(and wrong), I mean the 300 baudrate makes 20000 readline() and the 250000 make 5000 of them.

What's the problem? thank you

  • On the Micro I can understand that being the case. You tagged Uno as well. Are you sure you have experienced that on the Uno? – Majenko Nov 9 '16 at 18:03
5

On a direct USB CDC/ACM connection (as you get on the Micro) there is no such thing as baud rate.

Any baud rate setting performed by the host (the PC) is merely an instruction to the device (the Arduino) to say "I would like you to operate at this speed", not "I would like you to communicate with me at this speed".

It is used in situations where the PC may want to set the baud rate of a real UART interface within the device, such as when the ATMega16U2 is used as a USB interface on the Uno - in that case the PC tells the 16U2 that it wants to communicate at, say, 115200 baud, and the 16U2 sets its UART (the one that communicates with the ATMega328P) to 115200 baud. The actual PC to ATMega16U2 (or ATMega32U4 in the case of the Micro) is at the native USB 2 bulk packet rate.

enter image description here

It is also used as a "reset" instruction to the ATMega32U4 - if the CDC/ACM port is opened by the PC at 1200 baud and then immediately closed again the 32U4 resets and enters the bootloader. This makes programming (usually) easy, as long as the program on the chip hasn't crashed and left the USB interface in an unusable condition (as sometimes happens).

| improve this answer | |
  • Another question: It is right to think that the native usb used with micro is way faster than the ATMega16U2? Now I am using the Arduino Uno, and it makes(at 400'000 baudrate) 2855 readline(), while the Micro achieved 20'000. – Francesco Pegoraro Nov 9 '16 at 18:53
  • 2
    No, the USB is the same on both. The bottleneck is the connection between the two chips on the Uno which runs at the baud rate you specify, and is limited to less than the rate of USB. – Majenko Nov 9 '16 at 21:50
  • Is there any difference between Android setting baud-rate when connecting to Arduino via USB/serial and putty setting baud-rate when connecting to (virtual) COM-port (Arduino again)...? – Jaroslav Záruba May 4 '17 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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