// I2C Slave Code : Antero Metso Fab Academy 2022 group work - 18.11.2022 // References: // https://docs.particle.io/reference/device-os/api/wire-i2c/onrequest/ // https://github.com/ControlEverythingCommunity/MS5805-02BA01/blob/master/Arduino/MS5805_02BA01.ino // https://github.com/Koepel/How-to-use-the-Arduino-Wire-library/wiki/How-to-make-a-reliable-I2C-bus // https://www.instructables.com/ATTiny-USI-I2C-The-detailed-in-depth-and-infor/ // https://docs.arduino.cc/learn/communication/wire #include void setup() { // Set the speed of the bus Wire.setClock(1000000L); // A very low frequency of 10000Hz // Join as a slave // Set serial bus speed Serial.begin(9600); Serial.println("I AM ALIVE!"); Wire.begin(10); //set handles for the functions Wire.onReceive(receiveEvent); Wire.onRequest(requestEvent); } // Main (empty) loop void loop() { delay(1000); } // Function for handling received characters from the bus. void receiveEvent(int howmany){ Serial.print("Master: "); while (1 < Wire.available()) { char c = Wire.read(); Serial.print(c); } Serial.println("."); } // Function for handling character requests from the Master void requestEvent() { Wire.write(byte('O')); Wire.write(byte('H')); Wire.write(byte('!')); Wire.write(('\n')); }