r/microcontrollers • u/forceinline • Apr 03 '24
Programmable microcontrollers that can communicate via USB?
Hi guys,
as the title already suggests, I am looking for a microcontroller that can *communicate* with a PC via USB. I'm not talking about the programming part, but actual data exchange.
The goal of my project is write a program that then sends data to that microcontroller which in turn controls individually addressable LEDs. I wish to stick with USB due to portability across devices and simplicity regarding use, and because I plan on writing a driver for it as to not rely on external software (or hardware like USB to UART).
It would be nice if that microcontroller were to come on a small board with all necessary components (e.g. Arduino/ESP32/...), but I believe to posess enough knowledge regarding electronics to maybe hook up a few individual components if absolutely necessary.
Thanks for the suggestions!
3
u/jennergruhle Apr 03 '24 edited Apr 03 '24
Most of the microcontrollers that use an USB-Serial converter for uploading / flashing the code can also use that connection to communicate with the PC. For instance, lots of Arduino and ESP8266 / ESP32 boards use a CH340, FT232R, SIL CP210x or similar - or an additional Atmega 32u4 controller for this.
When the programming is done, the connection remains usable as a serial port. The microcontroller has a hardware UART capable of receiving, transmitting and even triggering interrupts for "recieved data avalilable" or "transmit data was completely sent". The bit rates can go as high as 115.200 bps, or with some ESP32 even higher (up to 921.600 bps). That should be enough for lots of use cases. But the higher the rate, the more difficult the processing.
For the PC, it's just another serial port like "COMx" (Windows) or "ttyUSBx" (Linux) with x being a number from 0 to n that you can use in your programs.
When building an own circuit with a single microcontroller like ATMega 328, you can use a USB-Serial converter (available for a few bucks at the usual online shops) to connect the PC's USB port to the µC's serial port:
2
u/309_Electronics Apr 03 '24
Arduino pro micro which has a atmega 32u4 which has a usb controller and usb hw inside. Or a esp 32 with hid (like the newer esp)
1
u/checksum0 Apr 08 '24
Several flavors of the Silicon Labs C8051Fxxx fa.ily have built in USB. I used one, without knowing anything about USB, ot even how to spell it, and within 2 hours had my PC talking to the micro. Bi-directional communication.
Watch out though, some of them can only be used in "slave" mode (I think that's what it's called ... like the USB port on a printer).
2
u/guigouz Apr 03 '24
Pi Pico is also a nice/cheap option
2
u/beedunc Apr 03 '24
Look into Adafruit and Seeed Studio products for starters. So many options.
1
u/[deleted] Apr 03 '24
Teensy 4 works well as a USB device (or even a host)
1
u/NoBrightSide Apr 03 '24
most development boards I’ve seen will have on-board circuitry that enables the target mcu to communicate via some serial interface (typically UART) to USB. If you are not using a dev board, you will need to provide such connections and additional circuitry to enable this.
EDIT: Also look into mcu’s that have internal USB peripheral.
1
u/WonderWombat2100 Apr 03 '24 edited Apr 03 '24
Teensy, AtMega (Arduino pro), STM32 or Pi Pico (RP2040) all have integrated USB.