Hi Flek,
This is great work, hopefully we will have this sorted very soon, for multiple Colour Sensors, boards and different mBot boards!
OK, my first hypothesis for the difference between boards.
Colour Temperature
Key difference between boards in my opinion is the ‘Colour Temperature’ of the supplied LED, see chart:
The ‘purple board’ appears to produce light closer to the Warm ~ 3000K range, whereas the ‘red board’ produces light closer to the Cool ~ 6000K range. This would explain why the ‘purple board’ has higher Red % and the ‘red board’ has higher Blue %.
To account for this could you add another variable to allow the user to select the ‘Colour Temperature’ of the LED they are using to illuminate the surface? i.e. [Warm, Cool] corresponding to the two different boards and in your driver it will adjust accordingly depending upon the light source temperature.
“trigger color sensor [Port6-10] colour temp. [Warm, Cool, Raw]”
Multiple Colour Sensors on TWI
(for the benefit of others following this thread)
The TCS34725 has a fixed address on the I2C bus (0x29). The mBots only have a single Two Wire Interface (TWI) or I2C bus and all Ports on the mBot are attached to the same bus. This means:
- It doesn’t matter which Port you attach a TWI interface to, it will be on the same TWI bus;
- That only one TCS34725 can be addressed/used at a time, even if attached to multiple ports;
So, for your driver the Port selection is not required (in the case of using a single TCS34725).
Also only one Colour Sensor can be installed/used on the mBlock platform.
TWI Switch (Multiplexer)
The TWI Switch (TCA9548a breakout board can be sourced for around $3 - 8USD) connects up to 8 devices to the main TWI bus. It acts as a switch so at any point in time only one of the attached devices is connected to the main TWI bus, all other devices are isolated from the TWI bus. This allows multiple devices with the same TWI address to ‘coexist’ on the same bus. A simple command is sent to the Switch to tell it which device to active, you then send commands on the TWI as normal, then switch to the next device, send commands etc.
I have just about finished an extension for mBlock that uses this switch. I will upload ASAP.
TWI Switch with multiple Colour Sensors
The TWI Switch can be used with up to 8 Colour Sensors, is readily available and would require no additional ‘custom’ parts besides hook up wires.
So the TWI Switch would be attached to a single port on the mBot, then multiple Colour Sensors (or other TWI/I2C devices) attached to the TWI Switch.
Programatically this would occur as follows:
- Set TWI Switch to route to the desired colour sensor
- Send commands to colour sensor
So for the extension, either:
- The colour sensor extension needs to know about the TWI Switch and include TWI Switch calls in the driver (tightly coupled); or
- Let the user switch the TWI Switch between colour sensors before making the call to the colour sensor commands.
The issue with the 1. is that it makes it difficult for using the same switch with multiple TWI devices. The issue with 2. is that the user will need to explicitly run any Initialisation code before using the Colour Sensor.
I like option 2 because it gives more flexibility and allows the future implementation for allowing multiple of any type of TWI devices, but happy to debate and be convinced otherwise (@tec_support -> Is there any architecture guidance around this?)
I will modify your extension to implement solution 2 and then send through for you for review/comment.
Completing the Colour Sensor and TWI Switch extension
Will need to modify both extensions to work with all of the mBot models. Can look at this once both extensions are playing together nicely