Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Salman Faris
Published © MIT

Color Terminal 🎨

The Color Terminal can be used to pick color from physical things by scanning its surface with Seeed Wio Terminal and TCS34725.

BeginnerFull instructions provided3 hours1,733
Color Terminal 🎨

Things used in this project

Hardware components

Wio Terminal
Seeed Studio Wio Terminal
×1
Adafruit RGB Color Sensor with IR filter and White LED - TCS34725
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Flux, Soldering
Solder Flux, Soldering
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Custom parts and enclosures

Color Terminal Fusion360

Schematics

Color Sensor

Code

ColorTerminal.ino

C/C++
/*
 * Author : Salman Faris 
 * Project : Color Terminal 
 * Date: 01/01/2021
 */


#include <Wire.h>
#include "Adafruit_TCS34725.h"
#include"TFT_eSPI.h"

TFT_eSPI tft;
TFT_eSprite spr = TFT_eSprite(&tft);  //sprite
#define TFT_GREY 0x5AEB // New colour

float red, green, blue;
String Hex = "#000000";

// our RGB -> eye-recognized gamma color
byte gammatable[256];

Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_101MS, TCS34725_GAIN_60X);

void setup() {

  tft.begin();
  tft.setRotation(3);

  //Head
  tft.fillScreen(TFT_GREY);
  tft.setFreeFont(&FreeSansBoldOblique18pt7b);
  tft.setTextColor(TFT_WHITE);
  tft.setCursor(55, 120);
  tft.print("Wio Terminal ");
  tft.setCursor(55, 160);
  tft.print("Color Picker");
  delay(3000);
  tft.fillScreen(TFT_GREY);

  red = 0;
  green = 0;
  blue = 0;


  pinMode(WIO_KEY_B, INPUT_PULLUP);
  Serial.begin(9600);
  //Serial.println("Color View Test!");

  if (tcs.begin()) {
    //Serial.println("Found sensor");
  } else {
    Serial.println("No TCS34725 found ... check your connections");
    while (1); // halt!
  }

  // thanks PhilB for this gamma table!
  // it helps convert RGB colors to what humans see
  for (int i = 0; i < 256; i++) {
    float x = i;
    x /= 255;
    x = pow(x, 2.5);
    x *= 255;

    //      if (commonAnode) {
    //gammatable[i] = 255 - x;
    //      } else {
    gammatable[i] = x;
    //      }
    Serial.println(gammatable[i]);
  }
}

void loop() {



  delay(60);  // takes 50ms to read
  if (digitalRead(WIO_KEY_B) == LOW) {

    tcs.getRGB(&red, &green, &blue);
    Serial.print("R: \t"); Serial.print(int(red));
    Serial.print("\tG: \t"); Serial.print(int(green));
    Serial.print("\tB: \t"); Serial.print(int(blue));

    tft.fillScreen(tft.color565(gammatable[(int)red], gammatable[(int)green] , gammatable[(int)blue]));
    Serial.print("\t");
    Serial.print((int)red, HEX); Serial.print((int)green, HEX); Serial.print((int)blue, HEX);
    Serial.print("\n");
  }
  else {
    Serial.println("IDLE STATE ");

    spr.createSprite(65, 30);
    spr.fillSprite(TFT_RED);
    spr.setFreeFont(&FreeSansBoldOblique12pt7b);
    spr.setTextColor(TFT_BLACK);
    spr.drawNumber(int(red), 10 , 0, 1);
    spr.pushSprite(65 , 5);
    spr.deleteSprite();

    spr.createSprite(65, 30);
    spr.fillSprite(TFT_GREEN);
    spr.setFreeFont(&FreeSansBoldOblique12pt7b);
    spr.setTextColor(TFT_BLACK);
    spr.drawNumber(int(green), 10 , 0, 1);
    spr.pushSprite(130 , 5);
    spr.deleteSprite();

    spr.createSprite(65, 30);
    spr.fillSprite(TFT_BLUE);
    spr.setFreeFont(&FreeSansBoldOblique12pt7b);
    spr.setTextColor(TFT_BLACK);
    spr.drawNumber(int(blue), 10 , 0, 1);
    spr.pushSprite(195 , 5);
    spr.deleteSprite();


    String Rhex = String((int)red, HEX);
    String Ghex = String ((int)green, HEX);
    String Bhex = String ((int)blue, HEX);
    Hex = '#' + Rhex + Ghex + Bhex;

    spr.createSprite(195, 30);
    spr.fillSprite(TFT_GREY);
    spr.setFreeFont(&FreeSansBoldOblique12pt7b);
    spr.setTextColor(TFT_WHITE);
    spr.drawString(Hex, 50 , 0, 1);
    spr.pushSprite(65 , 35);
    spr.deleteSprite();


  }
}

Credits

Salman Faris
26 projects β€’ 418 followers
Maker | Hardware Hacker | Electronics Enthusiast

Comments