Warning: Declaration of Db::query($query) should be compatible with mysqli::query($query, $resultmode = NULL) in /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php on line 29

Deprecated: Function get_magic_quotes_runtime() is deprecated in /var/www/u1300519/data/www/acoptex.com/_lib/CacheLite/Lite.php on line 757

Deprecated: Function get_magic_quotes_runtime() is deprecated in /var/www/u1300519/data/www/acoptex.com/_lib/CacheLite/Lite.php on line 757

Warning: Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' (this will throw an Error in a future version of PHP) in /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php on line 64

Warning: mysqli_fetch_array() expects parameter 2 to be int, string given in /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php on line 64

Deprecated: Function get_magic_quotes_runtime() is deprecated in /var/www/u1300519/data/www/acoptex.com/_lib/CacheLite/Lite.php on line 757

Deprecated: Function get_magic_quotes_runtime() is deprecated in /var/www/u1300519/data/www/acoptex.com/_lib/CacheLite/Lite.php on line 757

Warning: Cannot modify header information - headers already sent by (output started at /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php:0) in /var/www/u1300519/data/www/acoptex.com/_config/config.php on line 168

Warning: session_start(): Cannot start session when headers already sent in /var/www/u1300519/data/www/acoptex.com/_config/config.php on line 169

Warning: Use of undefined constant MYSQL_NUM - assumed 'MYSQL_NUM' (this will throw an Error in a future version of PHP) in /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php on line 92

Warning: mysqli_fetch_array() expects parameter 2 to be int, string given in /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php on line 92

Warning: Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' (this will throw an Error in a future version of PHP) in /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php on line 64

Warning: mysqli_fetch_array() expects parameter 2 to be int, string given in /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php on line 64
jobs.html_title
0

members

Easy Project 19h Raspberry PI Zero W board - RGB LED

of Acoptex.com in Raspberry Pi Zero W

Raspberry basics: Project 19h

Project name: Raspberry PI Zero W board - RGB LED

Tags: Raspberry, Raspberry PI Zero W board, vers 1.1, v 1.1, RGB LED, LED, RPi.GPIO library, time library

Attachments: rgbled.py

Raspberry Pi
Monitor or TV
HDMI cable
USB keyboard
USB mouse
Power supply
8GB SD card

In this project, you needed these parts (Dear visitors. You can support our project buy clicking on the links of parts and buying them or donate us to keep this website alive. Thank you):

1. Raspberry PI Zero W board 1 pc

2. Micro SD card with NOOBS and SD card adapter 1 pc

3. Micro USB power supply (2 A 5V or 5V 3A) 1 pc

4. USB keyboard 1 pc

5. USB mouse 1 pc

6. TV or PC monitor 1 pc

7. HDMI cable 1 pc

8. T-Cobbler Breakout and GPIO Cable 1 pc

9. Micro USB 2.0 OTG Cable 1 pc

10. Mini HDMI to HDMI Adapter (HDMI to Mini HDMI Adapter) 1 pc

11. 4-Port USB 2.0 Hub 1 pc

12. Breadboard  1 pc

13. RGB LED 1 pc 

14. Jumper cables  F-M, M-M

15. Resistor  3 pcs (220 Ohm each)

General

We will learn how to use RGB LED with Raspberry PI Zero W board. 

Understanding the RGB LED

RGB LEDs can emit various colors of light. They are manufactured by packaging three LEDs of red, green, and blue into a transparent or semitransparent plastic shell and lead out four pins. The three primary colors of red, green, and blue can be mixed to all kinds of colors by brightness, so you can make RGB LEDs emit light with all kinds of colors by controlling the circuit.

The three primary color red, green and blue of a RGB LED can compose various colors by brightness. We can adjust the brightness of LED with PWM technology. Raspberry Pi has only one channel hardware PWM output, but we need three channels to control the RGB LED. As a result, it is difficult to realize with the hardware PWM of Raspberry Pi. The softPwm library simulates PWM (softPwm) for us with software method. Based on this, we only need to include the header file softPwm.h, then call the API it provided to easily achieve multi-channel PWM output to control the RGB LED to display all kinds of colors.

There are two types of package for RGB LEDs. One is patch type, and the other is dual-inline type. The difference between them is color resolution. The former has better color resolution.

RGB LEDs can be categorized into common anode type and common cathode type. In this project, we use common cathode RGB LED.

Understanding the Raspberry PI Zero W board

You can read more about it here.

Signals and connections of the RGB LED

RGB LED module has 4 outputs: R (Red diode), G (Green diode), B (Blue diode) and GND (-). You do not need resistors for LED if you use PGB LED module as they are already soldered.

Signals and connections of the Raspberry PI Zero W board


Wiring


Step by Step instruction

We recommend using a high-performance SD card for increased stability as well as plugging your device into an external display to see the default application booting up.

1. Setup and preparation

We assume that you have Windows 10 installed on your PC and Raspbian OS installed on your Raspberry Pi Zero W board. 

  1. Do wiring.
  2. Insert your micro SD card with Raspbian OS into the TF card slot on the Raspberry Pi Zero W board. It will only fit one way.
  3. Connect Raspberry PI Zero W board mini HDMI port to your TV or Monitor HDMI (DVI) port (use HDMI cable and mini HDMI to HDMI adapter and/or HDMI to DVI adapter).
  4. Make sure that your monitor or TV is turned on, and that you have selected the right input (e.g. HDMI/DVI,  etc).
  5. Plug in micro USB 2.0 OTG Cable to USB data port of Pi Zero and 4-Port USB 2.0 Hub to micro USB 2.0 OTG Cable. 
  6. Plug in your USB mouse and USB keyboard to 4-Port USB 2.0 Hub.
  7. If you intend to connect your Raspberry Pi Zero vers 1.2 or vers 1.3 to the internet, connect a WiFi dongle to one of the 4-Port USB 2.0 Hub ports.
  8. Connect Micro USB power supply to Raspberry PI Zero board micro USB input.
  9. The Raspberry PI desktop will start up.
  10. Open Terminal window and type the command: sudo apt-get update
  11. Then type the command: sudo apt-get install 

2. Making the program

  1. Type this command in the Terminal: sudo nano rgbled.py

  2. Copy and paste the code from rgbled.py to opened window. Since it is a Python code, you need to be careful with the Tab characters as it is important to group the instruction as blocks in Python.

  3. Press Ctrl+X, Y, Enter buttons to save the file.
  4. Type the command in the Terminal: sudo python rgbled.py

  5. You will see the RGB LED light up and display different colors.

Code

The code is well explaned. Please check the comments in the code.

Summary

We have learnt how to use RGB LED with Raspberry PI Zero W board. 

You can modify the parameters of the function ledColorSet( ) by yourself, compile and run the program to see the color changes of the RGB LED.

Libraries in use

  • RPi.GPIO. This package provides a class to control the GPIO on a Raspberry Pi.
  • time

Script

  • Look for attached code on the begining of this project


Other projects of Acoptex.com
Medium Basics: Project 083w Sipeed Maixduino board - Using PlatformIO IDE of Acoptex.com in Sipeed Maixduino 08-08-2019
Medium Basics: Project 083e Sipeed Maixduino board - Uploading MaixPy of Acoptex.com in Sipeed Maixduino 04-08-2019
Medium Basics: Project 083f Sipeed Maixduino board - Using MycroPython of Acoptex.com in Sipeed Maixduino 04-08-2019

jobs.published_at
jobs.viewed