Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
A
AIDA-2020 TLU - Software
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
AIDA-2020 TLU - Software
Commits
bf0aca7a
Commit
bf0aca7a
authored
Jun 22, 2018
by
Paolo Baesso
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expanding functionalities for I2C display (Sparkfun)
parent
d6c22933
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
12 deletions
+72
-12
I2CDISP.py
packages/I2CDISP.py
+72
-12
No files found.
packages/I2CDISP.py
View file @
bf0aca7a
...
...
@@ -29,6 +29,9 @@ class LCD09052:
def
__init__
(
self
,
i2c
,
slaveaddr
=
0x3A
):
self
.
i2c
=
i2c
self
.
slaveaddr
=
slaveaddr
self
.
nRows
=
2
self
.
nCols
=
16
self
.
setLCDtype
(
self
.
nRows
,
self
.
nCols
)
def
test
(
self
):
print
"
\t
Testing display (LCD09052)"
...
...
@@ -40,37 +43,95 @@ class LCD09052:
self
.
setBrightness
(
0
)
time
.
sleep
(
0.2
)
self
.
setBrightness
(
250
)
for
ipos
in
range
(
1
,
1
8
):
for
ipos
in
range
(
1
,
1
7
):
self
.
writeChar
(
33
)
self
.
posCursor
(
1
,
ipos
-
1
)
time
.
sleep
(
0.1
)
self
.
writeChar
(
254
)
self
.
posCursor
(
2
,
1
)
for
ipos
in
range
(
1
,
1
8
):
for
ipos
in
range
(
1
,
1
7
):
self
.
writeChar
(
33
)
self
.
posCursor
(
2
,
ipos
-
1
)
time
.
sleep
(
0.1
)
self
.
writeChar
(
254
)
self
.
clear
self
.
clearLine
(
1
)
self
.
writeChar
(
33
)
time
.
sleep
(
0.1
)
self
.
writeChar
(
33
)
time
.
sleep
(
0.1
)
self
.
writeChar
(
33
)
time
.
sleep
(
0.1
)
self
.
writeChar
(
33
)
time
.
sleep
(
0.1
)
self
.
writeChar
(
33
)
time
.
sleep
(
0.1
)
self
.
clearLine
(
1
)
self
.
writeString
([
80
,
81
,
80
,
81
,
82
])
return
def
clear
(
self
):
### Clears the display and locates the curson on position (1,1), i.e. top left
i2ccmd
=
[
4
]
def
test2
(
self
):
self
.
clear
()
self
.
setBrightness
(
0
)
time
.
sleep
(
0.2
)
self
.
setBrightness
(
250
)
#myString= [80, 81, 80, 81, 82]
self
.
dispString
(
"192.168.200.32"
)
self
.
posCursor
(
2
,
1
)
self
.
dispString
(
"DUNE FANOUT"
)
return
def
dispString
(
self
,
myString
):
### Writes the string on the display
myInts
=
[]
for
iChar
in
list
(
myString
):
myInts
.
append
(
ord
(
iChar
))
self
.
writeString
(
myInts
)
return
def
writeString
(
self
,
myChars
):
### Writes a list of chars from the current position of the cursor
## NOTE: myChars is a list of integers corresponding to the ASCII code of each
## character to be printed. Use "dispString" to input an actual string.
#i2ccmd= [1, myChars]
myChars
.
insert
(
0
,
1
)
print
myChars
mystop
=
True
self
.
i2c
.
write
(
self
.
slaveaddr
,
i2ccmd
,
mystop
)
self
.
i2c
.
write
(
self
.
slaveaddr
,
myChars
,
mystop
)
def
posCursor
(
self
,
line
,
pos
):
### Position the cursor on a specific location
## line can be 1 (top) or 2 (bottom)
## pos can be [1, 16}
if
((
line
==
1
)
or
(
line
==
2
)
and
(
1
<=
pos
<=
16
)):
if
((
line
==
1
)
or
(
line
==
2
)
and
(
1
<=
pos
<=
self
.
nCols
)):
i2ccmd
=
[
2
,
line
,
pos
]
mystop
=
True
self
.
i2c
.
write
(
self
.
slaveaddr
,
i2ccmd
,
mystop
)
else
:
print
"Cursor line can only be 1 or 2, position must be in range [1,
16
]"
print
"Cursor line can only be 1 or 2, position must be in range [1,
"
,
self
.
nCols
,
"
]"
def
clearLine
(
self
,
iLine
):
### Clear line. Place cursor at beginning of line.
if
((
iLine
==
1
)
or
(
iLine
==
2
)):
i2ccmd
=
[
3
,
iLine
]
mystop
=
True
self
.
i2c
.
write
(
self
.
slaveaddr
,
i2ccmd
,
mystop
)
def
clear
(
self
):
### Clears the display and locates the curson on position (1,1), i.e. top left
i2ccmd
=
[
4
]
mystop
=
True
self
.
i2c
.
write
(
self
.
slaveaddr
,
i2ccmd
,
mystop
)
def
setLCDtype
(
self
,
nLines
,
nColumns
):
### Specifies the number of lines and columns in the display.
## This does not seem to do much but we use it anyway.
## NOTE: no check is performed on the nLines and nColumns parameters so be
## carefuls in using this function.
i2ccmd
=
[
5
,
nLines
,
nColumns
]
mystop
=
True
self
.
i2c
.
write
(
self
.
slaveaddr
,
i2ccmd
,
mystop
)
def
setBrightness
(
self
,
value
=
250
):
### Sets the brightness level of the backlight.
## Value is an integer in range [0, 250]. 0= no light, 250= maximum light.
...
...
@@ -84,12 +145,11 @@ class LCD09052:
mystop
=
True
self
.
i2c
.
write
(
self
.
slaveaddr
,
i2ccmd
,
mystop
)
def
writeChar
(
self
,
value
):
### Writes a char in the current cursor position
## The curso is then shifted right one position
## The curso
r
is then shifted right one position
## value must be an integer corresponding to the ascii code of the character
i2ccmd
=
[
1
,
value
]
i2ccmd
=
[
1
0
,
value
]
mystop
=
True
self
.
i2c
.
write
(
self
.
slaveaddr
,
i2ccmd
,
mystop
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment