domingo, 10 de febrero de 2013

The Remote Controller App

These are the steps you should go through to use my App "Omnicontrol" to control your own system.


- An Android device with the app loaded on it. You can download the compiled application from Google Play going here.
- A Bluetooth Modem. I use the RN-42.( )
- An Arduino Board. This example works only on the Mega or Leonardo Arduinos. I explain you later why.
- A USB cable.
- Some wiring materials.
- A computer with the Arduino Software.

This is what you must do:

1.- Wire the Modem in this way. 

The red cable is connected to the +5V, the black one to GND. Be informed that the Modem will be delivered to you without headers. So, a little bit of soldering will be needed.

2.- Connect the USB cable and load the test sketch. You can find it here:
It is a very short one!

3.- The modem will blink in red at this moment, because it is not linked to any other Bluetooth source. It's normal.

4.- Switch Bluetooth on in the Android device, search for new devices and pair it with the RN-42 modem.  This is the typical step you perform prior to use any Bluetooth device. Please refer to your Android documentation & the modem documentation if you need more information on this point. The modem shall appear as "Firefly ...........".

5.- Once you paired the devices in the Android device, start there the App "Omnicontrol". Press "Select device".  A list of all paired Bluetooth devices will be presented to you. Please press the name of the Bluetooth Modem you want to connect to (Again, "Firefly........."). You will go back then to the main screen.

6.- Press "Connect". If everything went Ok, after 1 or 2 seconds, the status bar will change from Red to Green and the text "Connected" will appear. The blinking red Led on the Modem switches off and the green one goes on (As in the picture above).

7.- If you press "Power On", the App starts sending telegrams. If you press it again, you stop the transmission. Have a look on this former entry of my blog to see a video with the whole process.

8.- While the communication is on, go to your computer and open the Serial Monitor in the Arduino IDE. (Tools -> Serial Monitor). You will see something like this:

The Structure is quite simple. There are letters, then associated values:
M -> Magnitude
A -> Angle
E -> Switch is On or Off. (E = Enable). When you switch off, you will receive a single time "E0", then communication stops.
T -> Turn

I programmed the Android App in such a way that when "Power On" is false, no communication takes place. If this is not OK for you, you can easily adapt the App to your own needs. F.ex. you may use this On/Off switch to control not the Move Enable but something else mounted on your robot.

The source Code is here:
This App is programmed with AppInventor. I will comment it in a next entry.

On the other side of the comm. channel, in you Arduino real sketch, you can read the values using a simple piece of code. Like this: (This works as it is on a Leonardo. The Serial1 must be changed to Serial2, 3 or 4 in the Arduino Mega)
r =;
    switch (r)
      case 'M' : vel = Serial1.parseInt();              // Magnitude
      case 'A' : ang = Serial1.parseInt();              // Angle
      case 'E' : moveEnable = Serial1.parseInt(); // Move Enable
      case 'T' : turning = Serial1.parseInt();         // Turning

I suggested you to use an Arduino Leonardo or Mega. Both boards have at least 2 Serial ports. This way you can upload & debug your Sketch through one port, while the Bluetooth communication is working on the other. This allows you to keep everything in place while modifying & debugging your sketchs.

The Arduino UNO has only 1 Serial port used for everything, included upload your sketchs.

This means: in an UNO, if you have the Bluetooth modem connected, you cannot connect your computer. Using this board is perfectly possible, but you will need to re-wire constantly from one configuration to the other each time you upload / test your sketch. Needles to say, the above mentioned test will not work on an UNO.

Bluetooth is tricky but the RN-42 do a nice job, making things much easier as I would expect. I ordered by mistake the HID version. It can be used too, but I recommend to use the normal one, the one I indicated before.

When using the Bluetooth modem, be sure to have adjusted the proper Baud Rate in your Arduino Serial Port (default value is 115200 Bauds) and that the Modem is working in SPP mode. If you are using the HID version, you must switch to this mode before using it. Again, refer to the modem documentation to see how to do it.

I didn't test this system with other Bluetooth modems, but if you are able to open a SPP channel with the correct Baud Rate on it, it must work too.


No hay comentarios:

Publicar un comentario