// I2C Master 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() { Wire.setClock(1000000L); Wire.begin(); // Join as master Serial.begin(9600); // put your setup code here, to run once: } int received[4]={0,0,0,0}; int reading='@'; void loop() { // Write data from master to host //Serial.println("Master writes to 10."); Wire.beginTransmission(10); Wire.write(byte('M')); Wire.write(byte('A')); Wire.write(byte('S')); Wire.write(byte('T')); Wire.write(byte('E')); Wire.write(byte('R')); Wire.write(byte('\n')); //Serial.println("endTransmission to 10: "); //Serial.println(Wire.endTransmission()); // End transmission to Slave #10 Wire.endTransmission(); delay(70); // Request data from Master //Serial.print("Wire requestFrom: "); //Serial.println(Wire.requestFrom(10, 4)); // (address,quantity) Wire.requestFrom(10,4); // Request data from the Slave #10 (address, quantity) Serial.print("Slave: "); while(Wire.available()){ // slave may send less than requested char c = Wire.read(); // receive a byte as character Serial.print(c); // print the character } delay(250); Serial.println(" "); }