• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps android to arduino communication through OTG

hello guys !
i was developing this app which sends my phone accelerometer reading to my arduino board. I want to use OTG cable as my mode of communication between the two. I have been able to obtain y accelerometer reading till now but the communication part is causing me problems.One problem is i want to remove the "send" button option as i want direct and continuous communication of accelerometer readings. Also i am doubtful is my arduino board will receive the data. Please help me out (I am really new to android studio as well as java and would really appreciate your help).This is my reference site.

http://android-er.blogspot.in/2014/09/send-data-from-android-to-arduino-uno.html

thank you
 
If you want continuous communication with the Arduino device, then I would do this by starting a thread. If you have no understanding of multithreading, then this question has a few good links

http://stackoverflow.com/questions/4722974/threading-example-in-android

If your communication thread has to do any kind of update on the UI, then use AsyncTask, which is designed to handle a background thread doing periodic updates to UI components, without holding up the main application thread.
However if your intention is simply to stream a load of data to the Arduino, with no interaction with the UI, then you could simply start a new Thread to do the work.

Code:
new Thread(new Runnable() {
    public void run() {
       // Talk to your Arduino
    }
  }).start();
 
Last edited by a moderator:
If you want continuous communication with the Arduino device, then I would do this by starting a thread. If you have no understanding of multithreading, then this question has a few good links

http://stackoverflow.com/questions/4722974/threading-example-in-android

If your communication thread has to do any kind of update on the UI, then use AsyncTask, which is designed to handle a background thread doing periodic updates to UI components, without holding up the main application thread.
However if your intention is simply to stream a load of data to the Arduino, with no interaction with the UI, then you could simply start a new Thread to do the work.

Code:
new Thread(new Runnable() {
    public void run() {
       // Talk to your Arduino
    }
  }).start();
i am really sorry but i still did not understand what to do...can you please tell it to me with reference to the code given in the link..i wanna know what and where to add.. :(
 
Well I could give you code, but I try to encourage people to learn something. By giving you code to paste in you won't really learn.
I've explained that you need to create a thread to handle communication with the Arduino. Do you understand what I mean by creating a thread? There are many web resources to help you with this, such as

https://docs.oracle.com/javase/tutorial/essential/concurrency/
http://www.tutorialspoint.com/java/java_multithreading.htm

Can I suggest that you try to create a simple thread in your app, to get familiar with this? It's really not that hard, once you understand the basic concepts.
 
Back
Top Bottom