Receiving I2C data from Sensor and Send to another Master

Hi,

I have to setup multiple sensors which are connected to ATTINY84A. One of the sensors is a BME280 which sends data over i2c. I am able to successfully read i2c data from an arduino and the sensor is working fine.

Now all the data should be sent to another Arduino board over i2c. Is this feasible?

In simple words, BME280 —i2c—> ATTiny84A —i2c----> Arduino Uno. Kindly suggest if I can read data as a master and then send data as a slave?

Best Regards,
Praveen

As long as you give different I2C addresses to the Arduinos, all devices can share the same bus. You decide whether the ATTiny sends its data to the Uno immediately (master) or on demand (slave).

For separate I2C busses an I2C multiplexer module can be used. But you risk loss of transmissions while the ATTiny queries the sensor and can not react on Uno requests.

DrDiettrich:
As long as you give different I2C addresses to the Arduinos, all devices can share the same bus. You decide whether the ATTiny sends its data to the Uno immediately (master) or on demand (slave).

For separate I2C busses an I2C multiplexer module can be used. But you risk loss of transmissions while the ATTiny queries the sensor and can not react on Uno requests.

Thank you for your response. The attiny should send data to Uno on demand (attiny as slave). The attiny will wake up on interrupt from Uno, read the sensor data, send and then go back to sleep.

Just to be more clear, there will be multiple attiny modules, each with multiple sensors. One Uno will control all attinys and yes, each attiny will have a separate address.

Do you have any example which makes it easy for me to understand?

I don't know what you did not understand so far. It may help if you describe your project more precisely.

You should understand that all devices on one I2C bus must have unique addresses, what's not the case with multiple sensors of the same type. Then add an I2C multiplexer to your master Uno, with one sensor at each bus. Or use SPI for communication between the Uno and the ATTinys, or for many BME280 sensors on one bus.

DrDiettrich:
I don’t know what you did not understand so far. It may help if you describe your project more precisely.

I guess I did not explain it right. Let me retry with a picture. Please check the attached image.

I have multiple slave arduino boards (shown as nano in the image) where each one is connected to sensors. One of the sensor sends data via i2c to arduino nano. Here Nano board is the master while the sensor is the slave. All is good till now. Once each nano’s collect the data, they get into sleep mode.

The uno raises an interrupt and each nano should turn on and send sensor data to Uno. The question which I have is:

  1. Is it possible to make an arduino nano master while receiving data and then make it a slave while sending data?
  2. Is there an example code or a project which is already done like this which helps me understand how it is done?
  3. Each nano will have a separate address in i2c which can be programmed. The question lies if they can be converted to slave and master both?

Note: Kindly ignore the pin connections in the image. They are made just to showcase connections. In the actual setup, every i2c connection is connected to SDA and SCL while also pull up resistors connected.

I don't see the need for the Nanos. All the LDRs could we wired directly to pins on the UNO using twisted pairs with filtering on the lines to reduce any residual pickup . The only need for I2C is for the RTC.

skyvan:
I don't see the need for the Nanos. All the LDRs could we wired directly to pins on the UNO using twisted pairs with filtering on the lines to reduce any residual pickup . The only need for I2C is for the RTC.

Thanks. What you see in the image is just an example. In real project, we have not less than 25 individual modules (Attiny84 with sensors, shown as nano in the image) which are all connected to Uno as master.

However, the question is different. Is it possible to use arduino as master to receive data and change to be a slave while sending data?

I don't get the use of the ATtiny84a (or the Nano, as per your image - which doesn't show the BME280 either, so I wonder what the purpose of that image is beyond confusion).

As that BME280 must connected to the same I2C bus (the ATtiny supports only one I2C bus, afaik - there are AVR chips that can do more than one I2C bus), why not read it straight from the Uno?

An I2C bus is very limited in length. It can be used between a sensor and a nearby Arduino, but not across multiple rooms. That's why you should use SPI for communication, eventually with RS-485 line drivers.

Maximum length of the SPI bus is afaik quite similar to that of the I2C bus. Both are meant for intra-PCB communication. A few meters of wiring is the practical limit.

For larger distances wireless may be the way to go.

wvmarle:
Maximum length of the SPI bus is afaik quite similar to that of the I2C bus. Both are meant for intra-PCB communication. A few meters of wiring is the practical limit.

Please read and understand my response #8. RS-232 can bridge miles, RS-485 even more.

I am not sure I have tried my best to make understand the problem. Ok, ignoring all the connection diagrams, sensors and everything else, kindly help me by answer this one question.

Suppose I am using Arduino Nano to read sensor data via I2C in one block of program. Now there is another Arduino Uno, which requests data from Arduino Nano. Is it possible that Nano acts as a slave and send data to Uno via I2C?

I need all communication via I2C only due to the number of nodes I have and the limited number of pins Uno has. In I2C, I can connect upto 127 devices and hence the question.

praveen_khm:
I need all communication via I2C only due to the number of nodes I have and the limited number of pins Uno has. In I2C, I can connect up to 127 devices and hence the question.

Sorry, clearly an “XY Problem” here!

I2C has its uses, but it strongly sounds as if this is not one.

If you describe in careful detail, the scope of your project, what distances are involved, exactly how many nodes are essential and how many are just desirable, how many sensors are intended, then we can sensibly discuss what structure may be appropriate.

I2C does support a multi-master layout, but having a single device act as both master and slave may be very hard (short of you writing the software to allow for this).

Besides, you're going to have a hard time connecting more than 2 BME280 sensors to the same bus, unless you use SPI for those. It indeed would probably make your project more feasible: have the Nanos communicate with the BME280 over SPI, and act as I2C slave only for the I2C. Then there's of course still the question of distance, as having so many BME280 in close proximity doesn't make much sense.