Hello everyone,
I have this idea that I want to implement for a long time, but I get stuck on whether it's feasible or not: I want to collect sensor data to an Arduino board in order to process it. The application is not specific and my question is general, but with focus on autopilot development.
Problem specs:
- An arduino board must collect data from one or more sensors
- The reply from said sensors may not be immediate and this should not block the Arduino main loop
- One ore more sensors may communicate only via i2c protocol.
(Number 2 is targeted towards the Bosch BMP085 sensor which needs a "start measurement" command and another "read measurement value" command a few ms later)
What I think is the right direction is an abstraction layer for the sensor network:
On the bottom layer, have a dedicated small Arduino to supervise each single sensor, read it as fast as possible and store the result internally. This Arduino may communicate with the sensor with analogRead, digitalRead, shift register input, serial, i2c or whatever protocol the sensor supports.
One layer above is the coordinating Arduino which runs the code where the measurements are needed. This Arduino can contact the rest of the "slaves", asking for their data. In turn, they will answer immediately with the last known good data. The communication should take place on a bus with specific protocol, in order to achieve the following:
- Allow for sensor-protocol-agnostic communication. The top-level Arduino will get the data, regardless of the protocol of the sensor.
- Adding duplicate sensors would be as simple as attaching another Arduino on the bus, with an unoccupied address.
- Sensor makes and models can be swapped in a specific application, without that affecting the top-level code.
Where I stumble:
I was thinking about using the i2c bus to hook all my Arduinos and have the top-level one act as master and the sensor-handlers act as slaves. But many sensors I want to use also communicate in i2c. That means that the low-level Arduinos would have to act as masters in order to control the sensor and read from it but also act as slaves when the top-level Arduino wants to read from them.
I have browsed the net for a couple of hours and also read the related Gammon blog, but I'm still not sure if the alleged multi-master i2c spec of the Wire library actually plays a role in this case.
Any comments or suggestions towards solving my problem are welcome.