1. Download our Official Android App: Forums for Android!

Apps android to arduino communication through OTG

Discussion in 'Android Development' started by akanksha_shahi0109, Jun 13, 2016.

  1. akanksha_shahi0109

    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    2
    Joined:
    Jun 13, 2016

    Jun 13, 2016
    2
    2
    16
    Female
    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
     

    Advertisement

    vdraq likes this.
  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,281
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,281
    10,383
    1,988
    Male
    Software developer
    South West of England
    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 (Text):
    1.  
    2. new Thread(new Runnable() {
    3.     public void run() {
    4.        // Talk to your Arduino
    5.     }
    6.   }).start();
    7.  
     
    #2 LV426, Jun 13, 2016
    Last edited: Jun 13, 2016
    vdraq likes this.
  3. akanksha_shahi0109

    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    2
    Joined:
    Jun 13, 2016

    Jun 13, 2016
    2
    2
    16
    Female
    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.. :(
     
    vdraq likes this.
  4. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,281
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,281
    10,383
    1,988
    Male
    Software developer
    South West of England
    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.
     
    vdraq likes this.

Share This Page

Loading...