Article Index

 

Page 205

Use GPIO 5, 6 for the Arduino NANO ESP32 

Change   Wire.setPins(16, 15); tp   Wire.setPins(5, 6);

#include "Wire.h"

void setup() {
  Serial.begin(9600);
  Wire.setPins(16, 15);
  Wire.begin();
}

void loop() {
  Wire.beginTransmission(0x40);
  Wire.write(0xE7);
  Wire.endTransmission(true);

  Wire.requestFrom(0x40, 1);
  char temp = Wire.read();
  Serial.printf("User Register = %X \r\n", temp);
  delay(2000);
}

 

Page 207

Use GPIO 5, 6 for the Arduino NANO ESP32 

Change   Wire.setPins(16, 15); tp   Wire.setPins(5, 6);

#include "Wire.h"

void setup() {
  Serial.begin(9600);
  Wire.setPins(16, 15);
  Wire.begin();
}

void loop() {
  Wire.beginTransmission(0x40);
  Wire.write(0xE3);
  Wire.endTransmission();

  int count;
  count = Wire.requestFrom(0x40, 3);

  char msb = Wire.read();
  char lsb = Wire.read();
  char check = Wire.read();
  Serial.printf("\nmsb %d \nlsb %d \nchecksum %d \n",
                                       msb, lsb, check);
  delay(2000);
}

Page 209 

Use GPIO 5, 6 for the Arduino NANO ESP32 

Change   Wire.setPins(16, 15); tp   Wire.setPins(5, 6);

#include "Wire.h"

void setup() {
  Serial.begin(9600);
  Wire.setPins(16, 15);
  Wire.begin();
}

void loop() {
  Wire.beginTransmission(0x40);
  Wire.write(0xF3);
  Wire.endTransmission();

  int count;
  do {
    count = Wire.requestFrom(0x40, 3);
    delay(2);
  } while (count == 0);
  char msb = Wire.read();
  char lsb = Wire.read();
  char check = Wire.read();
  Serial.printf("\nmsb %d \nlsb %d \nchecksum %d \n",
                                      msb, lsb, check);
  delay(2000);
}

 

Page 210

Use GPIO 5, 6 for the Arduino NANO ESP32 

Change   Wire.setPins(16, 15); tp   Wire.setPins(5, 6);

#include "Wire.h"

void setup() {
  Serial.begin(9600);
  Wire.setPins(16, 15);
  Wire.begin();
}

void loop() {
  Wire.beginTransmission(0x40);
  Wire.write(0xF3);
  Wire.endTransmission();
  delay(50);

  int count;
  count = Wire.requestFrom(0x40, 3);
  char msb = Wire.read();
  char lsb = Wire.read();
  char check = Wire.read();
  Serial.printf("\nmsb %d \nlsb %d \nchecksum %d \n",
                msb, lsb, check);
  delay(2000);
}

 

Page 213

Use GPIO 5, 6 for the Arduino NANO ESP32 

Change   Wire.setPins(16, 15); tp   Wire.setPins(5, 6);

#include "Wire.h"
uint8_t crcCheck(uint8_t msb, uint8_t lsb, uint8_t check) {
  uint32_t data32 = ((uint32_t)msb << 16) | ((uint32_t)lsb << 8) |
                                                 (uint32_t)check;
  uint32_t divisor = 0x988000;
  for (int i = 0; i < 16; i++) {
    if (data32 & (uint32_t)1 << (23 - i)) data32 ^= divisor;
    divisor >>= 1;
  };
  return (uint8_t)data32;
}

void setup() {
  Serial.begin(9600);
  Wire.setPins(16, 15);
  Wire.begin();
}

void loop() {
  Wire.beginTransmission(0x40);
  Wire.write(0xF3);
  Wire.endTransmission();

  int count;
  do {
    count = Wire.requestFrom(0x40, 3);
    delay(2);
  } while (count == 0);

  char msb = Wire.read();
  char lsb = Wire.read();
  char check = Wire.read();
  Serial.printf("\nmsb %d \nlsb %d \nchecksum %d \n",
                                            msb, lsb, check);
  unsigned int data16 = ((unsigned int)msb << 8) |
                                    (unsigned int)(lsb & 0xFC);
  float temp = (float)(-46.85 + (175.72 * data16 / (float)65536));
  Serial.printf("Temperature %f C \n", temp);

  Wire.beginTransmission(0x40);
  Wire.write(0xF5);
  Wire.endTransmission(false);


  do {
    count = Wire.requestFrom(0x40, 3);
    delay(2);
  } while (count == 0);
  msb = Wire.read();
  lsb = Wire.read();
  check = Wire.read();
  Serial.printf("msb %d \n\r lsb %d \n\r checksum %d \n\r",
         msb, lsb, check);
  data16 = ((unsigned int)msb << 8) | (unsigned int)(lsb & 0xFC);
  float hum = -6 + (125.0 * (float)data16) / 65536;
  Serial.printf("Humidity %f %% \n\r", hum);

  Serial.printf("crc = %d\n\r", crcCheck(msb, lsb, check));

  delay(2000);
}