Electronics > Projects, Designs, and Technical Stuff

Can Arduino carry data over USB?

(1/3) > >>

Ben321:
From what I've ready about it, the Arduino USB port seems to just be used to update your program, so you write the program on the PC and then upload it over USB to the Arduino. I'm wondering something though. Can that same port be used to transfer data to an Arduino running a program? Let's say I want to use an Arduino as interface between an external sensor, and my PC. The data pins on the Arduino can obviously collect digital data from the external sensor's analog-to-digital converter, and then I want to send that data from the Arduino over USB to my PC, which will be running software that will collect that data and log it (save the data to a file on the harddrive). Is this possible? Or do I need another board (shield board) that adds another USB port to the Arduino, rather than using its main USB port?

ejeffrey:
Yes.  The USB port acts as a regular serial port.

rstofer:
Tools->Serial Monitor is the console device in the IDE that uses the USB COM port of the Arduino.
How you format the data is up to you.  It is best if the data can be displayed as plain text on the Serial Monitor but it isn't required.

NiHaoMike:

--- Quote from: rstofer on November 08, 2019, 12:19:44 am ---How you format the data is up to you.  It is best if the data can be displayed as plain text on the Serial Monitor but it isn't required.

--- End quote ---
That's actually a very inefficient way to pack the data. It works if the data rate is low, but it's worth learning some better encoding schemes.
https://en.wikipedia.org/wiki/Binary-to-text_encoding
For a beginner, I suggest encoding the data as hex. It's straightforward to understand and leaves a lot of symbols left over for out of band communication. For example, you can use a newline character to denote the end of packet.

Renate:
Aw, if you're using an AVR8 to connect a sensor over USB there are better ways than using a serial over USB.
It would be better to use an AVR8 with a USB interface, like a ATMega32u4 (Leonardo in Arduino-speak, I think).

Using serial over USB gets into problems of framing/waiting for the 0x0a (newline or whatever).
Use the USB HID sensor protocol.
Ok, you don't have to get too serious about the descriptors, just make send things in regular HID reports.
Neat, clean, you never get half a report, like with serial over USB.

The one exception to all this is if you want/had to use a serial optoisolator, in which case serial out of the AVR8 to isolator to FTDI would work.
You could also use a USB optoisolator too.

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod