Float I2c

Steveiboy:
Sorry to dig this thread back up after been dead for do long as I was searching how to send a float over I2C.
I've got the code working posted by Nick in post for just sending 2 example values of 6.75 (fnum) & 29.31(foo) and I would like to add another slave to send example values of 13.32(fnum) & 3.25(foo).
I know I would have to alter the MY_ADDRESS say to 43 but the part I'm not sure of is how to get the master to read more than one slave unit.

Is this possible ??
if so how could I do it

Wire.requestFrom (SLAVE_ADDRESS,number_bytes,TRUE);

Controls which slave is being communicated with. Just create multiple request with different Slave Addresses. Of course you need 'slave' Arduinos with the same addresses.

Example Master Code Fragment

#define SLAVE_ADDRESS_1 0x58

#define SLAVE_ADDRESS_2 0x59

#define SLAVE_ADDRESS_3 0x5A

   float foo;
   long fnum;

   uint8_t datalen = (sizeof foo)+(sizeof fnum);

   // get info from the First Slave
   Wire.requestFrom (SLAVE_ADDRESS_1,datalen,true);
   if(Wire.available()==datalen){ // got correct size of packet
     I2C_readAnything (fnum);
     I2C_readAnything (foo);
     }
  
 // get info from the second Slave
   Wire.requestFrom (SLAVE_ADDRESS_2,datalen,true);
   if(Wire.available()==datalen){ // got correct size of packet
     I2C_readAnything (fnum);
     I2C_readAnything (foo);
     }
   // get info from the Third Slave
   Wire.requestFrom (SLAVE_ADDRESS_3,datalen,true);
   if(Wire.available()==datalen){ // got correct size of packet
     I2C_readAnything (fnum);
     I2C_readAnything (foo);
     }

The order you call I2C_readAnything(fnum), I2C_readAnything(foo) needs to match the order in the Slaves onRequest event handler.

Chuck.


Check out my Kickstarter Project Memory Panes an expansion RAM Shield for Mega2560's. It adds 1MB of RAM for those projects where 8KB is not enough.