Programming Arduino via bluetooth should be a natural application to any bluetooth serial module. As least, I believe so. Therefore, I brought a couple of cheapest bluetooth serial modules I can find along with my Arduino Kit (http://www.ebay.com/itm/Wireless-Bluetooth-Module-Slave-4Pin-Serial-Port-DuPont-Cable-For-Arduino-/160902163152?pt=US_USB_Bluetooth_Adapters_Dongles&hash=item2576842ad0). However, a natural application like this turns out to be a non readily available one. For some reasons, people is kind of accepting it, probably because there are some expensive solutions in the market (so cheap one shouldn’t work).
Anyway, to program a Arduino through bluetooth, we need to solve two problems. The first one is auto resetting the Arduino board, and the second one is to synchronize the resetting moment to the uploading moment. http://ame2.asu.edu/staff/kidane/ArdWilessBtProg.pdf solved the first one nicely, but not the second one. To use it, we need to send a char to the Arduino board though serial console to trigger the reset, while hoping that the uploading moment will hit the tiny resetting time frame (e.g. 2 seconds in case of Arduino UNO). (… I can’t even come close to make them meet …)
Fortunately, both short comings can be solved easily by modifying your the Arduino code a little bit. As a matter of fact, the Arduino IDE is sending two chars {0x30,0x20} to the Arduino board, and expecting two chars reply {0x14,0x10} to synchronize the upload process. We just need to mimic this behavior and resetting the board promptly, then we have a perfect syn. The following is the actual working Arduino source code for this. (The downside is you have to somehow escape ‘0’ from your input stream, which may or may not be a problem.)
//////////////////////////////////////////////////////
//
int uploadpin=8;
void setup()
{
Serial.begin(115200); // baudrate 115200 corresponds Arduino UNO,
// it can be different for different boards
pinMode(uploadpin,OUTPUT);
}
void loop()
{
// your codes here…
/////////////////////////////////////////
// Upload checking
if( Serial.peek()==‘0’ )
{
for( int i=0; i<100; i++ ) // repeat the check for a short peroid
{
if( Serial.read()==‘0’ && Serial.read()==’ ’ )
{
Serial.write(0x14); // reply two char to avrdude.exe
Serial.write(0x10); // for synchronization
digitalWrite(uploadpin,HIGH); // turn on the relay to ground the reset pin
}
delay(10); // cannot repeat too fast here
}
}
/////////////////////////////////////////
}
//
//////////////////////////////////////////////////////
With the above source code (and the solution described in the .pdf file), you should theoretically be able to upload sketch by clicking the upload button in the Arduino IDE. However, for some reasons (probably came from rxtxSerial.dll or the standard bluetooth driver), an error “avrdude: ser_open(): can’t open device “\.\COM16”: Element not found.” may happen. What’s this error actually saying is your bluetooth serial connection fail to reopen immediately after close. (Don’t panic, it’s okay). You can upload your sketch via console by calling avrdude.exe directly. Turn on the upload verbose by checking the FILE>Preferences>Show verbose output during>upload checkbox, click the upload button once, then you will find the avrdude command in the Arduino IDE reporting window. Here is an example
“C:\Arduino\arduino-1.0.1\hardware/tools/avr/bin/avrdude -CC:\Arduino\arduino-1.0.1\hardware/tools/avr/etc/av
rdude.conf -v -v -v -v -patmega328p -carduino -P\.\COM16 -b115200 -D -V -Uflash:w:C:\Users\Gary\AppData\Local\Temp\build4211658377325489507.tmp\code1.cpp.hex:i”
This command will stay exactly the same before you close the Arduino IDE window. So, you just need to copy it once, paste it in a console window, compile your Arduino source code, and keep reusing with same command for upload as long as the Arduino IDE window stay open.
Alternatively, stop the Arduino IDE from flushing the serial connection before uploading will also solve the problem. You can do that by editing your board setting in C:\Arduino\arduino-1.0.1\hardware\arduino\boards.txt. For Arduino UNO, add “uno.upload.disable_flushing=true”. Its a little bit risky to edit that file, do it unless you know what you are doing. ( Flushing the serial connection before uploading doesn’t seems do anything beside locking up the serial connection. Why is Arduino IED doing in the first place?)
<<<<>>>>
The solution described in the pdf, http://ame2.asu.edu/staff/kidane/ArdWilessBtProg.pdf , requires three simple, but very error prone steps. I simplified them for you. Just follow to the letter, don’t ask.
-
There is a reset pin in Arduino UNO. You don’t have to solder the transistor. Just connect it to reset pin via jump wire, it works fine.
-
Replace C:\Arduino\arduino-1.0.1\rxtxSerial.dll with http://servicios.ried.cl/arduino/temp/rxtxSerial-2.2_fixed_2009-03-17.rar
(For the details, http://arduino.cc/forum/index.php/topic,46977.0.html.) -
Update AT command of Bluetooth Mate.
The buadrate for upload of different board can be different. You can check C:\Arduino\arduino-1.0.1\hardware\arduino\boards.txt for details.
Unlike USB serial, Bluetooth Mate can only operate at a particular buadrate. To change the bluetooth mate buadrate, you can connect it to the computer with a USB-TTL cable, use a terminal software to send the AT command. The AT command is in a format like AT+BUAD1 or AT+BUAD2 or AT+BUAD3… The number 1, 2, 3 is the indices to a list of specific buadrates, e.g. 8->115200. (See http://thingylab.com/wiki/hc06_linvor_1.5_at_command_set for details).
If you don’t have a USB-TTL cable, you can simple use your Arduino board as one. Connect your bluetooth mate to your board like this
VCC | → | 5V |
---|---|---|
TX | → | TX(pin1) |
RX | → | RX(pin0) |
GND | → | GND |
, use a jump wire connect reset pin to ground, and connect the arduino board to computer with a usb cable.
At this point, you can send AT command via the Arduino IDE serial window. For testing, you can send “AT”, it should respond “OK”. ( For details, see http://arduino.cc/forum/index.php/topic,18243.0.html.)
(Tired… I should simply make a video instead of writing…)