Altimeter, the bug hunt

Computers are good at following instructions, but not at reading your mind —Donald Knuth.

… now it’s time for debugging. Is there a problem, officer?I’m afraid so; the PIC18LF14K50 does not support in-chip debugging. So I have two alternatives:

Print out the variables I want to check.

Test the code on a PIC18F4520.

So far I evaluated the two approaches with similar results.

Figure 1. The BMP085 barometric pressure sensor, a RF module, a protoboard and the mighty PIC18F4520 for debugging purposes.

The first thing I noticed was that the sensor’s address was not the correct one. I was using the libraries from Adafruit, slightly modified to adjust the code for using it in Microchip’s C18 compiler —I think software engineers call that refactoring. The Adafruit library defines the sensor’s address as

and that is one I took for granted. But there was something wrong because I was always getting 0xFFFF when reading from the sensor. And that’s not good. I haven’t looked into the Wire.h library to see how it works, but I am guessing that it gets the 7 bits of the address and adds and eighth bit for write/read. Why? Because the my code is essentially the same…

That’s one problem solved. The next one is that I am getting pressure readings of the order of 710 hPa at sea level —that’s equivalent to about 2200 m. The BMP085 requires a lot of bit shift operations to get from readings —raw values— to true pressure and true temperature; and I think that the C18 compiler does not get all along very well with it. But that’s work for tomorrow.