Giovanni Gentile
Published © GPL3+

Simple Python RGB Raspberry Pi Tutorial

A simple way to learn Raspberry Pi programming is trying to program a Raspberry Pi. Let's blink an RGB LED!

BeginnerFull instructions provided30 minutes9,712
Simple Python RGB Raspberry Pi Tutorial

Things used in this project

Hardware components

Raspberry Pi 2 Model B
Raspberry Pi 2 Model B
×1
RGB Diffused Common Cathode
RGB Diffused Common Cathode
×1
Resistor 330 ohm
Resistor 330 ohm
×3

Story

Read more

Schematics

RGB LED and Raspberry Pi

Code

rgb.py

Python
Command RGB led by using Python
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()

Credits

Giovanni Gentile

Giovanni Gentile

31 projects • 69 followers
Graduated in Psychology expert in new technologies and communication, with expertise in electronics, automation and home automation.

Comments