Go Down

Topic: Multiple TCS230 Color Sensors (Read 197 times) previous topic - next topic

gandarufu

My setup is as follows:


  • 5 x TCS230 Color Sensors (http://www.dx.com/p/tcs230-color-sensor-detector-module-for-arduino-148739?item=1#.WY7I9ilBouU)
  • 3 x CD74HC4067 multiplexers (https://eckstein-shop.de/SparkFun-Analog-Digital-MUX-Breakout-CD74HC4067)
  • MajicDesign's Library (https://github.com/MajicDesigns/MD_TCS230)


I'm trying to use 5 color sensors at the same time, but I'm not sure about the wiring / setup. My wiring looks like this:

  • All S2 pins from the sensors multiplexed and connectes to PIN 12
  • All S3 pins from the sensors multiplexed and connectes to PIN 13
  • All OUT pins from the sensors multiplexed and connectes to PIN 5
  • All S0-S3 of the multiplexers are connected to PIN 1-4


With my code / setup the values of the sensors seem to depend on each other - if I hold a white card in front of reader0, the values of all other readers change accordingly (and somewhat randomly).

This is the code that I'm trying to use:

Code: [Select]

#include <MD_TCS230.h>
#include <FreqCount.h>

// Pin definitions
#define COLOR_S2  12          // S2 Pins from ColorSensors bundled here
#define COLOR_S3  13          // S3 Pins from ColorSensors bundled here
#define COLOR_OE   8          // OE Pins from ColorSensors bundled here
#define COLOR_OUT  5          // Out-Pins from ColorSensors bundled here
#define M_OUT_0    1          // Controll Pins S0 from Multiplexers
#define M_OUT_1    2          // Controll Pins S1 from Multiplexers 
#define M_OUT_2    3          // Controll Pins S2 from Multiplexers
#define M_OUT_3    4          // Controll Pins S3 from Multiplexers

const int nrSensors = 5;
MD_TCS230 CS(COLOR_S2, COLOR_S3, COLOR_OE);


void setup() {
  Serial.begin(9600);
  pinMode(M_OUT_0, OUTPUT);
  pinMode(M_OUT_1, OUTPUT);
  pinMode(M_OUT_2, OUTPUT);
  pinMode(M_OUT_3, OUTPUT);

  CS.begin();
}

void loop() {
  readSensors();
}


void readSensors()
{

  for (int i = 0; i < nrSensors; i++) {
    digitalWrite(M_OUT_0, bitRead(i, 0));
    digitalWrite(M_OUT_1, bitRead(i, 1));
    digitalWrite(M_OUT_2, bitRead(i, 2));
    digitalWrite(M_OUT_3, bitRead(i, 3));

    static  bool  waiting;
    if (!waiting)
    {
      CS.read();
      waiting = true;
    }
    else
    {
      if (CS.available())
      {
        colorData  rgb;
        CS.getRGB(&rgb);
        Serial.print("Sensor ");
        Serial.print(i);
        Serial.print("RGB [");
        Serial.print(rgb.value[TCS230_RGB_R]);
        Serial.print(",");
        Serial.print(rgb.value[TCS230_RGB_G]);
        Serial.print(",");
        Serial.print(rgb.value[TCS230_RGB_B]);
        Serial.println("]");
        waiting = false;
        delay(50);
      }
    }
  }
}



I am not sure what to do with the OE pins of the sensors and would appreciate any help.
I tried connecting all OE pins to GND and used MD_TCS230 CS(COLOR_S2, COLOR_S3). I also tried connecting all OE pins to PIN 8, using MD_TCS230 CS(COLOR_S2, COLOR_S3, COLOR_OE); or even multiplexing them - nothing worked. I guess this only shows, how little I understand, what the OE pins are there for.

If anyone could point me in the right direction, I'd appreciate that very much.
Thanks in advance!

marco_c

The first thing is to test that the devices work on their own. This verifies the setup with respect to pins and frequency detection. If that does not work then the mux setup will not work also.

The OE is an active low input to the sensor that enables the output from the sensor. From the datasheet "Output enable (OE) places the output in the high-impedance state for multiple-unit sharing of a microcontroller input line." In other words, the OE will enable the frequency output of the sensor so that many sensors can be connected to the same microcontroller input. The high impedance state allows the outputs to be connected together without being damaged.

Your code can turn off the current OE (set the digital output to HIGH) and then turn on the output from the next sensor (digital output to LOW), take a reading, and flow on down the line. This implies there is no need for mux at all.
Arduino Libraries https://github.com/MajicDesigns?tab=Repositories
Parola for Arduino https://github.com/MajicDesigns/Parola
Arduino++ blog https://arduinoplusplus.wordpress.com

jremington

#2
Aug 13, 2017, 04:59 am Last Edit: Aug 13, 2017, 05:11 am by jremington
Quote
This implies there is no need for mux at all.
Agreed, according to my reading of the data sheet.

In the absence of the mux, you need one Arduino output pin for each sensor, to control the sensor's /OE line. The  connections to S0-3, and OUT can be shared among the sensors.

(I've been planning for some time on experimenting with this sensor -- note that in order to avoid confusion due to 700-1100nm IR radiation, you need an external filter. The data sheet suggests using a Hoya CM500.)

gandarufu

Thanks a bunch for the input, guys! I'm actually relieved to hear that it should be possible without MUX.

I wired everything up as jremington suggested: S2, S3 and OUT are shared among the sensors (PIN12, PIN13 and PIN 5). I gave every reader its own output pin (PIN7 and PIN8 in my case).

I then wrote some very crappy code and tested it with 2 sensors.


Code: [Select]

#define S2  12
#define S3  13
#define OE0  7
#define OE1  8

MD_TCS230 CS(S2, S3);

void setup() {
  Serial.begin(9600);
  pinMode(OE0, OUTPUT);
  pinMode(OE1, OUTPUT);
  digitalWrite(OE0, HIGH);
  digitalWrite(OE1, HIGH);
  CS.begin();
}

void loop() {
  readSensors();
}

void readSensors()
{
  for (int i = 0; i < 2; i++) {
    switch (i)
    {
      case 0:
        {
          digitalWrite(OE0, LOW);
          delay(50);
          break;
        }
      case 1:
        {
          digitalWrite(OE1, LOW);
          delay(50);
          break;
        }
    }


    static  bool  waiting;
    if (!waiting)
    {
      CS.read();
      waiting = true;
    }
    else
    {
      if (CS.available())
      {
        colorData  rgb;
        CS.getRGB(&rgb);
        Serial.print("Sensor ");
        Serial.print(i);
        Serial.print("RGB [");
        Serial.print(rgb.value[TCS230_RGB_R]);
        Serial.print(",");
        Serial.print(rgb.value[TCS230_RGB_G]);
        Serial.print(",");
        Serial.print(rgb.value[TCS230_RGB_B]);
        Serial.println("]");
        waiting = false;
        delay(50);
      }
    }

    switch (i)
    {
      case 0:
        {
          digitalWrite(OE0, HIGH);
          break;
        }
      case 1:
        {
          digitalWrite(OE1, HIGH);
          break;
        }
    }
  }



When I check the LEDs of the sensors, I can see that they are clearly switched on and off alternately, which looks like the setup is working. However, as far as the values go, the sensors are still active. For instance, when I switch sensor0 off via OE, and sensor1 on, I still only get readings from sensor0.
- When I only cover sensor1, nothing happens.
- When I cover sensor0, the values drop down halfway.
- When I cover sensor0 and then also sensor1, the values drop down all the way to black (0,0,0).

I thoght I cut the tracks on the PCB correctly, but they are very hard to spot. I have access to a multimeter tomorrow so I'll go check the connection between OE and GND and see if maybe that's the problem.


jremington

#4
Aug 13, 2017, 05:02 pm Last Edit: Aug 13, 2017, 05:05 pm by jremington
What tracks did you cut?

Have you verified with a multimeter that before modification, your breakout had OE connected to GND? And that afterward, it is NOT?

Do you have a schematic of the breakout board?

gandarufu

#5
Aug 14, 2017, 12:31 pm Last Edit: Aug 14, 2017, 04:18 pm by gandarufu
It turns out, I didn't cut the track at all. When I used the multimeter, it still showed 0 between GND and OE. It's so hard to see where the tracks are, so I'll just wait for a friend of mine who's better with electronics - maybe he can find the right track.

My sensors look like this:
sensor back
sensor front

I marked the track here, of which I thought it's the right one.
sensor track?


Anyhow, it's hard to tell from the pics anyway, so I'll post more results once my friend gets a look at the sensors. Thanks nevertheless!

gandarufu

UPDATE

So I checked my sensors with a mutlimeter. OE and GND showed 0 at first. After I cut the right track, I got some resistance, so I'm guessing it was the right one.
cut track


I checkd my sensors individually and as long as I only use one, the setup works okay. I'm not able to disable the sensor via OE set to HIGH though.

With two sensors I get the same result as before: I cannot enable / disable any of the two sensors and the values depend on each other. It's like I have one big sensor consisting of two smaller ones.

jremington

#7
Aug 16, 2017, 05:26 pm Last Edit: Aug 17, 2017, 12:27 am by jremington
I don't understand what this means: " It's like I have one big sensor consisting of two smaller ones."

If two outputs are attempting to pulse one pin, you should end up with uninterpretable nonsense.

You could try desoldering the /OE pin on the sensor chip, using a fine tipped solder pencil and a needle to lift the pin, then tack a wire onto it.

Terrible breakout board design!

marco_c

#8
Aug 16, 2017, 11:38 pm Last Edit: Aug 16, 2017, 11:44 pm by marco_c
I think you need to be careful to understand why you needed to cut the track. This was explained in the PDF for the library but I'll repeat it here.

Some of the breakouts connect the sensor's /OE pin directly to ground. This is to ensure that the sensor is enabled ON when it is powered. What this means, however, is that if you try and control the pin from the breakout edge connector (ie, set to HIGH), you effectively short the Arduino output pin (set HIGH) to ground, which shorts the power supply and shuts it down. The solution is to cut the sensor \OE to ground connection.

Other sensor breakout board properly pull the pin to ground using a resistor. In this case there should be no problem leaving it as it is - the resistor prevents the power supply short.

To decide which you have, you need to measure the resistance from the ground pin edge connector to the /OE pin edge connector. If there is no resistance, then the track needs to be cut between \OE on the sensor and ground on the breakout board. If there is a resistance, it should work ok

In any case, the first time you try and use the board and control \OE, you will know if the power supply shorts out.
Arduino Libraries https://github.com/MajicDesigns?tab=Repositories
Parola for Arduino https://github.com/MajicDesigns/Parola
Arduino++ blog https://arduinoplusplus.wordpress.com

jremington

Quote
To decide which you have, you need to measure the resistance from the ground pin edge connector to the /OE pin edge connector.
Evidently you did not read posts #5 and #6, in which the OP reported measuring 0 Ohms from /OE to GND.

marco_c

#10
Aug 17, 2017, 02:37 am Last Edit: Aug 17, 2017, 02:40 am by marco_c
Quote
Evidently you did not read posts #5 and #6
Actually I did, but thanks for pointing it out.

It worth stating the obvious and understanding why things are done in these forums as the skill level of participants varies considerably. There will be others using this as a reference for this in future.

@gandarufu:
Quote
After I cut the right track, I got some resistance, so I'm guessing it was the right one
After you cut the track you should have an open circuit, so if you are measuring any resistance at all you should investigate.
Arduino Libraries https://github.com/MajicDesigns?tab=Repositories
Parola for Arduino https://github.com/MajicDesigns/Parola
Arduino++ blog https://arduinoplusplus.wordpress.com

Go Up