data logging and i2c

i am new to this and I am trying to understand how to write the proper code to data log. I have 5 sensors set up on my UNO, all on the I2C data line (SDA,SCL).. I am confused about how to write the code to data log all 5 sensors. (SHT31-D,Si7021,BMP280,CCS811, VML6070)......

Thanks for any assistance..

Tell 7-bit I2C addresses for your all 4 sensors.

JAMES007MOORE:
i am new to this and I am trying to understand how to write the proper code to data log. I have 5 sensors set up on my UNO, all on the I2C data line (SDA,SCL).. I am confused about how to write the code to data log all 5 sensors. (SHT31-D,Si7021,BMP280,CCS811, VML6070)......

Thanks for any assistance..

Log where?
SD card?

I have seen many tutorials online for logging.

You are going to have to do this bit by bit.

No one is going to hand you a completed project.

.

JAMES007MOORE:
I am trying to understand how to write the proper code to data log. I have 5 sensors set up on my UNO

Does set up mean that those sensors are all operational, reading their respective values into some variables? Or haven't you got that far yet. If you haven't then that's not a datalogging issue...

If you have, the datalog example with the SD library shows how to concatenate 3 readings into a String to send.

Would be simple enough to adapt making the String from 3x analog readings to making it from a bunch of variables.

(Yeah, Strings are bad... )

The way I tackled this as an exercise, with just 2x I2C breakouts, which both have sample code with their libraries was:

  • edit (gilshultz reminded me I actually did this) Run the i2c scanner for each sensor alone and together
  • Test each sensor on its own, using its sample code
  • Create a blank sketch
  • Copied all the stuff above setup() from each, to above setup() in the new one: the includes etc
  • Copied all the stuff from each setup() into the new setup()
  • Copied both loops() into the new one, below the new loop()
  • Renamed those 2 loops() to reflect the sensor name
  • In the new loop(), put calls to the 2 sensor functions
  • Test to show the 2 sensors work together, and serial print their output
  • Tested SD card breakout with a sample sketch such as datalogger and cardinfo
  • Copied stuff from datalogger above setup() above new setup()
  • Copied stuff from datalogger setup() into new setup()
  • Copied datalogger loop() below new loop()
  • Renamed to reflect that it's the sd function
  • Called it from new loop(), after the calls to the sensors
  • Removed existing datalogger reads from analog pins
  • Created a new String from the variables created by the 2 sensors
  • Write to SD as in original datalogger
  • Viewed SD on laptop in notepad, success

Most of the hardware problems I see appear on the i@c buss. Be sure the I2C buss is terminated properly, if not you will get inconsistent results. This typically happens when you first test each sensor then place them on the I2C buss, the termination gets to stiff as most cards have pull up resistors on them. The bus should go from unit to unit, not a star configuration. Check your power supply and be sure it has enough power for everything, the UNO cannot reliably power that many sensors. The first test I do when connecting each sensor is run the I2C scan, it reports the I2C address. I record this in my source code. when you get this finished add sensors one at a time and scan again, if something is faulty you will probably find it at this point. Then one more scan when all sensors are connected. This response is to help you get started in solving your problem, not solve it for you.
Good Luck & Have Fun!
Gil

Good point @gilshultz on there perhaps being too many pullups for all the sensors together, if each board has its own.