I’ve just received Chip – The Pixel Pal from Soldering Sunday. It’s a very nice litte project. And I love the LEDs. They’re so biggggg ! 🙂
Mine came with the “Pixel Power”, that allows it to stand and light the LEDs, powered by a cell battery.
Along with all that, it also came with the “Pixel Pi Adapter” – a small adapter to connect to the Raspberry PI GPIO
Connect to the Raspberry PI
Chip plugs in to the Pixel Pi adapter on the side labeled “top”. It then plugs in to the Raspberry PI GPIO PINs with the side labeled “This Side Towards the Raspberry PI”. It connects in to the GPIO, the FIRST ROW of PINs – even numbering
According to the Pixel PI Pin Out Reference card that came with Chip, the following PINs are used for:
CHIP | Board PIN | GPIO PIN |
Left Eye | 12 | GPIO 18 |
Right Eye | 16 | GPIO 23 |
The Pixel Pi Adapter can also be used as an Arduino Header.
After Chip is assembled and plugged in to RPi, it’s time for some programming.
Programming
Open your favorite editor and copy the following code:
import RPi.GPIO as gpio from time import sleep gpio.setmode(gpio.BOARD) gpio.setwarnings(False) #Define eyes PINs leftEye = 12 rightEye = 16 # Function to blink a specific eye # Eye - the eye # Time - duration in seconds def blink (eye, time): gpio.output(eye, gpio.HIGH) sleep(time) gpio.output(eye, gpio.LOW) # Blink Eyes simultaneously # blinkTimes - How many times to blink # Time - duration in seconds def blinkEyes (blinkTimes, duration): for x in range (0,blinkTimes): gpio.output(leftEye,gpio.HIGH) gpio.output(rightEye,gpio.HIGH) sleep(duration) gpio.output(leftEye,gpio.LOW) gpio.output(rightEye,gpio.LOW) sleep(duration) # Blink Eyes one at a time # blinkTimes - How many times to blink # Time - duration in seconds def blinkatATime (blinkTimes, duration): for x in range (0,blinkTimes): gpio.output(leftEye,gpio.HIGH) sleep(duration) gpio.output(leftEye,gpio.LOW) sleep(duration) gpio.output(rightEye,gpio.HIGH) sleep(duration) gpio.output(rightEye,gpio.LOW) sleep(duration) # DIM Leds def dimEyes (dimTimes, duration): # Create PWM objects for LEDs left = gpio.PWM(leftEye, 100) right = gpio.PWM(rightEye, 100) # Start the duty cycle percentage - from 0 to 100 left.start(0) right.start(0) for z in range(0,dimTimes): for i in range(0,101): left.ChangeDutyCycle(i) right.ChangeDutyCycle(i) sleep(duration) for i in range(100,-1,-1): left.ChangeDutyCycle(i) right.ChangeDutyCycle(i) sleep(duration) # Setup the GPIOS gpio.setup(leftEye,gpio.OUT) gpio.setup(rightEye,gpio.OUT) print "Left Eye" blink (leftEye,1.5) print "Right Eye" blink (rightEye,1.5) print "Blinking both eyes" blinkEyes (8,0.3) print "Blinking each eye at a time" blinkatATime (8,0.1) print "Dimming" dimEyes(6,0.02) gpio.cleanup()
To execute the code, just run it as (I called it Chip.py, but use the name you gave it):
sudo python Chip.py
There you have it. Now you can imagine what you can create or make Chip do.
Here’s a video with the code running
References
For the PWM function
http://raspi.tv/2013/how-to-use-soft-pwm-in-rpi-gpio-pt-2-led-dimming-and-motor-speed-control