Skip to content

Commit 77240ea

Browse files
authored
Merge pull request #14 from trevorwslee/develop
Develop
2 parents f896bda + 15fa250 commit 77240ea

File tree

6 files changed

+120
-49
lines changed

6 files changed

+120
-49
lines changed

README.md

Lines changed: 84 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ to MicroPython / Python 3 for the [DumbDisplay Android app](https://play.google.
77
For a video introduction, please watch the YouTube video: [Introducing DumbDisplay MicroPython Library --
88
with ESP32, Raspberry Pi Pico, and Raspberry Pi Zero](https://www.youtube.com/watch?v=KVU26FyXs5M)
99

10-
Although the porting is work in progress, nevertheless, most of the core of DumbDisplay functionalities have been ported.
10+
Although the porting is still work-in-progress, a large portion of the core of DumbDisplay functionalities have been ported.
1111
Hopefully, this should already be helpful for friends that develop programs for microcontroller boards in MicroPython.
1212

13-
As hinted previously, even DumbDisplay MicroPython Library is originally targeted for MicroPython, it should be useable with regular Python 3, like in Raspberry Pi environment
14-
or even with desktop / laptop.
15-
16-
Consequently, DumbDisplay MicroPython Library might be an alternative way to prototype simple Android app driven remotely with Python 3 from desktop / laptop, say for displaying experiment result data and getting simple interaction with the user.
13+
As hinted previously, even DumbDisplay MicroPython Library is originally targeted for MicroPython, it should be useable with regular Python 3, like in Raspberry Pi environment or even with desktop / laptop.
14+
Consequently, DumbDisplay MicroPython Library might be an alternative way to prototype simple Android app driven remotely with Python 3 from desktop / laptop, say for displaying experiment result data and getting simple interactions from the user.
1715

1816

1917
Enjoy
@@ -25,7 +23,7 @@ Enjoy
2523
- [IO Mechanism](#io-mechanism)
2624
- [Layers](#layers)
2725
- [Auto-Pinning of Layers](#auto-pinning-of-layers)
28-
- [Feedback](#feedback)
26+
- [Feedbacks of Layers](#feedbacks-of-layers)
2927
- [Poll for Feedback](#poll-for-feedback)
3028
- [Callback for Feedback](#callback-for-feedback)
3129
- [Selected Demos](#selected-demos)
@@ -60,43 +58,46 @@ pip install git+https://github.com/trevorwslee/MicroPython-DumbDisplay
6058
6159
# Getting Started
6260
63-
The basic Python script setup is:
64-
1. import core, for creating `DumbDisplay` object
61+
To use DumbDisplay MicroPython Library, the basic Python script setup is:
62+
63+
1. Import core components, for creating `DumbDisplay` object
6564
<br>e.g.
6665
```
6766
from dumbdisplay.core import *
6867
dd = DumbDisplay()
6968
```
70-
- you can import the "core" components with ```from dumbdisplay.core import *```
71-
- or you can choose to import "all" components (including layers to be mentioned later) with ```from dumbdisplay.full import *```
72-
2. import IO mechanism, for creating IO object [to pass to DumbDisplay object], like
69+
- you can import the core components with ```from dumbdisplay.core import *```
70+
- or you can choose to import all components (including layers to be mentioned later) with ```from dumbdisplay.full import *```
71+
72+
2. Import IO mechanism, for creating IO object [to pass to DumbDisplay object] like
7373
<br>e.g.
7474
```
7575
from dumbdisplay.core import *
7676
from dumbdisplay.ios import *
77-
dd = DumbDisplay(io4Wifi("ssid", "password")) # the default is io4Inet()
77+
dd = DumbDisplay(io=io4Wifi("ssid", "password")) # the default is io4Inet()
7878
```
79-
- the default IO mechanism is `io4Inet()`, which uses Python networking support (not available for MicroPython)
80-
3. import layers, for creating layer objects [passing DumbDisplay object to them]
79+
- the default `io` is `io4Inet()`, which uses Python networking support (not available for MicroPython)
80+
81+
3. Import layer, for creating layer object [passing DumbDisplay object to it]
8182
<br>e.g.
8283
```
8384
from dumbdisplay.core import *
8485
from dumbdisplay.layer_ledgrid import *
8586
dd = DumbDisplay()
8687
l = LayerLedGrid(dd)
8788
```
88-
- you can choose to import "all" layers with ```from dumbdisplay.full import *```
89+
- you can choose to import all types of layers with ```from dumbdisplay.full import *```
8990
9091
9192
# More Details
9293
9394
## IO Mechanism
9495
95-
When create a `DumbDisplay` object, an IO object is needed (even though there is a default IO object)
96+
When create a `DumbDisplay` object, an IO object is needed
9697
- `io4Inet` (the default) -- Python networking support (not available for MicroPython)
9798
- `io4Wifi` -- MicroPython WiFi support (for Raspberry Pi Pico W, ESP32, etc.)
98-
- `io4Ble` -- MicroPython BLE support (for Raspberry Pi Pico W, ESP32, etc.)
9999
- `io4Uart` -- MicroPython UART support (for Raspberry Pi Pico W, ESP32, etc.)
100+
- `io4Ble` -- MicroPython BLE support (for ESP32, etc.)
100101
101102
E.g.
102103
```
@@ -107,92 +108,135 @@ dd = DumbDisplay(io4Wifi("ssid", "password"))
107108
108109
## Layers
109110
110-
Other then the `DumbDisplay`, you will need to create one or more layer objects to represent the UI:
111-
- `LayerLedGrid` -- a single LED, or a grid of multiple LEDs (**n** columns by **m** rows)
112-
<br>e.g.
111+
Other then the `DumbDisplay` object, you will need to create one or more layer objects to represent the visible portion of the UI:
112+
113+
- `LayerLedGrid` -- a single LED, or a row / column / grid of multiple LEDs (**n** columns by **m** rows)
113114
```
114115
from dumbdisplay.core import *
115116
from dumbdisplay.layer_ledgrid import *
116117
dd = DumbDisplay()
117118
l = LayerLedGrid(dd)
118119
```
120+
example:
119121
|[`demo_LayerLedGrid()` in `dd_demo.py`](dd_demo.py)|
120122
|:--:|
121123
|<img style="width: 300px; height: 300px;" src="screenshots/layer_ledgrid_2x2.png"></img>|
122124
123125
- `LayerLcd` -- a TEXT based LCD with configurable number of lines of configurable number of characters
124-
<br>e.g.
125126
```
126127
from dumbdisplay.core import *
127128
from dumbdisplay.layer_lcd import *
128129
dd = DumbDisplay()
129130
l = LayerLcd(dd)
130131
```
132+
133+
example:
131134
|[`demo_LayerLcd()` in `dd_demo.py`](dd_demo.py)|
132135
|:--:|
133136
|<img style="width: 300px; height: 300px;" src="screenshots/layer_lcd.png"></img>|
134137
135-
- `LayerGraphical` -- a graphical LCD that you can draw to, with common drawing operations
136-
<br>e.g.
138+
- `LayerGraphical` -- a graphical LCD that you can draw to with common drawing directives
137139
```
138140
from dumbdisplay.core import *
139141
from dumbdisplay.layer_graphical import *
140142
dd = DumbDisplay()
141143
l = LayerGraphical(dd)
142144
```
145+
146+
example:
143147
|[`demo_LayerGraphical()` in `dd_demo.py`](dd_demo.py)|
144148
|:--:|
145149
|<img style="width: 300px; height: 300px;" src="screenshots/layer_graphical.png"></img>|
146150
147-
- `LayerSelection` -- a group / grid of TEXT based LCD mostly for showing selection choices
148-
<br>e.g.
151+
- `LayerSelection` -- a row / column / grid of TEXT based LCDs mostly for showing selection choices
149152
```
150153
from dumbdisplay.core import *
151154
from dumbdisplay.layer_selection import *
152155
dd = DumbDisplay()
153156
l = LayerSelection(dd)
154157
```
158+
159+
example:
155160
|[`demo_LayerSelection()` in `dd_demo.py`](dd_demo.py)|
156161
|:--:|
157162
|<img style="width: 300px; height: 300px;" src="screenshots/layer_selection_1x3.png"></img>|
158163
159164
- `Layer7SegmentRow` -- a single 7-segment digit, or a row of **n** 7-segments digits
160-
<br>e.g.
161165
```
162166
from dumbdisplay.core import *
163167
from dumbdisplay.layer_7segrow import *
164168
dd = DumbDisplay()
165169
l = Layer7SegmentRow(dd)
166170
```
171+
172+
example:
167173
|[`demo_Layer7SegmentRow()` in `dd_demo.py`](dd_demo.py)|
168174
|:--:|
169175
|<img style="width: 300px; height: 300px;" src="screenshots/layer_7segment_3d.png"></img>|
170176
171-
- `LayerPlotter` -- a "plotter"
172-
<br>e.g.
177+
- `LayerPlotter` -- a "plotter" for plotting real-time data
173178
```
174179
from dumbdisplay.core import *
175180
from dumbdisplay.layer_plotter import *
176181
dd = DumbDisplay()
177182
l = LayerPlotter(dd)
178183
```
184+
185+
example:
179186
|[`demo_LayerPlotter()` in `dd_demo.py`](dd_demo.py)|
180187
|:--:|
181188
|<img style="width: 300px; height: 300px;" src="screenshots/layer_plotter.png"></img>|
189+
190+
as shown in th example, two types of data are fed to the plotter -- `X` and `Sin`
191+
```
192+
l.label("X", sin="Sin")
193+
```
194+
And the real-time values of `X` and `Sin` are fed like
195+
```
196+
for x in range(1000):
197+
sin = math.sin(x)
198+
l.set(x, sin=sin)
199+
time.sleep(0.8)
200+
```
201+
202+
- `LayerJoystick` -- a joystick; also can be a horizontal or vertical slider
203+
```
204+
from dumbdisplay.core import *
205+
from dumbdisplay.layer_joystick import *
206+
dd = DumbDisplay()
207+
l = LayerJoystick(dd)
208+
```
209+
210+
|[`demo_LayerJoystick()` in `dd_demo.py`](dd_demo.py)|
211+
|:--:|
212+
|<img style="width: 300px; height: 300px;" src="screenshots/layer_joystick.png"></img>|
213+
214+
as shown in the example
215+
* you can configure the joystick to be a horizontal or vertical slider by changing the `directions` parameter to `LayerJoystick`
216+
- param `maxStickValue`: the max value of the stick; e.g. 255 or 1023 (the default); min is 15
217+
- param `directions`: "lr" or "hori": left-to-right; "tb" or "vert": top-to-bottom; "rl": right-to-left; "bt": bottom-to-top;
218+
use "+" combines the above like "lr+tb" to mean both directions; "" the same as "lr+tb"
219+
* feedback -- to be talked about later -- is enabled by default, and you can poll for feedback like
220+
```
221+
while True:
222+
fb = l.getFeedback()
223+
if fb:
224+
print(f"* Feedback: {fb.type} at ({fb.x}, {fb.y})")
225+
```
182226
183227
## Auto-Pinning of Layers
184228
185229
In case of multiple layers, you can "auto pin" them together; otherwise, multiple layers will be stacked on top of each other
186-
187-
E.g.
188230
```
189231
AutoPin('V', AutoPin('H', l_ledgrid, l_lcd), AutoPin('H', l_selection, l_7segmentrow), l_graphical).pin(dd)
190232
```
233+
234+
Example:
191235
|[`demo_AutoPin()` in `dd_demo.py`](dd_demo.py)|
192236
|:--:|
193237
|<img style="width: 400px; height: 400px;" src="screenshots/autopin_layers.png"></img>|
194238
195-
## Feedback
239+
## Feedbacks of Layers
196240
197241
Certain user interaction, like pressing, with the layers (the UI) can trigger feedback to the corresponding layer objects
198242
@@ -205,7 +249,7 @@ or to enable feedback with auto flashing (UI feedback) of the layer by provide o
205249
l.enable_feedback("fl")
206250
```
207251
208-
There are two ways feedback of the layer can be received -- polling or callback
252+
There are two ways feedback of a layer can be received -- polling or callback
209253
210254
### Poll for Feedback
211255
@@ -237,19 +281,25 @@ The parameters passed to the callback `lambda`:
237281
- `type`: the type of feedback (as mentioned above)
238282
- `x`, `y`: the "coordinates" of the feedback (as mentioned above)
239283
284+
***Important*** note: Since DumbDisplay is "cooperative", you should give "time-slices" for DumbDisplay to process feedback signals from the Android app, like:
285+
```
286+
while True:
287+
dd.timeslice()
288+
```
289+
240290
Please take [`demo_Feedback_callback()` in `dd_demo.py`](dd_demo.py) as an example.
241291
242292
243293
# Selected Demos
244294
245-
Here is a few Raspberry Pi Pico PIO demos that might interest you
295+
Here are two Raspberry Pi Pico PIO demos
246296
247297
|[Respberry Pi Pico W Generating Tones With Programmable I/O (PIO) Using MicroPython](https://www.instructables.com/Respberry-Pi-Pico-W-Generating-Tones-With-Programm/)|[Respberry Pi Pico W NeoPixels Experiments With Programmable I/O (PIO) Using MicroPython](https://www.instructables.com/Respberry-Pi-Pico-W-NeoPixels-Experiments-With-Pro/)|
248298
|--|--|
249299
|![](screenshots/u_melody_dd.jpg)|![](screenshots/u_neopixeldd_dd.jpg)|
250300
251301
252-
[`PyTorchIntroductoryExperiments`](https://github.com/trevorwslee/PyTorchIntroductoryExperiments) shows two regular Python 3 demos that might interest you
302+
[`PyTorchIntroductoryExperiments`](https://github.com/trevorwslee/PyTorchIntroductoryExperiments) shows two regular Python 3 demos
253303
254304
|||
255305
|--|--|

dd_demo.py

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,23 @@ def demo_LayerPlotter():
155155
dd.timeslice()
156156

157157

158+
def demo_LayerJoystick(maxStickValue: int = 1023, directions: str = ""):
159+
from dumbdisplay.layer_joystick import LayerJoystick
160+
161+
# Create a DumbDisplay instance
162+
dd = _create_demo_dd()
163+
164+
# Create a LayerJoystick layer with the specified maxStickValue and directions, and set it up, like border and colors
165+
l = LayerJoystick(dd, maxStickValue=maxStickValue, directions=directions)
166+
l.border(5, "blue")
167+
l.colors(stick_color="green", stick_outline_color="darkgreen")
168+
169+
while True:
170+
fb = l.getFeedback()
171+
if fb:
172+
print(f"* Feedback: {fb.type} at ({fb.x}, {fb.y})")
173+
174+
158175
def demo_AutoPin():
159176
from dumbdisplay.full import LayerLedGrid, LayerLcd, LayerGraphical, Layer7SegmentRow, LayerSelection, AutoPin
160177

@@ -274,17 +291,21 @@ def run_mnist_app():
274291

275292

276293
if __name__ == "__main__":
277-
# demo_LayerLedGrid(2, 2)
278-
# demo_LayerLcd()
279-
# demo_LayerGraphical()
280-
# demo_Layer7SegmentRow()
281-
# demo_LayerSelection()
282-
# demo_LayerPlotter()
283-
284-
#demo_AutoPin()
285-
#demo_Feedback()
286-
demo_Feedback_callback()
287-
288-
# run_passive_blink_app()
289-
# run_sliding_puzzle_app()
290-
# run_mnist_app()
294+
demo_Feedback()
295+
296+
if True:
297+
demo_LayerLedGrid(2, 2)
298+
demo_LayerLcd()
299+
demo_LayerGraphical()
300+
demo_Layer7SegmentRow()
301+
demo_LayerSelection()
302+
demo_LayerPlotter()
303+
demo_LayerJoystick(directions="") # directions can be "", "lr" or "tb"
304+
305+
demo_AutoPin()
306+
demo_Feedback()
307+
demo_Feedback_callback()
308+
309+
run_passive_blink_app()
310+
run_sliding_puzzle_app()
311+
run_mnist_app()

dumbdisplay/ddlayer_joystick.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def __init__(self, dd, maxStickValue: int = 1023, directions: str = "", stickLoo
1515
super().__init__(dd, layer_id)
1616
def autoRecenter(self, auto_recenter: bool = True):
1717
self.dd._sendCommand(self.layer_id, "autorecenter", _DD_BOOL_ARG(auto_recenter))
18-
def colors(self, stick_color: str, stick_outline_color: str, socket_color: str, socket_outline_color):
18+
def colors(self, stick_color: str = "", stick_outline_color: str = "", socket_color: str = "", socket_outline_color = ""):
1919
self.dd._sendCommand(self.layer_id, "colors", _DD_COLOR_ARG(stick_color), _DD_COLOR_ARG(stick_outline_color), _DD_COLOR_ARG(socket_color), _DD_COLOR_ARG(socket_outline_color))
2020
def moveToPos(self, x: int, y: int, send_feedback: bool = False):
2121
'''

screenshots/layer_joystick.png

26.8 KB
Loading

screenshots/layer_joystick_tb.png

13.1 KB
Loading

screenshots/layer_joystock_lr.png

12.6 KB
Loading

0 commit comments

Comments
 (0)