Hi Brian:
Eric was over at my place today and we tested the attached Arduino
code with a potted depth sensor. Other than some crazy wiring issue, it
works just fine. The output of the depth sensor matches our reference
pressure sensor to within ~4 inches of water. Here's the scoop:
- Rather than try to debug Victor's or your code, I decided to just roll my
own C code, with very little abstraction in it.
- After figuring out two issues, the code worked just fine. First,
you need to add some time delay after sending commands to the sensor.
That's the purpose of the 10msec delays you'll see scattered about.
Second, the math that is shown in the datasheet requires 64-bit integers, which
the Arduino doesn't support. So I do the calculations in floating
point. You'll see a lot of explicit casts in the C-code, since I don't
fully understand how implicit casting works, and I didn't want to take any
chances.
- There are a number of 1-second delays in the code, that are related to
some debugging we're doing with the wiring. Right now the board works just fine,
until the pressure chamber is filled absolutely to the top with water, at which
point the depth sensor dies. The sensor works just fine with a
partially-filled chamber. There may be some crazy dielectric issue with
the I2C wiring. Eric's homework is to investigate it in the test tank, and
see what amount of wire immersion causes the interface to fail.
- The code I have included only does the linear fit for the temperature
sensor right now. I'm going to fork the code tonight and implement the
second-order fit. We did some temp sensor testing in pans of hot and cold
water, and the temperature was off by ~3 deg C in +5 deg C water. After I
code up the second-order fit, we need to repeat the experiment to see if it has
improved the accuracy to sufficient levels. This will be important for
diving at Tahoe, where the water is very cold.
- If you haven't debugged whatever issue is in the existing depth sensor
code, feel free to use this code instead. I'm going to do some cleanup on
it to remove extraneous print statements and the like, and it needs to have some
robustness added to it (error trapping, etc). But functionally, it works
fine.
- User interface stuff: Don't know if you've worked on the user
interface for the depth sensor, but it needs to have two features that I don't
believe exist right now: First, there needs to be a zero offset button
that zeros the depth sensor as part of the pre-dive check. This is
important when going back and forth between sea level and Tahoe, for
instance. Second, there needs to be a switch that selects between fresh
and salt water when converting from pressure to depth. I can get you the
relevant constants when you need them.
Have fun, and let me know what you think of my coding style (or lack
thereof :-) ).
-Walt