@jimit
Thank you for the answers. Have tried to use some code in the link. Yes, my code is similar.
Then I have isolated the I2C Scanner code and found a very confusing result, all addresses show up as active. Normally I expect to see only the actively used addresses as active.
Here the Scanner code. On M5Stack LCD screen I see all addresses white, see picture.
Is this really normal ?
To check if the cable is broken I will try to connect with the pins and not with the Grove, but could be the unstable connection is in DHT12 module .
And here the code I have used:
// I2C Scanner code used from this link to check if M5Stack is working
// https://github.com/PartsandCircuits/M5Stack-SAM/tree/master/M5Stack-SAM
// confusing part is that all I2C addresses are found in scan. That is surprising for me, because in a
// normal Arduino Uno(Mega you see only addresses which are actively used.
//
// Peter Obermeier 28 April 2018
#include <Wire.h>
#include <M5Stack.h>
void setup() {
M5.begin();
Wire.begin(9600);
}
void loop(){
byte error, address;
int nDevices;
byte ridx = 0;
byte lidx = 0;
boolean scanrun = HIGH;
// Create buttons
M5.Lcd.setTextSize(2);
M5.Lcd.setCursor(46,215);
M5.Lcd.setTextColor(RED);
M5.Lcd.printf("Scan");
M5.Lcd.drawRect(42,212,55,30,WHITE);
M5.Lcd.setCursor(135,215);
M5.Lcd.setTextColor(GREEN);
M5.Lcd.printf("Upd");
M5.Lcd.drawRect(130,212,55,30,WHITE);
M5.Lcd.setTextSize(1);
M5.Lcd.setTextColor(WHITE);
while(M5.BtnB.wasPressed()){
M5.update();
}
while(!M5.BtnB.wasPressed()){
if(scanrun==HIGH){
scanrun = LOW;
nDevices = 0;
for(address = 1; address < 127; address++ ){
ridx++;
if(ridx==17){
ridx = 1;
lidx++;
}
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0){
M5.Lcd.drawString(String(address,HEX),0+(ridx*18),45+(lidx*20),2);
nDevices++;
}else if (error==4){
M5.Lcd.drawString(F("ER"),0+(ridx*18),45+(lidx*20),2);
}else{
M5.Lcd.drawString(F("--"),0+(ridx*18),45+(lidx*20),2);
}
}
M5.update();
}else{
if(M5.BtnA.wasPressed()){
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setCursor(0,0);
M5.Lcd.print("new scan will start now ... ");
delay(2000);
M5.Lcd.fillScreen(BLACK);
ridx = 0;
lidx = 0;
scanrun = HIGH;
}
M5.update();
}
}
}