Arduino Remote/wireless Programming
The problem.
I develop a sketch near PC and I use usb and serial to “debug” in this case I create the lib for DHT12, I deliver a version on github of the library.
But arrive an issue: “when temperature go under 0 the readed value is wrong”.
Now I must test the problem on my freezer (:P) and I don’t want to rewrite a sketch and use WIFI for a simple situation like so.
So without rewrite sketch I want continue programming like previous, but my Arduino must go on my freezer.
I need 2 thing, one is a battery, but I don’t know how many test I must do so I need a rechargeable battery, and an adapter to work with microcontroller remotely, like Bluetooth
Components
For remote connection I’m goint to use:
Bluetooth adapter like:
- Bluetooth adapter like:
- HC-05
- o SPP-C (Very low cost)
- 0.1uf Capacitor (for HC-05).
Remote Connection
To create a remote connection without USB cable I want use bluetooth module as serial pass throw.
Than we must connect and program It with our Arduino. The connection schema is for programming bluetooth adapter.
In my lab I have 2 module an HC-05 and an SPP C.
But I use HC-05 to do wireless connection of my CNC router, but the low cost SPP C It’s sufficient.
Normally I use 115200 baud rate for serial transmission, so I configure my bluetooth module to that rate.
Configure Bluetooth Module: HC-05 (zs-040)
First upload this schetch on Arduino.
First you must pay attention to if button is present (to go on configuration mode press that button instead of but high pin 9 of the sketch). When led blink slow (every 2 secs) you are in configuration mode, configuration mode put device at 38400 baudrate, so you must put serial and software serial to that boudrate.
Than insert this command:
AT
AT+ORGL
AT+POLAR=1,0
AT+NAME=mischianti
AT+UART=115200,0,0
AT+INIT
That parameter set bluetooth in serial pass-throught mode.
You only pay attention to:
mischianti --> Device name to set
115200 --> Baudrate to set
Pay attention AT-ORGL reset device.
AT+INIT can give Error(17) but don’t worry It means that It’s already in that mode.
Configure Bluetooth Module: SPP C
First upload the schetch to Arduino:
The code for SPP-C isn’t so clean like HC-05, but the result remain the same.
Serial output baud rate is setting here:
#define SERIAL_SPEED 115200
Bluetooth comunication baud rate here:
#define BLUETOOTH_SPEED 38400
First time you must set to configure bluetooth to 9600 to HC-06 (not tested) devices, 38400 to SPP-C devices.
Than set bluetooth baudrate to set:
#define SET_BLUETOOTH_SPEED 115200
You can set new device name:
#define BT_NAME "TEST-Reef"
Send AT commands to the HC-05 bluetooth module with Arduino as serial pass-through
In the same way we use our bluetooth as serial pass-trough module we can use Arduino
as serial pass-trough to send commands to the bluetooth.
Upload default schetch to Arduino:
void setup() { // put your setup code here, to run once: } void loop() { // put your main code here, to run repeatedly: }
Connect bluetooth module to the same serial pin of Arduino, so you use Arduino only for transport of serial data:
Hold down the HC-05 button (if present) and connect the VCC, (led now flash slowly) (On my module I did not need to hold it down the button).
Now open the serial monitor connect it to the USB port of Arduino and set the 38400 default badrate of our bluetooth module, and select both CR and LN.
Now you should be in direct contact with the bluetooth module passing through our Arduino, try to send the AT command and wait for the OK.
So now you can send the AT commands that I have shown above:
AT
AT+ORGL
AT+POLAR=1,0
AT+NAME=mischianti
AT+UART=115200,0,0
AT+INIT
Using USB-TTL (FTDI) to send commands
Another solution (of course) is to send commands via a serial USB converter.
Make the connection and operate as above.
The EN pin and the VCC must be connected: P to go into programming mode.
Connect bluetooth adapter to Arduino to use as serial connection
For HC05 the only thing to note is that long leg (+) of capacitor going on reset, the negative going to DTR (or MCU-INT or State) of bluetooth adapter, you can use also a 0.1uf ceramic capacitor.
The SPP-C module in my case not work if I add capacitor, but work great without :D.
SPP-C is similar:
The rx of bluetooth adapter go wired on tx of microcontrollor, and tx to rx, than you must connect VCC and GND and DTR or MCU-INT or State of bluetooth adapter to reset of microcontroller.
For a better stability It’s good thing to do a voltage divider versus RX bluetooth pin like in the image because transfer voltage is 3.3v not 5v.
Simple Sketch and Upload Via USB
I create very simple sketch to upload, It’s only write progressive number on serial every 1500 milliseconds.
In the video is show standard usage via USB cable.
The Same Simple Sketch Upload Via Bluetooth
In this video the previously sketch upload remotely via Bluetooth without change code.
Real Test
Now I need response from the freezer.
From the deep of freezer, near the sausages, the remote test tell me that (damn) there is a bug on my DHT12 library when go under 0.
Thanks
Bug on DHT12 lib now fixed.