Skip to content

Latest commit

 

History

History
194 lines (150 loc) · 9.24 KB

README.md

File metadata and controls

194 lines (150 loc) · 9.24 KB

Raspberry Pi color checking project

A Raspberry Pi is useful in all kinds of ways, even if you are looking to make a project that can help people increase the quality of their lives. This project is meant for people who are colourblind or have trouble seeing. Using your raspberry pi and a colour sensor, we can make a cool gadget that determines the precise main colour of an object. It can even say what colour it is detecting by using a Text-To-Speech module.

Project description - How Does it work?

How does it work?

This project uses a colour sensor to determine the main colour of an object. The Hue colour parameter (a number that represents the “pure colour tint”) is calculated based on the RGB-values that are read from the sensor. From the Hue parameter, it is possible to determine which basic colour is presented to the sensor. If the button (connected to GPIO pin 20) is pressed, the corresponding colour is printed on the terminal and can be heard using the on-board audio (using a Text-To-Speech program). Optionally, you can also attach an OLED screen and all of the regular RGB and HSV colour parameters will be displayed, together with the determined colour.

You will need to do the following things for the project to work:

Level of difficulty: intermediate

MATERIALS

Ingredients:

Whadda Pi 4 starter kit Whadda TCS3200 colour sensor
Whadda Raspberry Pi 4 starter set Whadda TCS3200 colour sensor
Whadda RPi DIY kit Whadda 0.96'' OLED screen
Whadda Raspberry Pi DIY kit Whadda 0.96" OLED screen

Tools:

  • Working locally on Raspberry Pi:
    • HDMI Screen/monitor
    • USB Keyboard
    • USB Mouse
    • Internet connection (WiFi or wired ethernet)
  • Working remotely on pc:
    • PC
    • RPi & PC connected to same network (WiFi or wired ethernet)

PROGRAMMING the development board

Dev board: Raspberry Pi (3B/B+, 4B)

Code language: Python (3)

Difficulty: Intermediate

Preparations:

  1. If you don't have a (recent) version of Raspberry Pi OS installed on the Pi's microSD card, go to raspberrypi.org/downloads and download the latest version of the Raspberry Pi Imager. Use the Raspberry Pi Imager to flash the MicroSD card with the latest verion of Raspberry Pi OS.

From this point on there are 2 ways to configure the pi: on the pi itself by connecting the necessary peripherals (mouse, keyboard and screen) to it directly, or using your pc to connect to it remotely. If you plan to use the 1st option you can skip step 2 and proceed directly to step 3.

  1. If you want to use WiFi follow this guide to configure the WiFi access details before you proceed. Navigate to the SD Card partition named BOOT and add an empty file called ssh. Make sure that this file doesn't have a file extension. In Windows you might need to check the File name extensions box in the View tab in file explorer to be able to do this.

  2. Insert the MicroSD card into the Pi and connect all of your peripherals (if you're planning to use a seperate monitor). Also plugin a network cable if you're planning to use a wired ethernet connection. Power up the pi by connecting it to the USB power supply adapter.

  3. Wait 2-3 min until the pi is fully booted. If you're using a seperate monitor, run through the initial Raspberry Pi OS setup wizard to configure network connections, etc... If you're connecting to the pi remotely, go to your network router setup webpage or use an IP-scanner (e.g. Angry IP Scanner) to find the assigned IP-address of your pi and connect to it by opening Powershell/Terminal and type in the following command: ssh pi@<REPLACE WITH IP ADDRESS>. The default password is raspberry.

  4. To make sure your pi is fully up-to-date, run the following command: sudo apt update && sudo apt upgrade -y

  5. Enable the I2C interface (necessary to use the OLED display) by running sudo raspi-config and selecting 3 Interface Options > P5 I2C > Yes.

Installing necessary software

Run the following commands:

  1. Make sure the python package manager (pip) is installed:
sudo apt install python3-pip
  1. Install git client so we can easily download the project code
sudo apt install git
  1. Download the project code
git clone https://github.com/WhaddaMakers/RPi-colour-checker.git && cd ./RPi-colour-checker
  1. Install the Text-To-Speech module using our install script:
sudo chmod +x install_tts.sh && sudo ./install_tts.sh
  1. Install the required python modules:
pip3 install -r requirements.txt
  1. If you are using headphones via the 3.5 mm audio jack, use the raspi-config tool to select the forced headphones audio output
sudo raspi-config
1 System options > S2 Audio > 1 Headphones

Prepping the connection

It is possible to wire everything up without a breadboard using Male-to-Female jumper wires, although using a breadbord and a Raspberry Pi GPIO extension/breakout board will make the process a lot easier.

Connection Tables

TCS3200 Color sensor Raspberry Pi
V 3V3
G GND
OE GND
LED GND
GND GND
S0 GPIO 5
S1 GPIO 6
S2 GPIO 13
S3 GPIO 19
OUT GPIO 26
0.96" OLED Raspberry Pi
VCC 3V3
GND GND
SCL SCL1
SDA SDA1
Button Raspberry Pi
Top right pin GPIO 20
Bottom left pin GND

Connection Diagram

Run the program!

Now it's finally time to test the setup!

If you have an OLED screen installed, you can run the program by entering this command:

python3 whadda_you_see.py --OLED

If you don't have an OLED screen wired up, use this command:

python3 whadda_you_see.py

If you don't want to add the python3 to the command every time to run it, you can make the program executable without it by running the following command:

sudo chmod +x whadda_you_see.py

You can now run the program by using these commands:

./whadda_you_see.py
OR
./whadda_you_see.py --OLED

Extending/Altering the code

If you want to add and/or change colours you can add additional elif statements after the line color_str = "RED":

elif hue_deg > 340 and hue_deg < 356:
        color_str = "RED"
## ADD YOUR OWN COLOUR COMPARE FUNCTIONS HERE ##
# example:
elif hue_deg > 160 and hue_deg < 210:
  color_str = "CYAN/TEAL"
################################################
else:
  color_str = "No valid color detected"

Change the numbers in the elif statement to alter the hue boundaries for which a certain colour name will be set. If you want to get a bit of a "feel" for hue parameters you can use an HSV colour picker and alter the Hue parameter to see what the corresponding colours are.