How to read 2 TCS230 color sensors at the same time?

Hello,

I've been trying for a long time to read 2 TCS230 color sensors at the same time, using the logic of the ColorMatch example from the library MD_TCS230 which works with a NonBlocking reading... The biggest problem is that setEnable(0) and setEnable(1) doesn't seems to work and I keep get readings of just one sensor. I really need help with this... I've searched on the internet and couldn't find and example of someone reading two of these sensors at the same time... Did someone ever tried doing this?! Does someone have at least an idea?!

Thank you \o/

Post your code.

Or to say it another way this time in song:-

Give us a schematic as well.

Hello again, sorry for not posting my code from the first time... Post your code, post your code... (singing) :smiley:

ColorMatch_Kaue_V3.zip (1.61 KB)

So what Arduino do you have?

Did you read this notice in the MD_TCS230 library?

** IMPORTANT NOTE**
FreqCount imposes a limitation that the frequency can only be
counted on specific pins and limits the use of oither pins as
follows:
Board Input Pin Pins Unusable with analogWrite()


Arduino Uno 5 3, 9, 10, 11
Arduino 2009 5 3, 9, 10, 11
Arduino Mega 47 9, 10, 44, 45, 46
Sanguino 1 12, 13, 14, 15

And the Frequency counter library says:-

FreqCount requires the input frequency as a digital level signal on a specific pin.

Board Frequency
Input Pin Pins Unusable
with analogWrite()
Teensy 3.0, 3.1, 3.2 13 -
Teensy LC 13 -
Teensy 2.0 11 4, 10, 12, 14, 15
Teensy++ 2.0 6 1, 24, 25, 26, 27
Teensy++ 1.0 6 1, 24, 25, 26, 27
Arduino Uno 5 3, 9, 10, 11
Arduino Leonardo 12 6, 9, 10, 13
Arduino Mega 47 9, 10, 44, 45, 46
Sanguino 1 12, 13, 14, 15

Yes I read, and Im using an Arduino Mega. Also I was reading the documentation, and the library code and the autor wrote that people should use digitalWrite to enable and disable sensors, instead of using his method setEnable... Well, I tried, still not working... I cant disable one to read the other and vice versa.

\o/

Ok so you read that and decided to ignore it, why?

Your pin assignments are all wrong. The point is that you have to use the same pin to measure the frequency on both sensors and only enable the output on one of them. From what I can see you are not doing this in your code. The mega shows only one pin you can use and you don't seem to be using it.

No I didnt ignore it, I tried using digitalWrite after I posted the code, also why the pin assignment are all wrong, I mean, I dont have to declare that im using the pin 47 for reading both sensors, I just have to say which pins are S2, S3 and OE on each sensor. In order to enable a sensor I have to set its OE pin to LOW and the other one to HIGH, this way I should be reading one at a time, but doesnt work... But I keep getting readings of just one sensor and the values are all wrong...
Any ideas? Am I doing something wrong?

\o/

Can you post a schematic of how you have wired it up please. I would have thought that somewhere you would have to tell the code you are looking at pin 47, but I can't see that.

I just have to say which pins are S2, S3 and OE on each sensor.

Apart from the OE all the pins on the two pins can be the same. There is no need to have any others on different pins. Show the code where you used digital write to enable them.
Note you need to put the OE pin from the sensor you don't want HIGH before you put the pin from the sensor you do want LOW. If for an instant both OE lines are LOW then you could damage your sensors.

But I keep getting readings of just one sensor and the values are all wrong...

Hang on, are you saying the readings you are getting are wrong anyway?

A few things to look at:

  1. The OE is enabled low (from memory). Please check. That is is why the call to enable/disable is in the library.
  2. What sensors are you using. Have you looked at the PDF that comes wit the library and made sure that the OE is not always enabled by the circuit board connecting OE to ground?
  3. You need to make sure that the code disables the currently enabled sensor before enabling the second one.
  4. Make sure that you can get this working with one sensor before you become a pioneer with 2 sensors. If it does not work for 1 it will never work with 2.

Please also show us (a photo properly focused is probably good enough) how you are connecting the wires.

@Grumpy_Mike: The FreqCount library only uses one pin and there is nowhere to select which it uses - it just defaults based on the hardware type. This is confusing for many users - hence the big notice in the code (which many fail to read anyway).

The FreqCount library only uses one pin and there is nowhere to select which it uses

Thanks

The OE is enabled low (from memory)

Yes it is.

I am worried that his code goes:-

    CS_E.setEnable(false);
    CS_D.setEnable(true);

Which assuming that the ~OE was previously set at :-

CS_D.setEnable(true);
CS_E.setEnable(false);

Would result in both ~OE pins being low at the same time for a short period.

Why on Earth anyone needs a library to control this sensor is beyond me. It is another case of libraries gone mad. Libraries should be reserved for non trivial code.

Agree both need to be disabled before the selected one is enabled.

Many of the sensor boards have OE wired to ground on the PCB. This stops anything being able to control the sensor and could be the cause of the incorrect readings, as both sensors would be enabled no matter what the setting are.

Libraries should be reserved for non trivial code.

I guess that is a view. Another view is that encapsulating a device (like this sensor) as an class/object can make using the device easier, especially for inexperienced users (which abound in the Arduino world). Libraries in Arduino-land are not really libraries, as you well know. Anyway, this is not the OPs problem.