Skip to content

Commit 32fa05c

Browse files
Merge branch 'dev'
2 parents 0049ec2 + 3a12068 commit 32fa05c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1503
-186
lines changed

README.md

Lines changed: 32 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,59 @@
1-
# PyLetMeCreate
1+
![logo](https://static.creatordev.io/logo-md-s.svg)
22

3-
This is the python binding of the LetMeCreate library. It requires Python 3. See [LetMeCreate](https://github.com/francois-berder/LetMeCreate) for the complete list of interface and click board supported.
43

5-
## Integration in Openwrt
4+
# PyLetMeCreate
65

7-
Before reading any further, make sure that you installed the LetMeCreate library as shown on its github page.
6+
This is the python binding of the LetMeCreate library. It requires Python 3. See [LetMeCreate](https://github.com/francois-berder/LetMeCreate) for the complete list of interface and click board supported.
7+
PyLetMeCreate relies on LetMeCreate, hence it is important that both versions match.
88

9+
Examples are installed in /usr/bin/pyletmecreate_examples.
910

10-
### Installation steps
11+
## Integration in Openwrt
1112

12-
Clone the library and openwrt somewhere on you computer:
13+
PyLetMeCreate is already part of Imagination Technologies' OpenWrt.
14+
To compile the library (only possible once you built Openwrt once):
1315

1416
```sh
15-
$ mkdir ci-40
16-
$ cd ci-40
17-
$ git clone https://github.com/CreatorDev/openwrt.git
18-
$ mkdir -p custom/pyletmecreate
19-
$ cd custom/pyletmecreate
17+
$ make package/pyletmecreate/{clean,compile} -j1 V=s
2018
```
21-
#### Stable release
2219

23-
If you are only interested in getting the latest release of LetMeCreate library, then download a copy of Makefile.stable located in miscellaneous folder. Copy this file inside the pyletmecreate folder you have just created and rename it to Makefile.
24-
25-
#### Development configuration
20+
### Installation steps
2621

27-
If you are interested in modifying the library, getting the latest changes, then clone it in custom/pyletmecreate folder you just created:
22+
You can install PyLetMeCreate package on OpenWRT executing:
2823

2924
```sh
30-
$ git clone https://github.com/francois-berder/PyLetMeCreate.git
25+
$ opkg install pyletmecreate
3126
```
3227

33-
Copy the Makefile to the right location:
34-
```sh
35-
$ cp PyLetMeCreate/miscellaneous/Makefile.devel Makefile
36-
```
28+
Each release has the ipk as an attachment. You can download the ipk, copy it to your Ci40 and install with opkg:
3729

38-
This project uses two branches. The dev branch contains all the latest changes and should not be considered stable. The dev branch is sometimes merged to master once new features are considered stable.
39-
40-
#### Register PyLetMeCreate in Openwrt
41-
42-
To register the feed in openwrt, go back in openwrt folder and open feeds.conf.default.
43-
Add this line:
44-
```
45-
src-link custom /change/this/path/to/the/location/of/ci-40/custom/directory/
46-
```
47-
48-
Update and install all feeds:
4930
```sh
50-
$ ./scripts/feeds update -a
51-
$ ./scripts/feeds install -a
31+
$ opkg install path-to-the-ipk
5232
```
53-
Select python3-letmecreate in make menuconfig. It will automatically select python3 and letmecreate. Then, compile Openwrt:
5433

55-
```sh
56-
$ make -j1 V=s
57-
```
58-
To create an ipk, run this command (only possible once you built Openwrt once):
59-
60-
```sh
61-
$ make package/pyletmecreate/{clean,compile} -j1 V=s
62-
```
34+
### Usage example
6335

64-
### Installation of PyLetMeCreate on Ci40
6536

66-
#### Install PyLetMeCreate using ipk
37+
```python
38+
#!/usr/bin/env python3
39+
"""This example shows how to read the temperature using a Thermo3 Click
40+
on Mikrobus 1.
41+
"""
6742

68-
In openwrt folder, the ipk is located in bin/pistachio/packages/custom. Transfer it to your Ci40 using scp:
69-
```sh
70-
$ scp bin/pistachio/packages/custom/python3-letmecreate_1.0.1_pistachio.ipk root@<ip-of-your-ci40>:/tmp
71-
```
43+
from letmecreate.core import i2c
44+
from letmecreate.core.common import MIKROBUS_1
45+
from letmecreate.click import thermo3
7246

73-
On you Ci40:
74-
```sh
75-
$ opkg install /tmp/python3-letmecreate_1.0.1_pistachio.ipk
76-
```
7747

78-
#### Install PyLetMeCreate by copying letmecreate folder
48+
# Initialise I2C on Mikrobus 1
49+
i2c.init()
50+
i2c.select_bus(MIKROBUS_1)
7951

52+
# Read temperature
53+
thermo3.enable(0)
54+
print('{} degrees celsius'.format(thermo3.get_temperature()))
55+
thermo3.disable()
8056

81-
In your PyLetMeCreate folder, transfer the files to:
82-
```sh
83-
$ scp letmecreate root@<ip-of-your-Ci40>:/usr/lib/python3.5/site-packages
57+
# Release I2C
58+
i2c.release()
8459
```
85-
86-
This will only work if python3.5 is already installed on your Ci40. You might need to change the directory path if you have a different version of Python installed.

examples/accel_example.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python3
2+
"""This example shows how to use the Accel Click wrapper of the LetMeCreate to
3+
obtain 3-axis accelerometer data.
4+
5+
It continuously displays latest accelerometer measurements with at a rate
6+
of 10Hz. The user has to interrupt the program to exit it by pressing Ctrl+C.
7+
8+
The Accel Click must be inserted in Mikrobus 1 before running this program.
9+
"""
10+
11+
from letmecreate.core import spi
12+
from letmecreate.core.common import MIKROBUS_1
13+
from letmecreate.click import accel
14+
from time import sleep
15+
16+
spi.init()
17+
spi.select_bus(MIKROBUS_1)
18+
accel.use_spi()
19+
accel.enable()
20+
21+
while True:
22+
measure = accel.get_measure()
23+
print('{0:9.3f} {1:9.3f} {2:9.3f}'.format(measure[0], measure[1], measure[2]))
24+
sleep(0.1)
25+
26+
accel.disable()
27+
spi.release()

examples/adc_example.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env python3
2+
"""This example shows how to use the ADC Click wrapper of the LetMeCreate
3+
library.
4+
5+
It reads ADC values from the four channels. Each value should be in range
6+
0..4095. If no wires are connected to the channels of the ADC Click, then
7+
the values should be random.
8+
9+
The ADC Click must be inserted in Mikrobus 1 before running the program.
10+
"""
11+
from letmecreate.core import spi
12+
from letmecreate.click import adc
13+
14+
15+
spi.init()
16+
17+
for i in range(adc.ADC_CLICK_CHANNEL_COUNT):
18+
print('channel {} value: {}'.format(i, adc.get_raw_value(i)))
19+
20+
spi.release()

examples/alphanum_example.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python3
2+
"""This example shows how to use the Alphanum Click wrapper of the LetMeCreate
3+
to display characters.
4+
5+
It displays "Ci" using both displays by enabling them one after the other at
6+
100Hz to give the illusion that both characters are displayed at the same
7+
time. The user has to interrupt the program to exit it by pressing Ctrl+C.
8+
*
9+
The Alphanum Click must be inserted in Mikrobus 1 before running this
10+
program.
11+
"""
12+
13+
from letmecreate.core.common import MIKROBUS_1
14+
from letmecreate.core import spi
15+
from letmecreate.click import alphanum
16+
import time
17+
18+
19+
spi.init()
20+
alphanum.init(MIKROBUS_1)
21+
alphanum.write('C', 'i')
22+
23+
while True:
24+
alphanum.select_left_display()
25+
time.sleep(0.01)
26+
alphanum.select_right_display()
27+
time.sleep(0.01)

examples/bargraph_example.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python3
2+
"""This example shows how to use the BarGraph Click wrapper of the LetMeCreate
3+
library.
4+
5+
It turns on gradually all the LED's from left to right in 2 seconds.
6+
7+
The BarGraph Click must be inserted in Mikrobus 1 before running this program.
8+
"""
9+
10+
from letmecreate.core.common import MIKROBUS_1
11+
from letmecreate.core import spi
12+
from letmecreate.click import bargraph
13+
from time import sleep
14+
15+
16+
spi.init()
17+
bargraph.set_intensity(MIKROBUS_1, 100.0)
18+
19+
value = 1
20+
for i in range(10):
21+
bargraph.set_value(value)
22+
value <<= 1
23+
value |= 1
24+
sleep(0.2)
25+
26+
spi.release()

examples/color2_example.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python3
2+
"""This example shows how to use the Color2 Click wrapper of the LetMeCreate
3+
library.
4+
5+
The Color2 Click must be plugged in Mikrobus 1 of Ci40.
6+
"""
7+
8+
from letmecreate.core import i2c
9+
from letmecreate.click import color2
10+
11+
12+
i2c.init()
13+
color2.enable()
14+
15+
measure = color2.get_color()
16+
color2.disable()
17+
i2c.release()
18+
19+
print('red : {}'.format(measure[0]))
20+
print('green: {}'.format(measure[1]))
21+
print('blue : {}'.format(measure[2]))

examples/color_example.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python3
2+
"""This example shows how to use the Color Click wrapper of the LetMeCreate.
3+
4+
It takes a measurement from the sensor, prints it in the terminal and exits.
5+
6+
The Color Click must be inserted in Mikrobus 1 before running this program.
7+
"""
8+
9+
from letmecreate.core import i2c
10+
from letmecreate.click import color
11+
12+
i2c.init()
13+
color.enable()
14+
measure = color.get_color()
15+
color.disable()
16+
i2c.release()
17+
18+
print('clear: {}'.format(measure[0]))
19+
print('red : {}'.format(measure[1]))
20+
print('green: {}'.format(measure[2]))
21+
print('blue : {}'.format(measure[3]))

examples/data/image.jpg

14.5 KB
Loading

examples/eve_example_1.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env python3
2+
"""This example shows some basic features of the EVE Click wrapper of the
3+
LetMeCreate library.
4+
5+
It displays a green screen for three seconds, then displays some text for
6+
another three seconds.
7+
8+
Before running this program:
9+
- the EVE Click must be inserted in Mikrobus 1
10+
- a WQVGA screen must be connected to the EVE Click.
11+
"""
12+
13+
from letmecreate.core import spi
14+
from letmecreate.core.common import MIKROBUS_1
15+
from letmecreate.click import eve
16+
from time import sleep
17+
18+
spi.init();
19+
spi.set_mode(MIKROBUS_1, 0)
20+
21+
eve.enable(MIKROBUS_1)
22+
23+
# Display a green screen for 3 seconds
24+
eve.clear(0, 255, 0)
25+
eve.display()
26+
27+
sleep(3)
28+
29+
# Display some text
30+
eve.clear(0, 0, 0)
31+
eve.draw(eve.FT800_TEXT,
32+
[240, # x
33+
136, # y
34+
31, # font (31 is the largest font)
35+
eve.FT800_OPT_CENTER, # options
36+
"Hello World !".encode('utf-8')]) # All strings must be encoded
37+
eve.display()
38+
39+
sleep(3)
40+
41+
eve.disable(MIKROBUS_1)
42+
spi.release()

examples/eve_example_2.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env python3
2+
"""This example shows features related to the touch screen of the EVE Click
3+
wrapper of the LetMeCreate library.
4+
5+
It first performs calibration of the touch screen, then it prints the
6+
coordinates of the touch event. Press Ctrl+C to exit program.
7+
8+
Before running this program:
9+
- the EVE Click must be inserted in Mikrobus 1
10+
- a WQVGA screen must be connected to the EVE Click.
11+
"""
12+
13+
from letmecreate.core import spi
14+
from letmecreate.core.common import MIKROBUS_1
15+
from letmecreate.click import eve
16+
17+
touch_screen_event = False
18+
last_event_x = 0
19+
last_event_y = 0
20+
21+
def callback(x, y):
22+
global touch_screen_event
23+
global last_event_x, last_event_y
24+
last_event_x = x
25+
last_event_y = y
26+
touch_screen_event = True
27+
28+
29+
spi.init()
30+
spi.set_mode(MIKROBUS_1, 0)
31+
32+
eve.enable(MIKROBUS_1);
33+
34+
# Perform calibration of touch screen
35+
eve.calibrate()
36+
37+
# Add your own callback after calibration, otherwise you might get
38+
# incorrect coordinates.
39+
eve.attach_touch_callback(callback)
40+
41+
eve.clear(0, 0, 0)
42+
eve.draw(eve.FT800_TEXT,
43+
[240,
44+
136,
45+
31,
46+
eve.FT800_OPT_CENTER,
47+
"Tap on the screen".encode('utf-8')])
48+
eve.display()
49+
50+
while True:
51+
52+
# Wait until the user touches the screen or that it exits
53+
while not touch_screen_event:
54+
pass
55+
56+
eve.clear(0, 0, 0)
57+
eve.draw(eve.FT800_TEXT,
58+
[240,
59+
136,
60+
25,
61+
eve.FT800_OPT_CENTER,
62+
"Touch event detected at:".encode('utf-8')])
63+
eve.draw(eve.FT800_TEXT,
64+
[240,
65+
180,
66+
25,
67+
eve.FT800_OPT_CENTER,
68+
"x: {}, y: {}".format(last_event_x, last_event_y).encode('utf-8')])
69+
eve.display()
70+
71+
eve.disable(MIKROBUS_1)
72+
spi_release()

0 commit comments

Comments
 (0)