Share My Creation Android USB Arduino

Control inputs and output of Arduino with Android. Switch 4 Arduino outputs by the toggle switches and read 4 inputs by the 4 lights, read voltage of 2 analogue inputs and adjust analog output (PWM). Digital inputs are pulled up. Analog inputs not used can be connected to GRD. The Arduino update data every 1 second. Library felUsbSerial has to be added to the B4A code, can be downloaded from GitHub.
Software includes code for Arduino Uno or Nano. Arduino sends 8 bytes and receives 2 bytes.
Connect Arduino to Android via OTG (On The Go) cable, the Arduino gets its power from the Android device.

screengrab-io405.png


arduino_io.png
 

Attachments

  • arduino_io_b4r.zip
    1.2 KB · Views: 523
  • io2_b4a.zip
    6.8 KB · Views: 158
Last edited:
Hi,
Thanks for nice sharing. Because it is just about communication so a question raised if we use Data cable instead of OTG, does it work because we don't need +5V from OTG to power Arduino Nano? Thanks.
 

Filippo

Expert
Licensed User
Longtime User
Hi,
Thanks for nice sharing. Because it is just about communication so a question raised if we use Data cable instead of OTG, does it work because we don't need +5V from OTG to power Arduino Nano? Thanks.
Unfortunately, it cannot work without an OTG cable.
 

moty22

Active Member
Licensed User
Data cable instead of OTG
The OTG cable is the same as data cable with an extra pin connected to ground. The OTG cable tells the the portable device to become a USB host (master), without it the device is like a USB storage.
If you connect external 5V to the Vin of the Arduino then the portable device stops sourcing current to the Arduino and the loads connected to the outputs, this will save you battery life. As was said you have to use OTG cable or make one.
 
Thanks moty22 for detail...
It means it is not only the Power Source from mobile to arduino but OTG cable's extra pin shorted to ground change android phone to host mode (master) to communicate with arduino (slave). Even we use external power to arduino we have to use OTG cable just for mode changing. I think this is what I understand. Thanks.
 

stari

Active Member
Licensed User
Longtime User
If you connect external 5V to the Vin of the Arduino then the portable device stops sourcing current to the Arduino and the loads connected to the outputs, this will save you battery life. As was said you have to use OTG cable or make one.
Hello,
i don't understand exactly.
Can you give me circuit diagram?
I have connected Arduino Nano with tablet Galaxy note and communication is not problem. Only i must at the same time charge tablet.
THKS
 

stari

Active Member
Licensed User
Longtime User
No problem, there are also otg adapters with usb-c.
Everything is fine. Only when I turn off the power and turn it on again, the Galaxy goes into charging and there is no more communication. I have to physically unplug the connector, plug it back in, and then communication works again, but charging doesn't. I think my Galaxy doesn't support OTG.
 

moty22

Active Member
Licensed User
Everything is fine.
If you communicate with Arduino or can see another USB device like a mouse or USB flash Key then you must have OTG. Android devices with GO Edition don't have OTG.
When you switch your device ON Android asks for the permissions again for security, it is the same with my tablet. You can't have OTG and charge at the same time because with OTG the device generates 5V for the USB device so it has to disconnect the charger. I tried once to force 6V into the USB while the OTG is on and the tablet didn't charge or take any current.
I'm an electronic engineer like you I'm not a software programmer. This creation doesn't scale properly, I will correct it in the next few days.
 

Filippo

Expert
Licensed User
Longtime User
Everything is fine. Only when I turn off the power and turn it on again, the Galaxy goes into charging and there is no more communication. I have to physically unplug the connector, plug it back in, and then communication works again, but charging doesn't. I think my Galaxy doesn't support OTG.
With an OTG adapter, simultaneous charging is absolutely not possible. It is not supported by any device.
 

stari

Active Member
Licensed User
Longtime User
If you communicate with Arduino or can see another USB device like a mouse or USB flash Key then you must have OTG. Android devices with GO Edition don't have OTG.
When you switch your device ON Android asks for the permissions again for security, it is the same with my tablet. You can't have OTG and charge at the same time because with OTG the device generates 5V for the USB device so it has to disconnect the charger. I tried once to force 6V into the USB while the OTG is on and the tablet didn't charge or take any current.
I'm an electronic engineer like you I'm not a software programmer. This creation doesn't scale properly, I will correct it in the next few days.
And what is the solution to have communication with Arduino and charging at the same time? I'm looking online, but I can't find it.
 

moty22

Active Member
Licensed User
I assume phones or tablets with wireless charging can charge while working.
I don't know of any other solution. Once I opened the cover and connected a source of 1.5A directly to the battery and after a few hours the device showed that the battery is low despite the voltage on it was 4.2 volt which means fully charged. I concluded that Android don't measure only the battery voltage, it also measures the time that your device is on.
Android don't include in its software the ability to read more than 1 USB, so all have only 1.
In a few days I will add a Bluetooth version, with that you can charge while communicating.
 
Last edited:

stari

Active Member
Licensed User
Longtime User
I assume phones or tablets with wireless charging can charge while working.
I don't know of any other solution. Once I opened the cover and connected a source of 1.5A directly to the battery and after a few hours the device showed that the battery is low despite the voltage on it was 4.2 volt which means fully charged. I concluded that Android don't measure only the battery voltage, it also measures the time that your device is on.
Android don't include in its software the ability to read more than 1 USB, so all have only 1.
In a few days I will add a Bluetooth version, with that you can charge while communicating.
I also have a version already made with the added HM11 BT. Well, there are no problems here.
 
Top