Introduction: Simple Python RGB Raspberry Pi Tutorial

A simple way to start the Raspberry Pi programming way is try to programming a Raspberry Pi. Now I have created this simple tutorial. You can follow the simple passages and make a simple RGB wireless lamp.
All the components are a RGB led, comune cathode, three resistences (120 Ohm + 120 Ohm + 100 Ohm), a pinplug for Raspberry Pi GPiO, and a piece of perfboard.

Materials

You can also buy this RGB led with resistors

Step 1: The Circuit

The circuit is very simple. You can also use a breadboard and some jumper cable.

Follow the scheme, and solder the components on the perfboard. Use a RGB common cathode and 3 resistor. Use the 120 Ohm resistor for blue and green pin and 100 Ohm for red pin.

Step 2: Plug the Circuit

Now you are a RGB circuit for Raspberry Pi. Plug the circuit on GPiO in this position.

The Blue pin in the 25

The Green pin in the 24

The Red pin in the 23

Pay attention of the numbers of pin. In this project we use a GPIO pin number. for thi reason we follow the GPIO numeration. Like in the image, you can view the pin number and the GPIO number. The RGB led use the GPIO pins 23, 24 and 25. Also the RGB led use the GND pin between the pins 24 and 25.
Please double-check before start your system. You can burn Raspberry Pi.

Step 3: Start the Raspberry by Terminal

Now you can run the Raspberry Pi. Connect by Terminal if you use MAC OSX or Linux. If you use a Windows system, you can download putty (www.putty.org). Connect by a ssh protocol, and use the terminal for write the Python program and for command the RGB led light.

An important feature of Raspberry Pi is the presence of Python. Now Raspbian have inside a version of Python. You can test the presence of Python in your Raspbian system by this command:

Python

When you write this command if the system have installed Python write on the screen the Python version.

Step 4: Write the Program

Type on the terminal:

sudo nano rgb.py

After this put the code in the terminal window.

(see the py file)

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

RED = 25

GREEN = 24

BLUE = 23

GPIO.setup(RED,GPIO.OUT)

GPIO.output(RED,0)

GPIO.setup(GREEN,GPIO.OUT)

GPIO.output(GREEN,0)

GPIO.setup(BLUE,GPIO.OUT)

GPIO.output(BLUE,0)

try:

while (True):

request = raw_input(“RGB—>”)

if (len(request) == 3):

GPIO.output(RED,int(request[0]))

GPIO.output(GREEN,int(request[1]))

GPIO.output(BLUE,int(request[2]))

except KeyboardInterrupt:

GPIO.cleanup()

Push CTRL + X button and save the rgb.py file.

Step 5: Command the RGB Led by the Terminal

Now you can start the program.

Write

sudo python rgb.py

You can read RGB-->

Now use 0 for OFF the color and 1 for ON color.

Use first number for Red, second number for Green and third for Blue.

For blue write 001 and after click enter

For green write 010 and after click enter

For red write 100 and after click enter

The fun comes when you start mixing colors.

Try 101 click enter and see the color.

Comments

About This Instructable

4,273views

31favorites

License:

More by masteruan:Arduino Edit, Compile, Upload, Read Serial by LInux Pocket ChipMeteo Node IoT Smart Meteo StationO-Zone: DIY Bluetooth Battery Lamp
Add instructable to: