Libraries for communication between Arduino and Android

5

I am a beginner Arduino programmer trying to make a connection with my cell phone (Android) and / or my laptop using Java.

I did some research and so far I've found three examples of how this might work:

  • Using rxtx libraries (GNU IO)
  • Using Java IO (Sockets).
  • Using HTTP client.
  • I'm happy that I'm getting closer and closer to understanding how information goes from Java to Arduino and from Arduino to Java, but what about these three ways there are to implement it? What is the main difference?

    In a few weeks (after some study) I look forward to communicating my Android phone with Arduino with Bluetooth (I'm using wired LAN so far), what is the best library to follow?

        
    asked by anonymous 18.05.2014 / 15:18

    1 answer

    8

    There are two sides to look at in this situation: the Arduino side and the Android side.

    Arduino

    On the Arduino side, you have several options, but the most common ones are:

    • Use the Serial class to send and receive data via the RX and TX terminals of the adapter. Then you attach a Bluetooth adapter to these terminals, and it will do the transmission / reception (there are several models, brands and sizes of Bluetooth adapters for Arduino, you have to choose one) / p>

    • If you have a WiFi Shield , then you can connect the shield to Arduino, and use the WiFi class to communicate via HTTP, or TCP or UDP (depends on your need). This solution is usually a bit more expensive than the Bluetooth in terms of cost $. However, there are already several examples that accompany the Arduino IDE to assist in the first steps (menu File > Examples > WiFi ).

    Android

    On the Android side, it depends on which of the two solutions you chose on the Arduino side.

    Bluetooth

    If you have opted for Bluetooth , your solution will be to pair the Arduino on your Android device, and use the BluetoothAdapter and BluetoothSocket to start a communication using SPP ( Serial Port Profile ).

    There is a very complete example of how to do this on this site .

    WiFi - Socket

    If you have chosen to use WiFi Shield on the Arduino side, then you have to decide which communication mode you will use.

    You can choose to simply send and receive raw data through a socket TCP, using the Socket from Android. There are several tutorials on how to use sockets, here's an interesting .

    WiFi - HTTP

    Still, you can choose to send the data through the HTTP protocol.

    With this type of solution you do not even have to create an Android application, since communication can be done through a common browser, from any operating system. There is a great example, very simple, for this along with the Arduino IDE: File > Examples > WiFi > SimpleWebServerWiFi .

    Now, if you really want to create an Android application and communicate via HTTP, you can use several classes, including AndroidHttpClient

    There is a small example of how to do this in this other OS question: How do I use the Simple HTTP client in Android?

    As for my personal experiences, I usually communicate in this order (order of preference in my daily life):

  • Bluetooth : The Bluetooth adapter is cheaper, and you do not need a display or display to find out what the < in> Arduino WiFi Shield , every time it connects to WiFi
  • WiFi Shield via socket: Sending and receiving raw data over a TCP connection between the two usually speed up Arduino's response because it does not have to worry about protocol HTTP, and all the extra data that is sent because of the protocol
  • WiFi Shield via HTTP: Although it causes more data to travel on both sides, and the answer is not always so fast on the Arduino side, using this solution connect Arduino not only to a device, but to several devices, including without needing to create an Android application, as this communication can be done through a conventional browser of any operating system

    li>
  • 18.05.2014 / 16:19