ESP32 - I2C Scanner using Arduino IDE (working)

User avatar
jgustavoam
Posts: 10
Joined: Thu Feb 01, 2018 2:43 pm
Location: Belo Horizonte , Brazil
Contact:

ESP32 - I2C Scanner using Arduino IDE (working)

Postby jgustavoam » Sat Feb 17, 2018 3:17 pm

Picture of circuit ( ESP32 DEVKIT) :
https://www.flickr.com/photos/jgustavoam/39420488295/in/album-72157665409004158/

I did my first test with I2C Interface using Arduino IDE. And it works !
I2C scanner based on code of Nick Gammon http://www.gammon.com.au/forum/?id=10896
Very simple ! The I2C clock frequency is almost 100 KHz (97.96 KHz). I can't change this.

NOTE > PCF8574 - max frequency = 100 KHz (does not work with 400 KHz).
PCF8574 Datasheet = https://www.nxp.com/docs/en/data-sheet/PCF8574_PCF8574A.pdf

Circuit Diagram - SDA = GPIO_21 and SCL = GPIO_22 .
Very Important = You MUST use Pullup Resistors of 3K3 ohms.

Without then it does not work ! I still do not know, how to configure (Arduino IDE) pullup internal resistors. Change jumpers A0,A1 and A2 to modify address. Default PCF8574 address is 0x20 ( Decimal 32).

Picture of circuit diagram:
https://www.flickr.com/photos/jgustavoam/39420646405/in/album-72157665409004158/

Decoding I2C Pulses with Logic Analyzer :
https://www.flickr.com/photos/jgustavoam/26446652648/in/album-72157665409004158/


I2C Scanner (Arduino IDE 1.8.5) :

Code: Select all

[code]
// ESP32 I2C Scanner
// Based on code of Nick Gammon  http://www.gammon.com.au/forum/?id=10896
// ESP32 DevKit - Arduino IDE 1.8.5
// Device tested PCF8574 - Use pullup resistors 3K3 ohms !
// PCF8574 Default Freq 100 KHz

#include <Wire.h>

void setup()
{
  Serial.begin (115200); 
  Wire.begin (21, 22);   // sda= GPIO_21 /scl= GPIO_22
}

void Scanner ()
{
  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;

  Wire.begin();
  for (byte i = 8; i < 120; i++)
  {
    Wire.beginTransmission (i);          // Begin I2C transmission Address (i)
    if (Wire.endTransmission () == 0)  // Receive 0 = success (ACK response)
    {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);     // PCF8574 7 bit address
      Serial.println (")");
      count++;
    }
  }
  Serial.print ("Found ");     
  Serial.print (count, DEC);        // numbers of devices
  Serial.println (" device(s).");
}

void loop()
{
  Scanner ();
  delay (100);
}

[/code]


Console IDE (115200 Bps)

Code: Select all

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:812
load:0x40078000,len:0
load:0x40078000,len:11404
entry 0x40078a28

I2C scanner. Scanning ...
Found address: 32 (0x20)
Found 1 device(s).

I2C scanner. Scanning ...
Found address: 32 (0x20)
Found 1 device(s).
Retired IBM Brasil
Electronic hobbyist since 1976.

Who is online

Users browsing this forum: No registered users and 2 guests