Tuesday, August 09, 2011

Arduino pro mini + bluesmirf + FTDI basic

Tonight I got my Ubuntu Lucid machine to program a 3.3v Arduino Pro Mini using a 3.3v FTDI Basic USB->TTL serial interface, and then got them both to talk to a BlueSmirf bluetooth->TTL serial board.

To get the bluetooth board to work, I wired it to the USB board so that I could talk to it from both ends: its serial lines and over bluetooth.  (See photo)

I ran minicom and connected to /dev/ttyUSB0, talking to the USB board and thus to the serial lines on the bluesmirf.  This bluesmirf was set up to communicate at 57600 baud, which I had to find by trial and error.  Once I got the right baud rate, typing "$$$" got me a "CMD" prompt as the manual suggests.  I switched it over, so now it uses 115200 baud.

On the bluetooth side, I used these instructions to talk to the bluesmirf over bluetooth from my glaptop:

Once I ran this: sudo rfcomm connect 0 00:06:66:04:B1:C2 1

I thought it was going to let me type to the bluetooth device, but really it's just creating /dev/rfcomm0 and then doing nothing. So with that command running in another window, I ran minicom and pointed it at /dev/rfcomm0, at which point I was able to type and see it in the other minicom window (pointed at /dev/ttyUSB0), and vice versa.

So that's how I knew the bluesmirf board was working.

To get the arduino running on my lucid machine, I had to apt-get install gcc-avr and avr-libc, make sure my JAVA_HOME was set right (because I have sun-java6-jre installed): export JAVA_HOME=/usr/lib/jvm/java-6-sun/jre

Then I downloaded the 64-bit linux install from here: http://arduino.cc/en/Main/Software and unpacked it into a folder in my home directory.  Then I cd'ed into it and ran ./arduino.  I tried the http://arduino.cc/en/Tutorial/Blink example, and it worked great.

Next, I wired the arduino to the bluesmirf as shown here:

I left the bluesmirf TX unconnected to the arduino RX so that it wouldn't interfere when I programmed the arduino.  I used the "arduino" IDE to compile the following program, which just dumps some stuff over the serial port any time the reset button is hit.  The only change from the stock arduino "ASCII table" example is the change to 115200 baud, and pulling pin 13 high to assert the CTS hardware flow control line on the bluesmirf.  (I could also just as easily have run a wire from VCC to that line):

  ASCII table
 Prints out byte values in all possible formats:  
 * as raw binary values
 * as ASCII-encoded decimal, hex, octal, and binary values
 For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII
 The circuit:  No external hardware needed.
 created 2006
 by Nicholas Zambetti 
 modified 18 Jan 2009
 by Tom Igoe
 This example code is in the public domain.

void setup() 
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
  // prints title with ending line break 
  Serial.println("ASCII Table ~ Character Map"); 

// first visible ASCIIcharacter '!' is number 33:
int thisByte = 33; 
// you can also write ASCII characters in single quotes.
// for example. '!' is the same as 33, so you could also use this:
//int thisByte = '!';  

void loop() 
  // prints value unaltered, i.e. the raw binary version of the 
  // byte. The serial monitor interprets all bytes as 
  // ASCII, so 33, the first number,  will show up as '!' 

  Serial.print(", dec: "); 
  // prints value as string as an ASCII-encoded decimal (base 10).
  // Decimal is the  default format for Serial.print() and Serial.println(),
  // so no modifier is needed:
  // But you can declare the modifier for decimal if you want to.
  //this also works if you uncomment it:

  // Serial.print(thisByte, DEC);  

  Serial.print(", hex: "); 
  // prints value as string in hexadecimal (base 16):
  Serial.print(thisByte, HEX);     

  Serial.print(", oct: "); 
  // prints value as string in octal (base 8);
  Serial.print(thisByte, OCT);     

  Serial.print(", bin: "); 
  // prints value as string in binary (base 2) 
  // also prints ending line break:
  Serial.println(thisByte, BIN);   

  // if printed last visible character '~' or 126, stop: 
  if(thisByte == 126) {     // you could also use if (thisByte == '~') {
    // This loop loops forever and does nothing
    while(true) { 
  // go on to the next character

Once I flashed the arduino, I connected from my laptop to the bluesmirf over bluetooth, hit the reset button, and saw the table as expected in the minicom window connected to /dev/rfcomm0.  First try, even. :)


Anonymous said...

Hi can u send me corect commands that u send to the BT modul to se it up in 9600,1,N,8 just in uart pipe mode write me on orlin369@abv.bg thanks :).

Anonymous said...

I don't remember exactly, but the manual is here: http://www.sparkfun.com/datasheets/Wireless/Bluetooth/rn-bluetooth-um.pdf

And it looks like the command to set the baud rate would be "SU,96". "SL,N" should set no parity, and "S7,0" should set 8 data bits, but these are also the default values, so you shouldn't need to change them.