So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By aalhard
#93057 I cant figure out how to use i2c on this
https://fccid.io/2AKBPESP8266-S3/User-M ... 594791.pdf

this code finds no i2c devices with any value for SDA&SCL

Code: Select all#include <Arduino.h>
#include <Wire.h>

#define DISPLAY_ERROR false
#define LOOP_DELAY    10000
#define USER_PIN      true
 
// Customize I2C bus pins for ESP8266 or ESP32
const int PIN_SCL = 14;
const int PIN_SDA = 12;

String I2Ctest() {
  byte error, address;
  int nDevices;
  String s;
 
  s="Scanning...\n";
 
  nDevices = 0;
  for(address = 1; address < 127; address++ ) { 
    Wire.beginTransmission(address);
    error = Wire.endTransmission();
 
    if (error == 0) {
      s+="I2C device found at 0x";
      if (address<16)
        s+="0";
        s+=String(address,HEX);
        s+="\n";
 
      nDevices++;
    } else if ( error > 0 ) {
      if ( DISPLAY_ERROR ) {
        s+="Unknow error at 0x";
        if (address<16)
          s+="0";
          s+=String(address,HEX);
          s+="\n";
      } 
    }   
  }
  if (nDevices == 0)
    s+="No I2C devices found\n";
  else
    s+="done\n";
  return s;
}

void setup() {
  Serial.begin(115200);
  Serial.println("I2C scanner");
  #if USER_PIN
    Wire.begin(PIN_SDA, PIN_SCL);
  #else
    Wire.begin();
  #endif
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println(I2Ctest());
  delay(LOOP_DELAY);
}