I am trying to use adxl345 to send vibration signals with the ESP32 as the microcontroller. However, the serial monitor only outputs "ADXL345 is not connected" despite having my connections correct which are just vcc to 3.3v, gnd to gnd, sda to d21, and scl to d22. I have also tried using the CS and SDO connections, but still the same output. Could it be a sensor issue? Since the ESP32 is functioning, i checked it too. I also have a code for checking I2C devices connection but still outputs no I2C connected.
Here is my main code (not everything):
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>
// Initialize ADXL345 sensor
Adafruit_ADXL345_Unified adxl = Adafruit_ADXL345_Unified(12345);
void setup() {
Serial.begin(115200);
if (!adxl.begin()) {
Serial.println("ADXL345 not detected. Check wiring!");
while (1);
}
Here is the code for like a test to see if an I2C device is connected
#include <Wire.h>
void setup() {
Serial.begin(115200);
Wire.begin(); // Default SDA=21, SCL=22
Serial.println("Scanning for I2C devices...");
}
void loop() {
byte error, address;
int 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");
Serial.println(address, HEX);
nDevices++;
}
}
if (nDevices == 0) Serial.println("No I2C devices found. Check wiring!");
delay(2000);
}



