Project

General

Profile

« Previous | Next » 

Revision c5ac7e4c

Added by dsorber over 13 years ago

Added a couple more scripts including one to talk to the 7 segment display.

View differences:

525.743/code/test scripts/7seg.py
import sys
import time
import smbus
SEGMENTS_OFF = 0x00
SEGMENT_G = 0x01
SEGMENT_F = 0x02
SEGMENT_E = 0x04
SEGMENT_D = 0x08
SEGMENT_C = 0x10
SEGMENT_B = 0x20
SEGMENT_A = 0x40
SEGMENT_DOT = 0x80
DIGIT_0 = SEGMENT_A | SEGMENT_B | SEGMENT_C | SEGMENT_D | SEGMENT_E | SEGMENT_F
DIGIT_1 = SEGMENT_B | SEGMENT_C
DIGIT_2 = SEGMENT_A | SEGMENT_B | SEGMENT_G | SEGMENT_E | SEGMENT_D
DIGIT_3 = SEGMENT_A | SEGMENT_B | SEGMENT_G | SEGMENT_C | SEGMENT_D
DIGIT_4 = SEGMENT_F | SEGMENT_G | SEGMENT_B | SEGMENT_C
DIGIT_5 = SEGMENT_A | SEGMENT_F | SEGMENT_G | SEGMENT_C | SEGMENT_D
DIGIT_6 = SEGMENT_A | SEGMENT_F | SEGMENT_G | SEGMENT_E | SEGMENT_D | SEGMENT_C
DIGIT_7 = SEGMENT_A | SEGMENT_B | SEGMENT_C
DIGIT_8 = SEGMENT_A | SEGMENT_B | SEGMENT_C | SEGMENT_D | SEGMENT_E | SEGMENT_F | SEGMENT_G
DIGIT_9 = SEGMENT_A | SEGMENT_B | SEGMENT_C | SEGMENT_D | SEGMENT_F | SEGMENT_G
class SevenSegmentDisplay(object):
digit_map = {'0': DIGIT_0,
'1': DIGIT_1,
'2': DIGIT_2,
'3': DIGIT_3,
'4': DIGIT_4,
'5': DIGIT_5,
'6': DIGIT_6,
'7': DIGIT_7,
'8': DIGIT_8,
'9': DIGIT_9}
def __init__(self):
self.bus = smbus.SMBus(1)
self.address = 0x38
# 2 digits at 9ma sink
self.bus.write_byte_data(self.address, 0x00, 0x35)
def segment_test(self):
print 'Testing segments...'
self.bus.write_byte_data(self.address, 0x00, 0x3E)
time.sleep(3)
self.bus.write_byte_data(self.address, 0x00, 0x35)
print 'Test complete'
def read_status(self):
return bus.read_byte(address)
def write_digit0(self, pattern):
self.bus.write_byte_data(self.address, 0x03, pattern)
def write_digit1(self, pattern):
self.bus.write_byte_data(self.address, 0x01, pattern)
def clear(self):
self.write_digit0(SEGMENTS_OFF)
self.write_digit1(SEGMENTS_OFF)
def display_number(self, number):
str_num = '%02d' % number
self.write_digit1(self.digit_map[str_num[1]])
self.write_digit0(self.digit_map[str_num[0]])
def main():
display = SevenSegmentDisplay()
# segment test
display.segment_test()
# blink segment G x20
for ctr in xrange(20):
display.clear()
time.sleep(0.1)
SEGMENT_G
display.write_digit1(SEGMENT_G)
display.write_digit0(SEGMENT_G)
time.sleep(0.1)
# outer snake clockwise, both
segs = [SEGMENT_F, SEGMENT_A, SEGMENT_B, SEGMENT_C,
SEGMENT_D, SEGMENT_E]
for xtr in xrange(2):
for segment in segs:
display.clear()
display.write_digit1(segment)
display.write_digit0(segment)
time.sleep(0.2)
# outer snake counter clockwise, both
segs = [SEGMENT_E, SEGMENT_D, SEGMENT_C, SEGMENT_B,
SEGMENT_A, SEGMENT_F]
for xtr in xrange(2):
for segment in segs:
display.clear()
display.write_digit1(segment)
display.write_digit0(segment)
time.sleep(0.2)
# figure 8 both (clockwise start)
segs = [SEGMENT_G, SEGMENT_F, SEGMENT_A, SEGMENT_B, SEGMENT_G,
SEGMENT_E, SEGMENT_D, SEGMENT_C]
for xtr in xrange(3):
for segment in segs:
display.clear()
display.write_digit1(segment)
display.write_digit0(segment)
time.sleep(0.1)
# figure 8 both (counter clockwise start)
segs = [SEGMENT_G, SEGMENT_E, SEGMENT_D, SEGMENT_C, SEGMENT_G,
SEGMENT_F, SEGMENT_A, SEGMENT_B]
for xtr in xrange(3):
for segment in segs:
display.clear()
display.write_digit1(segment)
display.write_digit0(segment)
time.sleep(0.1)
# count down
while True:
for num in xrange(99, -1, -1):
display.clear()
display.display_number(num)
time.sleep(0.3)
if __name__ == '__main__':
sys.exit(main())
525.743/code/test scripts/LED_cycle.py
import itertools
import sys
import RPIO
from blinky_pattern import cylon, randomize, turn_on_top_down, turn_off_top_down,\
turn_on_bottom_up, turn_off_bottom_up
outputs = [23, 24, 25, 8, 7]
def main():
# Use the BCM addressing scheme
RPIO.setmode(RPIO.BCM)
# Setup input
RPIO.setup(22, RPIO.IN)
# Setup all five outputs
for gpio in outputs:
RPIO.setup(gpio, RPIO.OUT)
RPIO.output(gpio, False)
# Setup switch interrupt with debounce
RPIO.add_interrupt_callback(22, switch_callback, edge='rising',
pull_up_down=RPIO.PUD_DOWN, threaded_callback=True,
debounce_timeout_ms=150)
print 'Okay, waiting for interrupts...'
# Main (blocking) loop
while True:
RPIO.wait_for_interrupts()
def switch_callback(gpio_id, val):
global CURRENT
print 'Switch activated! %s --- %s' % (gpio_id, val)
# Turn off current LED
RPIO.output(CURRENT, False)
# Get next output and turn it on
CURRENT = out_iterator.next()
print CURRENT
RPIO.output(CURRENT, True)
if __name__ == '__main__':
sys.exit(main())
525.743/code/test scripts/button_LED.py
import RPIO
CURRENT = 23
outputs = [23, 24, 25, 8, 7]
out_iterator = itertools.cycle(outputs)
CURRENT = outputs[0]
def main():
# Use the BCM addressing scheme
......
# Setup switch interrupt with debounce
RPIO.add_interrupt_callback(22, switch_callback, edge='rising',
pull_up_down=RPIO.PUD_DOWN, threaded_callback=True,
debounce_timeout_ms=100)
debounce_timeout_ms=150)
print 'Okay, waiting for interrupts... %d' % CURRENT
print 'Okay, waiting for interrupts...'
# Main (blocking) loop
while True:
RPIO.wait_for_interrupts()
def switch_callback(gpio_id, val):
global CURRENT
print 'Switch activated! %s --- %s' % (gpio_id, val)
print outputs
# Turn off current LED
RPIO.output(CURRENT, False)
# Get next output and turn it on
CURRENT = out_iterator.next()
print CURRENT
RPIO.output(CURRENT, True)
525.743/code/test scripts/saa1064_i2c_test.py
import sys
import time
import smbus
bus = smbus.SMBus(1)
address = 0x38
def main():
status = bus.read_byte(address)
print 'POR Status: %d' % status
bus.write_byte_data(address, 0x00, 0x35)
for shift in xrange(0, 8):
val = (1 << shift)
print val
bus.write_byte_data(address, 0x01, val)
time.sleep(0.1)
for shift in xrange(0, 8):
val = (1 << shift)
print val
bus.write_byte_data(address, 0x03, val)
time.sleep(0.1)
if __name__ == '__main__':
sys.exit(main())

Also available in: Unified diff