Libraries for communication between Arduino and Android

Asked

Viewed 7,213 times

5

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

I’ve done some research and so far I’ve found three examples of how this can work:

  1. Using rxtx libraries (GNU IO)
  2. Using Java IO (Sockets).
  3. Using HTTP client.

I’m glad I’m getting closer to understanding how information goes from Java to Arduino and from Arduino to Java, but what about these three ways is there 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 local network with cable so far), which is the best library to follow?

  • 3

    @DBX8, it is recommended to wait the 5 minutes in which the user has the right to modify the post without it being in the history (grace period, in English)

1 answer

8

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

Arduino

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

  • Use the class Serial, to send and receive data via terminals RX and TX of the plate. Then you couple an adapter Bluetooth to these terminals, and he will be in charge of making the transmission/ reception (there are several models, brands and sizes of Bluetooth adapters for Arduino, it remains to choose one of them).

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

Android

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

Bluetooth

If you have chosen Bluetooth, your solution will be to pair the Arduino on your Android device, and use the services of the classes Bluetoothadapter and Bluetoothsocket to initiate a communication using SPP (Serial Port Profile).

There’s a pretty complete example of how to do this on that website.

Wifi - Socket

If you have chosen to use Wifi Shield on the Arduino side, then it remains for you to decide which mode of communication you will use.

You can choose to simply send and receive raw data through a socket TCP, using the class Socket android. There are several tutorials teaching how to use sockets, here’s an interesting.

Wifi - HTTP

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

With this type of solution you don’t even need to effectively create an Android application, because communication can be done through a common browser, 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, among them Androidhttpclient

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


As for my personal experiences, I usually make the communication in that order (order of preference in my day-to-day life):

  1. Bluetooth: The adapter Bluetooth is cheaper, and you don’t need a monitor, or a display, to find out which IP was obtained by Wifi Shield Arduino, every time he connects to Wifi

  2. Wifi Shield via socket: Send and receive raw data, through a TCP connection between the two, usually speed up the response of Arduino, because he does not have to worry about the HTTP protocol, and all extra data that is sent because of the protocol

  3. Wifi Shield via HTTP: Although it causes more data to travel on both sides, and the response is not always as fast on the Arduino side, by using this solution you can connect the Arduino not only to one device, but to several devices, including without need to create an Android application as this communication can be done through a conventional browser of any operating system

  • Thank you very much, your reply was of great help. I know it sounds unprofessional, but could you please see if you can help me with the post http://answall.com/questions/16234/conexao-com-socket-android ?? I’ve been trying to light the LED13 for a long time, and with Jbutton it worked. I copied exactly the same code for android and it doesn’t work.

  • Hi @user8649! No problem! I just commented on your other question. Here at Stackoverflow, you should indicate whether or not the answer was what you wanted, through that icon that is just below the answer score ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.