Wire i2c getting data from CPS122 (CPS120 similar)

I have a CPS122 barometer on a board that i'm trying to get the temperature and pressure data from using Wire, i'm stuck, i just cant get my head around the datasheet:-

There is examples for the CPS120 but that is slightly different, has anyone used this and can they help with (be gentle i'm new to this) thanks :-

#include<Wire.h>
#define Addr 0x6D

void setup() 
{
   Wire.begin();
   Serial.begin(115200);
   delay(300);
}

void loop()
{
byte buff[8];

Wire.beginTransmission(Addr);
int error = Wire.endTransmission();
if( error != 0)
{
 Serial.println( "CPS122 not acknowledging to its address");
}

// Give the sensor time to do the conversion.
delay( 300);

int n = Wire.requestFrom( Addr , 8);
if( n != 8)
{
 Serial.println( "Could not request data from CPS122");
}
else
{
 for( int i=0; i<8; i++)
 {
   buff[i] = (byte) Wire.read();

   if( buff[i] < 0x10)
     Serial.print( "0");
   Serial.print( buff[i], HEX);
   Serial.print( ", ");
 }
 Serial.println();
}}

according to the datasheet, you need to write to address 6 before you start reading the pressure and temperature data

  1. Wire.beginTransmission(Addr)
    2.Wire.write(0x06)
    3.Wire.endTransission(false) // does not send a STOP
    4.Wire.requestFrom(Addr, 5) // restart and read 5 data bytes
1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.