Thursday 19 May 2011

Testing Components

From a blank breadboard to working components took over a month of occasional tinkering. The 'easy' things ended up being a pain in the ass.

The 'kind of working' integrated components

Step 1 - Getting the RN-42 working. This was much easier than I thought, once I had soldered the required pins. I just used the circuit in the data sheet, applied power, searched for the bluetooth device from the desktop then connected. I used TeraTerm as the terminal emulator program to access the device using $$$ to enter command mode and play with the settings. A few tips:
  • Soldering pins onto the surface mount device was not too hard. I tinned up some copper wire with solder, put a tiny dab of solder onto the surface mount pad, then soldered the two together with a minimium of head. This is a pretty easy and quick method for prototyping with SMD components.
  • The bluetooth stack on a PC is a pain in the ass. Connecting to a SPP device via a virtual COM port via a terminal emulator is far from reliable. I ended up having to restart my system way too often to reconnect to the RN-42 in between power cycles. If you can write some code to connect via bluetooth without the virtual COM port it will be much more reliable. I have used Java desktop JSR-82 based code to do that now. 

Step 2 - Getting the Microcontroller working with the RN-42. This was much harder than I thought. I eventually worked out how to hook everything up and program using ICSP via the PICKIT. The tutorial here plus Hari Nair's PIC24F code helped. The most difficult thing was working out baud rate on both the RN-42 (which is set via command mode) and the PIC24F (which is dependant on the clock rate). Eventually I got it all working and was able to print 'Hello BlueFlyVario' via bluetooth to the terminal emulator.

The most painful thing with the PIC24F was when I wanted to use U2 rather than U1 as the UART port. The U2RX is on pin 5, which also happens to be used for AN3. A very poorly documented feature of the PIC24F is that if you are going to use a pin that can be used as an analogue input as a digital input (which the UART needs) then you have to set the corresponding ADxPCFG register, as by default it is set as an analogue input. In this case the call '_PCFG3=1;' was all that was required - after eight hours of pain.

Step 3 - Interfacing with the BMP 085. This was pretty easy. Hari Nair's code was very helpful for the interfacing. Instead of doing all of the calculations on the PIC I just dumping the pressure every measurement cycle to the uart.
  • You might be able to see from the image that I picked up the status pin of the RN 42 (pin 21 - PIO5) via an I/O on the PIC. I programmed it so the PIC code only runs when the bluetooth is connected.
  • Rather than pause for the pressure conversion I am picking up End Of Conversion from the BMP085 to measure the subsequent pressure measurement as fast as possible.
  • The BMP085 breakout does not allow access to VDD Digital and VDD Analogue as separate power inputs. This means that it is not possible to shield the analogue power input from the digital switching using inductors. This meant that the RMS error of the pressure measurements was about 30% higher than the datasheet said was possible. 
This test setup allowed me to play with BMP085. I tried over many tinkering sessions to optimise the filtering and code. As it turns out (now) this is all unimportant as my current plan is simply to measure pressure as many times as possible in about 50 ms then dump the average pressure to the uart (allowing 20 pressure measurements a second). I only measure the temperature a few times a second for the compensated calculation.

Another thing that is kind of important is that all of the ancillary characters that I was tempted to 'print' to the uart costs a lot of micro controller processing time. In the end I am only dumping a very short string with the pressure as an int in pascals.

At this point I thought I had cracked it, I would soon have a working vario...