What library should i use?

Good afternoon, help with this question: ESP32-C3-DevkitC-02v1.1 board, an ADC is connected to it - BH45B1225v110 (data sheet can be found here - https://www.holtek.com/productdetail/-/vg/BH45B1225) i2c bus. I need to read the HIRCC register and set a value for it (enable it). But as I understand it, this requires an ADC control library, because. it uses a special syntax that the Arduino does not understand by default. ( The text on the screen is not related to the task, it is only an example of the syntax for reading ADC registers, but without libraries, arduino does not understand it):


what library should i use ? *"direct adc" - is not compatible with esp 32.

the BH45B1225 appears to have an I2C interface
have a look at ESP32 I2C
try running the I2C scanner to see if the device is found
upload a schematic of your circuit
when uploading code upload the text (not an image) using code tags </> it makes it easy to read

If so then the library is mentioned in a
#include <TheLibrary.h>
in the sample code from where you picked your snippet.

A more careful look at the linked page reveals helpful buttons. But I suspect that you have to Sign In before the buttons can be used.

here in this code this bunch of ESP32-C3 + BH45B1225 works - and gives out the address of the ADC - 0x68

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <Adafruit_I2CDevice.h>

//#define I2C_SDA 8
//#define I2C_SCL 9

void setup() {
  Wire.begin();
  Serial.begin(115200);
  Serial.println("\nI2C Scanner");
}
 
void loop() {
  byte error, address;
  int nDevices;
  Serial.println("Scanning...");
  nDevices = 0;
  for(address = 1; address < 127; address++ ) {
    Wire.beginTransmission(address);
    error = Wire.endTransmission();
    if (error == 0) {
      Serial.print("I2C device found at address 0x");
      if (address<16) {
        Serial.print("0");
      }
      Serial.println(address,HEX);
      nDevices++;
    }
    else if (error==4) {
      Serial.print("Unknow error at address 0x");
      if (address<16) {
        Serial.print("0");
      }
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0) {
    Serial.println("No I2C devices found\n");
  }
  else {
    Serial.println("done\n");
  }
  delay(3000);          
}

Wrong approach :frowning:

You don't have to access internal ADC registers of the controller, as your code tries. Instead use I2C (Wire library) to communicate with the external ADC. Read in detail section "Functional Description" in the data sheet. It contains the register names and addresses which you can access, and what the register contents mean.

You may be better off with a different ADC that comes with an Arduino library and sample code.

the BH45B1225 datasheet gives the I2C address range as 0xA to 0xD0
your result could be 0xD0 shifted right 1 bit to 0x68
have a look at the BH45B1225 Software Library - see if there is code you could port to the Arduino otherwise you will have to write code yourself
@DrDiettrich advice to change to an ADC supported by an Arduino Library sounds a good idea

I agree, the idea is good. But just think, they hired me without experience and they want me to do this task for the specified bunch.

Edit: I assume you have experience programming in C/C++ and have used microcontrollers?

sounds like you have been given an ESP32 connected to a BH45B1225 and told to get it working
if the BH45B1225 Software Library contains sample C/C++ code you can use that as a starting point to port to the ESP32 (check the copyright)
at a minimum you would need to change the I2C function calls used to access the the original microcontroller I2C interface to suit the Wire library for the ESP32

Some experience is required to understand the module data sheet. You can improve your experience by studying an existing Arduino solution, better than reading other sources that do not result in immediately usable code.

I had programming experience in C# as a student. But I encountered microcontrollers for the first time.

I agree, you need to gain more experience, where would you advise to start?

Start reading more carefully, e.g. what I wrote in my #5 and #9.

if your background is C# it may be worth doing a web search for C and C++ vers C# to get some idea of the differences between the languages

if you are new to microcontrollers and C/C++ get some experience with the Arduino IDE and try running and modifing some some of the example programs under File>Examples
e.g. attach an LED to the ESP32 modify the File>Examples>Blink to blink the LED ON/OFF (try different ESP32 GPIO pins)

if your target is to write code for the BH45B1225 I2C experiment with some I2C sensors
e.g. TMP102

  1. run the example code in TMP102 directory examples
  2. in conjunction with the TMP102 datasheet look at the library source code in directory src and the ESP32 I2C examples

you should then have some idea of the problems you will face porting the BH45B1225 to an ESP32
if there is sample BH45B1225 C/C++ source code even for a different microcontroller it can give you a starting point - low level I2C read and write functions tend to be similar