A simple way to start Raspberry Pi programming is trying to program 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 an RGB LED, common cathode, three resistors (120 Ohm + 120 Ohm + 100 Ohm), a pin plug for Raspberry Pi GPIO, and a piece of perfboard.Materials
- Stripline pin or some jumper cables for Raspberry Pi
The circuit is very simple. You can also use a breadboard and some jumper cable.Step 2: Plug the circuit
Now you are plugging in an 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 this reason we follow the GPIO numeration. Like in the image, you can view the pin number and the GPIO number. The RGB LED uses GPIO pins 23, 24 and 25. Also the RGB LED uses the GND pin between the pins 24 and 25. Please double-check before start your system. You can burn the 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 to write the Python program and for command the RGB LED light.
An important feature of Raspberry Pi is the presence of Python. Now Raspbian has inside of it a version of Python. You can test the presence of Python in your Raspbian system by this command:
When you write this command, if the system has Python installed, it will 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 code below). 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 as OFF of the color and 1 for ON color. Use the 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.