I2C scan failed for i2c us on Tx & Rx pin -ESP8266(Node MCU)
Posted: Sat Apr 04, 2020 6:54 pm
I am using this code to scan two no. of i2c bus - one is default (4,5) and other is on Tx & Rx pin(1,3) by enabling them through FUNCTION_3. Please see the code:
But output on software serial port is:
05:21:36.888 -> I2C scanner. Scanning bus 0...
05:21:36.888 -> Found address: 57
05:21:36.943 -> Found address: 58
05:21:36.943 -> I2C scanner. Scanning bus 1...
05:21:36.943 -> Found address: 57
05:21:36.943 -> Found address: 58
05:21:36.943 -> I2C device check DONE.
05:21:41.939 -> I2C scanner. Scanning bus 0...
05:21:41.939 -> Found address: 57
05:21:41.975 -> Found address: 58
05:21:41.975 -> I2C scanner. Scanning bus 1...
05:21:41.975 -> Found address: 57
05:21:41.975 -> Found address: 58
05:21:42.021 -> I2C device check DONE.
It is unable to detect devices on i2c bus enabled on pin (1,3) i.e. Tx & Rx. Please find the mistake in my i2c scan code.
Code: Select all
#include <Wire.h>
#include <SoftwareSerial.h>
#include <SSD1306Wire.h>
TwoWire Wire1;
SoftwareSerial swSer(14, 12, false, 128);
SSD1306Wire *display;
void setup(void) {
swSer.begin(115200);
pinMode(1, FUNCTION_3);
pinMode(3, FUNCTION_3);
delay(5);
Wire.begin();
display = new SSD1306Wire(0x3c , 1, 3);
Wire1.begin(4,5);
}
void loop()
{ swSer.println("I2C scanner. Scanning bus 0...");
for (byte i = 8; i < 127; i++)
{
Wire.beginTransmission(i);
if (Wire.endTransmission() == 0)
{
swSer.println("Found address: " + String(i));
// check address
if ((i == 32) or (i == 39))
{
// found device, do something..
}
delay(1);
}
}
Wire.endTransmission();
swSer.println("I2C scanner. Scanning bus 1...");
for (byte i = 8; i < 127; i++)
{
Wire1.beginTransmission(i);
if (Wire1.endTransmission() == 0)
{
swSer.println("Found address: " + String(i));
// check address
if (i == 64)
{
// found device, do something..
}
delay(1);
}
}
Wire1.endTransmission();
swSer.println("I2C device check DONE.");
delay(5000);
}
But output on software serial port is:
05:21:36.888 -> I2C scanner. Scanning bus 0...
05:21:36.888 -> Found address: 57
05:21:36.943 -> Found address: 58
05:21:36.943 -> I2C scanner. Scanning bus 1...
05:21:36.943 -> Found address: 57
05:21:36.943 -> Found address: 58
05:21:36.943 -> I2C device check DONE.
05:21:41.939 -> I2C scanner. Scanning bus 0...
05:21:41.939 -> Found address: 57
05:21:41.975 -> Found address: 58
05:21:41.975 -> I2C scanner. Scanning bus 1...
05:21:41.975 -> Found address: 57
05:21:41.975 -> Found address: 58
05:21:42.021 -> I2C device check DONE.
It is unable to detect devices on i2c bus enabled on pin (1,3) i.e. Tx & Rx. Please find the mistake in my i2c scan code.