rikosaita
Posts: 3
Joined: Mon May 25, 2015 9:48 am

Accesing TCS3200 Color Sensor

Mon Jun 15, 2015 3:11 am

I've been successful in finding and using information on the TCS3200 Sensor.

However, I cannot find any Raspberry Pi (found for Arduino) information on accessing the R,G,B Channel in TCS3200 chip/module. If you can point me in the right direction or give a demo code I would appreciate it.

Here its the information about TCS3200
http://www.dfrobot.com/wiki/index.php?t ... SEN0101%29
Thanks

User avatar
joan
Posts: 14195
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Accesing TCS3200 Color Sensor

Thu Jul 02, 2015 9:53 pm

This is work in progress but it may be useful.

Notes
  • You need to shroud the sensor to cut out extraneous light
  • The module I have has OE connected to ground. Check yours. It will be a short-circuit if you try to disable readings by setting OE high.
  • To get reliable readings you need to calibrate. I do this by using a black card and then a white card at the start of the session. The Python __main__ does that.
  • Once calibrated I got repeatable results from different coloured sheets of paper.
Updated code is available at http://abyz.co.uk/rpi/pigpio/code/TCS3200_py.zip

webm screencast of piscope TCS3200 capture. The number triplets at the bottom left of the screen are the calculated RGB, the frequency per colour, and the number of cycles read to calculate the frequency.

Code: Select all

#!/usr/bin/env python

# 2015-07-02
# TCS3200.py
# Public Domain

import time
import threading

import pigpio

class sensor(threading.Thread):
   """
   This class reads RGB values from a TCS3200 colour sensor.

   GND   Ground.
   VDD   Supply Voltage (2.7-5.5V)
   /OE   Output enable, active low. When OE is high OUT is disabled
         allowing multiple sensors to share the same OUT line.
   OUT   Output frequency square wave.
   S0/S1 Output frequency scale selection.
   S2/S3 Colour filter selection.

   OUT is a square wave whose frequency is proprtional to the
   intensity of the selected filter colour.

   S2/S3 selects between red, green, blue, and no filter.

   S0/S1 scales the frequency at 100%, 20%, 2% or off.

   To take a reading the colour filters are selected in turn for a
   fraction of a second and the frequency is read and converted to
   Hz.  
   """
   def __init__(self, pi, OUT, S2, S3, S0=None, S1=None, OE=None):
      """
      The gpios connected to the sensor OUT, S2, and S3 pins must
      be specified.  The S2, S3 (frequency) and OE (output enable)
      gpios are optional.
      """
      threading.Thread.__init__(self)
      self._pi = pi

      self._OUT = OUT
      self._S2 = S2
      self._S3 = S3

      self._mode_OUT = pi.get_mode(OUT)
      self._mode_S2 = pi.get_mode(S2)
      self._mode_S3 = pi.get_mode(S3)

      pi.write(OUT, 0) # disable output gpio
      pi.set_mode(S2, pigpio.OUTPUT)
      pi.set_mode(S3, pigpio.OUTPUT)

      self._S0 = S0
      self._S1 = S1
      self._OE = OE

      if (S0 is not None) and (S1 is not None):
         self._mode_S0 = pi.get_mode(S0)
         self._mode_S1 = pi.get_mode(S1)
         pi.set_mode(S0, pigpio.OUTPUT)
         pi.set_mode(S1, pigpio.OUTPUT)

      if OE is not None:
         self._mode_OE = pi.get_mode(OE)
         pi.set_mode(OE, pigpio.OUTPUT)
         pi.write(OE, 0) # enable device

      self.set_sample_size(50)

      self._period = 0.25 # 4 readings per second

      self.set_frequency(1) # 2%

      self._rgb_black = [0]*3
      self._rgb_white = [10000]*3

      self._set_filter(3) # Clear

      self.Hertz=[0]*3 # latest triplet
      self._Hertz=[0]*3 # current values

      self.tally=[1]*3 # latest triplet
      self._tally=[1]*3 # current values

      self._delay=[0.1]*3 # tune delay to get TALLY readings

      self._edge = 0

      self._start_tick = 0
      self._last_tick = 0

      self._cb_OUT = pi.callback(OUT, pigpio.RISING_EDGE, self._cbf)
      self._cb_S2 = pi.callback(S2, pigpio.EITHER_EDGE, self._cbf)
      self._cb_S3 = pi.callback(S3, pigpio.EITHER_EDGE, self._cbf)

      self._read = True

      self.daemon = True

      self.start()

   def _cbf(self, g, l, t):

      if g == self._OUT:
         if self._edge == 0:
            self._start_tick = t
         else:
            self._last_tick = t
         self._edge += 1

      else: # Must be transition between colour samples
         if g == self._S2:
            if l == 0: # Clear -> Red
               self._edge = 0
               return
            else:      # Blue -> Green
               colour = 2
         else:
            if l == 0: # Green -> Clear
               colour = 1
            else:      # Red -> Blue
               colour = 0

         if self._edge > 1:
            self._edge -= 1
            td = pigpio.tickDiff(self._start_tick, self._last_tick)
            self._Hertz[colour] = (1000000 * self._edge) / td
            self._tally[colour] = self._edge
         else:
            self._Hertz[colour] = 0
            self._tally[colour] = 0

         self._edge = 0

         # Have we a new set of RGB?
         if colour == 1:
            for i in range(3):
               self.Hertz[i] = self._Hertz[i]
               self.tally[i] = self._tally[i]

   def run(self):
      while True:
         if self._read:

            next_time = time.time() + self._period

            self._pi.set_mode(self._OUT, pigpio.INPUT) # enable output gpio

            # The order Red -> Blue -> Green -> Clear is needed by the
            # callback function so that each S2/S3 transition triggers
            # a state change.  The order was chosen so that a single
            # gpio changes state between the change in colour to be
            # sampled.

            self._set_filter(0) # Red
            time.sleep(self._delay[0])
            self._set_filter(2) # Blue
            time.sleep(self._delay[2])
            self._set_filter(1) # Green
            time.sleep(self._delay[1])
            self._pi.write(self._OUT, 0) # disable output gpio
            self._set_filter(3) # Clear

            delay = next_time - time.time()

            if delay > 0.0:
               time.sleep(delay)

            # Tune the next set of delays to get reasonable results
            # as quickly as possible.

            for c in range(3):
               # Calculate dly needed to get a decent number of samples
               if self.Hertz[c]:
                  dly = self._samples / float(self.Hertz[c])

                  # Constrain dly to reasonable values
                  if dly < 0.001:
                     dly = 0.001
                  elif dly > 0.5:
                     dly = 0.5

                  self._delay[c] = dly

         else:
            time.sleep(0.1)

   def pause(self):
      """
      No more readings will be made until resume is called.
      """
      self._read = False

   def resume(self):
      """
      Resumes readings (after a call to pause).
      """
      self._read = True

   def get_Hertz(self):
      """
      Returns the latest Hertz reading.
      """
      return self.Hertz

   def get_rgb(self, top=255):
      """
      Returns the latest RGB reading.

      The raw colour Hertz readings are converted to RGB values.

      By default the RGB values are constrained to be between
      0 and 255.  A different upper limit can be set by using
      the top parameter.
      """
      rgb = [0]*3
      for c in range(3):
         v = self.Hertz[c] - self._rgb_black[c]
         s = self._rgb_white[c] - self._rgb_black[c]
         p = top * v / s
         if p < 0:
            p = 0
         elif p > top:
            p = top
         rgb[c] = p
      return rgb

   def cancel(self):
      """
      Cancels the sensor and release all used resources.
      """
      self._cb_S3.cancel()
      self._cb_S2.cancel()
      self._cb_OUT.cancel()

      self.set_frequency(0) # off

      self._set_filter(3) # Clear

      self._pi.set_mode(self._OUT, self._mode_OUT)
      self._pi.set_mode(self._S2, self._mode_S2)
      self._pi.set_mode(self._S3, self._mode_S3)

      if (self._S0 is not None) and (self._S1 is not None):
         self._pi.set_mode(self._S0, self._mode_S0)
         self._pi.set_mode(self._S1, self._mode_S1)

      if self._OE is not None:
         self._pi.write(self._OE, 1) # disable device
         self._pi.set_mode(self._OE, self._mode_OE)

   def set_black_level(self, rgb):
      """
      Sets the black level calibration.
      """
      for i in range(3):
         self._rgb_black[i] = rgb[i]

   def set_white_level(self, rgb):
      """
      Sets the white level calibration.
      """
      for i in range(3):
         self._rgb_white[i] = rgb[i]

   def _set_filter(self, f):
      """
      Set the colour to be sampled.

      f  S2  S3  Photodiode
      0  L   L   Red
      1  H   H   Green
      2  L   H   Blue
      3  H   L   Clear (no filter)
      """
      if f == 0: # Red
         S2 = 0; S3 = 0
      elif f == 1: # Green
         S2 = 1; S3 = 1
      elif f == 2: # Blue
         S2 = 0; S3 = 1
      else: # Clear
         S2 = 1; S3 = 0

      self._pi.write(self._S2, S2); self._pi.write(self._S3, S3)

   def get_frequency(self):
      """
      Returns the current frequency scaling.
      """
      return self._frequency

   def set_frequency(self, f):
      """
      Sets the frequency scaling.

      f  S0  S1  Frequency scaling
      0  L   L   Off
      1  L   H   2%
      2  H   L   20%
      3  H   H   100%
      """
      if f == 0: # off
         S0 = 0; S1 = 0
      elif f == 1: # 2%
         S0 = 0; S1 = 1
      elif f == 2: # 20%
         S0 = 1; S1 = 0
      else: # 100%
         S0 = 1; S1 = 1

      if (self._S0 is not None) and (self._S1 is not None):
         self._frequency = f
         self._pi.write(self._S0, S0)
         self._pi.write(self._S1, S1)
      else:
         self._frequency = None

   def set_update_period(self, t):
      """
      Sets the period between RGB updates.
      """
      if (t >= 0.1) and (t < 2.0):
         self._period = t

   def set_sample_size(self, samples):

      if (samples < 10) or (samples > 1000):
         samples = 50

      self._samples = samples

if __name__ == "__main__":

   import sys

   RED=21
   GREEN=20
   BLUE=16

   def wait_for_return(str):
      if sys.hexversion < 0x03000000:
         raw_input(str)
      else:
         input(str)

   pi = pigpio.pi()

   p = 0.333

   # Bottom view
   #
   # GND    VCC
   # OE     OUT
   # S1     S2
   # S0     S3

   s = sensor(pi, 24, 22, 23, 4, 17, 18)
   s.set_update_period(p)
   s.set_frequency(2) # 20%
   s.set_sample_size(20)

   wait_for_return("Calibrating black, press RETURN to start")

   for i in range(5):
      time.sleep(p)
      rgb = s.get_Hertz()
      print(rgb)
      s.set_black_level(rgb)

   wait_for_return("Calibrating white, press RETURN to start")

   for i in range(5):
      time.sleep(p)
      rgb = s.get_Hertz()
      print(rgb)
      s.set_white_level(rgb)

   if True:
   #try:
      while True:
         time.sleep(p)
         rgb = s.get_rgb()
         r = rgb[0]
         g = rgb[1]
         b = rgb[2]
         print(rgb, s.get_Hertz(), s.tally)
         pi.set_PWM_dutycycle(RED, r)
         pi.set_PWM_dutycycle(GREEN, g)
         pi.set_PWM_dutycycle(BLUE, b)

   if True:
   #except:

      print("cancelling")
      s.cancel()
      pi.stop()

soneri91
Posts: 1
Joined: Tue Jan 26, 2016 2:09 pm

Re: Accesing TCS3200 Color Sensor

Thu Jan 28, 2016 11:28 am

[email protected] ~ $ sudo python renktcs.py
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Can't connect to pigpio on localhost(8888)

Did you start the pigpio daemon? E.g. sudo pigpiod

Did you specify the correct Pi host/port in the environment
variables PIGPIO_ADDR/PIGPIO_PORT?
E.g. export PIGPIO_ADDR=soft, export PIGPIO_PORT=8888

Did you specify the correct Pi host/port in the
pigpio.pi() function? E.g. pigpio.pi('soft', 8888))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Traceback (most recent call last):
File "renktcs.py", line 361, in <module>
s = sensor(pi, 24, 22, 23, 4, 17, 18)
File "renktcs.py", line 48, in __init__
self._mode_OUT = pi.get_mode(OUT)
File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 1054, in get_mod e
return _u2i(_pigpio_command(self.sl, _PI_CMD_MODEG, gpio, 0))
File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 834, in _pigpio_ command
sl.s.send(struct.pack('IIII', cmd, p1, p2, 0))
AttributeError: 'NoneType' object has no attribute 'send'





Why am I getting this error code??
thank you for your help..

User avatar
joan
Posts: 14195
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Accesing TCS3200 Color Sensor

Thu Jan 28, 2016 2:10 pm

Code: Select all

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Can't connect to pigpio on localhost(8888)

Did you start the pigpio daemon? E.g. sudo pigpiod

Did you specify the correct Pi host/port in the environment
variables PIGPIO_ADDR/PIGPIO_PORT?
E.g. export PIGPIO_ADDR=soft, export PIGPIO_PORT=8888

Did you specify the correct Pi host/port in the
pigpio.pi() function? E.g. pigpio.pi('soft', 8888))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

ramye
Posts: 1
Joined: Fri Apr 22, 2016 3:42 pm

Re: Accesing TCS3200 Color Sensor

Fri Apr 22, 2016 3:52 pm

did anyone manage to make the TCS3200 Color sensor work on raspberry pi

User avatar
joan
Posts: 14195
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Accesing TCS3200 Color Sensor

Fri Apr 22, 2016 5:46 pm

ramye wrote:did anyone manage to make the TCS3200 Color sensor work on raspberry pi
Err, yes. See above.

Pritom
Posts: 2
Joined: Sun Jun 05, 2016 7:20 am

Re: Accesing TCS3200 Color Sensor

Sun Jun 05, 2016 7:36 am

Hi,
I have been working with TCS3200 color sensor that comes from Keyestudio and am trying to detect colors of multi color liquids. I followed this discussion and was able to read RGB data accordingly. But the RGB value doesn't represent the particular color that I want it to detect :| . I have the following confusion regarding the code:

1) Why do we need to calibrate the black and white color first? Can the process be done without using this primary calibration?

2) When I connect the S1 pin to 17 no. pin of the Pi, I simply get no data. And suddenly it starts showing data like [100L,10L,3L]. I don't understand what is 'L' stands for. I don't know if it stands for Low :roll: .

3) I would really appreciate an explanation of the code.
Hope to hear back soon. :)

Sylbur
Posts: 5
Joined: Mon Jun 13, 2016 2:54 am

Re: Accesing TCS3200 Color Sensor

Mon Jun 13, 2016 4:32 am

Hi
you could write to what pins connect the output to TCS3200 color sensor, I would be very grateful because your code returns me all zeros

User avatar
joan
Posts: 14195
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Accesing TCS3200 Color Sensor

Mon Jun 13, 2016 7:51 am

Pritom wrote:Hi,
I have been working with TCS3200 color sensor that comes from Keyestudio and am trying to detect colors of multi color liquids. I followed this discussion and was able to read RGB data accordingly. But the RGB value doesn't represent the particular color that I want it to detect :| . I have the following confusion regarding the code:

1) Why do we need to calibrate the black and white color first? Can the process be done without using this primary calibration?

2) When I connect the S1 pin to 17 no. pin of the Pi, I simply get no data. And suddenly it starts showing data like [100L,10L,3L]. I don't understand what is 'L' stands for. I don't know if it stands for Low :roll: .

3) I would really appreciate an explanation of the code.
Hope to hear back soon. :)
  1. The point of the calibration is to try to take into account the current lighting situation which will vary according to local circumstances. If you have stable lighting remove that code and use preset values.
  2. The code always uses Broadcom numbered GPIO. The L is a Python artefact. I don't remember why it adds the L. You can safely ignore it, in Python 3 I don't think L happens any more.
  3. The code reads the frequency of the PWM generated by the R, G, and B filters. To understand the code you need to understand the datasheet. The examples I do are really to show the sort of standard techniques to use with pigpio. I'm sure you can improve on the code.

User avatar
joan
Posts: 14195
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Accesing TCS3200 Color Sensor

Mon Jun 13, 2016 7:54 am

Sylbur wrote:Hi
you could write to what pins connect the output to TCS3200 color sensor, I would be very grateful because your code returns me all zeros
All references to GPIO use Broadcom numbers. E.g. 4 means GPIO4 which is on pin 7.

Sylbur
Posts: 5
Joined: Mon Jun 13, 2016 2:54 am

Re: Accesing TCS3200 Color Sensor

Mon Jun 13, 2016 12:33 pm

That's not what I meant
24 OE
22 OUT
23 S0
4 S1
17 S2
18 S3
is it correct connection? because I have zeros
sometimes canceled, I received a message

Code: Select all

Exception in thread Thread-2 (most likely raised during interpreter shutdown):
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
  File "/home/pi/gleba/TCS3200.py", line 335, in run
  File "/home/pi/gleba/TCS3200.py", line 277, in _set_filter
  File "/usr/lib/python2.7/dist-packages/pigpio.py", line 1138, in write
<type 'exceptions.TypeError'>: 'NoneType' object is not callable
Thanks for the answer
Last edited by Sylbur on Tue Jun 14, 2016 1:29 pm, edited 1 time in total.

User avatar
joan
Posts: 14195
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Accesing TCS3200 Color Sensor

Mon Jun 13, 2016 1:00 pm

The class __init__ has

Code: Select all

   def __init__(self, pi, OUT, S2, S3, S0=None, S1=None, OE=None):
      """
      The gpios connected to the sensor OUT, S2, and S3 pins must
      be specified.  The S2, S3 (frequency) and OE (output enable)
      gpios are optional.
      """
The above shows the positional parameter ordering.

Unfortunately the comment is wrong it should read, "The S0, S1 (frequency) and OE (output enable) gpios are optional."

Default settings in code are

Code: Select all

s = TCS3200.sensor(pi, 24, 22, 23,  4, 17, 18)
#                      OUT S2  S3  S0  S1  S3
You have 24 OE, 22 OUT, 23 S0, 4 S1, 17 S2, 18 S3

Have you updated the TCS3200.sensor call to reflect the GPIO you are using?

Sylbur
Posts: 5
Joined: Mon Jun 13, 2016 2:54 am

Re: Accesing TCS3200 Color Sensor

Mon Jun 13, 2016 4:57 pm

Thank you very much for your help, finally receives some data which change under the influence of color. Could you still describe the output? :ugeek:

White
([255, 255L, 255L], [6265L, 5865L, 7715L], [37, 31, 26])
Black
([0, 0, 0], [562L, 520L, 706L], [20, 20, 20])
Green
([27L, 48L, 18L], [1237L, 1610L, 1317L], [23, 22, 21])
Red
([74L, 24L, 23L], [2263, 1108, 1446], [26, 21, 20])
Blue
([66L, 70L, 104L], [2091, 2060, 3633], [29, 23, 23])

The first is the range of colors RGB, the second light intensity? and the third is I have no idea

User avatar
joan
Posts: 14195
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Accesing TCS3200 Color Sensor

Mon Jun 13, 2016 5:47 pm

I briefly explained in viewtopic.php?p=783796#p783796

The first triplet is the RGB values.

The second triplet is the PWM frequency in hertz generated for the R, G, and B filters. The PWM frequency is proportional to the amount of each colour.

The third triplet is the number of cycles of PWM the software needed to calculate the PWM frequency for R, G, and B.

The second and third triplets are only useful during debugging so you needn't worry about them.

Sylbur
Posts: 5
Joined: Mon Jun 13, 2016 2:54 am

Re: Accesing TCS3200 Color Sensor

Tue Jun 14, 2016 1:09 pm

Hi
I wanted to ask you about one thing, how to speed up the script?

Code: Select all

self.set_update_interval(0.1) # One reading per second.

Code: Select all

 interval = 0.02
I found two places but you can only change it to 100ms. how many can be increased to a maximum read speed and how?

Thank you very much for your help

User avatar
joan
Posts: 14195
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Accesing TCS3200 Color Sensor

Wed Jun 15, 2016 5:15 pm

Sylbur wrote:Hi
I wanted to ask you about one thing, how to speed up the script?

Code: Select all

self.set_update_interval(0.1) # One reading per second.

Code: Select all

 interval = 0.02
I found two places but you can only change it to 100ms. how many can be increased to a maximum read speed and how?

Thank you very much for your help
You'd have to change the code.

I do not remember why I used a lower limit of 0.1 seconds, perhaps because I didn't think there was any point in sampling more than 10 times a second.

Change the code to remove the lower bound check in set_update_interval and see if it works at higher rates.

Pritom
Posts: 2
Joined: Sun Jun 05, 2016 7:20 am

Re: Accesing TCS3200 Color Sensor

Fri Jun 17, 2016 1:59 pm

Thanks a lot Joan :) . Actually I am using a black enclosure around the sensor to get rid of the calibration part . Now, what kind of change should I bring to eliminate the calibration parts :? I did the following changes in get_rgb function and commented out the set_black_level and set_white_level functions . But it did not worked well :roll: . What else should I change?

Code: Select all

 def get_rgb(self, top=255):
      """
      Returns the latest RGB reading.

      The raw colour Hertz readings are converted to RGB values.

      By default the RGB values are constrained to be between
      0 and 255.  A different upper limit can be set by using
      the top parameter.
      """
      rgb = [0]*3
      for c in range(3):
         #v = self.Hertz[c] - self._rgb_black[c]
         v = self.Hertz[c] - self._rgb_black[c]
         #s = self._rgb_white[c] - self._rgb_black[c]
         #p = top * v / s
         p = top * v 

        if p < 0:
            p = 0
         elif p > top:
            p = top
         rgb[c] = p
      return rgb
Also I could not understand (import sys) why have you defined static values for R,G and B :geek: ?
RED=21
GREEN=20
BLUE=16
Waiting to hear back soon 8-) .

Sylbur
Posts: 5
Joined: Mon Jun 13, 2016 2:54 am

Re: Accesing TCS3200 Color Sensor

Sat Jun 18, 2016 6:35 am

Hi
I reduced range like you said, but then stops working, the data do not change according to color.
1) tell how long it will take up to properly read color 1ms 10ms?
2) if you find some time to check the same with the reduced range stops working, it reads all the time maybe 20 or 1000 times per sec, but the data changed after a few minutes, and by the end still did not understand your script so it himself for now I am not change
3) It occurred to me with you, you can convert your code gpio 23 to 18 and works exactly the same

Code: Select all

s = TCS3200.sensor(pi, 24, 22, 18,  4, 17, 18)
Do you might have some influence on reading color?

User avatar
joan
Posts: 14195
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Accesing TCS3200 Color Sensor

Sat Jun 18, 2016 7:59 am

You could try setting the frequency higher than the default 2% with set_frequency.

The higher the frequency the faster the response. If you go from setting 1 (2%) to setting 2 (20%) the readings may be faster.

I'm afraid it is down to you to find reliable settings for your scenario.

jbrownnz
Posts: 1
Joined: Mon Jul 25, 2016 11:52 pm

Re: Accesing TCS3200 Color Sensor

Tue Jul 26, 2016 12:00 am

Hi sylbur, i see you got some outputs for his, i have some students attempting to detect colours and we get the same initial error message that you recieved, are you able to help out by letting us know what leads you connected from the sensor to get this to work, in a reply to you earlier it looks as though sensor 3 goes to 2 places which can;t be correct. We are using a pi 3 and have found very little help online available. many thanks
Sylbur wrote:Thank you very much for your help, finally receives some data which change under the influence of color. Could you still describe the output? :ugeek:

White
([255, 255L, 255L], [6265L, 5865L, 7715L], [37, 31, 26])
Black
([0, 0, 0], [562L, 520L, 706L], [20, 20, 20])
Green
([27L, 48L, 18L], [1237L, 1610L, 1317L], [23, 22, 21])
Red
([74L, 24L, 23L], [2263, 1108, 1446], [26, 21, 20])
Blue
([66L, 70L, 104L], [2091, 2060, 3633], [29, 23, 23])

The first is the range of colors RGB, the second light intensity? and the third is I have no idea

User avatar
joan
Posts: 14195
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Accesing TCS3200 Color Sensor

Tue Jul 26, 2016 5:47 am

It would help if you posted a clear photo or photos of your set-up showing the connections between the Pi and the sensor.

It would help if you say what software you are using and if you have made any alterations.

Finally it would help if you posted a sample of the output you are getting when you run the software.

lepore
Posts: 1
Joined: Fri Oct 14, 2016 7:30 pm

Re: Accesing TCS3200 Color Sensor

Fri Oct 14, 2016 7:33 pm

Hi,

Working on trying to setup the TCS3200 with the pi, anyone have some simple source code I can play around with?

User avatar
joan
Posts: 14195
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Accesing TCS3200 Color Sensor

Fri Oct 14, 2016 8:47 pm

lepore wrote:Hi,

Working on trying to setup the TCS3200 with the pi, anyone have some simple source code I can play around with?
It's not a particularly simple device. You won't find simple source code.

mattmiller
Posts: 2100
Joined: Thu Feb 05, 2015 11:25 pm

Re: Accesing TCS3200 Color Sensor

Wed Nov 09, 2016 11:08 pm

Hi Joan
Just trying one of these out
I've connected s2,s3 and out to 5,6 and 13 on my pi
i've not connectted the other pins (as you imply they are optional)

i amended line 361

Code: Select all

   s = sensor(pi, 5,6,13)
but after the black and white calibrtion steps I then get this

Code: Select all

Calibrating white, press RETURN to start
[0, 0, 0]
[0, 0, 0]
[0, 0, 0]
[0, 0, 0]
[0, 0, 0]
Traceback (most recent call last):
  File "col.py", line 386, in <module>
    rgb = s.get_rgb()
  File "col.py", line 223, in get_rgb
    p = top * v / s
ZeroDivisionError: integer division or modulo by zero
Exception in thread Thread-2 (most likely raised during interpreter shutdown):
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
  File "col.py", line 162, in run
  File "col.py", line 288, in _set_filter
  File "/usr/lib/python2.7/dist-packages/pigpio.py", line 1138, in write
<type 'exceptions.TypeError'>: 'NoneType' object is not callable

User avatar
joan
Posts: 14195
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Accesing TCS3200 Color Sensor

Thu Nov 10, 2016 8:41 am

@mattmiller

That's what you will get if the TCS3200 is not connected to the GPIO. Did you remove an exception handler? Mine just says cancelling and exits.

Return to “Automation, sensing and robotics”