1

On Arduino forums, there's a post where someone improved the USB communication and made it super-fast. I don't understand how he did this, and I'm trying to recreate this, but failing.

My test code

I made a simple program on Python for testing; here it's:

import serial
import sys
import datetime

ser = serial.Serial(
   port = 'COM9',
   baudrate = 26*115200, #biggest number acceptable by python
   parity = serial.PARITY_NONE,
   stopbits = serial.STOPBITS_ONE,
   bytesize = serial.EIGHTBITS
)

if ser.isOpen() == False :
   ser.open()
   if ser.isOpen() == False :
      print("Can't open serial port")
      sys.exit(1)    

start = datetime.datetime.now()
s = b'abc'*10000    
ser.write(s)    
total_len = len(s)    
end = datetime.datetime.now()    
speed = total_len/(end - start).total_seconds()/1e6    
print("Speed: " + str(speed) + " MB/s")

And I made a simple Arduino program to read:

char buf[500];

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

void loop() {
  if (Serial.available() > 0) {
     Serial.readBytes(buf, 500);
  }
}

With this, my best result was 0.2 MB/s with my Arduino mega. However, on that post, they reached 12 Mbit/s = 1.5 MB/s!!!!! This is insane!

Atemmpting to achieve their result:

Apparently Arduino libraries are different than before, so just taking their code and putting it in my arduino\avr\cores\arduino directory doesn't work. So I started trying to edit the code myself. I'm a C++ dev, so supposedly this should be doable... but...

The problem I faced

So eventually, the problem I faced was that there are two Serial communication modes (apparently) UART and CDC. The code from the forum uses CDC, while my Arduino IDE uses UART. I tried enabling CDC using:

#define USBCON

but this lead to the error:

error: #error "Targets with both UART0 and CDC serial not supported"

At this point I don't know how to continue, as I'm not a hardware expert. But I'd like your opinion on this whole thing:

  1. Is it possible to get these speeds? How?
  2. If it's, why is it not in the default Arduino library?
  3. In case there's no easy answer for the other questions, is switching from UART to CDC easy, so that I could continue my testing?
2

Is it possible to get these speeds? How?

Not without a 32-bit Arduino with a USB interface.

If it's, why is it not in the default Arduino library?

Because you can't use it on an 8-bit Arduino without a USB interface.

In case there's no easy answer for the other questions, is switching from UART to CDC easy, so that I could continue my testing?

Yes, get a 32-bit Arduino with a USB interface such as the Arduino Due that the poster of that thread used.

  • Oh, I see. So the only problem is that I'm using mega? So Due or Teensy 3.6 should be fast? Thanks for explaining! I ordered these and they're on their way :) – The Quantum Physicist Aug 26 '17 at 18:53
  • 1
    You can't use that code on the Teensy, it's a completely different system. The Teensy already has very optimized USB anyway. – Majenko Aug 26 '17 at 18:54
  • Hello again. May I ask, what's the best speed I should expect from Teensy 3.6? I got 1.15 MB/s. I was hoping of getting to the full 480 mbps = 60 MB/s. Is that possible? – The Quantum Physicist Aug 29 '17 at 20:48
  • You'd be better off asking that kind of thing on the teensy forums. I'd say 1.15MBps on a HS USB connection is fine for a bulk endpoint. – Majenko Aug 29 '17 at 21:09

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.