Permalink
Browse files

v0.4 and improved README

Auto detects the Raspberry Pi version, moved examples to its own folder,
and much improved README instructions with added installation
instructions
1 parent c299a42 commit 987e4ee83110ec6ae6fbb318f65da882b91f2b9f @Boeeerb committed Aug 17, 2013
@@ -7,7 +7,7 @@
from piglow import PiGlow
from time import sleep
-piglow = PiGlow(1)
+piglow = PiGlow()
while True:
count = range(0, 256, +1)
@@ -7,7 +7,7 @@
from piglow import PiGlow
from time import sleep
-piglow = PiGlow(1)
+piglow = PiGlow()
piglow.all(0)
@@ -10,7 +10,7 @@
from time import sleep
import psutil
-piglow = PiGlow(1)
+piglow = PiGlow()
while True:
@@ -7,7 +7,7 @@
from piglow import PiGlow
from time import sleep
-piglow = PiGlow(1)
+piglow = PiGlow()
while True:
piglow.white(10)
@@ -7,7 +7,7 @@
from piglow import PiGlow
from time import sleep
-piglow = PiGlow(1)
+piglow = PiGlow()
val = 20
colour = 1
@@ -7,7 +7,7 @@
from piglow import PiGlow
from time import sleep
-piglow = PiGlow(1)
+piglow = PiGlow()
val = 0
count = 1
while True:
@@ -7,7 +7,7 @@
from piglow import PiGlow
from time import sleep
-piglow = PiGlow(1)
+piglow = PiGlow()
val = 20
colour = 1
@@ -6,7 +6,7 @@
from piglow import PiGlow
-piglow = PiGlow(1)
+piglow = PiGlow()
val = input("White: ")
piglow.white(val)
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
157 README.md
@@ -2,39 +2,32 @@
Here is a small Python module for the PiGlow addon by Pimoroni, it will let you flex the LED muscles of this fantastic addon.
-## SN3218 Addressing
-<p align="center">
-<img src="https://raw.github.com/Boeeerb/PiGlow/master/SN3218_addressing.jpg" alt="PiGlow Addressing"/>
-</p>
-
-## Python LED Addressing
-<p align="center">
-<img src="https://raw.github.com/Boeeerb/PiGlow/master/LED_addressing.jpg" alt="PiGlow Addressing"/>
-</p>
-
## Files
- piglow.py - Python module you'll import into your script
- - all.py - This will increase then decrease all the LEDs together
- - cycle.py - This will cycle the colours together from center to the end back to the center
- - indiv.py - Quickly increase and decrease the LEDs independantly
- - test.py - You choose the brightness of each LED colour group, to see how it will look
- - arm.py - Cycle each of the PiGlow arms, showing both methods
- - cycle2.py - Switch each individual colour using the piglow.colour method
- - indiv2.py - Switch each LED on individually in a loop cycle
- - cpu.py - Show your current CPU usage on the PiGlow (requires psutils)
+ - examples/all.py - This will increase then decrease all the LEDs together
+ - examples/arm.py - Cycle each of the PiGlow arms, showing both methods
+ - examples/cpu.py - Show your current CPU usage on the PiGlow (requires psutils)
+ - examples/cycle.py - This will cycle the colours together from center to the end back to the center
+ - examples/cycle2.py - Switch each individual colour using the piglow.colour method
+ - examples/indiv.py - Quickly increase and decrease the LEDs independantly
+ - examples/indiv2.py - Switch each LED on individually in a loop cycle
+ - examples/test.py - You choose the brightness of each LED colour group, to see how it will look
+
## Requirements
+ sudo apt-get install python-smbus
sudo apt-get install python-psutils
+
## Functions
The functions of piglow are:
```python
from piglow import PiGlow
-piglow = PiGlow([0/1])
+piglow = PiGlow()
piglow.colour([1-6],[0-255]) # 1=White, 2=Blue, 3=Green, 4=Yellow, 5=Orange, 6=Red
piglow.white([0-255]) # Control all the white LEDs
piglow.blue([0-255]) # Control all the blue LEDs
@@ -53,11 +46,135 @@ piglow.arm3([0-255]) # Control the left arm (with PiGlow logo at the
All colours are from 0 (off) to 255 (super duper eye numbing bright!)
+## Installation instructions
+
+### Preparation
+
+First to download and install the required libraries
+
+ sudo apt-get update
+ sudo apt-get install python-smbus python-psutil -y
+
+
+ - SMBus is required to talk over i2c bus with the PiGlow
+ - psutil is required for cpu.py example to get current CPU usage
+
+
+To enable the i2c driver you need to make a few changes
+
+ sudo nano /etc/modules
+
+Then make sure the following is at the end of the file
+
+ i2c-dev
+ i2c-bcm2708
+
+So it looks like this:
+<p align="center">
+<img src="https://raw.github.com/Boeeerb/PiGlow/master/Pictures/etc-modules.jpg" alt="etc-modules"/>
+</p>
+
+Ctrl + x and Y to exit save the file, now edit the next
+
+ sudo nano /etc/modprobe.d/raspi-blacklist.conf
+
+And remove the #'s from the beginning so it looks like:
+
+<p align="center">
+<img src="https://raw.github.com/Boeeerb/PiGlow/master/Pictures/etc-modprobe.jpg" alt="etc-modprobe"/>
+</p>
+
+Ctrl + x and Y to exit and save the file, now reboot
+
+ sudo reboot
+
+### Downloading the PiGlow module and testing
+
+Now create a directory for it to live in then change to that directory:
+
+ mkdir piglow
+ cd piglow
+
+
+Next get the latest version of PiGlow python module:
+
+ wget https://raw.github.com/Boeeerb/PiGlow/master/piglow.py
+
+This will give you a file called piglow.py, this is the module and will do all the hardwork.
+
+Now download the test script to make sure it works
+
+ wget https://raw.github.com/Boeeerb/PiGlow/master/Examples/test.py
+
+And run it by typing and setting a number between 0 (off) and 255 (brightest)
+
+ sudo python test.py
+
+If it works successfully you can choose the level of brightness as shown
+<p align="center">
+<img src="https://raw.github.com/Boeeerb/PiGlow/master/Pictures/piglow-test.jpg" alt="piglow-test"/>
+</p>
+
+### Starting your script
+
+Now hopefully it should run the test.py successfully, you can browse the other examples created here
+
+ https://github.com/Boeeerb/PiGlow/blob/master/Examples/
+
+To create your own script just start it with importing the module
+
+ from piglow import PiGlow
+
+Now initialise the module into piglow variable
+
+ piglow = PiGlow()
+
+
+That's it!
+
+Use the function list for a list of combinations you can use to set individual or groups of LED's on or off.
+
+A few examples:
+
+ piglow.all(10) # Set all LED's to 10
+ piglow.red(100) # Set red LED's to 100
+ piglow.led(3,0) # Turn LED (Top yellow off)
+
+And combine it with time.sleep to make effects
+
+ from piglow import PiGlow
+ from time import sleep
+
+ piglow = PiGlow()
+
+ piglow.all(0)
+
+ piglow.all(10)
+ sleep(1)
+ piglow.red(100)
+ sleep(1)
+ piglow.led(3,0)
+
+
+## SN3218 Addressing
+<p align="center">
+<img src="https://raw.github.com/Boeeerb/PiGlow/master/SN3218_addressing.jpg" alt="PiGlow Addressing"/>
+</p>
+
+## Python LED Addressing
+<p align="center">
+<img src="https://raw.github.com/Boeeerb/PiGlow/master/LED_addressing.jpg" alt="PiGlow Addressing"/>
+</p>
+
+
+
+
Enjoy!
Jason
+Twitter @boeeerb
http://www.boeeerb.co.uk
-Buy from http://shop.pimoroni.com/collections/accessories/products/piglow
+Buy from http://shop.pimoroni.com/collections/accessories/products/piglow
View
@@ -1,22 +1,32 @@
#####################################################
## Python module to control the PiGlow by Pimoroni ##
## ##
-## Written by Jason - @Boeeerb - v0.3 17/08/13 ##
+## Written by Jason - @Boeeerb - v0.4 17/08/13 ##
+## jase@boeeerb.co.uk ##
#####################################################
##
-## v0.3 - Added fix from topshed
-## v0.2 - Code cleanup by iiSeymour
-## v0.1 - Initial release
+## v0.4 - Auto detect Raspberry Pi revision - 17/08/13
+## v0.3 - Added fix from topshed - 17/08/13
+## v0.2 - Code cleanup by iiSeymour - 15/08/13
+## v0.1 - Initial release - 15/08/13
##
from smbus import SMBus
+import RPi.GPIO as rpi
bus = 0
-
class PiGlow:
- def __init__(self, i2c_bus=1):
+ def __init__(self):
+ if rpi.RPI_REVISION == 1:
+ i2c_bus = 0
+ elif rpi.RPI_REVISION == 2:
+ i2c_bus = 1
+ else:
+ print "Unable to determine Raspberry Pi revision."
+ exit
+
self.bus = SMBus(i2c_bus)
self.bus.write_i2c_block_data(0x54, 0x00, [0x01])
self.bus.write_byte_data(0x54, 0x13, 0xFF)

0 comments on commit 987e4ee

Please sign in to comment.