[solved] HC-05 wireless programming + disabling auto reset

Hello :slight_smile:

I am working on a project where an Arduino Pro Mini 328 5V is not easily accessible, and to solve possible bugs, or simply update program, I needed wireless programming. But my issue is, adding wireless programming forces the arduino to be reset on serial connection.

Based on other people's ideas, I have previously successfully made wireless Bluetooth programming of an Arduino Mega 2560 with a HC-05 BT Serial module (image here). Hopefully, after setting the HC-05's baud rate to 57600 to match the baud rate of the avrdude config, the same trick can be used on the Pro Mini.

Another way to do that on my Pro Mini is to simply connect the STATE pin of the HC-05 directly to the DTR pin of the Pro Mini (I'm not sure if it's OK... but it worked), with the same AT configuration for the HC-05. For some reason I need to use the other way, but I tested and the issue is the same with both ways.

But forget about the Pro Mini. The issue is the same on both the Pro Mini and the Mega 2560. The problem is, to allow wireless programming, the HC-05 must do something (with its STATE pin) to the RESET (or DTR) pin when the Serial link is established, and this resets the arduino. If I disconnect the STATE pin, then I can connect to the arduino without resetting it, but obviously I can't program it wirelessly.

I would like an elegant workaround...

The best idea I can think actually is:

  • The arduino controls a transistor acting as a switch for digitally (dis)connecting the STATE pin.

  • When I want to program the arduino, I first send a Serial command to the arduino, like "PROG", which will tell the arduino to switch the STATE pin on for one minute, allowing the arduino to be reset at the next serial connection thus allowing the wireless programming. Then I have one minute to close Serial connection, press the Upload button, and upload/verify the sketch... Or, if nothing is done during this minute, then the arduino will switch the STATE pin off, allowing to connect to the arduino without resetting it.

  • The program will always contain some code to switch the STATE pin on at startup, for one minute (again), then switch it off forever (... until a "PROG" command is received) so that the next serial connections will not reset the arduino. One minute is, if I ever want to reprogram twice in a short time (e.g. if I noticed a small mistake in my code just after pressing Upload button) so that I don't have to send "PROG" again.

In theory, it should work, and I will try soon.

What do you think? Any better ideas?

So I used a 2N2222 NPN transistor and coded my idea, it seems to work pretty well!

I've got some problems.. tried a pull up resistor on the transistor base to force it HIGH when arduino is booting. But it seems the transistor let current flow sometimes when it shouldn't, I don't know why. I will investigate later today.

Here is my current setup, working as expected! Sorry I can't draw schematics, and I think a Fritzing is easily understandable by all.

Arduino's pin 2 is used to control the transistor as a switch between the HC-05's STATE pin and the Arduino's RST pin. The code and hardware works great... but for how long?

I am not electronic engineer! I have doubts about what I did here. Please experts, check my setup and tell me if things are wrong, or how I could simplify it. I will try with a PNP later.

Edit: Apparently the pull up on the transistor base causes problems and is not needed, so I removed it for now.

Edit: there are still problems after some more testing.. Maybe I should play with the values of r5 and r6. Or I'm missing something :S

I re did the whole circuit after sleeping... Also used KiCAD for the first time, here is the result:

RX, TX, VCC, GND are not connected for clarity.

As said in a previous post, you can remove C1 and R4 and connect to DTR instead of RST, if your Arduino Pro Mini have a DTR pin. The result is the same (same circuit on the board).

Possibly a HM-10 module can be used instead of HC-05, I will try this tomorrow.

I also tried with C1 = 68nF (683), it worked as well (my 100nF (104) capacitors are measured ~70nF anyway...), maybe some lower values will work as well.

I'm testing it since 2 days and it seems to work perfect. It never failed to upload a new sketch (after I type command "prog" or less than 30 seconds after the arduino started), and it never resets the arduino after that.

I can share code if needed, but it's basically just a digitalWrite( 2, HIGH/LOW ) whenever you want to enable/disable auto reset on HC-05 serial connection.

:slight_smile:

Well, I decided to give the ESP8266 a try. I bought some Nodemcu 1.0 and with the help of ArduinoOTA library I can reprogram my Nodemcu by Wifi. I knew nothing about wifi but that was easy enough to setup! I think it will totally replace the arduino and hc-05 in my project(s)... :).

Hello quix or anyone, I know this post is about two years old, but I am trying to do the exact same thing on the HC-0, run into the same issue. I find you solution is very feasibly. But I have a few questions. I hope you can help.

  1. On my HC-05 board, it does not have a State pin, instead it has a LED labelled in place of State pin, is LED pin the same as State pin? are they both connected to pin32?
  2. The LED pin is used to blink and LED, does it sent out a pulse of certain interval? In order to trigger the pn2222, doesn't it really only need one pulse upon upload when it re-sets the Arduino? How does your circuit handle the subsequent pulses? Sorry if I sound ignorant, my electronic knowledge is very limited, still learning. :frowning: Thanks.

Hello :slight_smile:

On my module, STATE pin is connected to pin 32 (PIO9), the blinking LED is connected to pin 31 (PIO8). Some modules have two LEDs, one on pin 31 and the other one on pin 32. Pin 32 doesn't pulse, it's at one logic level when connected, and the other logic level when disconnected (logic can be inverted with AT+POLAR). I suggest that you simply solder a wire to pin 32.

You can use a multimeter in continuity mode to check where the led is connected. It's connected to a resistor, and the other side of that resistor is connected to pin 31.

The transistor is controlled by the arduino and acting like a switch: most of the time it is turned OFF, making it impossible for the HC-05's pin 32 to pull Arduino's Reset to ground, as to avoid arduino being reset everytime a connection is made with the HC-05. It's only turned ON programmatically, for a minute when the arduino is rebooted or when I type a command.

If you need more help just ask, I may be able to find an old sketch or something.. :slight_smile: