Revision 74eab0f1
Added by dsorber over 13 years ago
| 525.743/code/test scripts/relay.py | ||
|---|---|---|
|
|
||
|
import RPIO
|
||
|
|
||
|
def main():
|
||
|
|
||
|
if len(sys.argv) < 2:
|
||
|
print 'Error, you must specify at least one argument'
|
||
|
return
|
||
|
|
||
|
# Use the BCM addressing scheme
|
||
|
RPIO.setmode(RPIO.BCM)
|
||
|
from status_led import LED
|
||
|
|
||
|
# Setup output
|
||
|
RPIO.setup(17, RPIO.OUT)
|
||
|
|
||
|
if sys.argv[1] == '1':
|
||
|
class Relay(object):
|
||
|
|
||
|
def __init__(self):
|
||
|
# Use the BCM addressing scheme
|
||
|
RPIO.setmode(RPIO.BCM)
|
||
|
|
||
|
# Setup output for relay
|
||
|
RPIO.setup(17, RPIO.OUT)
|
||
|
RPIO.output(17, False)
|
||
|
|
||
|
# Instantiate the relay status LED (23)
|
||
|
self.led = LED(23)
|
||
|
|
||
|
def on(self):
|
||
|
self.led.on()
|
||
|
RPIO.output(17, True)
|
||
|
print 'Relay on'
|
||
|
else:
|
||
|
|
||
|
def off(self):
|
||
|
self.led.off()
|
||
|
RPIO.output(17, False)
|
||
|
print 'Relay off'
|
||
|
|
||
|
def main():
|
||
|
|
||
|
import time
|
||
|
|
||
|
relay = Relay()
|
||
|
print 'Quick relay unit test'
|
||
|
print 'Turning relay on...'
|
||
|
relay.on()
|
||
|
time.sleep(5)
|
||
|
print 'Okay that\'s enough of that'
|
||
|
relay.off()
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
| 525.743/code/test scripts/status_led.py | ||
|---|---|---|
|
import sys
|
||
|
|
||
|
import RPIO
|
||
|
|
||
|
class LED(object):
|
||
|
|
||
|
def __init__(self, gpio_num):
|
||
|
self.gpio_num = gpio_num
|
||
|
self.state = False
|
||
|
|
||
|
# Use the BCM addressing scheme
|
||
|
RPIO.setmode(RPIO.BCM)
|
||
|
|
||
|
# Configure GPIO as output and turn off
|
||
|
RPIO.setup(self.gpio_num, RPIO.OUT)
|
||
|
RPIO.output(self.gpio_num, False)
|
||
|
|
||
|
def on(self):
|
||
|
self.state = True
|
||
|
RPIO.output(self.gpio_num, True)
|
||
|
|
||
|
def off(self):
|
||
|
self.state = False
|
||
|
RPIO.output(self.gpio_num, False)
|
||
|
|
||
|
def toggle(self):
|
||
|
self.state = not self.state
|
||
|
RPIO.output(self.gpio_num, self.state)
|
||
|
|
||
|
def main():
|
||
|
|
||
|
import time
|
||
|
|
||
|
led1 = LED(23)
|
||
|
led2 = LED(7)
|
||
|
print 'Quick status LED unit test'
|
||
|
print 'Turning on LED1'
|
||
|
led1.on()
|
||
|
time.sleep(1)
|
||
|
print 'Turning on LED2'
|
||
|
led2.on()
|
||
|
time.sleep(1)
|
||
|
print 'Turning off LED1'
|
||
|
led1.off()
|
||
|
for ctr in xrange(0, 10):
|
||
|
time.sleep(1)
|
||
|
led1.toggle()
|
||
|
led2.toggle()
|
||
|
print 'Toggle iteration %d' % (ctr + 1)
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
sys.exit(main())
|
||
|
|
||
| 525.743/code/test scripts/tmp512.py | ||
|---|---|---|
|
def device_id(self):
|
||
|
return '0x%04X' % self.read_reg(0x1F)
|
||
|
|
||
|
def _convert_temp(self, raw_val):
|
||
|
temp = (raw_val >> 3) * 0.0625
|
||
|
# Convert C to F
|
||
|
return (temp * 1.8) + 32
|
||
|
|
||
|
def local_temp(self):
|
||
|
return self.read_reg(0x08)
|
||
|
return self._convert_temp(self.read_reg(0x08))
|
||
|
|
||
|
def temp_sensor1(self):
|
||
|
return self._convert_temp(self.read_reg(0x09))
|
||
|
|
||
|
def temp_sensor2(self):
|
||
|
return self._convert_temp(self.read_reg(0x0A))
|
||
|
|
||
|
|
||
|
def main():
|
||
|
|
||
|
temp1 = TMP512(0x5c)
|
||
|
temp2 = TMP512(0x5d)
|
||
|
print '0x%04X' % temp1.read_reg(0x01)
|
||
|
print '0x%04X' % temp1.read_reg(0x09)
|
||
|
print '0x%04X' % temp1.read_reg(0x00)
|
||
|
print temp1.device_id()
|
||
|
print '0x%04X' % temp1.local_temp()
|
||
|
print 'The local temp1 is %d' % temp1.local_temp()
|
||
|
print 'The local temp2 is %d' % temp2.local_temp()
|
||
|
print 'The remote1 temp1 is %d' % temp1.temp_sensor1()
|
||
|
print 'The remote2 temp1 is %d' % temp1.temp_sensor2()
|
||
|
|
||
|
# bus = smbus.SMBus(1)
|
||
|
# address = 0x5c
|
||
Did a bit more work. The remote temperature readings are way off, I need to figure out why.