Skip to content

Instantly share code, notes, and snippets.

@jenschr
Last active September 26, 2023 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jenschr/0105ccc56ca0e1ae7758928d5cff21c1 to your computer and use it in GitHub Desktop.
Save jenschr/0105ccc56ca0e1ae7758928d5cff21c1 to your computer and use it in GitHub Desktop.
Simple code snippet for reading Amphenol Pressure sensors with I2C output such as the NPA-700 and NPA-730.
/*
* Simple code snippet for reading Amphenol
* Pressure sensors with I2C output such as
* the NPA Series of Surface-Mount Pressure
* Sensors NPA-700 and NPA-730.
*
* This basic snippet will likely work for
* similar sensors of other brands also.
* I used NPA-730B-05WD to test this. It's
* not an Arduino Library, but that's also
* not required since the part is simple.
*/
#include "Wire.h"
byte data[4];
int combined = 0;
void setup() {
Serial.begin(9600);
Wire.begin();
}
void loop() {
// Read just the pressure
Wire.requestFrom(0x28, 2);
data[0] = Wire.read();
data[1] = Wire.read();
combined = (data[0] << 8) | data[1];
combined -= 8200; // Compensate
Serial.print(combined,DEC);
// Read the pressure & temp (but print only temp)
Wire.requestFrom(0x28, 4);
data[0] = Wire.read();
data[1] = Wire.read();
data[2] = Wire.read();
data[3] = Wire.read();
combined = (data[2] << 8) | data[3];
Serial.print(" : ");
Serial.println(combined,DEC);
delay(100);
}
@bazjo
Copy link

bazjo commented Sep 26, 2023

possible addition for NPA-730 (others similar)

byte data[4];
uint16_t pressure_bits = 0;
uint16_t temperature_bits = 0;
double pressure = 0.0;
double temperature = 0;

 /*
      Reference documents
      https://f.hubspotusercontent40.net/hubfs/9035299/Documents/AAS-920-477J-NovaSensor-NPA-SurfaceMnt-013019-web.pdf
      https://f.hubspotusercontent40.net/hubfs/9035299/Documents/AAS-910-289F-030315-web.pdf
  */
  Wire.requestFrom(0x28, 4);
  data[0] = Wire.read();
  data[1] = Wire.read();
  data[2] = Wire.read();
  data[3] = Wire.read();
  
  pressure_bits = ((data[0] & 0b00111111) << 8) | data[1];
  temperature_bits = (data[2] << 3) | (data[3] >> 5);
  
  Serial.print("|Raw Values - Pressure: ");
  Serial.print(pressure_bits, DEC);
  Serial.print(", Temperature: ");
  Serial.print(temperature_bits, DEC);

  //P_min = 0 hPa, P_max = 30 psi = 2068.428 hPa, Out_min = 1638, Out_max = 14745
  pressure = ((pressure_bits - 1638) / (14745.0 - 1638.0)) * (2068.428 - 0.0);
  temperature = ((temperature_bits * 200.0) / 2048.0) - 50.0;

  Serial.print(" | Processed Values - Pressure:");
  Serial.print(pressure, DEC);
  Serial.print(" hPa, Temperature: ");
  Serial.print(temperature, DEC);
  Serial.print(" °C |\r\n");```

@jenschr
Copy link
Author

jenschr commented Sep 26, 2023

Good one!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment