- Joined
- Dec 13, 2005
Ok, I'm starting to realize I may have gotten in over my head trying to teach myself python. But, I just picked up a Raspberry Pi and plan to screw around with it and a couple arduinos. So while I'm waiting for the arduinos, I figured I'd play around with the GPIO port on the Pi with a couple LEDs.
Now of course, being a member of this forum, my first thought is how high can I clock this thing. What's a problem with OCing? Heat. So I tossed an LED and resistor on one of the pins, wrote a basic program, said let there be light, that works.
Now the trouble. My plan is to have an LED that blinks when it warms up, stays on when it gets hotter. Fairly basic but still gets into some of the lower level stuff.
Here's what I have so far:
For the most part, it seems to be working. Goes in, grabs the temperature, but then just keeps dropping into the "High" if statement. The printed temps show between 42,000-43,000 (42C-43C, which are the same as grabbing it directly from the command line). if I hard code it to something like 45,000, does the same thing.
I'm using the newer model B Pi with 512MB of ram running Raspbian in case that has anything to do with it.
Now of course, being a member of this forum, my first thought is how high can I clock this thing. What's a problem with OCing? Heat. So I tossed an LED and resistor on one of the pins, wrote a basic program, said let there be light, that works.
Now the trouble. My plan is to have an LED that blinks when it warms up, stays on when it gets hotter. Fairly basic but still gets into some of the lower level stuff.
Here's what I have so far:
Code:
import time
import RPi.GPIO as GPIO
GPIO.cleanup()
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7,GPIO.OUT)
while True:
# gets temp, temp is in mC
tempReading = 0
f = open('/sys/class/thermal_zone0/temp', 'r')
# cuts off newline
tempReading = f.readline(5)
# mid temps
if tempReading <= 50000 and tempReading >= 45000:
GPIO.output(7,GPIO.HIGH)
time.sleep(0.5)
GPIO.output(7,GPIO.LOW)
time.sleep(0.5)
print("In mid loop", tempReading)
# high temps
elif tempReading > 50000:
GPIO.output(7,GPIO.HIGH)
time.sleep(1)
print("In high loop", tempReading)
# low temps
elif tempReading < 45000:
GPIO.output(7,GPIO.LOW)
time.sleep(1)
print("In low loop", tempReading)
else:
print("Temp error", tempReading)
time.sleep(1)
For the most part, it seems to be working. Goes in, grabs the temperature, but then just keeps dropping into the "High" if statement. The printed temps show between 42,000-43,000 (42C-43C, which are the same as grabbing it directly from the command line). if I hard code it to something like 45,000, does the same thing.
I'm using the newer model B Pi with 512MB of ram running Raspbian in case that has anything to do with it.