Revision e45aa19e
Added by dsorber over 13 years ago
| 525.743/code/test scripts/blinky_pattern.py | ||
|---|---|---|
|
import sys
|
||
|
import time
|
||
|
|
||
|
import RPIO as GPIO
|
||
|
import RPIO
|
||
|
|
||
|
outputs = [23, 24, 25, 8, 7]
|
||
|
|
||
|
def main():
|
||
|
# Use the BCM addressing scheme
|
||
|
GPIO.setmode(GPIO.BCM)
|
||
|
RPIO.setmode(RPIO.BCM)
|
||
|
|
||
|
# Setup all five outputs
|
||
|
for gpio in outputs:
|
||
|
GPIO.setup(gpio, GPIO.OUT)
|
||
|
GPIO.output(gpio, False)
|
||
|
for RPIO in outputs:
|
||
|
RPIO.setup(RPIO, RPIO.OUT)
|
||
|
RPIO.output(RPIO, False)
|
||
|
|
||
|
while True:
|
||
|
cylon()
|
||
| ... | ... | |
|
|
||
|
|
||
|
def turn_on_top_down():
|
||
|
for gpio in outputs:
|
||
|
GPIO.output(gpio, True)
|
||
|
for RPIO in outputs:
|
||
|
RPIO.output(RPIO, True)
|
||
|
time.sleep(.25)
|
||
|
|
||
|
def turn_on_bottom_up():
|
||
|
for gpio in reversed(outputs):
|
||
|
GPIO.output(gpio, True)
|
||
|
for RPIO in reversed(outputs):
|
||
|
RPIO.output(RPIO, True)
|
||
|
time.sleep(.25)
|
||
|
|
||
|
def turn_off_top_down():
|
||
|
for gpio in outputs:
|
||
|
GPIO.output(gpio, False)
|
||
|
for RPIO in outputs:
|
||
|
RPIO.output(RPIO, False)
|
||
|
time.sleep(.25)
|
||
|
|
||
|
def turn_off_bottom_up():
|
||
|
for gpio in reversed(outputs):
|
||
|
GPIO.output(gpio, False)
|
||
|
for RPIO in reversed(outputs):
|
||
|
RPIO.output(RPIO, False)
|
||
|
time.sleep(.25)
|
||
|
|
||
|
def cylon():
|
||
|
for gpio in outputs[:-1]:
|
||
|
GPIO.output(gpio, True)
|
||
|
for RPIO in outputs[:-1]:
|
||
|
RPIO.output(RPIO, True)
|
||
|
time.sleep(.08)
|
||
|
GPIO.output(gpio, False)
|
||
|
RPIO.output(RPIO, False)
|
||
|
|
||
|
for gpio in outputs[::-1][:-1]:
|
||
|
GPIO.output(gpio, True)
|
||
|
for RPIO in outputs[::-1][:-1]:
|
||
|
RPIO.output(RPIO, True)
|
||
|
time.sleep(.08)
|
||
|
GPIO.output(gpio, False)
|
||
|
RPIO.output(RPIO, False)
|
||
|
|
||
|
def randomize():
|
||
|
rand_val = random.randint(0, 31)
|
||
|
# LED1 - GPIO23
|
||
|
# LED1 - RPIO23
|
||
|
if rand_val & 0b00001:
|
||
|
GPIO.output(23, True)
|
||
|
RPIO.output(23, True)
|
||
|
else:
|
||
|
GPIO.output(23, False)
|
||
|
# LED2 - GPIO24
|
||
|
RPIO.output(23, False)
|
||
|
# LED2 - RPIO24
|
||
|
if rand_val & 0b00010:
|
||
|
GPIO.output(24, True)
|
||
|
RPIO.output(24, True)
|
||
|
else:
|
||
|
GPIO.output(24, False)
|
||
|
# LED3 - GPIO25
|
||
|
RPIO.output(24, False)
|
||
|
# LED3 - RPIO25
|
||
|
if rand_val & 0b00100:
|
||
|
GPIO.output(25, True)
|
||
|
RPIO.output(25, True)
|
||
|
else:
|
||
|
GPIO.output(25, False)
|
||
|
# LED4 - GPIO8
|
||
|
RPIO.output(25, False)
|
||
|
# LED4 - RPIO8
|
||
|
if rand_val & 0b01000:
|
||
|
GPIO.output(8, True)
|
||
|
RPIO.output(8, True)
|
||
|
else:
|
||
|
GPIO.output(8, False)
|
||
|
# LED5 - GPIO7
|
||
|
RPIO.output(8, False)
|
||
|
# LED5 - RPIO7
|
||
|
if rand_val & 0b10000:
|
||
|
GPIO.output(7, True)
|
||
|
RPIO.output(7, True)
|
||
|
else:
|
||
|
GPIO.output(7, False)
|
||
|
RPIO.output(7, False)
|
||
|
time.sleep(0.1)
|
||
|
|
||
|
|
||
| 525.743/code/test scripts/pushbutton.py | ||
|---|---|---|
|
# Use the BCM addressing scheme
|
||
|
RPIO.setmode(RPIO.BCM)
|
||
|
|
||
|
# Setup input
|
||
|
# Setup all five outputs
|
||
|
RPIO.setup(22, RPIO.IN)
|
||
|
|
||
|
RPIO.add_interrupt_callback(22, switch_callback, edge='both',
|
||
| ... | ... | |
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
sys.exit(main())
|
||
|
sys.exit(main())
|
||
| 525.743/code/test scripts/relay.py | ||
|---|---|---|
|
import sys
|
||
|
|
||
|
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)
|
||
|
|
||
|
# Setup output
|
||
|
RPIO.setup(17, RPIO.OUT)
|
||
|
|
||
|
if sys.argv[1] == '1':
|
||
|
RPIO.output(17, True)
|
||
|
print 'Relay on'
|
||
|
else:
|
||
|
RPIO.output(17, False)
|
||
|
print 'Relay off'
|
||
|
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
sys.exit(main())
|
||
|
|
||
| 525.743/code/test scripts/saa1064_i2c_test.py | ||
|---|---|---|
|
bus.write_byte_data(address, 0x03, val)
|
||
|
time.sleep(0.1)
|
||
|
|
||
|
# print 'Starting write...'
|
||
|
# bus.write_byte(address, 0x0)
|
||
|
# bus.write_byte(address, 0x3E)
|
||
|
# print 'Segment test at 9ma'
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
| 525.743/code/test scripts/tmp512.py | ||
|---|---|---|
|
import sys
|
||
|
import time
|
||
|
|
||
|
import smbus
|
||
|
|
||
|
class TMP512(object):
|
||
|
|
||
|
def __init__(self, address):
|
||
|
self.bus = smbus.SMBus(1)
|
||
|
self.address = address
|
||
|
|
||
|
def _reverse16(self, value):
|
||
|
""" A quick hack method for reversing byte order for a 16 bit value """
|
||
|
str_val = '%04X' % value
|
||
|
new_val = str_val[2:4] + str_val[0:2]
|
||
|
return int(new_val, 16)
|
||
|
|
||
|
def read_reg(self, reg):
|
||
|
raw = self.bus.read_word_data(self.address, reg)
|
||
|
return self._reverse16(raw)
|
||
|
|
||
|
def device_id(self):
|
||
|
return '0x%04X' % self.read_reg(0x1F)
|
||
|
|
||
|
def local_temp(self):
|
||
|
return self.read_reg(0x08)
|
||
|
|
||
|
|
||
|
def main():
|
||
|
|
||
|
temp1 = TMP512(0x5c)
|
||
|
print '0x%04X' % temp1.read_reg(0x00)
|
||
|
print temp1.device_id()
|
||
|
print '0x%04X' % temp1.local_temp()
|
||
|
|
||
|
# bus = smbus.SMBus(1)
|
||
|
# address = 0x5c
|
||
|
# # 2 digits at 9ma sink
|
||
|
# # bus.write_byte_data(self.address, 0x00, 0x35)
|
||
|
# print '0x%02X' % bus.read_word_data(address, 0x00)
|
||
|
# print '0x%02X' % bus.read_word_data(address, 0x1F)
|
||
|
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
sys.exit(main())
|
||
Adding code I wrote a while ago. I'm starting to create objects for each of the major functions/components of the board.