Electronics > Projects, Designs, and Technical Stuff
Can Arduino carry data over USB?
Ben321:
--- Quote from: NiHaoMike on November 12, 2019, 01:29:58 pm ---
--- Quote from: Ben321 on November 12, 2019, 08:34:21 am ---Why not just send binary data over serial? Serial ports support 8-bit bytes, and rates up to a couple megabits-per-second (at least when using a modern USB to serial converter). Of course, I don't know if Arduino supports 8-bit bytes, or if it is limited to 7-bit bytes (text mode only). And I'm not sure what its data rate limit is.
--- End quote ---
Framing - knowing when one packet ends and the next begins - can be a problem if you don't have an "out of band" value to use as the frame delimiter. The link I posted earlier describes ways of encoding that leaves room for out of band framing.
--- End quote ---
One thing that is guarantied with a serial port (whether native serial on a mother board, or serial-over-USB) is that every byte sent gets received, unless the physical cable gets disconnected. As for making sure the entire set of bytes in your data set is recognized properly is to prepend your raw data with a 4 byte header. That header is an unsigned 32bit integer that tells the number of bytes following the header will be your data packet. Then encapsulate everything within those simple packets, everything from control signals to data transfer. Basically when using serial, you need to create your own protocol, but fortunately that is simple. You just need to write the software at each end of the connection and program it to use your protocol.
Psi:
--- Quote from: imo on November 08, 2019, 04:57:58 pm ---Even an atmega8 can transfer data via USB..
--- End quote ---
Technically a ATTiny85 can transfer data over Ethernet :-DD
mikerj:
--- Quote from: NiHaoMike on November 12, 2019, 01:29:58 pm ---
--- Quote from: Ben321 on November 12, 2019, 08:34:21 am ---Why not just send binary data over serial? Serial ports support 8-bit bytes, and rates up to a couple megabits-per-second (at least when using a modern USB to serial converter). Of course, I don't know if Arduino supports 8-bit bytes, or if it is limited to 7-bit bytes (text mode only). And I'm not sure what its data rate limit is.
--- End quote ---
Framing - knowing when one packet ends and the next begins - can be a problem if you don't have an "out of band" value to use as the frame delimiter. The link I posted earlier describes ways of encoding that leaves room for out of band framing.
--- End quote ---
Fixed length frames makes framing very easy, though can introduce other problems.
ejeffrey:
--- Quote from: Ben321 on January 03, 2020, 06:01:27 am ---
--- Quote from: NiHaoMike on November 12, 2019, 01:29:58 pm ---
--- Quote from: Ben321 on November 12, 2019, 08:34:21 am ---Why not just send binary data over serial? Serial ports support 8-bit bytes, and rates up to a couple megabits-per-second (at least when using a modern USB to serial converter). Of course, I don't know if Arduino supports 8-bit bytes, or if it is limited to 7-bit bytes (text mode only). And I'm not sure what its data rate limit is.
--- End quote ---
Framing - knowing when one packet ends and the next begins - can be a problem if you don't have an "out of band" value to use as the frame delimiter. The link I posted earlier describes ways of encoding that leaves room for out of band framing.
--- End quote ---
One thing that is guarantied with a serial port (whether native serial on a mother board, or serial-over-USB) is that every byte sent gets received, unless the physical cable gets disconnected.
--- End quote ---
That assumption is a good way to create an unreliable product. Unless you have an out-of-band way to reset the device into a known state (such as by togging GPIO on the USB->serial adapter like the arduino) your microcontroller doesn't actually know when the "cable is connected." Also, even after connection, if the device sends data before the host application opens the port the OS will drop the data. Its really best to use explicit frame synchronization always. Then if your host and device ever get out of sync they can resynchronize after a single message. There are plenty of simple ways to do this depending on what data you need to transmit and what overhead is acceptable.
Mechatrommer:
i've done that binary data transfer in packets (64 bytes per packet for most efficient/speed transfer iirc, nearly 8KB of total data per capture) but sadly the code is in asm and you need to work closely with FTDI API on PC client side to do handshaking before any data is to be transferred reliably http://soasystem.com/eng/amla/index.htm ... provided your arduino board is using FTDI chip, not the CH341 (not sure and never tried on that china serial IC). if you transfer in HEX format, you'll have double (or more depending on what HEX format you use) the size to transfer compared to raw binary. you better just get on with standard serial communication library provided by the arduino if you only need/want to send ASCII (8 bits per byte compared to 16 bits per byte/data/character in HEX format). fwiw...
Navigation
[0] Message Index
[*] Previous page
Go to full version