Arduino Tx problem when connected to smartphone

Hi all,

I'm trying to develop simple android app which will get some sensor data via arduino.

My problem is when i connect arduino to phone it doesn't start Tx streaming to my smartphone it just Powers on and doesnt send any data (what is strange is when i plug and unplug phone couple of times and try to connect wih app sometimes Tx becomes on and data from arduino start to come to phone )

This behaveor is not same with my computer.When i plug arduino to my computer its immidately starts to send values (Tx is on and also i can connect and see data via COM3)

What can cause this random behavior for phone ? when i plug and give Access to this arduino device why its not always start to stream Tx ? Do i need to update my firmware ı use Arduino UNO

I’m still trying to solve my problem. as far as i understand when i click ok from phone to use usb attached device ( arduino ) arduino reset itself and comminication is lost.i need to prevent arduino from reset. i set DTR as false but stilli face same problem. Any idea ?

Are you using a proper OTG USB cable ?

Please also show us the sketch being used using code tags ( </> )

Fact that it works on a computer would indicate that the cable you are using is possibly incorrect or an issue in the sketch or even a phone setting.

Dear Ballscrewbob,

Thank you for your answer.Seems i fixed autoreset problem. on Android side my serialport settings was after i moved them before it now its like following and it seems i fixed restarting problem.

My problem is now more strange :slight_smile: i downloaded anohter program to test phone and card connection.Program name is Seial Monitor. i open this porgram plug cable it asks for permission i select ok from phone and it Works ( not everytime )

When i try with same with my android code it behave same asks for permission i click connect i debug and i get no connection error it connects but no data comes.No tx light also.

I know when i put it like this its seems obvious there is a problem with my android code but im not sure because my code also Works randomly.

Is there any phone settings to do or should i upgrade firmware of arduino im confused of so much random behavior :slight_smile:

my sketch very simple i just count and write to serial it Works i tested it.


if ( {

Im sorry but that loks like partial code and is not in code tags ( </> )

The last time I tried serial over android to a UNO (using BT) I had to try a few different apps until I found a reliable one but that was a long time ago and I cannot remember what it was as I moved to ESP8266’s for RF work.

Yes i wanted to Show just part of code i changed.I think i need goog reliable android usb serial library

im currently using this one

i found some example codes to try but maybe i will try another library.

LOL thats how I tend to do it and try a few examples before i commit to hacking up a sketch to make it do what I need.

Not always pretty but it usually works.

:slight_smile: yes i plan to understand how it Works first and then i will write new one for myself.What makes me crazy is it Works i change nothing and try again and it doesnt work :slight_smile:

From that I can only deduce loose connection or a phone issue as the sketch doesnt change once its up and running

It is more reliable with Serial Monitor Lite program. I connect and mostly it works. It uses different library tomorrow I will give it a try. I didnt think I will face so much problems. :slight_smile:

You have to remember that a lot of libs are made by individuals who sometimes just make them to work for themselves but put them out for others to play with. You will come across a lot of similar libs and some work better than others.

OK. seems i solved communication problem with another library.How do you read bytes from serial communication ? i mean if numbers are like 1 2 3 or 33 55 18 its ok but when it comes to number with 3 or more following problem starts

199 becomes 1 99 etc. How to be sure that i get full number to buffer which is coming from arduino ?

Thats probably a sketch issue.

A lot of that depends on how you are making up the number to send.

There are some pretty good tutorials on swapping from numbers to strings and vice versa.

Do i have to check values i have and put them in order ? lets say arduino sent me 556/n (/n for new line) and i buffered untill 55 and 6 and \n left for next buffer will i get 6\n55 ? how i will keep it consistent ?

You would probably get 55 then a newline and then the 6.

Without the whole sketch its a little like stabbing in the dark.
You could use a larger buffer and then just strip out any unwanted spaces, zeros etc.
Or even just try sending the full buffer right after newline is called.
Again stabbing in the dark a little.

Actually my sketch is very simple just printing numbers from 1 to 1000 for test.
In prod. It will send only 1 and 0 maybe only 1 I will decide that later. So It should not be problem I think. I notice that I loose some data. For example it's counting 102 103 no 104 and it jumps to 105. I tested with another program it also loses some data. This program which I tested and my application use same library. Maybe because of library I'm not sure.but is not so important at that moment.
By the way did you ever completed this kind of project ? Now I'm searching how i will power up both arduino and android device ? When I plug arduino gets power from phone. I need to find a way to power up the phone. How can I do that ?

As I said I went the BT route initially and then ESP8266 to Arduinos for better range.

BT is IMHO a better option to start as you can still use the serial monitors etc.

I dont know of any cables that would split like I think you need but that isnt to say they dont exist.

I have seen the dropped numbers before in my "thingspeak" sketches when debugging and also on the CREATE editor. In create they pretty much fixed it but with thingspeak it was my sketch sending too quickly and the fact that I had a small buffer issue with the way I was formg the numbers.
If it wasnt a full number it dropped it cleared the buffer and moved onto the next complete number.

It seemed almost random and took a while to figure out. I used other peoples examples until I got a stable readout. Then I used the relevant parts of thier sketch to incorporate into my own.

Thank you for your answers :slight_smile: it seems i will have to test and calibrate for my own case.About my power supply question ? Do you have any idea or advice for me ? I read in internet that when tablet or phone works in host mode it gives power to connected device.At the same time i need to charge the tablet.How can do this ?

Do a search for “otg with charging” It seems I was wrong and you may be able to buy a suitable cable.

I did so far but i cannot say that i found good answer.I found this following link.Seems like its what i want.But i didnt undertand i need some spesific hardware or not ? For example i use arduino uno r3 im trying to understand if i need arduino usb hotshiled or not.If i can solve this power problem im good to go :slight_smile: