USB Host Shield 2.0 - Serial Communication Via USB Cable to Client Device CP2102

I’m so confused so any assistance is greatly appreciated. I have a device that I wish to connect to my Arduino Uno/Mega/ESP8266 and communicate via serial commands. The device can connect via USB so I wish for the Arduino to be the USB host and the device the USB client.

The device has a female mini USB connection and a Silicon Labs CP2102 chip. The manufacturer gave me Serial Commands to communicate with it so I know what commands to send and how to configure the serial ports. I have the usb host shield 2.0 but I just can’t figure out how to simply connect and send serial commands over the USB cable.

I’m not sure if I’m just not searching properly or if I’m using the wrong terminology or if this is impossible to do.

Any help is greatly appreciated.

The device is CP2102

It doesn't make sense to connect a USB2UART converter chip to an Arduino Mega (by an USB Host Shield). What are you trying to achieve? Is it possible that you try to connect another device to the Mega which is using the CP2102 for the usual connection to a PC? If that's true, what exact device do you have?

The standard library for the USB Host Shield 2.0 (I guess you're using that as you didn't specify in detail) doesn't have a driver for the CP2101, by default only drivers for ACM, FTDI and PL2303 are part of the library. I found a fork of it that supports the chip but you have to check if your vendor-/product-ID is supported too and if the driver actually works.

Thank you, as I said I'm very confused so I appreciate your assistance.

I have a handheld device that we use in our everyday work - typically we plug it into a PC and upload the data at the end of the shift using the manufacturers software, which is clunky and time-consuming. My initial solution to this was to build a little application that we ran on our Android phones and this works great using this library:

The downside is someone still has to sit there with an Android phone - so I figured if I could make it work with a piece of hardware sitting on the desk (Arduino/Mega/ESP8266) that we can plug the device into and then upload the records automatically without having to use the device manufacturers software.

I know it's possible for me to do everything I need to do with the device itself and I know it operates on CP2102 driver at 460800 baud - I just can't figure out how to send/receive serial data to the device from one of my microcontrollers.

I assumed I needed the USB Host Shield 2.0 in order to achieve this, but once I started digging into it I kept seeing comments about that being over-complicated and to just use the second serial pin on the Mega.

I have now purchased just about every driver and adapter I can find on Sparkfun/Amazon and am no closer than when I started. :frowning:

TL;DR: I need my microcontroller to communicate over a USB cable via serial communication

Linux supports the cp210x chip so a raspberry pi should be able to talk to the device.

Thank you.

I know I must sound totally obtuse here, but can you help me understand what prevents the Arduino/Mega/ESP8266 that I have from doing this?

My device connects when I use the usb_desc Example so I know there is connectivity between the USB Host Shield and the client device.

What stops me from establishing a serial communication to that device from here?

There are many USB to Serial chip families such as PL2303, FTDI, CH34X, and CP210X. The USB Host Shield library does not have software support for CP210X (and CH34X). If you have the software dev skills and docs for the CP210x, you could write a driver but it is not easy.

Pylon pointed me towards this: GitHub - henla464/USB_Host_Shield_Library_2.0: Forked "USB Host Shield Library 2.0" with CP210x driver

So it looks like I just need to understand this a bit better and try to tweak it for my usage, yeah?

So it looks like I just need to understand this a bit better and try to tweak it for my usage, yeah?

With that software you might get access to the serial stream of that device. Do you know what protocol the manufacturer's software use to read the data from that device? Without that knowledge you will have a hard time to write a software on an Arduino compatible device to do the same.

Why do you still make a secret about the type and model of that "device"?

Do you know what protocol the manufacturer's software use to read the data from that device?

It uses serial commands. I can successfully communicate using a Serial Terminal on my Windows PC and my Macbook.

I think it's RS232 but I am not certain about that.

Why do you still make a secret about the type and model of that "device"?

I didn't think that would provide any benefit. It's a calibration device that is made by a small manufacturer in China - I thought the CP2102 chip was the important part.

I think it's RS232 but I am not certain about that.

RS232 is a physical interface. The CP2102 is an USB chip that emulates a serial interface on the USB bus. For PCs there are drivers to support this. for the USB Host Shield the linked library is the only driver I know of. Have you tried it with that library?

Yeah it doesn’t support the CP210X driver by default, although another user here pointed me towards a forked version of the repo it was just a tad over my head.

In the meantime, I am prototyping my device using a Raspberry Pi and will hopefully be able to circle back around and port it to the Arduino in the near future.

Lord, I wish people would answer the question at hand, not diffuse around it like "what model of hardware is that? why don't you use something Linux?". The Arduino USB-Host shield says it can offer operation with USB-Serial converters, which becomes a selling point to trying it in the first place. One would assume that means there's a library... maybe (hopefully) some documentation... on how to make that feature work.

Instead, every thread I look up on the subject has people diffusing around it, saying "why do you need an Arduino for that? Why not use {some much more complex, even more difficult to program Linux box} instead?".

Arduino's benefit is that it's simple, straightforward. Not like Raspberry Pi which boots an entire Linux kernel and has mountains of baggage carried around for media, networking, user access, partitions, etc etc etc...

Every thread I've looked up on this matter always starts off with someone asking "hey, information is lacking on doing this, has anyone done it? any guidance?", and the only replies are people hell-bent on convincing OP that they don't need Arduino or shouldn't bother. Especially the poor OP in the latter example, where OP actually put in significant effort to create a working CP210x driver, and the only response they get after untold hours of work is basically "lol but why tho?".

I've got a charger I want to control that has a USB port, comes up as USB serial of course (CP210x chip). I speak AVR for a living; very familiar with programming Arduino. Every time I touch Linux I spend a whole night just getting the thing operational. Not pleasant. Much less hassle to throw an Arduino at something.

Arduino’s benefit is that it’s simple, straightforward. Not like Raspberry Pi which boots an entire Linux kernel and has mountains of baggage carried around for media, networking, user access, partitions, etc etc etc…

The Arduino is simple and straightforward for sensors and other hardware connected directly or over I2C/SPi and the like. But as soon as it comes to USB, the Arduino is a bad fit. The baggage you claim for the Raspberry Pi is then a blessing as Linux comes with tons of drivers for USB devices.

Especially the poor OP in the latter example, where OP actually put in significant effort to create a working CP210x driver, and the only response they get after untold hours of work is basically “lol but why tho?”.

According to that thread the OP there implemented a sketch to communicate with a CP210x device, a driver is another story.
I keep thinking that connecting a USB slave device to an Arduino with a host shield is using the wrong tool for the job. I know that if the only tool you have is a hammer everything looks like a nail but don’t expect that if you ask how to open your radio screws in an expert forum the people there tell you to use a hammer just because you don’t want to buy a screw driver.

I’ve got a charger I want to control that has a USB port, comes up as USB serial of course (CP210x chip). I speak AVR for a living; very familiar with programming Arduino. Every time I touch Linux I spend a whole night just getting the thing operational. Not pleasant. Much less hassle to throw an Arduino at something.

Feel free to implement a CP210x driver for the host shield. But don’t expect us to help you using a hammer to open a screw.

I know this is kind of dated but I suppose other people will also want to know how to do this. These guys aren’t going to be much help because nobody is writing the drivers for the CP210x devices. I know exactly what this guy is talking about because I searched high and low for the same thing namely, some code to make my simple, cheap, 3421 based USB hub work with the CP210x chips. I haven’t got around to looking at Henrik Larsson’s library yet but he does say there are drivers there for that and maybe they will work for me when I figure it out.
What I finally found was a PIC that was programmed to take serial commands from my ESP’s in this case, and convert them to something the CP210x chips understand over USB. Really simple. I just wanted to talk to a handheld meter. A meter than can talk to PC’s and stuff all day. Wanted to use a $3 processor to do that, not a $700 PC or a $35 Raspberry Pi. But anyway, it doesn’t seem like it’s these guys place to try to talk us out of using their tools just because.
Anyway, this great device is sold by HobbyTronics and while it may not be so cheap in it’s breakout board form, if you have to talk to a CP210x chip with an Arduino, ESP or any small processor it makes it possible instead of a daunting task which nobody seems willing to help you with. You can also get it in the chip form so it is less expensive, <$10.

Finally got an ESP32 with the Arduino IDE working with the USB Mini 2.0 boards that I have. They actually say Du1noFun USB m1m1 v2.0. dated Aug. 16, 2014

Counted pins on DuinoFun CCW from the bottom left corner like an IC with USB connector to the left. Skipped the pads across the right end. So 12 pins on each long side. See picture here: https://www.arduino.cn/thread-81435-1-1.html

Found out from this page that my DuinoFuns had the pins mismarked. Followed the drawing here which is correct. Credit to kn1cht and philipn7 for pointing him out at: ESP32 with usb host shield · Issue #1271 · espressif/arduino-esp32 · GitHub

Use ESP32 Pins to DuinoFun Pins Signal and notes
D5 P1 SS
D23 P2 MOSI
D19 P3 MISO
D18 P4 SCLK
D17 (TX2) P23 INT
3V3 P9 3.3V
VIN (5V really 4.56) P24 VBUS
3V3 P15 RST (is connected thru 3.3K to 3V3 and directly to EN)
GND P11 GND (possilby other GND on P16)

In order for this to work, the patch was made that removes the trace between VBUS and the 3V3 power bus near the 2.2K resistor. Anyway, if wired this way, make sure P24 does not have continuity to P9. You can see an example of this patch here: https://www.hackster.io/139994/plug-any-usb-device-on-an-esp8266-e0ca8a

Next, per blog entry by hyshiah on this page: https://github.com/espressif/arduino-esp32/issues/1271 made changes to usbhost.cpp and avrpins.h. I'm not sure if this is necessary but the whole thing is really complex, how it tries to incorporate all kinds of possible boards and initialize the SPI with the right pins. This patch adds a macro

in avrpins.h to return the pin number associated with a pin name like SPI_CLK (you see them all over the place along with some function like SPI_CLK::clear(). This patch adds SPI_XXX::pinNum()) Finally, another "if" is added to usbhost.h to use the new macros to call SPI.begin() with the pins as parameters. Guess it works because it now
communicates with the ESP32.

So to use the USB Mini on the other SPI channel on the ESP32 all you need to do is change the pin assingments in the avrpins.h file. I assigned 12 to P19, 13 to P23, 14 to P18 and 15 to P5. That corresponds to MISO, MOSI, SCLK and SS. Changed the wiring to these pins and it worked. These are all dedicated pins for the SPI bus.

After getting the USBDesc example to work with this arrangement, tried the FTDI loopback example and it worked. I found all of these examples to have strange output features. Not just Serial.println() or something. Made changes to something I recognized. So finally got around to the CP210x loopback example in Henrik Larsen's Github fork of the standard USB_Host_Shield_2.0 library: Https://github.com/henla464/USB_Host_Shield_Library_2.0

All I really did was add the CP210x.cpp and CP210x.h files from Henrik's forked library and tried his CP210x loopback example. It's really just like the FTDI loopback example but with a couple different includes, etc. Worked great. I just plugged another ESP32 into the DuinoFun module with a USB cable so the first ESP32 was talking to the second one's CP2102.

Hope this helps someone who has been having trouble making this work and maybe I'll get the hang of this corkscrew editor. Really kind of a crap shoot what it looks like when you are done.

Edit: So I tidied this explanation up some, drew a wiring diagram, made an example .ino program, and zipped up my version of the library that works. You can see all this by going to my website to read or download any of it here. Hope that helps.

I know this post is from a long time ago but in case you didn't get your project going I thought I would point you to mine. I did get the MAX3421 based USBMini working with a ESP32. Talks to CP210x chips. Uses the standard libraries mostly. Find it here.

Sorry but this is the dumbest editor I have ever tried to use.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.