Anyhow, one facet of my idea stream is based on the Raspberry Pi. And I've done absolutely nothing with it - except hook up a cheezy surveillance system that takes a picture every minute and makes it available through a free DNS.
Now, before lunch, I want to do the LED blink example.
First, I just put in the LED (with 330 ohm) between 3V and GND and that works. Now, I've hooked it up between Pin 11 and GND in anticipation of following the steps on Rahul Kar's page.
Says import RPI.GPIO. What if that doesn't work? Man this is a crappy tutorial? Says do "sudo blah blah" - but that makes me nervous.
Now, I putty into the Pi and try :
#!/usr/bin/python
import RPi.GPIO as GPIO
from time import sleep
# to use Raspberry Pi board pin numbers
GPIO.setmode(GPIO.BOARD)
def blink(pin):
GPIO.output(pin,GPIO.HIGH)
time.sleep(1)
GPIO.output(pin,GPIO.LOW)
time.sleep(1)
return
# set up GPIO output channel
GPIO.setup(11, GPIO.OUT)
# blink GPIO17 50 times
for i in range(0,50):
blink(11)
GPIO.cleanup()
pi@raspberrypi ~/projects $ ./rahul_kar_led.py
Traceback (most recent call last):
File "./rahul_kar_led.py", line 16, in
GPIO.setup(11, GPIO.OUT)
RuntimeError: No access to /dev/mem. Try running as root!
pi@raspberrypi ~/projects $ sudo !$
sudo ./rahul_kar_led.py
Traceback (most recent call last):
File "./rahul_kar_led.py", line 19, in
blink(11)
File "./rahul_kar_led.py", line 11, in blink
time.sleep(1)
NameError: global name 'time' is not defined
Scary? :)
I was trying to be smart and keep what I had from (I think) Jake Beningo's course a few monats ago : "from time import sleep" - which means I should then use just sleep(1). Instead, I decide to be a student again and change to "import time". And, works!
pi@raspberrypi ~/projects $ sudo ./rahul_kar_led.py
./rahul_kar_led.py:17: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(11, GPIO.OUT)
And the Pi takes a picture while the LED is ON..
Okay, that's done. Now, I want to run a command each time the webserver serves this image so that I toggle the LED each time. Wouldn't that be cool?
And the realization : the R Pi world is being run by a bunch of !@#$s - I tried about 10 searches - "how to read state of GPIO output on raspberry pi" - nothing!
No comments:
Post a Comment