Can Multiple I2C Sensors Be Run Simultaneously
robotics
Posts: 90
in Propeller 1
Hi,
One of the useful features of the Propeller 1 is that you can interogate the status or results of 8 different sensors simultaneously using a different Cog for each sensor. The Time-Of-Flight Distance Measuring Sensor VL6180X ( https://www.adafruit.com/products/3316 ) has a fixed I2C address. I am new to the I2C world, but it appears that the Propeller 1 has only 1 set of pins that can be used for I2C devices. So am I correct that you could not have 8 VL6180X sensors on 8 different Cogs so that you can obtain 8 distance measurements simultaneoulsy?
I advance, thank you and happy holidays!
One of the useful features of the Propeller 1 is that you can interogate the status or results of 8 different sensors simultaneously using a different Cog for each sensor. The Time-Of-Flight Distance Measuring Sensor VL6180X ( https://www.adafruit.com/products/3316 ) has a fixed I2C address. I am new to the I2C world, but it appears that the Propeller 1 has only 1 set of pins that can be used for I2C devices. So am I correct that you could not have 8 VL6180X sensors on 8 different Cogs so that you can obtain 8 distance measurements simultaneoulsy?
I advance, thank you and happy holidays!
Comments
Here are a few drivers in the OBEX:
http://obex.parallax.com/search/i2c
st.com/content/ccc/resource/technical/document/application_note/b4/f0/79/ec/ca/54/45/07/DM00114403.pdf/files/DM00114403.pdf/jcr:content/translations/en.DM00114403.pdf
But, as DavidZ mentioned, you could have up to 16 i2C buses on the Propeller, which is cool, so each device could have the same i2C address but on a separate bus.
If you are new to i2C, Parallax has a pretty good DIY i2C Learn reference you might want to have a look-see at:
learn.parallax.com/tutorials/language/propeller-c/propeller-c-simple-protocols/diy-i2c
-Phil
One possible solution using 9 pins scheme: From the VL6180x data sheet, one command starts the acquisition process, and another command reads the returned data. (section 2.4.1, single shot range/ALS operation) Therefore it might be possible to send the same "start" command to all of them simultaneously, and then read back the data one at a time when they are finished. There is a status flag that can be read to ascertain the busy/done state.
A salient point about "simultaneous" is that the range acquisition time depends mightily on both the range and on the reflectivity of the object. (Table 7 in the data sheet). It is roughly 0.1 to 10 milliseconds when an object is well within the field of view. So even if they are started at the same time, the finish times will be staggered. How often do you expect to take readings?
In regards to DavidZemon's question, I would prefer to program this in Spin. In regards to Tracy Allen's question, I would like to take readings as frequent as possible, so in regard to Table 7 , the worst case longest time period would be used.
Erlend
Erlend
What does your code look like now? Seeing the code would better help in tracking down the problem.
The clock and data activity to the shift register at reset would not be recognized by any I2C device as it does not generate a start condition, therefore all activity is ignored.
Hope this helps,
Erlend
I think I brought that up in a previous post in this thread, but the OP might not have understood it.
-Phil
Erlend
-Phil
1) pass the pin numbers with each and every method call.
-- i2c.method(sdapin,sclpin, da da da) for every i2c method
-- pins default to inputs in all cogs so no initialization or start method is necessary for the pins per se.
-- All sub objects have to know the pin numbers as constants or as passed from a parent object.
-- Simple, but pin parameter(s) accompany every method call.
2) Store the pin numbers in VAR space, passed in a Start or Init method.
-- Every child object that uses the i2c object needs to be init'd
-- Each initialization in the sub-objects creates its own copy of the pin variables
-- Only copy of the object code in HUB, even with multiple instances of i2c buss
-- Subsequent method calls do not need the two pin numbers as parameters in every method call.
-- Bug potential in forgetting to init a sub-object's pins.
3) Store the pin numbers in DAT space, passed in a Start or Init method.
-- Only one object (usually the top one) needs to Init the pin numbers
-- Child objects have to declare the i2c OBJ, but don't have to Init it, the DAT variables are global.
-- Low bug potential, Init it and forget it.
-- Method calls don't need the two pin numbers as parameters.
-- Easy to cover with locks, important to avoid conflict if multiple cogs will share the same i2c buss
-- Down side is multiple copies of the object code to support multiple instances of i2c buss.
Nice summary. I have gotten there now, but the way OBJ, DAT, and VAR is handled in Spin was a big mystery to me. I prefer the DAT approach (as per my sig ).
Erlend