I have a problem reading from the SI7210 sensor

hello, i have a problem, reading from the sensor si7120
Datasheet: SI7210 pdf, SI7210 Download, SI7210 Description, SI7210 Datasheet, SI7210 view ::: ALLDATASHEET :::

#include <Wire.h>
#include <Arduino.h>


#define reg_chip 0xC0
#define reg_hByte 0xC1
#define reg_lByte 0xC2
#define otp_data_addr 0xE2
#define SLAVEaddr 0x30


void initializeSensor() {
 
    Wire.beginTransmission(SLAVEaddr);
    Wire.write(0xC9); 
    Wire.endTransmission();
    delay(100);
}



void setup()
{
    Serial.begin(115200);
  Wire.begin(21,22);
  delay(1000);;
  initializeSensor();
//--------------------------------------------------
  // iwc address scanner
  byte error, address;
  for (address = 1; address < 127; address++)
  {
    Wire.beginTransmission(address);
    delay(100);
    error = Wire.endTransmission();
    delay(1);

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address < 16)
        Serial.print("0");
      Serial.print(address, HEX);
      Serial.println("  !");
    }
  }
//--------------------------------------------------

  // Read ChipID
  Wire.beginTransmission(SLAVEaddr);
  Wire.write(0x04);
  Wire.write(0x01);
  Wire.write(reg_hByte);
  Wire.endTransmission();
  byte result = Wire.endTransmission();

  delay(100);

  Wire.requestFrom(SLAVEaddr, 1);
  delay(100); 
  byte chipID = Wire.read() >> 4;
  delay(100);
  Serial.print("ChipID: ");
  Serial.println(chipID, DEC);
  
}

void loop()
{
  int16_t field;
  float result;
  float scale = 204.7f;

  // Read high byte
  Wire.beginTransmission(SLAVEaddr);
  Wire.write(0x04);
  Wire.write(0x01);

  Wire.write(reg_hByte);
  Wire.endTransmission(false);
  delay(100);

  Wire.requestFrom(SLAVEaddr, 1);
  delay(1);
  byte highByte = Wire.read();
  delay(100);


  // read low byte
  Wire.beginTransmission(SLAVEaddr);
  Wire.write(0x04);
  Wire.write(0x01);
  Wire.write(reg_lByte);
  Wire.endTransmission(false);
  delay(100);
 
  Wire.requestFrom(SLAVEaddr, 1);
  delay(1);
  byte lowByte = Wire.read();
  delay(100);



  field = ((highByte & 0x7F) << 8) | lowByte;
  field -= 16384;

  result = (256*highByte+lowByte -16384)* (0.00125);
  Serial.println(result);

  delay(1000);
}

I do get an value, but always the same. The address is right. Maybe there is a special register to set?
Am i right, that the value should change, when i put a magnet near the sensor?
I use the esp32 and visual studio code
What i get:
I2C device found at address 0x30 !
ChipID: 0
-20.48
-20.48
-20.48
-20.48
-20.48
-20.48
-20.48
-20.48
-20.48
-20.48
-20.48

thanks for help

You need to do a repeated start so use

Wire.endTransmission(false); //repeated start

when you send the register address.

1 Like

Thanks for the links they help.
Your problem is not unexpected, and your wiring may be the root cause. Since hardware is involved, it’s crucial to provide an accurate, annotated schematic of your circuit as it is currently wired. Please note that Fritzing diagrams are not considered proper schematics; they are wiring diagrams and are often not helpful for troubleshooting.

What to Include:

  1. Annotated Schematic: Show all connections, including power, ground, and power sources. This helps us understand how your circuit is set up and identify any potential issues.

Why This Matters:

We have no way of knowing the specifics of your setup unless you provide that information. Clear and detailed descriptions enable us to offer the most accurate help possible. Without these details, it’s difficult to diagnose and solve the issues you're experiencing.

If all you know how to make is a Fritzing wiring diagram that is OK

So I have to do Wire.endTransmission(false); every time i send an reg. address?
Wire.beginTransmission(SLAVEaddr);

  Wire.write(0x04);
  Wire.endTransmission(false)
  Wire.write(0x01);
  Wire.endTransmission(false)
  Wire.write(reg_hByte);
  Wire.endTransmission(false);
  delay(100);

Like this or is one time enough?

This schematic is like this

Like you have it now in your code, just once at the end

Okey, do have that now, but i still get the same value the whole time.

Not 5V!!!
Must be 3.3V or you will damage the ESP

1 Like

I didn´t notice that...
It´s 5V now

You mean it 3.3v now?

1 Like

The board is already printed. But i have an extra placement boafd for the esp32 wroom and we got told, that we can connect the pins with 5V. So i think this should be fine.

For the SI7210 it is fine but you have the 4.7K resistors that are connected to the ESP connected to 5V and that will damage the ESP pins.

If want to leave it connected to 5V, it's up to you.
Did you put the false when you read the chip ID?

Okey, thank you for the hint.
And yes, i did change it, but i still get the same results as before

Post your new code

#include <Wire.h>
#include <Arduino.h>


#define reg_chip 0xC0
#define reg_hByte 0xC1
#define reg_lByte 0xC2
#define otp_data_addr 0xE2
#define SLAVEaddr 0x30
#define autoinc_bit_reg

void initializeSensor() {
 
    Wire.beginTransmission(SLAVEaddr);
    Wire.write(0xC9); 
    Wire.endTransmission();
    delay(100);
}



void setup()
{
    Serial.begin(115200);
  Wire.begin(21,22);
  delay(1000);;
  initializeSensor();
//--------------------------------------------------
  // iwc address scanner
  byte error, address;
  for (address = 1; address < 127; address++)
  {
    Wire.beginTransmission(address);
    delay(100);
    error = Wire.endTransmission();
    delay(1);

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address < 16)
        Serial.print("0");
      Serial.print(address, HEX);
      Serial.println("  !");
    }
  }
//--------------------------------------------------

  // Read ChipID
  Wire.beginTransmission(SLAVEaddr);
  Wire.write(0x05);
  Wire.write(reg_hByte);
  Wire.endTransmission(false);
  

  delay(100);

  Wire.requestFrom(SLAVEaddr, 1);
  delay(10); 
  byte chipID = Wire.read() >> 4;
  delay(100);
  Serial.print("ChipID: ");
  Serial.println(chipID, DEC);
}

void loop()
{
  
  float result;


  // Read high byte
  Wire.beginTransmission(SLAVEaddr);
  Wire.write(0x05);
  Wire.write(reg_hByte);
  Wire.endTransmission();

  delay(100);

  Wire.requestFrom(SLAVEaddr, 1);
  delay(10);
  byte highByte = Wire.read();
 


  // read low byte
  Wire.beginTransmission(SLAVEaddr);
  Wire.write(0x05);
  Wire.write(reg_lByte);
  Wire.endTransmission();
  delay(100);
 
  Wire.requestFrom(SLAVEaddr, 1);
  delay(10);
  byte lowByte = Wire.read();
  delay(100);



  result = (256*highByte+lowByte -16384)* (0.00125);
  Serial.println(result);

  delay(1000);
}

Try this code. See if it reads the chip ID


#include <Wire.h>
#include <Arduino.h>


#define reg_chip 0xC0
#define reg_hByte 0xC1
#define reg_lByte 0xC2
#define otp_data_addr 0xE2
#define SLAVEaddr 0x30


void initializeSensor() {

  Wire.beginTransmission(SLAVEaddr);
  Wire.write(0xC9);
  Wire.endTransmission();
  delay(100);
}



void setup()
{
  Serial.begin(115200);
  Wire.begin(21, 22);
  delay(1000);;
  // initializeSensor();
  //--------------------------------------------------
  // iwc address scanner
  byte error, address;
  for (address = 1; address < 127; address++)
  {
    Wire.beginTransmission(address);
    delay(100);
    error = Wire.endTransmission();
    delay(1);

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address < 16)
        Serial.print("0");
      Serial.print(address, HEX);
      Serial.println("  !");
    }
  }
  //--------------------------------------------------


  // Read ChipID
  Wire.beginTransmission(SLAVEaddr);
  Wire.write(0xC0);
  byte result = Wire.endTransmission(false);

  delay(10);
  Wire.requestFrom(SLAVEaddr, 1);
  byte chipID = Wire.read() >> 4;
  Serial.print("ChipID: ");
  Serial.println(chipID);

}

void loop()
{

}

Yes it does, thank you!

So do you see how it's done?
Just write the register address, do endTransmission (false), then read 1 byte of data.

Yes, but i still won´t get any value from register =0xc1 and 0xc2, the field value