Hi,
since I2C is a (serial) bus you can´t do simultaneous communication on two salves.
They need to have different device addresses and need to be accessed one after the other. Straight forward.
(This is the main idea behind a (serial) bus.)
Klaus
You will realize that most I2C devices have pins used to determine address offset, so that even devices of the same kind can be at the same busIs it possible to simultaneously retrieve the data from them
Okay so i can use the i2c scanner library to find the addresses of the devices right? So once i find them, i initiate communication with that particular device with wire.beginTransmission and then do i have to take the data from the internal registers of the device or can i use other libraries on the internet to get the data other than from its raw form?I'm running an LCD, real time clock, two ADCs and two 8-bit ports on I2C, fed from a nodeMCU right now and it all works fine. I'll be dropping the nodeMCU and using a bare ESP8266 in the final production. All you need to do is provide a different address for each I2C device. All the devices monitor the SDA and SCL lines continuously, looking for start and stop conditions. When a start is detected, the next byte is the address and if it matches the one for the particular device, it wakes up and communicates, all the other devices stay idle.
Brian.
I only plan on reading data and i have a temperature sensor and a heart rate-oxygen saturation level sensor. I just need the data from them in real time.You normally get the device addresses from the data sheet. Most I2C devices have addresses you can change by wiring pins to VDD, VSS or sometimes another pin. This allows you to connect more than one of the same device but see them as having different addresses.
In Arduino IDE, yes, to write to an I2C device use:
Wire.beginTransmission(I2CAddress); // sends start bit sequence and the address to the i2C bus
Wire.write(I2CDataByte); // this can be repeated to send more data
Wire.endTransmission(); // send stop bit sequence.
To read a device use:
Wire.requestFrom(I2CAddress,numberOfBytes); // last parameter is the number of bytes you expect the device to return
IncomingByte = Wire.read();
Other libraries may use the same underlying functions but return the data in a different format. For example reading a time/date device might convert the data transferred by the commands above into a readable form like day of the week, month name, 12 or 24 hour time or an alarm setting.
Brian.
That depends on what the original format is. For example, if the device returned a value which should be interpreted as 1234, but it is stored as 8-bit values, the I2C interface would have to read at least two bytes because a single byte can only hold values up to 255. '1234' might be stored as BCD '12' and '34' in which case you multiply the 12 by 100 and add the 34. Or, it might be stored in binary as 0x4d2 being '0x04' and '0xd2' in which case you shift the 0x04 eight places to the left and add the 0xd2 to get the value back then convert it to decimal. Some device specific libraries do this for you but they only replicate the basic instructions above.If not, how do i convert the raw data to a readable value after using your above mentioned commands?
So how do i take two different datas from the same sensor, that is heart rate and oxygen saturation in blood?That depends on what the original format is. For example, if the device returned a value which should be interpreted as 1234, but it is stored as 8-bit values, the I2C interface would have to read at least two bytes because a single byte can only hold values up to 255. '1234' might be stored as BCD '12' and '34' in which case you multiply the 12 by 100 and add the 34. Or, it might be stored in binary as 0x4d2 being '0x04' and '0xd2' in which case you shift the 0x04 eight places to the left and add the 0xd2 to get the value back then convert it to decimal. Some device specific libraries do this for you but they only replicate the basic instructions above.
As FvM explained, printf() and sprintf() are your friends because they convert many different number types into a more usable or printable format.
Brian.
You can get the answer for this from previous replies.So how do i take two different datas from the same sensor
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?