Strange behaviour of following same sketch:
// Wire Slave Receiver
// by Nicholas Zambetti <http://www.zambetti.com>
// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this
// Created 29 March 2006
//Modified June2022 by Andrea Pagliari
//To use LCD Screen on Arduino Iot MKR and MKR Wifi1010
//**Wire
#include <Wire.h>
//EndOfWire**
//**MKRIotCarrier
int ScreenSwitch = 1;
//#include <Arduino_MKRIoTCarrier.h>
/* Create a carrier object */
//MKRIoTCarrier carrier;
//EndOf **MKRIotCarrier
void setup()
{
//**Wire
Wire.begin(0x40); // join i2c bus with address 0x40 which is the address the master send data to
digitalWrite(SDA, 0);//added to disable internal pull up resistors
digitalWrite(SCL, 0);//added to disable internal pull up resistors
Wire.onReceive(receiveEvent); // register event
//EndOfWire**
//Initialize the MKR IoT Carrier
/*carrier.begin();
carrier.display.setRotation(0);
carrier.display.enableDisplay(1);*/
//**SerialDebug
Serial.begin(9600); // start serial for debug output
//EndOfSerialDebug**
}
void loop()
{
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
Serial.print("EventRECEIVED");// debug
int x = Wire.read(); // receive byte as an integer
/* carrier.display.fillScreen(ST77XX_RED); //red background
carrier.display.setTextColor(ST77XX_WHITE); //white text
carrier.display.setTextSize(6); //medium sized text
carrier.display.setCursor(80, 100); //sets position for printing (x and y)
carrier.display.print(x); // print the integer*/
Serial.print("Speed=");
Serial.println(x); // print the integer
}
This way it perfectly works as i2c slave receiver.
As soon as I uncomment the MKR IoT part as following:
// Wire Slave Receiver
// by Nicholas Zambetti <http://www.zambetti.com>
// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this
// Created 29 March 2006
//Modified June2022 by Andrea Pagliari
//To use LCD Screen on Arduino Iot MKR and MKR Wifi1010
//**Wire
#include <Wire.h>
//EndOfWire**
//**MKRIotCarrier
int ScreenSwitch = 1;
#include <Arduino_MKRIoTCarrier.h>
/* Create a carrier object */
MKRIoTCarrier carrier;
//EndOf **MKRIotCarrier
void setup()
{
//**Wire
Wire.begin(0x40); // join i2c bus with address 0x40 which is the address the master send data to
digitalWrite(SDA, 0);//added to disable internal pull up resistors
digitalWrite(SCL, 0);//added to disable internal pull up resistors
Wire.onReceive(receiveEvent); // register event
//EndOfWire**
//Initialize the MKR IoT Carrier
carrier.begin();
carrier.display.setRotation(0);
carrier.display.enableDisplay(1);
//**SerialDebug
Serial.begin(9600); // start serial for debug output
//EndOfSerialDebug**
}
void loop()
{
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
Serial.print("EventRECEIVED");// debug
int x = Wire.read(); // receive byte as an integer
carrier.display.fillScreen(ST77XX_RED); //red background
carrier.display.setTextColor(ST77XX_WHITE); //white text
carrier.display.setTextSize(6); //medium sized text
carrier.display.setCursor(80, 100); //sets position for printing (x and y)
carrier.display.print(x); // print the integer
Serial.print("Speed=");
Serial.println(x); // print the integer
}
..it stops working as I2c slave receiver and didn't get any data.
Has someone already faced this strange behaviour of I2c in combination with MKR Iot Carrier with MKR WiFi1010?
Thanks a lot for your support.
BR
Andrea