Color recognition board using the ESP8266 and the TAOS TCS230 color-to-frequency module

This is a wifi enabled board that reads color components Red, Green and Blue of any material placed closed to the sensor.

The reading of the color components is done via a TCP request to the board and the percentage color component values are returned in a JSON string.

The sequence for reading is done by sending the following strings via TCP on port 9999:

acquire

(wait 5 seconds for acquisition to complete)

read

The return message is in JSON format as follows:

{“RGB”: [{ “Red:”: “53”, “Green”: “23”, “Blue:”: “24”}]}

each number representing the percentage of that color. The board can be configured via web browser without the need for a serial interface to program it!

This board can be purchased at Tindie, press here to go to Tindie store

Advertisements

About hbouzas

Born in Buenos Aires, Argentina. Studied Physics at the University of Buenos Aires. Joined Schlumberger in February 1985 in Houston, Texas, and worked in several technical and managerial positions until 2000. From 2000 until 2008 held several management positions in Abingdon, UK; Calgary, Alberta and London, UK. Worked in the areas of Geophysical Exploration, Geological Modeling, Structural Modeling, Reservoir Modeling and Petroleum Economics and holds several patents. He is currently the Norway Technology Center Manager for Schlumberger Information Solutions and is based in Oslo and Stavanger. Main interest are software, technology, innovation, 3D visualization, design, human computer interaction, energy, environment.
This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to Color recognition board using the ESP8266 and the TAOS TCS230 color-to-frequency module

  1. Moreno says:

    Hello Horacio,

    Can you share the source code?

    Thanks!!!

    Moreno

  2. hbouzas says:

    file.writeline([[red=0 ]])
    file.writeline([[green=0 ]])
    file.writeline([[blue=0 ]])
    file.writeline([[all=0 ]])
    file.writeline([[IP_posted = 0]])
    file.writeline([[color_done=0]])
    file.writeline([[pin=5]])
    file.writeline([[cur_color=0]])
    file.writeline([[start=0]])
    file.writeline([[count=0]])
    file.writeline([[s_length=100]])
    file.writeline([[freq_multi=1000000]])
    file.writeline([[function pin1cb(level)]])
    file.writeline([[if cur_color == 0 and count == 0 then]])
    file.writeline([[ gpio.mode(6,gpio.OUTPUT)]])
    file.writeline([[ gpio.mode(7,gpio.OUTPUT)]])
    file.writeline([[ gpio.write(6,gpio.HIGH)]])
    file.writeline([[ gpio.write(7,gpio.LOW)]])
    file.writeline([[elseif cur_color == 1 and count == 0 then]])
    file.writeline([[ gpio.mode(6,gpio.OUTPUT)]])
    file.writeline([[ gpio.mode(7,gpio.OUTPUT)]])
    file.writeline([[ gpio.write(6,gpio.LOW)]])
    file.writeline([[ gpio.write(7,gpio.LOW)]])
    file.writeline([[elseif cur_color == 2 and count == 0 then]])
    file.writeline([[ gpio.mode(6,gpio.OUTPUT)]])
    file.writeline([[ gpio.mode(7,gpio.OUTPUT)]])
    file.writeline([[ gpio.write(6,gpio.HIGH)]])
    file.writeline([[ gpio.write(7,gpio.HIGH)]])
    file.writeline([[elseif cur_color == 3 and count == 0 then]])
    file.writeline([[ gpio.mode(6,gpio.OUTPUT)]])
    file.writeline([[ gpio.mode(7,gpio.OUTPUT)]])
    file.writeline([[ gpio.write(6,gpio.LOW)]])
    file.writeline([[ gpio.write(7,gpio.HIGH)]])
    file.writeline([[end]])
    file.writeline([[if count == 0 then]])
    file.writeline([[ start = tmr.now()]])
    file.writeline([[end]])
    file.writeline([[tmr.wdclr()]])
    file.writeline([[count=count+1]])
    file.writeline([[if count > s_length then]])
    file.writeline([[ if cur_color == 0 then]])
    file.writeline([[ all=(tmr.now()-start)/s_length]])
    file.writeline([[ cur_color=1]])
    file.writeline([[ print(all )]])
    file.writeline([[ elseif cur_color == 1 then]])
    file.writeline([[ red=(tmr.now()-start)/s_length ]])
    file.writeline([[ cur_color=2]])
    file.writeline([[ print(red )]])
    file.writeline([[ elseif cur_color == 2 then]])
    file.writeline([[ green=(tmr.now()-start)/s_length]])
    file.writeline([[ cur_color=3]])
    file.writeline([[ print(green )]])
    file.writeline([[ elseif cur_color == 3 then]])
    file.writeline([[ blue=(tmr.now()-start)/s_length]])
    ile.writeline([[ cur_color=0]])
    file.writeline([[ color_done=1 ]])
    file.writeline([[ gpio.mode(pin,gpio.INPUT)]])
    file.writeline([[ print(blue )]])
    file.writeline([[ end]])
    file.writeline([[ count=0]])
    file.writeline([[end]])
    file.writeline([[end]])
    file.writeline([[function init_STA()]]) — 1
    file.writeline([[sv:close()]])
    file.writeline([[sv=net.createServer(net.TCP, 30) ]])
    file.writeline([[sv:listen(9999,function(c)]]) — 2
    file.writeline([[print(“Server created”) ]])
    file.writeline([[print(“Waiting to receive”) ]])
    file.writeline([[print(color_done) ]])
    file.writeline([[c:on(“receive”, function(c, pl)]]) — 3
    file.writeline([[print(“Receiving”) ]])
    file.writeline([[print(pl) ]])
    file.writeline([[if IP_posted == 0 then]])
    file.writeline([[wifi_ip = wifi.sta.getip()]])
    file.writeline([[if wifi_ip ~= nil then]])
    file.writeline([[print(“Writing WEB PAGE out\n”) ]])
    file.writeline([[c:send(” “)]])
    file.writeline([[c:send(” “)]])
    file.writeline([[c:send(” “)]])
    file.writeline([[c:send(“ESP8266 WIFI module IP address is:”..wifi_ip..”\n”)]])
    file.writeline([[c:send(” “)]])
    file.writeline([[print(“ESP8266 WIFI module IP address is:”..wifi_ip..”\n”) ]])
    file.writeline([[else]])
    file.writeline([[c:send(” “)]])
    file.writeline([[c:send(” “)]])
    file.writeline([[c:send(” “)]])
    file.writeline([[c:send(“ESP8266 WIFI module IP address is NIL\n”)]])
    file.writeline([[c:send(” “)]])
    file.writeline([[print(“ESP8266 WIFI module IP address is NIL”) ]])
    file.writeline([[end]])
    file.writeline([[IP_posted = 1]])
    file.writeline([[end]])
    file.writeline([[if string.sub(pl,1, 7) == “acquire” then]]) — Received string read
    file.writeline([[cur_color=0]])
    file.writeline([[red=0 ]])
    file.writeline([[green=0 ]])
    file.writeline([[blue=0 ]])
    file.writeline([[all=0 ]])
    file.writeline([[IP_posted = 1]])
    file.writeline([[color_done=0]])
    file.writeline([[cur_color=0]])
    file.writeline([[start=0]])
    file.writeline([[count=0]])
    file.writeline([[gpio.mode(pin,gpio.INT)]])
    file.writeline([[gpio.trig(pin, “down”, pin1cb)]])
    file.writeline([[elseif string.sub(pl,1, 5) == “readf” then ]]) — Received string get, gets the color split
    file.writeline([[if color_done == 1 then ]]) — 5
    file.writeline([[ freq_all =(freq_multi/all)]])
    file.writeline([[ freq_red =(freq_multi/red)]])
    file.writeline([[ freq_green =(freq_multi/green)]])
    file.writeline([[ freq_blue =(freq_multi/blue)]])
    file.writeline([[ print(all )]])
    file.writeline([[ print(red )]])
    file.writeline([[ print(green )]])
    file.writeline([[ print(blue )]])
    file.writeline([[ print(freq_all )]])
    file.writeline([[ print(freq_red )]])
    file.writeline([[ print(freq_green )]])
    file.writeline([[ print(freq_blue )]])

    file.writeline([[c:send(‘{“RGBF”: [{ “Red:”: “‘ .. freq_red .. ‘”, “Green”: “‘ .. freq_green .. ‘”, “Blue:”: “‘ .. freq_blue .. ‘”, “All:”: “‘ .. freq_all .. ‘”}]}’)]])
    file.writeline([[color_done=0 ]])
    file.writeline([[end ]]) — 5
    file.writeline([[elseif string.sub(pl,1, 5) == “readp” then ]]) — Received string get, gets the color split
    file.writeline([[if color_done == 1 then ]]) — 5
    file.writeline([[ freq_red =(freq_multi/red)]])
    file.writeline([[ print(freq_red )]])
    file.writeline([[ freq_green =(freq_multi/green)]])
    file.writeline([[ print(freq_green )]])
    file.writeline([[ freq_blue =(freq_multi/blue)]])
    file.writeline([[ print(freq_blue )]])
    file.writeline([[ col_sum =freq_red+freq_green+freq_blue]])
    file.writeline([[ print(col_sum )]])
    file.writeline([[ perc_red = (100*freq_red)/col_sum]])
    file.writeline([[ print(perc_red )]])
    file.writeline([[ perc_green = (100*freq_green)/col_sum]])
    file.writeline([[ print(perc_green )]])
    file.writeline([[ perc_blue = (100*freq_blue)/col_sum]])
    file.writeline([[ print(perc_blue )]])
    file.writeline([[c:send(‘{“RGBP”: [{ “Red:”: “‘ .. perc_red .. ‘”, “Green”: “‘ .. perc_green .. ‘”, “Blue:”: “‘ .. perc_blue .. ‘”}]}’)]])
    file.writeline([[color_done=0 ]])
    file.writeline([[end ]]) — 5
    file.writeline([[end ]]) — 4
    file.writeline([[end)]]) — 3
    file.writeline([[end)]]) — 2
    file.writeline([[end]]) — 1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s