[PYTHON] Arduino UNO: Search for the maximum communication speed of USB2 UART (1)

The maximum USB2 UART speed of Arduino UNO is 115200bps ??

It is written that the maximum UART speed of Arduino is 115200 even if I check each place, and I do not guarantee any more. However, as far as I'm trying, communication is possible even if I set 921600bps. Looking at the site below, there is also a measurement result on the oscilloscope that the communication speed itself has peaked at 500000 bps. https://arduino.stackexchange.com/questions/296/how-high-of-a-baud-rate-can-i-go-without-errors Let's measure how fast the Arduino UNO USB2 UART can actually communicate.

Arduino UNO component level limit

Here, Arduino is premised on Arduino UNO R3 (Revision 3). Let's take a look at the settings of the external OSC, ATmega328P, and USB2UART IC. The circuit diagram can be downloaded from the following. https://www.arduino.cc/en/uploads/Main/Arduino_Uno_Rev3-schematic.pdf

ATmega328P is the main microcomputer. The main clock is equipped with a 16MHz crystal. From this relationship, it seems that the UART connected to ATmega328P can be up to Max 2Mbps. If you use FTDI's USB 2 UART chip externally, you can communicate at this speed.

For Arduino ATmega16U2 is installed for USB communication (Virtual Com Port). It seems that this microcomputer is responsible for UART ⇔ USB conversion and FW writing. The main clock is equipped with a 16MHz crystal. The maximum UART communication speed here is 2 Mbps. Because ATmega328P and ATmega16U2 are connected by UART It seems that 2Mbps is the maximum speed for the entire system.

Create a communication time confirmation program

Let's create a program to measure this communication speed. A program that communicates 1 byte with each other Measure the time required to send 100 kbytes for each.

100kbyte * 2 (send / receive) * 8 (bit) / seconds = ??? bps

Arduino side transmission and reception

SpeedText.ino


#include <Wire.h>
#define BAUDRATE 500000

char buffer[0x10];

void setup() {
  Wire.begin();
  Serial.begin(BAUDRATE);
}

void loop() {
  if (Serial.available() > 0) {
    buffer[0] = Serial.read();
    Serial.write('!');
  }
}

PC side transmission / reception (Python)

SpeedText.py


import sys
import serial
import time

from StopWatch import *

datasize = 1024*100

if __name__ == "__main__":

    print("Arduino USB Speed Test")
    sw1 = StopWatch("No1")
    ser = serial.Serial()
    ser.baudrate = 500000
    com_str = 'COM3'
    ser.port = com_str
    ser.open()
    time.sleep(2)
    print("start")

    sw1.start()
    for i in range(datasize):
        ser.write(str.encode("!"))
        data = ser.read(1)
    print(sw1.name + ":" + str(sw1.stop()))
    print("finesh")

Measurement result 209.718 seconds When I calculate it, 1024 * 100 * 2 * 8 / 209.718 = 7812bps It is quite slow even though I set 50000bps.

Check the communication speed at other baud rates. Even if I set 115200bps, the measurement result is almost the same as 209.7144 seconds. When 57600bps is set, it is almost doubled to 419.4265 seconds. Approximately 3906bps So, according to the Web information, Arduino seems to be the maximum speed of 115200bps when using a USB-UART connection.

Virtual COM Port Driver can be set to 2Mbps and can actually communicate. However, I would like to investigate separately whether some communication path becomes a bottleneck.

Recommended Posts

Arduino UNO: Search for the maximum communication speed of USB2 UART (1)
Google search for the last line of the file in Python
Python> sys.path> List of strings indicating the path to search for modules