Arduino Mega - Using the USB

Hello

I'm making a project with an Arduino Mega and would like to, among others, use the built-in USB and one of the standard UARTs to act like a bridge for some sensors in the same way a FTDI-based converter does. Is this possible? I've searched a little, and it seems the answer is no, that the USB is solely for programming purposes, but I was hoping to be wrong.

The Mega has a ATmega16U2 microcontroller that acts as a USB-to-Serial bridge (virtual COM port). On a normal Arduino, it basically does the same thing as an FTDI converter. However, because it's a microcontroller, and not a single-purpose FTDI chip, you can flash it with any firmware you like (e.g. USB MIDI firmware like Hiduino), but you'll probably lose the ability to program the ATmega2560.

Please tell us what you actually want to do. If you really need a flexible USB connection, get something with native USB support in the main MCU, like the Leonardo/Micro, Due or a Teensy.

Pieter

Ok, I'm making a project where the mega controls some buttons and a 2x16 display, but at the same time, it should be able to connect to a PC via USB and to an external sensor using serial.

I know I could use an FTDI converter and just connect that to a regular serial port, but it seems a waste if it's possible to use USB directly. Changing board completely to be able to skip the FTDI-converter is definitely possible.

I'll take a look at the models you suggested. I just need the board to be able to function as a USB client, to bridge the USB data over to a serial port (both directions) and at the same time have enough IOs to control the display, a few buttons and an analogue input for a potmeter.

PieterP:
The Mega has a ATmega16U2 microcontroller that acts as a USB-to-Serial bridge (virtual COM port). On a normal Arduino, it basically does the same thing as an FTDI converter.

You don’t need an extra FTDI converter, the ATmega16U2 handles serial to USB communication. It’s a USB CDC virtual COM port. You can send and receive data over the connection.

Marty_DK:
I just need the board to be able to function as a USB client, to bridge the USB data over to a serial port (both directions)

That’s exactly what the ATmega16U2 does.

Pieter

So, what you're saying is that the programming USB on the Mega can also be used by my program? Preferably without reflashing the U2.. Sorry if I'm asking very basic questions here, but USB is new to me, so I'm starting with the most basic things :)

Also, can you reference any example code, by any chance?

Marty_DK: ...and it seems the answer is no, that the USB is solely for programming purposes...

The first basic sketch in the examples of the IDE teaches you how to output a sensorvalue to the serial monitor or serial plotter on the PC. Try to go through all of them. They sort of build on top of each other. Leo..

Marty_DK: So, what you're saying is that the programming USB on the Mega can also be used by my program? Preferably without reflashing the U2.. Sorry if I'm asking very basic questions here, but USB is new to me, so I'm starting with the most basic things :)

Also, can you reference any example code, by any chance?

Any of the program examples that come with the Arduino IDE that use Serial to write data to or receive data from the Arduino Serial Monitor will be using the standard USB port on the Arduino and the USB cable.

You can also write your own PC program to communicate with the Arduino using the USB cable.

...R

Wow, I can't believe it was that easy! This opens so many possibilities.. Thank you guys for helping me despite my obvious cluelessness. This works a charm!

Marty_DK:
Wow, I can’t believe it was that easy!

That’s what the Arduino is all about :slight_smile:

…R