Send serial commands via USB Host

Hi all,

I want to send serial commands (like "Serial.printLn(payload)") via the USB Host 2.0. How can I implement this in my code? Is there a special command in the USB Host Library to send the Serial.printLn via the USB Host shield?

Do you have a USB Host Shield 2.0? In this case an extended library with a lot of drivers is available. There is no support for the Stream/Print interface but it should be quite easy to provide a wrapper around the cdcacm driver to provide that but with the easy implementation you loose a lot of performance.

The original Arduino Host Shield does only support very few device types (mostly HID) and no serial adapter is included.

pylon:
Do you have a USB Host Shield 2.0? In this case an extended library with a lot of drivers is available. There is no support for the Stream/Print interface but it should be quite easy to provide a wrapper around the cdcacm driver to provide that but with the easy implementation you loose a lot of performance.

The original Arduino Host Shield does only support very few device types (mostly HID) and no serial adapter is included.

I have the 2.0 version. I know there are a lot of drivers, but I can't find how to use them and implement them into my code.

I have the 2.0 version. I know there are a lot of drivers, but I can't find how to use them and implement them into my code.

Is your device supported by an existing driver? What device are we talking about?

pylon:
Is your device supported by an existing driver? What device are we talking about?

Sorry, I forgot to mention. I have a Neato XV-21 robot vacuum, it has a built in serial interface which works via USB (some kind of usb to serial converter).

I can send commands at it in a serial terminal and it gives back information etc. As far as I know it just uses the most simple SPI, but here's the datasheet of the chip which does all the USB serial communication: https://www.nxp.com/docs/en/data-sheet/LPC3141_43.pdf

The LPC3141 is not a USB to serial converter but a microcontroller which probably will do some other tasks in that robot too. Which USB driver is used on your PC if you connect that port to it?

If it useds the rather common ACM driver your lucky, otherwise I would strongly suggest that you find another way to connect to that robot. Or forget the Arduino and use a Raspberry Pi which probably contains a driver for that protocol already.

As far as I know it just uses the most simple SPI

I have no clue how you get to SPI in this regard.

pylon:
The LPC3141 is not a USB to serial converter but a microcontroller which probably will do some other tasks in that robot too. Which USB driver is used on your PC if you connect that port to it?

If it useds the rather common ACM driver your lucky, otherwise I would strongly suggest that you find another way to connect to that robot. Or forget the Arduino and use a Raspberry Pi which probably contains a driver for that protocol already.

I have no clue how you get to SPI in this regard.

If works perfectly with the default Microsoft Serial Port driver, so I guess I'm lukcy. I know that chip is a microcontroller, but the USB port goes directly to that chip. It has a built in serial interface (SPI).

If works perfectly with the default Microsoft Serial Port driver, so I guess I'm lukcy.

I'm definitely no Microsoft specialist but in my understanding the Microsoft Serial Port Driver is only responsible for an actual hardware serial interface (the chip once was 16550, no it's usually in a mainboard chip but has the same functionality).

To use a virtual serial port provided by a USB device you need an additional driver. Very common representatives of this category are FTDI, ACM, PL2303 and recently CH340, none of them has a driver originating from Microsoft to my knowledge.

The current host shield software supports FTDI, ACM, PL2303 and the rather exotic XR21B1411. If your CPU doesn't emulate one of these protocols you either have to develop your own driver or change the platform as I noted earlier.

I know that chip is a microcontroller, but the USB port goes directly to that chip. It has a built in serial interface (SPI).

SPI is a synchronous serial interface. The type of serial interface we were talking about is an asynchronous serial interface (UART style). You can use the SPI interface only if you're able to change the firmware running on that MCU.

pylon:
I'm definitely no Microsoft specialist but in my understanding the Microsoft Serial Port Driver is only responsible for an actual hardware serial interface (the chip once was 16550, no it's usually in a mainboard chip but has the same functionality).

To use a virtual serial port provided by a USB device you need an additional driver. Very common representatives of this category are FTDI, ACM, PL2303 and recently CH340, none of them has a driver originating from Microsoft to my knowledge.

The current host shield software supports FTDI, ACM, PL2303 and the rather exotic XR21B1411. If your CPU doesn't emulate one of these protocols you either have to develop your own driver or change the platform as I noted earlier.

SPI is a synchronous serial interface. The type of serial interface we were talking about is an asynchronous serial interface (UART style). You can use the SPI interface only if you're able to change the firmware running on that MCU.

There is a special driver from Neato, but that's only to update the firmware. Serial communication works fine with the default Microsoft driver. As far as I can tell it doesn't use any additional driver. The default Microsoft driver should be CDC/ACM.

And the USB connection of the microcontroller is stated as SPI in the datasheet, I don't know what they mean by it then. The chip has UART TX and RX too but they aren't connected to anything unfortunately.

But anyway, since it works with ACM, I should be able to make it work with the USB host shield right? But how can I send serial commands via the USB host shield with the ACM protocol? I can't find any examples or explanation.

But anyway, since it works with ACM, I should be able to make it work with the USB host shield right? But how can I send serial commands via the USB host shield with the ACM protocol? I can't find any examples or explanation.

The library includes an example for ACM, it's called "acm_terminal". The example simply sends every thing received on the serial interface (of the Arduino) to the ACM device connected to the USB Host Shield (and vice-versa). It's quite self-explanatory.

pylon:
The library includes an example for ACM, it's called "acm_terminal". The example simply sends every thing received on the serial interface (of the Arduino) to the ACM device connected to the USB Host Shield (and vice-versa). It's quite self-explanatory.

First of all, thank you so much for your help so far.

After trying some stuff I found out the Neato is using the RS232 protocol, not ACM... I can send commands to the Neato via Termite (a RS232 terminal) and that works fine. Is this also possible with the USB Host Shield?

EDIT: Nvm, only internally it uses RS232 I think? When connected to USB it uses ACM. But what I want to do is possible, this guy has done it before: Serial commands via usb connected to usb 2 serial device - #22 by undertoe - Hardware - Particle

EDIT2: I think the acm_example isn't working on my NodeMCU... I connected it like this:

NodeMCU running acm_example -> USB Host Shield -> Arduino Uno running code to respond to serial input

But it doesn't seem to get the commands through to the Arduino Uno. What am I doing wrong?

I would be surprise if the USB Host Shield works with a NodeMCU. It's designed to work with 5V Arduinos. If you have a special 3V3 version you should have noted that. Try to connect a mouse to the host shield and run a mouse example. Does that work?

pylon:
I would be surprise if the USB Host Shield works with a NodeMCU. It's designed to work with 5V Arduinos. If you have a special 3V3 version you should have noted that. Try to connect a mouse to the host shield and run a mouse example. Does that work?

The mini version of the USB host shield is 3.3V, you have to mod it to work on 5v (which I did to test it on the Arduino Uno).

That's exactly what I was planning to try today, I'll let you know if that works!

The mini version of the USB host shield is 3.3V, you have to mod it to work on 5v (which I did to test it on the Arduino Uno).

It would have been nice to inform us that you're not using the standard USB Host Shield V2.0.

To get us informed now, please post links to all used hardware! And post a wiring diagram!