-
Notifications
You must be signed in to change notification settings - Fork 0
/
pi_lite_hello_world.py
57 lines (46 loc) · 1.03 KB
/
pi_lite_hello_world.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
#--------------------------------------
#
# Pi-Lite Hello World Example
#
# Author : Matt Hawkins
# Date : 01/10/2013
#
# http://www.raspberrypi-spy.co.uk/
#
#--------------------------------------
import sys
import serial
import time
# Define message complete with
# carriage return at the end
message1 = "Hello World!\r"
message2 = "Pi-Lite messages are easy!\r"
# Configure Pi serial port
s = serial.Serial()
s.baudrate = 9600
s.timeout = 0
s.port = "/dev/serial0"
try:
# Open serial port
s.open()
except serial.SerialException, e:
# There was an error
sys.stderr.write("could not open port %r: %s\n" % (port, e))
sys.exit(1)
print "Serial port ready"
# Clear display
s.write("$$$ALL,OFF\r")
# Send message 1 to the Pi-Lite
print message1
s.write(message1)
# Short delay to allow the
# 12 character message to finish
time.sleep(6)
# Send message 2 to the Pi-Lite
print message2
s.write(message2)
# Short delay to allow the
# 26 character message to finish
time.sleep(12)
print "Good bye"