Description
Please fill the info fields, it helps to get you faster support ;)
If you have a Guru Meditation Error, please decode it:
https://github.com/me-no-dev/EspExceptionDecoder
----------------------------- Remove above -----------------------------
Hardware:
Board: ESP32 Pico D4 Kit
Core Installation/update date: ?11/jul/2017?
IDE name: Arduino IDE
Flash Frequency: 40Mhz
Upload Speed: 115200
Description:
I have been searching for an example of 2 concurrent I2C ports in Arduino. I have found an example 2 port scanner , but the second port does not drive any outputs to the lines.
I have tried each individually and they work fine. I have tried manually attaching and detaching a single port to see if I could simply switch with one driver, no luck.
The actual configuration will require one port to be a master and one port to be a slave.
And thoughts or insights?
Sketch:
#include <Arduino.h>
#include <Wire.h>
#include <dummy.h> //for esp32
#define SDA1 21
#define SCL1 22
//#define SDA1 19
//#define SCL1 23
#define SDA2 19
#define SCL2 23
TwoWire1 I2Cone = TwoWire1(0);
TwoWire2 I2Ctwo = TwoWire2(1);
void scan1(){
Serial.println("Scanning I2C Addresses Channel 1");
uint8_t cnt=0;
for(uint8_t i=0;i<128;i++){
I2Cone.beginTransmission(i);
uint8_t ec=I2Cone.endTransmission(true);
if(ec==0){
if(i<16)Serial.print('0');
Serial.print(i,HEX);
cnt++;
}
else Serial.print("..");
Serial.print(' ');
if ((i&0x0f)==0x0f)Serial.println();
}
Serial.print("Scan Completed, ");
Serial.print(cnt);
Serial.println(" I2C Devices found.");
}
void scan2(){
Serial.println("Scanning I2C Addresses Channel 2");
uint8_t cnt=0;
for(uint8_t i=0;i<128;i++){
I2Ctwo.beginTransmission(i);
uint8_t ec=I2Ctwo.endTransmission(true);
if(ec==0){
if(i<16)Serial.print('0');
Serial.print(i,HEX);
cnt++;
}
else Serial.print("..");
Serial.print(' ');
if ((i&0x0f)==0x0f)Serial.println();
}
Serial.print("Scan Completed, ");
Serial.print(cnt);
Serial.println(" I2C Devices found.");
}
void setup(){
Serial.begin(115200);
I2Cone.begin(SDA1,SCL1,400000); // SDA pin 21, SCL pin 22 TTGO TQ
I2Ctwo.begin(SDA2,SCL2,400000); // SDA pin 5, SCL pin 4 builtin OLED
}
void loop(){
delay(500);
scan1();
Serial.println();
delay(500);
delay(500);
scan2();
Serial.println();
delay(2000);
}