Arduino Master/Slave

HI,

I was interested how to make 2 arduinos to communicate with each other and I found this easy tutorial:

Now what I understood from that is you connect the arduinos each other as in the tutorial and writing a simple code you make one of the arduino Master and the other Slave which you give the slave a Address

Wire.begin(4);

Now this address is any kind of number we like to use?
After using that address we can send from the Master to slave characters and integers, but can we send from Slave to master?
To send from Slave to master we need to put Master address too? Or that will work as Slave to Slave?
If we add 2 more extra arduino's they will work in the same principle ?

Well what i need is 4 arduinos but to be able to send from one to another data to transmite and receive.

Looking that code:
Slave

void setup()
{
  Wire.begin(4);                // join i2c bus with address #4
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600);           // start serial for output
}

That Slave is turned into receive "mode" can we make it to be able to receiver and transmit ?

Domino60:
HI,

I was interested how to make 2 arduinos to communicate with each other and I found this easy tutorial:
https://www.arduino.cc/en/Tutorial/MasterWriter

Now what I understood from that is you connect the arduinos each other as in the tutorial and writing a simple code you make one of the arduino Master and the other Slave which you give the slave a Address

Wire.begin(4);

Now this address is any kind of number we like to use?
After using that address we can send from the Master to slave characters and integers, but can we send from Slave to master?
To send from Slave to master we need to put Master address too? Or that will work as Slave to Slave?
If we add 2 more extra arduino's they will work in the same principle ?

Well what i need is 4 arduinos but to be able to send from one to another data to transmite and receive.

Looking that code:
Slave

void setup()

{
  Wire.begin(4);                // join i2c bus with address #4
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600);          // start serial for output
}




That Slave is turned into receive "mode" can we make it to be able to receiver and transmit ?

Do research on I2C communications, Using Arduino Wire Library.

We don't do Home Work!

chuck.

Homework?
Isn't this arduino forum? I ask for help and get me some info how to work with it and you tell me go search
somewhere else? wth, I came to arduino forum not to a random forum, I'm talking about arduino and that's not homework but something that i don't understand and i need answers in my questions....

arduino.cc forum tell people to get somewhere else by (chucktodd )

Thanks a lot....

Member Nick Gammon has a good webpage on I2C comms. Do some reading there.

I think you would the answers you need there.

Member Nick Gammon has a good webpage on I2C comms. Do some reading there.
Gammon Forum : Electronics : Microprocessors : I2C - Two-Wire Peripheral Interface - for Arduino
I think you would the answers you need there.

Thanks

Now this address is any kind of number we like to use?

Yes and no. Yes, you can pick any number you like that is less than 128. However the I2C standard does describe some special meaning for numbers less than 7. Fortunately this has no effect on two Arduinos talking to each other with no other I2C devices on the same bus.

To send from Slave to master we need to put Master address too? Or that will work as Slave to Slave?

The I2C system is "multi master" meaning it can allow any of the devices on the network to take over the role of the master and start transmitting. However the Arduino libraries don't allow this. If you give a slave address to Wire.begin() then you can never transmit as a master. Switching Arduinos in and out of slave or master mode is possible but this will give you a lot more problems getting the system to work.

If you need to send data from a slave to a master or from a slave to another slave, you should make the master regularly check the slave to find out if it has anything to send and then the master can distribute the data as required.

Yes and no. Yes, you can pick any number you like that is less than 128. However the I2C standard does describe some special meaning for numbers less than 7. Fortunately this has no effect on two Arduinos talking to each other with no other I2C devices on the same bus.

So I can pick any kind of number to be address above 10 and bellow 120 for example and i got 100+ addresses to use. But what if i connect a sensor that use A4 A5 is there a specific address for that sensor? address scanner? because as i know you can't program the sensor giving him a personal address it should have already a address inside. How do i know that?

The I2C system is "multi master" meaning it can allow any of the devices on the network to take over the role of the master and start transmitting. However the Arduino libraries don't allow this. If you give a slave address to Wire.begin() then you can never transmit as a master. Switching Arduinos in and out of slave or master mode is possible but this will give you a lot more problems getting the system to work.

If we have a stable network a Master can only receive and Slave transmit?

Well what I wanna build is 3 Uno's, one master and 2 slaves, the Master will only receive data, the 2 slaves will transmit the data to Master but one of the slaves will give data to another slave too.

So it gonna be like that:
Master (receive from 2 slaves);
Slave 1 (will transmit to Master and Slave 2);
Slave 2 (will transmit only to Master).

I've seen and read and i will re-read the CrossRoads there is a lot of useful info but to convince myself / my brain :smiley: I need to hear from other people the answer from my questions.

Almost forgot my question :smiley:
If i have a network as i described above and have some extra sensor plugged (A4,A5) on the "network" will that decrease the speed? and how slow that will be?

Domino60:
Homework?
Isn't this arduino forum? I ask for help and get me some info how to work with it and you tell me go search
somewhere else? wth, I came to arduino forum not to a random forum, I'm talking about arduino and that's not homework but something that i don't understand and i need answers in my questions....

arduino.cc forum tell people to get somewhere else by (chucktodd )

Thanks a lot....

Why would you not want to understand how to use the hardware. Do you expect people to do it for you? Phillips Electronics Invented the I2C bus. Their documentation explains how the bus works. Arduino is not the authoritative source for I2C bus information. You will have to go to somewhere else for that info. Arduino can tell you the syntax of the function calls of their implementation. You should develop an understanding of the protocol, the hardware that supports this protocol. Your obvious ignorance (lack of knowledge) on the subject tells me you need to research what I2C is. You are asking general questions that could be answered by a simple web search.

Develop the general knowledge so that you can ask incisive questions.

This forum's value is its experience in the intricacies of the Arduino I2C implementation.

Chuck

So I can pick any kind of number to be address above 10 and bellow 120 for example and i got 100+ addresses to use. But what if i connect a sensor that use A4 A5 is there a specific address for that sensor? address scanner? because as i know you can't program the sensor giving him a personal address it should have already a address inside. How do i know that?

Yes, the datasheet for any I2C device will tell you what address it uses and you cannot use that address for your own things on the bus. Most devices have a choice of a few different addresses, selected by connecting some of the pins to GND or Vcc. Some can be programmed to use any address.

So it gonna be like that:
Master (receive from 2 slaves);
Slave 1 (will transmit to Master and Slave 2);
Slave 2 (will transmit only to Master).

The master controls the bus. It can request data from Slave 1. That data might be "I have no new data" or it might be the actual data. Since you are programming that yourself, you can decide.
The master can then send whatever data it wants to Slave 2.

Almost forgot my question
If i have a network as i described above and have some extra sensor plugged (A4,A5) on the "network" will that decrease the speed? and how slow that will be?

The speed of the network does not change. But if you spend half of your time talking to device 1 then you need to divide up the remaining time available to talk to the other two devices.

chucktodd

I picked the words key from your comment to answer you :

you not understand how to use the hardware.

(lack of knowledge)

You are asking general questions

that could be answered by a simple

answer? :smiley:

Develop the general knowledge

There is no better way to answer you comment, lack of knowledge made me to come here, few months ago
I don't even knew about I2C so that's why i came here to ask how do you work with it and general simple question that you may know but lazy to answer. A good student is a mirror of his good teacher.

Yes, the datasheet for any I2C device will tell you what address it uses and you cannot use that address for your own things on the bus. Most devices have a choice of a few different addresses, selected by connecting some of the pins to GND or Vcc. Some can be programmed to use any address.

Let's say in the worst situation there is no datasheet for the sensor is there a way to know the address?

The speed of the network does not change. But if you spend half of your time talking to device 1 then you need to divide up the remaining time available to talk to the other two devices.

Well I'm gonna ask it in different way.
How much time will take to send a packet of 8bit?

Try to specify what distinguishes your master controller from the slaves, when almost every controller can talk to another one?

Each sending controller becomes the bus master for the time of that transmission, and every receiver must have its unique bus address, an interrupt handler for incoming transmissions (onReceive), and eventually an handler for transmitting requested data (onRequest). See examples for the Wire library.

While you can assign addresses to every controller at will, buying I2C modules without data sheets or documented addresses is a stupid idea. You can use an I2CScanner (code) to find existing devices on your bus, but details about reading and writing device specific data and registers can be found only in the data sheets.

Standard transmission (bit clock) speeds are 100 and 400 kHz, see the data sheets of your modules what speeds they support.

DrDiettrich:
Each sending controller becomes the bus master for the time of that transmission, and every receiver must have its unique bus address, an interrupt handler for incoming transmissions (onReceive), and eventually an handler for transmitting requested data (onRequest). See examples for the Wire library.

Which specific example would that be?

MorganS:
the Arduino libraries don't allow this. If you give a slave address to Wire.begin() then you can never transmit as a master.

Domino60:
chucktodd

Well I'm gonna ask it in different way.
How much time will take to send a packet of 8bit?

50uS

chuck