Auto-Reset for Arduino-BT

Hi,

I was really missing the Auto-Reset Feature for the Arduino-BT, therefore I did it myself. It can be added to existing V06 boards but it would be nice to have it in future versions of the Arduino-BT.

It can be easily done by setting the iWRAP parameters to configure a WT-11 GPIO pin as DTR (e.g. PIO7) and connecting it to the ATmega reset pin using a little curcuit. The curcuit is needed because the WT-11 DTR signal is not inverted (this could be configured) and because the WT-11 uses 3,3V logic.

You will also need a slightly adapted version of avrdude which clears the DTR signal when closing the connection, otherwise the reset will only work once. An experimental patch can be found here: AVR Downloader/UploaDEr - Patches: patch #6866, bug #26703: [Feature Request]... [Savannah]

The auto-reset should be configurable via a jumper to disable it because for normal operation you don't want that the ATmega resets every time you open a bluetooth connection.

This is the iWRAP command for PIO7:

SET CONTROL MSC DCE 00 80 00 00 00 00

The curcuit and its connections has to look like this:

Part list:
R1 100 kOhm
R2 100 Ohm
C1 22 nF
D1 1N4148
Q1 BC547C

Similar types of D1 and Q1 will also work.

MikeT

To make the Auto-Reset actually work, you need to avoid the reset of the WT-11 bluetooth chip when the Arduino bootloader starts, because the reset kills the bluetooth connection.

Simple solution
The easiest way is to connect the reset pin of the WT-11 (PIN 1 on SV2) to GND. The Arduino is connected using a 2k2 resistor so this doesn't hurt it.

With this modification it will no longer be possible to enter the iWRAP command mode other than using the escape sequence (SET CONTROL ESCAPE).

Advanced Solution
A more advanced way is using the WT-11 PIO6 pin to switch to command mode without resetting it.

Here the instructions for the advanced solution:

  1. Enable the hardware escape pin by executing the following iWrap command:
SET CONTROL ESCAPE - 40 1

You can use the "Init Bluetooth Module" sketch as a base for this. I will make such a sketch if anybody is interested.

  1. Cut the connection to the WT-11 reset line directly beneath the WT11.

  2. Connect the signal which was previously connected to the RESET pin to the PIO6 pin of the WT11 (the next pin) . This way it is possible to switch very fast to command mode without resetting the WT-11 and loosing all connections. This is also compatible with existing applications and the original bootloader.

  3. Optionally use an Arduino bootloader which is very close to the Duemilanove bootloader (see next posting)

MikeT

Here the description of the modified bootloader for the Arduino-BT. It is very close to the Arduino Duemilanove bootloader. It doesn't reset the WT-11 and doesn't send the unnecessary initialization commands to the WT-11. It best works together with the "Advanced solution" from above.

I used the current bootloader of arduino-0016 and adapted it to the Arduino-BT. Here are the changes:

  1. Set the Arduino pin PD7 to low
// first clear the output before setting the DDR to avoid even a short
// pulse on the WT-11 reset line
PORTD &= ~PD7;
DDRD |= PIND7;

B) Use a baud rate of 115200 baud (can be set in the Makefile)

C) The calculation of the baud rate registers has to be taken from HardwareSerial::begin (identical to the formula of the original Arduino-BT bootloader) because the standard formula doesn't work with the WT-11. The difference between the nominal and real baud rate is too high (125000 baud instead of possible 111111 baud for a nominal baud rate of 115200). This formula does some rounding (+ BAUD_RATE /2 before dividing by BAUD_RATE) instead of just using floor() for the remainder of the division:

UBRR0H = ((F_CPU / 16 + BAUD_RATE / 2) / BAUD_RATE - 1) >> 8;
UBRR0L = ((F_CPU / 16 + BAUD_RATE / 2) / BAUD_RATE - 1);

The modified formula can also be used for other Arduino hardware.

MikeT

To make the Auto-Reset work multiple times in a row, also a patched version of avrdude is necessary because the one delivered with arduino-017 sets the DTR signal, but it doesn't reset it on closing the serial connection.

The patch is currently under development and can be found here:
AVR Downloader/UploaDEr - Patches: patch #6866, bug #26703: [Feature Request]... [Savannah]. I hope it will make it into one of the next official Arduino versions.

When you need a preliminary binary, please contact me.

MikeT

Mike, I think this patch will solve some of the problems I've been having. How do I actually install it?

Thanks!
Tom

Hi Tom,

for Linux / Mac OS X it's easy. You might need to install some required packages, if you don't already have them: subversion bison flex automake libusb-dev.

For Windows it's really a pain setting up a working build environment with MinGW, msys, svn. I wouldn't recommend compiling it yourself. You can download it here: http://www.5dot1.de/arduino/avrdude_svn_878.zip

The archive also contains the updated avrdude.conf and boards.txt for the Arduino IDE

To download and compile avrdude yourself:

svn co svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude
cd avrdude
./bootstrap
./configure
make all

MikeT

I have a newer Mac with 10.5.8. What is:

: subversion bison flex automake libusb-dev.

?

Is there a compiled file for mac?

thanks!

Hi Tom,

I don't have a Mac, at least not yet. Maybe I get one when they bring out an iMac 21,5" with a Core i7 CPU, USB 3.0 and SATA.

subversion, bison, flex and automake are tools which are needed to compile avrdude. libusb-dev is a library for specific USB devices, I'm not sure if it is needed on OS X.

On Linux you use the package manager of your system (e.g. dpkg or aptitude on Debian systems) and select the named packages.

Apple supplies xcode (http://developer.apple.com/tools/xcode/) as gcc toolchain for OS X after registering to ADC Online Membership (free of charge) under the following address: http://developer.apple.com/products/membership.html

I don't know, whether xcode already includes the named tools or how to install them on OS X.

Hopefully the new avrdude will be delivered with Arduino-18!

MikeT

hello Mike T

you seems to be very pwerfull with Arduino, but your explainations are too hard for me:

i don't know what must i do to follow what you said.

Could you please be very basic and detailed because when you said "do this" i always wonder how must i do it !!

may be a kind of tutorial could be great..

thanks

I agree that MikeT has great Arduino powers.

Jackie Chan is to Kungfu
as
MikeT is to Arduino

Happy holidays Mike, and thanks for all your help!

Mike, when you added the auto reset to your arduino BT, did it work once and then stop working? Did the avrdude patch fix the problem completely? I'm getting an issue where 9 times out of 10, an upload errors out, with a statement relating to resource busy. The first upload isn't always the one that works.

The trial for version 0018 does not help.

Hi wingnut87,

when you added the auto reset to your arduino BT, did it work once and then stop working?

Yes, this was the reason for the change of avrdude. Arduino-18 still uses an old version of avrdude and the new version is not even scheduled for Arduino-19 >:( Please refer to the issue #106: Google Code Archive - Long-term storage for Google Code Project Hosting.

Have you removed the WT-11 reset from the bootloader or disabled the WT-11 reset pin by connecting it to GND via a 100 Ohm resistor?

MikeT

I actually don't have an Arduino BT. It is just a bunch of components on a proto board. The weird thing is that sometimes it will program a couple times in a row. Sometimes I'll try 10 times before it works. There is no consistent situation where it only works the first time.

About the patch, I'm a mechanical engineer and only have very basic programming skills. I can download and compile the code, but would not really know if what I was doing was wrong, or if the code isn't the answer. I guess I'll just try it this weekend.

Can you describe your hardware and the cabling (especially the reset pins of the ATMega and the Bluetooth chip). Do you use a normal Arduino Duemilanove or just a ATMega with the Arduino bootloader? Which bootloader do you use?

schematic

Mike, I have an arduino pro mini and bluesmirf gold with an rn41 from Roving networks. I have added a wire to the bluesmirf to get the DTR pin, and configured the module to use it. From the pin, I trigger an NPN transistor which pulls the DTR pin on the mini to ground. Then I have a 10k resistor between the DTR and +3.3V to discharge C2 on the mini so I can use it again. I am using the pro mini bootloader, but changed the baud to 19200. Everything is running at 19200.

So this wiring scheme actually consistently resets the arduino (bootloader blinks), and once in a while, I actually get a successful program. I have a scope I can borrow. It seems maybe the timing is off just a tad and the bootloader begins looking for the program too late (perhaps the reset takes too long). If I lengthen the bootloader wait time like you showed my a while back, it still does not work.

You can also connect your arduinobt an another arduino:

  1. Set a jumper between pins 5+6 (Reset+GND) of the ICSP connector on the Arduino Duemilanove. This puts the TX line of the ATmega to a high impedance state.

  2. Set a jumper between pins 5+6 (Reset+GND+Reset) of the ICSP connector on the Arduino-BT

  3. Connect some pins between the two Arduinos:
    Arduino-BT Duemilanove
    RX (PD0) => TX (PD1)
    TX (PD1) <= RX (PD0)
    GND = GND

  4. Connect the power cable to the Arduino-BT

  5. Connect the USB cable between the Arduino Duemilanove and your PC

  6. Start a terminal programmme (I use putty, you can also use Hyperterminal) and set the baud rate to the baud rate of your Arduino-BT which is normally 115200 but in your case it is 9600. Type the command (you won't see what you type):
    Code:
    SET

to see if your connection is working. It shows the most important settings.

  1. Type the following commands in the terminal window:
    Code:
    SET CONTROL BAUD 115200,8n1

Now you have to switch the baud rate of ther terminal programme to 115200.

  1. Optionally: Define a pin to restore some default settings.
    On a low-high edge on the WT-11 pin PIO5 (bit 5 = mask 0x20), all these commands are executed and restore the default config:
    Code:
    SET CONTROL BIND 1 20 RISE SET BT AUTH * 12345
    SET CONTROL BIND 2 20 RISE SET CONTROL BAUD 115200,8n1
    SET CONTROL BIND 3 20 RISE SET BT PAGEMODE 3 2000 1
    SET CONTROL BIND 4 20 RISE SET BT ROLE 0 f 7d00
    SET CONTROL BIND 5 20 RISE SET CONTROL ECHO 0
    SET CONTROL BIND 6 20 RISE SET CONTROL ESCAPE - 00 1
    SET CONTROL BIND 7 20 RISE SET CONTROL CONFIG 102D

  2. Optionally you can send the following command to enable the Over-The-Air provisioning via Bluetooth. This means you don't need a cable for sending commands, but you can open a second serial bluetooth connection to the Arduino-BT command channel:
    Code:
    SET PROFILE OTA on

To disable it, use
Code:
SET PROFILE OTA

  1. When you are finished, don't forget to remove the jumpers

(thanks to MikeT)