Skip to content

Instantly share code, notes, and snippets.

@didasy
Created May 18, 2017 09:23
Show Gist options
  • Select an option

  • Save didasy/801fe56b04b3a203fa71068471159d91 to your computer and use it in GitHub Desktop.

Select an option

Save didasy/801fe56b04b3a203fa71068471159d91 to your computer and use it in GitHub Desktop.
MPX5700AP to PSI for STM32Duino
float getPressure(int raw) {
// raw 0-4095, get from analogRead();
// 0.001221001221001221 is from 5v/4095
// General info:
// range of voltage reading is 0V-5v
// the sensor outputs 0V or +ZPO to (0v or ZPO)+4.5V, while the range is 4.587v - 4.7v - 4.813v
// each KPa is 6.4mV or 0.0064V
float voltage = raw * 0.001221001221001221;
// Initializing pressure variable as float
float pressure = 0.0;
// 0.184v to 0.409 ZPO, we choose the middle one
float zeroPressureOffset = 0.2965;
// 0-4.6v reads 0-700KPa, the rest is 100KPa over 0.3V
if (voltage < 4.6) {
// pressure = voltage * 700.0/4.6; it raises 700KPA over 4.6 volt
// with compensation: pressure = (voltage - zeroPressureOffset) * 700.0/4.6;
// without compensation: pressure = voltage * 152.173913;
pressure = (voltage - zeroPressureOffset) * 152.173913;
} else {
pressure = 700.0 + (voltage-4.6) * (100.0 / 0.3);
// last piece raises 100KPa over 0.3 Volt.
// can be optimized to p = c1 + v * c2
}
return pressure * 0.145037738; // convert KPa to PSI
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment