ADS1115 e ESP32 wiring and sketch not working

Hi everyone,
To have a more correct reading of the values ​​of a thermistor I am trying to use the ADC converter ADS1115.
I tried to connect it as shown in the picture ... but when I try to read the values ​​it goes wrong and then starts printing wrong characters.

this is the sketch used to read the voltage

#include <Wire.h>
#include <Adafruit_ADS1015.h>

Adafruit_ADS1115 ads(0x48);
float Voltage = 0.0;

void setup(void)
{
Serial.begin(9600);
ads.begin();
}

void loop(void)
{
int16_t adc0;

adc0 = ads.readADC_SingleEnded(0);
Voltage = (adc0 * 0.1875)/1000;

Serial.print("AIN0: ");
Serial.print(adc0);
Serial.print("\tVoltage: ");
Serial.println(Voltage, 7);
Serial.println();

delay(1000);
}

And this is the error i get

Guru Meditation Error: Core  1 panic'ed (InstrFetchProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x800d0f3c  PS      : 0x00060530  A0      : 0x400d0ee8  A1      : 0x3ffb1f00 
A2      : 0x3ffc0260  A3      : 0x00000048  A4      : 0x00000002  A5      : 0x00000001 
A6      : 0x00060320  A7      : 0x00000000  A8      : 0x00000002  A9      : 0x00000080 
A10     : 0x00000002  A11     : 0x00000048  A12     : 0x3ffc0260  A13     : 0x00000002 
A14     : 0x00000001  A15     : 0x3ffb1f0c  SAR     : 0x0000001d  EXCCAUSE: 0x00000014 
EXCVADDR: 0x800d0f3c  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0x00000000 

Backtrace: 0x400d0f3c:0x3ffb1f00 0x400d0ee5:0x3ffb1f30 0x400d100d:0x3ffb1f50 0x400d1083:0x3ffb1f70 0x400d0c64:0x3ffb1f90 0x400d24f9:0x3ffb1fb0 0x400889d9:0x3ffb1fd0

Rebooting...
a8⸮⸮⸮*!ġ$+U!⸮ ⸮⸮a@HP;	1 ⸮j⸮*!ġ$⸮a@⸮⸮⸮w⸮	1P<⸮>|⸮	1⸮⸮⸮@⸮	1⸮⸮⸮⸮䂍P⸮⸮`⸮I!T ⸮⸮*!ġ$+	1P<⸮>|⸮a,⸮⸮⸮⸮+!⸮P;a,⸮$⸮w⸮

about this error exception decoder says

PC: 0x400d103c: Adafruit_ADS1015::readADC_SingleEnded(unsigned char) at /Users/matteoandreoli/Documents/Arduino/libraries/Adafruit_ADS1X15/Adafruit_ADS1015.cpp line 182
EXCVADDR: 0x00000000

Decoding stack results
0x400d103c: Adafruit_ADS1015::readADC_SingleEnded(unsigned char) at /Users/matteoandreoli/Documents/Arduino/libraries/Adafruit_ADS1X15/Adafruit_ADS1015.cpp line 182
0x400d235d: String::changeBuffer(unsigned int) at /Users/matteoandreoli/Library/Arduino15/packages/esp32/hardware/esp32/1.0.4/cores/esp32/WString.cpp line 168
0x400889d9: vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c line 143

n the attached photo you can see the scheme I followed for the connections, my version is 16bit not 12 as in the photo and i have connected to A0.. what did i wrong? is it wired correctly?

thank you very much

are you sure you connected to the SDA and SCl pins on the esp32?

ESP32 I2C Communications indicates they are pins 21 and 22

This will be the clue to the error 'EXCVADDR: 0x800d0f3c.' Most likely the Adafruit library is doing a bad thing and causing the error, from experience. To prove its the library use another library for the A:D.

There is documentation in the ESP32 API that will show you how to troubleshoot the issue. My experience is that I end up re-writing the Adafruit library for ESP32 compatibility.

The ESP32 is using freeRTOS, even if you don't, to manage system operations. freeRTOS is a multi threading OS. With a few changes, made by ESPRESSIF, freeRTOS is also a multi processing OS. I found many Adafruit libraries do not handle being in a multi environment very well or they use malloc and the like which are not thread safe.

Examples of baddies.

The ESP32 main processor has 3 memory main memory areas; 1 area for each core and one shared pool area. Something like malloc() can grab an area of memory, bypassing the ESP32 memory manager, going around the freeRTOS OS. Bypassing the OS, the OS does not recognize that malloc() set aside RAM as being set aside. The ESP32 has pmalloc() which is a thread safe malloc() wrapper that makes the OS aware of the memory allocation.

The ESP32 assigns a variable to the core the variable is made on. Lets say an array is made and when the ESP was assigning the variable to memory, the ESP was doing a core0 thing so it made the variable on core0. Your program was defaulted to being assigned to core1. When your program, running on core1, goes to access the variable on core0, the OS says fault. If you did not write any cross core code.


You might be interested in looking through the ESP32 API.

Consider the ESP32 has a Sigma-delta Modulation module, built in. https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/sigmadelta.html

ntroduction
ESP32 has a second-order sigma-delta modulation module. This driver configures the channels of the sigma-delta module.

Functionality Overview
There are eight independent sigma-delta modulation channels identified with sigmadelta_channel_t. Each channel is capable to output the binary, hardware generated signal with the sigma-delta modulation.

gcjr:
are you sure you connected to the SDA and SCl pins on the esp32?

ESP32 I2C Communications indicates they are pins 21 and 22

I think i wrong to wire GND!!!! really sorry.. now if i run i2c scan

#include <Wire.h>
 
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(5000);          
}

it give me the right adress!

Scanning...
I2C device found at address 0x48
done

Scanning...
I2C device found at address 0x48
done

And also voltage code seems to work..
Now i need to connect thermistor in the right way..becouse it seems not to work..and then to find the right code to make it work..thank you very much :slight_smile:

@Idahowalker thank you very much it's quite specific for my low knowledge but i will try to check the link you sujjest me..

Thank you very much!