I am new and lost I have been searching the internet about how to transfer data of multiple sensors from one Arduino to another using i2c but no luck. all the codes and tutorials online focus on multiple slaves with one sensor. The attached fritzing is not my project but my project involves 22 pressure sensors which I need to log their reading in excel using plx, so the pic is just for demonstrating the idea.

The main idea is to transfer sensors data from the salve to the master over i2c.

I just need an answer is this doable or not plz enter image description here

  • Do you know how to transfer one sensor's data over I2C? – Majenko Aug 15 '19 at 21:07
  • yes i did it for one sensor – tofi Aug 15 '19 at 21:07
  • Then you can do it with more sensors. Just request (and send) more data. – Majenko Aug 15 '19 at 21:08
  • if it is not too much to ask is there any example u can send me to follow? – tofi Aug 15 '19 at 21:09
  • 1
    Take your code. Where you request the data for 1 sensor, change that to request the data for more than 1 sensor. Where your code responds with the data for 1 sensor, change it to respond with the data for more than 1 sensor. – Majenko Aug 15 '19 at 21:10

There's two basic ways of doing it.

  1. Send a byte from the master to the slave first to select which sensor you want, then request the data for the currently selected sensor, or
  2. Request lots of bytes from the slave and fill them in one at a time as the requests arrive.

The first way is the slow, but "I2C" way of doing it - basically each sensor is its own register in the slave, and you select which register you want to read from.

The second way is faster, but you have to keep track internally of where you are.

A good compromise is to implement "auto increment" which does both scenarios: if you send a byte it sets the current sensor to read from. Then each read returns the current sensor and increments the sensor number internally in the slave, so the next read will get the next sensor.

That way you have a way to "reset" the sensor index that you are reading from, and it's reasonably quick to get all the sensors, since you just need to do multiple reads after a single write.

| improve this answer | |
  • Wire.begin(9);//9 here is the address(Mentioned even in the master board code) Wire.onReceive(xxx); void xxx(int bytes) { l = Wire.read();//Receive value from master board Serial.print("Pressure 12= "); Serial.print(l); Serial.println(" PSI "); } this is the code i used to read data from slave for one sensor which is working fine how to add registory for each sensor? – tofi Aug 15 '19 at 21:17
  • That looks like you're sending from the master to the slave, not from the slave to the master. You have it backwards. – Majenko Aug 15 '19 at 21:18
  • 1
    will research on UART and how to use it Thank you – tofi Aug 15 '19 at 21:26
  • 1
    on the receiving end of ur code, how is it gonna look to store each sensor data? – tofi Aug 15 '19 at 21:30
  • 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.