User Tools

Site Tools


parallax_ms5607_barometric_altimeter

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

parallax_ms5607_barometric_altimeter [2014/09/04 14:31] (current)
Line 1: Line 1:
 +====== Parallax_MS5607_Barometric_Altimeter ======
  
 +{{wiki:​ParallaxMS5607BarometricAltimeter.jpeg?​300|Altimeter Module reads Pressure and Temperature,​ Altitude must be calculated.}}
 +=Introduction=
 +The Parallax MS5607 Altimeter is a pressure and temperature sensing chip loaded with some firmware and thrown on a breakout board. They are readily available at Radio Shack. It uses i2c communication to provide values which can be used to calculate an altitude. Unfortunately,​ the documentation is not straight forward enough for me to easily follow. Thus this wiki page to try to get things together in a concise format.
 +
 +=i2c Protocol=
 +
 +Since Java doesn'​t support unsigned fields, any command that has a MSB (starts with) a 1 will have to be converted. Thus, the command passed to the i2c interface will be a negative byte with a different value.
 +
 +In order to do this conversion, take the command byte, subtract 1, do a bitwise complement and then you will have a magnitude. ​
 +
 +For C3:
 +
 +*10100110
 +*-1
 +*10100101
 +*Comp
 +*01011010
 +*Hex
 +*0x5A Signed > -0x5A
 +
 +Thank you Java for forcing us to use signed fields.
 +
 +=====Commands=====
 +*Device Address= 0x76 or 0x77 (118 or 119) depending on CSB
 +*Reset= 0x1E
 +*Read Calibration Coefficients
 +**C1= 0xA2 > -0x5E
 +**C2= 0xA4 > -0x5C
 +**C3= 0xA6 > -0x5A
 +**C4= 0xA8 > -0x58
 +**C5= 0xAA > -0x56
 +**C6= 0xAC > -0x54
 +
 +=====Parsing=====
 +The unit will return 3 byte and 2 byte values when queried. These need to be parsed into signed java fields. The following functions return longs that represent the bytes that came in over i2c. Here's that code:
 +
 +<​syntaxhighlight lang="​java">​
 +public final int TwoByteToInt(byte[[]] b) 
 + {
 + int i = 0;
 + i |= b[[0]] & 0xFF;
 + i <<= 8;
 + i |= b[[1]] & 0xFF;
 + return i;
 + }
 +
 +public final long ThreeByteToLong(byte[[]] b) 
 + {
 + long i = 0;
 + i |= b[[0]] & 0xFF;
 + i <<= 8;
 + i |= b[[1]] & 0xFF;
 + i <<= 8;
 + i |= b[[2]] & 0xFF;
 + return i;
 + }
 +</​syntaxhighlight>​
 +
 +=Calculations=
 +The following code shows a way to use java to get Temperature,​ Pressure, and Altitude from the module:
 +<​syntaxhighlight lang="​java">​
 +double Temp;
 +double dT;
 +double Offset;
 +double Sens;
 +double Pressure; <​nowiki>//</​nowiki>​Temp Compensated Pressure in mbar
 +double baroAltPre;
 +double pRatio;
 +double seaPressure;​
 +int baroAlt;
 +
 +
 + <​nowiki>//</​nowiki>​Temperature Conversion
 + dT= d2 - c5*Math.pow(2,​ 8);
 + Temp= 2000 + dT*c6/​Math.pow(2,​23);​
 + Temp= Temp/100; <​nowiki>//</​nowiki>​Scales for readability
 +
 +
 + <​nowiki>//</​nowiki>​Offsets and Sensitivity
 + Offset= c2*Math.pow(2,​ 17) +(c4 *dT ) /​Math.pow(2,​ 6);
 + Sens= c1*Math.pow(2,​ 16) + c3*dT/​Math.pow(2,​7);​
 +
 +
 + <​nowiki>//</​nowiki>​Pressure Calculation
 + Pressure= (d1*Sens/​Math.pow(2,​21) - Offset) / Math.pow(2,​15);​
 + Pressure= Pressure/​100;​ <​nowiki>//</​nowiki>​Scales for readability
 +
 + <​nowiki>//</​nowiki>​Altitude Calculation
 + seaPressure=1014;​
 + pRatio=seaPressure/​Pressure;​
 + baroAltPre= (Math.pow(pRatio,​ .19022256)-1)*(Temp+273.15) /.0065;
 + baroAlt= (int) (baroAltPre * 3.28084); <​nowiki>//</​nowiki>​Converts to feet and places in int for easy use
 +</​syntaxhighlight>​
parallax_ms5607_barometric_altimeter.txt ยท Last modified: 2014/09/04 14:31 (external edit)