2x Atmegas 1x Sensor

Hi,

Little story for start, a while ago I was thinking to use several atmegas and transmit the sensor
data from one atmega to another thru I2C with atmega code..etc but today I was thinking if everything
is connected thru I2C A4,A5 can I directly use a single sensor like temperature sensor connect it to all
atmegas A4,A5 and receive in each atmega the data from the sensor? Will be any problem or everything will be fine?

3x ATmegas
1x sensor-> A4,A5 (to all 3x ATmegas328).

D.60

It would be far better to have one Arduino read the sensor, do whatever computations are needed, and send information to the other Arduinos.

Why do you have multiple Arduinos needing data from one sensor?

It would be far better to have one Arduino read the sensor, do whatever computations are needed, and send information to the other Arduinos.

Why do you have multiple Arduinos needing data from one sensor?

I need to use one sensor with multiple ATmegas, one atmega will use the data and do some tasks,
the other one will store that data from the sensor on a sd card ..etc

So I was thinking without losing time each ATmega to get the data from the sensor directly
without interacting with other ATmegas.

It's a good idea or should use other method ?

It's a good idea or should use other method ?

What would be a good idea would be to try. Personally, I have my doubts that you can read one sensor from multiple Arduinos, but the only way to know for certain is to try.

This will work with some sensors and not with others. This will work with some wiring schemes (e.g. grounds connected together) and not with others. For I2C it will matter whether the Arduinos try to read the sensor at the same time or somehow communicate so that their reads are interleaved. Without more information (say, wiring, synchronization scheme, etc.) it is unclear.

Yea but let me give an example,

3 people, 1 person telling a story and the other 2 just listening, can't be that as well with 1 sensor and 2 atmegas?

the 2 persons that listen will not talk to each other but just listen they will know the same language (code)
and understand what the 1 guy telling (story/sensor data), can't that be possible?

As I know from past I read few things about I2C the A4,A5 pins, you can connect a lot of devices and make them communicate with eachother, but why wouldn't be possible 2 atmegas taking from a single sensor data?

My point in my project is that I need space in the code and using extra code to take the data from the sensor
and from the 1st atemga to send it to the 2nd that from my view of point it's kinda waste of time. In the 1st atemga I want to do complex tasks.

I2C works differently. Basically one person tells another one to tell him / her a story; not to tell the world a story.

You can use multi-master though. I don't know if the current Arduino library supports it !!

If two masters ask for data, one of them will win and get the bus; the loosing one needs to try later again. See multimaster i2c bus

You possibly also can make a sniffer; master controls the bus and talks to device; sniffer just analyses the data and stores it on SD card.

If it's wise to go the complicated route is another story.

Yea but let me give an example,

can't that be possible?

In that analogy, there is one book (one sensor), one reader, and three people (including the reader) hearing the story. THAT is possible, and a good idea.

But that is not what you say you want to do.

I2C works differently. Basically one person tells another one to tell him / her a story; not to tell the world a story.

You can use multi-master though. I don't know if the current Arduino library supports it !!

Ok but let's say you don't connect them as masters but just as simple atmegas with only the sensor code
to receive from the sensor the data, would be that possible?

But that is not what you say you want to do.

In my brain i had exactly what you said but sometimes people don't understand me :smiley:

I believe you can have two masters attempt to access a slave at the same time, it will (should) just fail. So you might be able to have a kind of collision detection and retry scheme.

I believe you can have two masters attempt to access a slave at the same time, it will (should) just fail. So you might be able to have a kind of collision detection and retry scheme.

So that means I can't avoid the communication with 2 atmegas, I will need to take the sensor data process it
in my tasks and send it to the 2nd atemga to store it on a sd card. Dam it, I try to avoid complex tasks and extra code but looks like I will not be able to do that.

aarg:
I believe you can have two masters attempt to access a slave at the same time, it will (should) just fail. So you might be able to have a kind of collision detection and retry scheme.

One should fail, the other should succeed (see the link I provided earlier). How it's implemented in the Arduino libraries is another question.

The datasheet of the micro on the ATmega mentions hardware arbitration for the 2-wire serial interface so if it's implemented correctly in the libraries it's just a matter of detecting the error and retry.