SDA, SCL problem

Hi,

I got 3 different kind of sensors and they just use VSS, GND, SCL, SDA (Only).

My problem here is that i got just one Atmega328p-pu and there is only 2 pins
that have SDA and SCL wich are A5 and A4, i need all 3 sensors work in the same time
and receive the data to actually combine them and do some "action".

Is there any way to make somehow and connect all 3 sensors in one ATmega328p and get the data.
Am i wrong that you need to connect sensor pins (sda,scl) only at atmega sda and scl or you can use
other analog pins for that? A0 ~ A5.

You connect all of the sensors to the same two pins. That's one of the features of I2C. It's a "bus" type topology.

Connect all the sensors to the same pin?

There are diferent sensors with different data how the atmega can get data from 3 differet sensors
with the same 2 pins ? O_o

Each I2C device has a different address. You can usually connect several identical devices because they have other pins which can be tied high or low to set an individual address for each device.

Read Nick Gammon's article on I2C

Domino60, check on the Internet what a bus is.

In short, a bus is a shared communication medium on which every device of the network is connected. Different strategies can be adopted to send data to the good device.

Thanks a lot, I'd like to be informed more and more but I don't have a lot of time for that.
Isn't there a tutorial?

You connect all of the sensors to the same two pins.

I'd like to see that in a tutorial how to connect 2 sensors or more just to that 2 pins on the ATmega328
and get data from both sensors and print them on the serial monitor.

Look at this

I2C bus looks like 2 device communicating each other. I2C BUS

I'll make it more newbe explanation about what i want to do.

I have a temperature sensor module and a compas sensor module, both of them use sda,scl but
the atmega328p have only 2 pins with sda and scl wich are A4, A5. How I'm gonna connect them
to get the data from both sensors ? O_O

Breadboard.....

Twist wires together.....

Domino60:
I2C bus looks like 2 device communicating each other. I2C BUS

There are none so blind as those that will not see.

Is there a normal answer or tutorial or example of my problem ?
Explain what is the link you send me to what exactly should i look for, or read.

I could search on my own on the internet but i know from experience even if i search about arduino
the links will always come on arduino forum.
So i gave a try to just axplain normaly what's my problem and get a normal answer.

Is there a normal answer or tutorial or example of my problem ?

I think our problem is that we don't see what your problem is.

How I'm gonna connect them to get the data from both sensors ?

Talk to one device, get its results, then talk to the other device and get its results.

Domino60:
Is there a normal answer or tutorial or example of my problem ?

The link I posted above contains LOADS of pictures all showing MANY devices connected to SDA, SCL and ground. What the devices are is largely irrelevant. This is how they connect.

You can twist wires together, you can use a breadboard. You can solder them together. Heck even use a piece of string soaked in brine if you like. As long as they ALL get conncected to SDA and SCL (and gnd)

I think OP is wondering how to physically connect 2xSDA and 2xSCL when he has only one of each socket at A4 and A5.

See attached pic: brown and yellow from A4 anf A5 to breadboard; 2x browns out to left for 2 devices' SDA and 2x yellow out to right for 2 devices' SCL.

I know how to connect wires you need to be really dumb to not understand what exactly you need to connect.

You have muscles on your body, they are connected each other to actually move and do stuffs
but for that you need what? Brain

I need code.... how to make them to communicate with the atmega328 that's my problem
code, how? and get them in real time not with huge delays
How to get the data from the sensors????

HOW? (CODE?)

JimboZA:
I think OP is wondering how to physically connect 2xSDA and 2xSCL when he has only one of each socket at A4 and A5.

You must be as dumb as me. The OP is talking about code :slight_smile:

Give me just a simple example code how to print the data from 2 (or more) sensors that are connected in the same pins just a simple example.

that's what im asking for from the beginning, you can't just connect the wires and done it's working
you need a code don't you?

Domino60:
I know how to connect wires you need to be really dumb to not understand what exactly you need to connect.

You have muscles on your body, they are connected each other to actually move and do stuffs
but for that you need what? Brain

I need code.... how to make them to communicate with the atmega328 that's my problem
code, how? and get them in real time not with huge delays
How to get the data from the sensors????

HOW? (CODE?)

CODE here

Domino60:
I need code....

Why the [expletive deleted] didn't you say so 4 hours ago? You kept going on about how to connect 4 wires to 2 pins.... or so we read it, anyway.

What sensors are they?- use the wire library and maybe whatever other library the vendor may have provided.

Follow the vendor's instructions for getting each sensor to run, and do that for each one in the same sketch. As long as they have different addresses they'll be good to go. Run the i2c scanner (look in playground) to check they have different addresses.

The output from the sensors will be in variables as usual. The RTC1307 for example uses a tm structure so you can display hours separately from minutes for example.

Nobody here can provide a generic code to run 3 as yet anonymous sensors.....

Arduino's Wire library which is natively installed with your IDE. Look at the library reference page to know how to send and receive data thru I2C bus using it.

You'll have to look at your devices' datasheet to know more about communication with them specifically.