Communicating with ESP32 microcontroller to phone via USB cable

Thread Starter

zazas321

Joined Nov 29, 2015
926
Hello. In my project, I need to have a wired connection between the phone and the ESP32 microcontroller.

I would like to achieve the same results as if I connect the ESP32 to the PC. When the ESP32 is connected to the PC via the USB, it is recognised as a COM PORT and I can send serial data to my microcontoller via the Terminal and communicate with it without any problems.

On my phone, I have downloaded the following APP : https://play.google.com/store/apps/details?id=de.kai_morich.serial_usb_terminal&hl=en&gl=US

I have connected one end of cable to my phone and the other end of the cable to the ESP32. I have powered up the ESP32 via the external 3.3V. Unfortunately, on the APP, the serial device is not detected.


I would like to know what could be wrong and how to properly do it. Is this possible that both my phone and ESP32 is acting as slave and hence it will not work? How to fix this issue if that is the case?
 

Jon Chandler

Joined Jun 12, 2008
56
If your phone has USB-To-Go, you'll need an adapter cable that converts the phone's micro-B or C connector to a USB-A connector and a standard USB-A to mirco-B connector to connect to the ESP32. Not all phones support USB-To-Go and you may have to enable it under settings.

With an ESP32, you could also use a Blurtooth terminal emulator on your phone and modify the ESP32 to use Bluetooth.
 

Thread Starter

zazas321

Joined Nov 29, 2015
926
If your phone has USB-To-Go, you'll need an adapter cable that converts the phone's micro-B or C connector to a USB-A connector and a standard USB-A to mirco-B connector to connect to the ESP32. Not all phones support USB-To-Go and you may have to enable it under settings.

With an ESP32, you could also use a Blurtooth terminal emulator on your phone and modify the ESP32 to use Bluetooth.

Does that mean that ESP32 also has to support USB to go? Because ESP32 does not support this from what I know.
Also, this may be too complicated as this required additional steps as you have mentioned ( checking if the phone supports OTG, enabling options and etc.. )

Ideally there should be NO additional setup required, a person should just plug USB cable to ESP32 and phone and communicate via the serial without the need to do anything else. Is that possible? It is okay if there is a hardware modifications as long as the person does not need to worry about any settings and etc

Regarding the Bluetooth, this would not work in my case because for the final product, there will be a custom APP on the phone and it will work on serial commands. At the moment, I want to simply test it with a simple USB terminal if I can achieve some sort of communication.
 
Last edited:

Yaakov

Joined Jan 27, 2019
3,930
In spite of appearances, you are more likely to find using a cable more complicated and difficult than using Bluetooth.

Classic Bluetooth and BLE offer serial profiles (UART services), so it is perfect for your custom app.

This article might help. I think starting with the wire is foolish economy. Even if you make it work in one case, making it work consistently is probably not going to happen, and your zeroconf requirement is exceedingly unlikely.
 

Thread Starter

zazas321

Joined Nov 29, 2015
926
If this was my choice, I would use BLE to communicate with the app and not worry about anything else. Unfortunately, this is the requirement and the device must be able to communciate in 3 different ways (BLE, WiFi and Serial). A person can choose whichever method he wants. I believe the default method will be Serial but other methods will also be implemented. In short: I must be able to communicate when the BLE/WiFi is not working.
 

Yaakov

Joined Jan 27, 2019
3,930
Well, I can't be sure, but as far as I understand it, you will have to build custom hardware to interface the ESP32 to the phone. iPhones and Android phones will have very different requirements.

The zeroconf requirement doesn't seem achievable without custom interface hardware.
 

Thread Starter

zazas321

Joined Nov 29, 2015
926
I see. I hoped that this would work in a simmilar way as the ESP32 to PC connection. I simply plug the USB cable to the PC and I can see the serial port and can communicate through it.

Is that not the case with the phone?
 

Yaakov

Joined Jan 27, 2019
3,930
It is completely different for the phone. In the case of the PC, you are using USB with an environment that has drivers to handle the virtual serial device provided by the cable. The phone doesn't have anything like that.
 

BobTPH

Joined Jun 5, 2013
4,236
That app, if I understand it, should allow you to talk to the ESP32 serial line through a serial to usb adapter, exactly like you do on your PC. i.e. phone connects to adapter connects to ESP via TX and RX. It sounds like you are trying to connect USB to USB. That is not what it does.

Bob
 
Actually, USB-To-Go works exactly the same as a PC. The phone is a USB host device.

But this is an Android-only feature, and is not available on all Android phones.
 

Yaakov

Joined Jan 27, 2019
3,930
Actually, USB-To-Go works exactly the same as a PC. The phone is a USB host device.

But this is an Android-only feature, and is not available on all Android phones.
While it might be the case, I was not aware of native drivers for USB UART emulators as part of USB-to-Go implementations. I thought it did HID and mass storage.
 

BobTPH

Joined Jun 5, 2013
4,236
While it might be the case, I was not aware of native drivers for USB UART emulators as part of USB-to-Go implementations. I thought it did HID and mass storage.
The app he linked to is the driver.

This app supports USB to serial converters based on
- FTDI FT232, FT2232, ...
- Prolific PL2303
- Silabs CP2102, CP2105, ...
- Qinheng CH340, CH341
and devices implementing the USB CDC protocol like
- Arduino using ATmega32U4
- Digispark using V-USB software USB
- BBC micro:bit using ARM mbed DAPLink firmware
Bob
 

Yaakov

Joined Jan 27, 2019
3,930
So USB-to-Go might be an Android solution, but it won't work for iPhone which can use hardware solutions to connect peripherals via the Lightning connector.
 
While it might be the case, I was not aware of native drivers for USB UART emulators as part of USB-to-Go implementations. I thought it did HID and mass storage.
I quite assure you, it IS the case. I have used terminal emulators on Android to communicate to CH340 USB chips tied to PIC microcontroller as well as various ESP8266 AND ESP32 devices.
 
USB-To-Go supports many types of devices natively – keyboards, cameras, USB thumb drives, some printers, etc. I plugged in a USB hand-held barcode scanner and it worked instantly. It's an extremely convenient feature to have available.
 

Yaakov

Joined Jan 27, 2019
3,930
USB-To-Go supports many types of devices natively – keyboards, cameras, USB thumb drives, some printers, etc. I plugged in a USB hand-held barcode scanner and it worked instantly. It's an extremely convenient feature to have available.
All of those but the printer are HID or mass storage. I didn’t realize it had native support for UARTs, though.
 

Thread Starter

zazas321

Joined Nov 29, 2015
926
Thanks all for the replies.

The esp32 has a micro usb port. I have picked up a micro usb - to usb A adapter and connected it to my Android phone via the usb C cable. When I plugged the cable into my phone, an option popped up if I want to use this as OTG device. When I selected it, I could open a terminal and connect to the device and send messages.


So this might work for most Android phones but unfortunately wont work on Iphones since they do not support OTG. Perhaps I should consider this option and assume that the users will be Android only
 

Thread Starter

zazas321

Joined Nov 29, 2015
926
I was testing with other phone (Samsung Galaxy S8) and it did not work in the beggining. Nothing pops up when I plug the cable even though the S8 should support OTG. Something must be messed up with the phone.

I have tried with multiple other phones and it was working fine except that one phone. That is why I said it was not working - just some issue with the phone..
 
Top