Skip to content

Commit cb82878

Browse files
committed
Badger2040W: Add README.md for MicroPython.
1 parent 2952fd7 commit cb82878

File tree

1 file changed

+258
-0
lines changed

1 file changed

+258
-0
lines changed
Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
# Badger 2040 WW <!-- omit in toc -->
2+
3+
Badger 2040 WW is a Raspberry Pi Pico W powered E Ink badge.
4+
5+
- [Summary](#summary)
6+
- [Differences between Badger 2040 W and Badger 2040](#differences-between-badger-2040-w-and-badger-2040)
7+
- [Getting Started](#getting-started)
8+
- [Constants](#constants)
9+
- [Screen Size](#screen-size)
10+
- [E Ink Pins](#e-ink-pins)
11+
- [Power Pins](#power-pins)
12+
- [Activity LED Pin](#activity-led-pin)
13+
- [Function Reference](#function-reference)
14+
- [Basic Drawing Settings](#basic-drawing-settings)
15+
- [Pen Colour](#pen-colour)
16+
- [Pen Thickness](#pen-thickness)
17+
- [Displaying Images](#displaying-images)
18+
- [Updating The Display](#updating-the-display)
19+
- [Update](#update)
20+
- [Clear](#clear)
21+
- [Partial Update](#partial-update)
22+
- [Update Speed](#update-speed)
23+
- [LED](#led)
24+
- [Buttons](#buttons)
25+
- [Waking From Sleep](#waking-from-sleep)
26+
- [Button Presses](#button-presses)
27+
- [Real-time Clock](#real-time-clock)
28+
- [Update Speed](#update-speed-1)
29+
- [System speed](#system-speed)
30+
31+
# Summary
32+
33+
## Differences between Badger 2040 W and Badger 2040
34+
35+
Badger 2040 W switches from the Badger-specific drawing library of Badger 2040, to our generic PicoGraphics library.
36+
37+
PicoGraphics brings some great improvements, such as JPEG support with ditering and cross-compatibility between all of our other display products.
38+
39+
We've tried to make the transition as simple as possible, but there are a few breaking changes you'll need to be aware of:
40+
41+
* `pen()` is now `set_pen()`
42+
* `update_speed()` is now `set_update_speed()`
43+
* `thickness()` is now `set_thickness()` and *only* applies to Hershey fonts
44+
* `image()` and `icon()` are deprecated, use JPEGs instead.
45+
* `invert()` is not supported.
46+
47+
See the [PicoGraphics function reference](../picographics/README.md) for more information on how to draw to the display.
48+
49+
Additionally Badger 2040 W does not have a "user" button since the bootsel (which originally doubled as "user") is aboard the attached Pico W.
50+
51+
## Getting Started
52+
53+
:warning: If you're using the examples-included firmware you're good to go, otherwise you'll need to copy `examples/badger2040w/lib/badger2040w.py` and `examples/badger2040w/lib/network_manager.py` over to your Badger 2040 W.
54+
55+
To start coding your Badger 2040 W, you will need to add the following lines of code to the start of your code file.
56+
57+
```python
58+
import badger2040w
59+
badger = badger2040w.Badger2040W()
60+
```
61+
62+
This will create a `Badger2040W` class called `badger` that will be used in the rest of the examples going forward.
63+
64+
## Constants
65+
66+
Below is a list of other constants that have been made available, to help with the creation of more advanced programs.
67+
68+
### Screen Size
69+
* `WIDTH` = `296`
70+
* `HEIGHT` = `128`
71+
72+
### E Ink Pins
73+
* `BUSY` = `26`
74+
75+
### Power Pins
76+
* `ENABLE_3V3` = `10`
77+
78+
### Activity LED Pin
79+
* `LED` = `22`
80+
81+
# Function Reference
82+
83+
## Basic Drawing Settings
84+
85+
Since Badger 2040 W is based upon PicoGraphics you should read the [PicoGraphics function reference](../picographics/README.md) for more information about how to draw to the display.
86+
87+
### Pen Colour
88+
89+
There are 16 pen colours - or "shades of grey" - to choose, from 0 (black) to 15 (white).
90+
91+
Since Badger2040W cannot display colours other than black and white, any value from 1 to 14 will apply dithering when drawn, to simulate a shade of grey.
92+
93+
```python
94+
pen(
95+
colour # int: colour from 0 to 15
96+
)
97+
```
98+
99+
### Pen Thickness
100+
101+
:warning: Applies to Hershey fonts only.
102+
103+
Thickness affects Hershey text and governs how thick the component lines should be, making it appear bolder:
104+
105+
```python
106+
set_thickness(
107+
value # int: thickness in pixels
108+
)
109+
```
110+
111+
## Displaying Images
112+
113+
Badger 2040 W can display basic JPEG images. They must not be progressive. It will attempt to dither them to the black/white display.
114+
115+
To display a JPEG, import and set up the `jpegdec` module like so:
116+
117+
```python
118+
import badger2040w
119+
import jpegdec
120+
121+
badger = badger2040w.Badger2040W()
122+
jpeg = jpegdec.JPEG(badger.display)
123+
```
124+
125+
`badger.display` points to the PicoGraphics instance that the Badger2040W class manages for you.
126+
127+
You can open and display a JPEG file like so:
128+
129+
```python
130+
jpeg.open_file("/image.jpg")
131+
jpeg.decode(x, y)
132+
```
133+
134+
Where `x, y` is the position at which you want to display the JPEG.
135+
136+
## Updating The Display
137+
138+
### Update
139+
140+
Starts a full update of the screen. Will block until the update has finished.
141+
142+
Update takes no parameters, but the update time will vary depending on which update speed you've selected.
143+
144+
```python
145+
badger.update()
146+
```
147+
148+
### Clear
149+
150+
Before drawing again it can be useful to `clear` your display.
151+
152+
`clear` fills the drawing buffer with the pen colour, giving you a clean slate:
153+
154+
```python
155+
badger.clear()
156+
```
157+
158+
### Partial Update
159+
160+
Starts a partial update of the screen. Will block until the update has finished.
161+
162+
A partial update allows you to update a portion of the screen rather than the whole thing.
163+
164+
That portion *must* be a multiple of 8 pixels tall, but can be any number of pixels wide.
165+
166+
```python
167+
partial_update(
168+
x, # int: x coordinate of the update region
169+
y, # int: y coordinate of the update region (must be a multiple of 8)
170+
w, # int: width of the update region
171+
h # int: height of the update region (must be a multiple of 8)
172+
)
173+
```
174+
175+
### Update Speed
176+
177+
Badger 2040 W is capable of updating the display at multiple different speeds.
178+
179+
These offer a tradeoff between the quality of the final image and the speed of the update.
180+
181+
There are currently four constants naming the different update speeds from 0 to 3:
182+
183+
* `UPDATE_NORMAL` - a normal update, great for display the first screen of your application and ensuring good contrast and no ghosting
184+
* `UPDATE_MEDIUM` - a good balance of speed and clarity, you probably want this most of the time
185+
* `UPDATE_FAST` - a fast update, good for stepping through screens such as the pages of a book or the launcher
186+
* `UPDATE_TURBO` - a super fast update, prone to ghosting, great for making minor changes such as moving a cursor through a menu
187+
188+
```python
189+
update_speed(
190+
speed # int: one of the update constants
191+
)
192+
```
193+
194+
## LED
195+
196+
The white indicator LED can be controlled, with brightness ranging from 0 (off) to 255:
197+
198+
```python
199+
led(
200+
brightness # int: 0 (off) to 255 (full)
201+
)
202+
```
203+
204+
## Buttons
205+
206+
Badger 2040 W features five buttons on its front, labelled A, B, C, ↑ (up) and ↓ (down). These can be read using the `pressed(button)` method, which accepts the button's pin number. For convenience, each button can be referred to using these constants:
207+
208+
* `BUTTON_A` = `12`
209+
* `BUTTON_B` = `13`
210+
* `BUTTON_C` = `14`
211+
* `BUTTON_UP` = `15`
212+
* `BUTTON_DOWN` = `11`
213+
214+
Additionally you can use `pressed_any()` to see if _any_ button has been pressed.
215+
216+
## Waking From Sleep
217+
218+
### Button Presses
219+
220+
When running on battery, pressing a button on Badger 2040 W will power the unit on. It will automatically be latched on and `main.py` will be executed.
221+
222+
There are some useful functions to determine if Badger 2040 W has been woken by a button, and figure out which one:
223+
224+
* `badger2040w.woken_by_button()` - determine if any button was pressed during power-on.
225+
* `badger2040w.pressed_to_wake(button)` - determine if the given button was pressed during power-on.
226+
* `badger2040w.reset_pressed_to_wake()` - clear the wakeup GPIO state.
227+
* `badger2040w.pressed_to_wake_get_once(button)` - returns `True` if the given button was pressed to wake Badger, and then clears the state of that pin.
228+
229+
### Real-time Clock
230+
231+
Badger 2040 W includes a PCF85063a RTC which continues to run from battery when the Badger is off. It can be used to wake the Badger on a schedule.
232+
233+
234+
## Update Speed
235+
236+
The E Ink display on Badger 2040 W supports several update speeds. These can be set using `set_update_speed(speed)` where `speed` is a value from `0` to `3`. For convenience these speeds have been given the following constants:
237+
238+
* `UPDATE_NORMAL` = `0`
239+
* `UPDATE_MEDIUM` = `1`
240+
* `UPDATE_FAST` = `2`
241+
* `UPDATE_TURBO` = `3`
242+
243+
## System speed
244+
245+
The system clock speed of the RP2040 can be controlled, allowing power to be saved if on battery, or faster computations to be performed. Use `badger2040w.system_speed(speed)` where `speed` is one of the following constants:
246+
247+
* `SYSTEM_VERY_SLOW` = `0` _4 MHz if on battery, 48 MHz if connected to USB_
248+
* `SYSTEM_SLOW` = `1` _12 MHz if on battery, 48 MHz if connected to USB_
249+
* `SYSTEM_NORMAL` = `2` _48 MHz_
250+
* `SYSTEM_FAST` = `3` _133 MHz_
251+
* `SYSTEM_TURBO` = `4` _250 MHz_
252+
253+
On USB, the system will not run slower than 48MHz, as that is the minimum clock speed required to keep the USB connection stable.
254+
255+
It is best to set the clock speed as the first thing in your program, and you must not change it after initializing any drivers for any I2C hardware connected to the qwiic port. To allow you to set the speed at the top of your program, this method is on the `badger2040w` module, rather than the `badger` instance, although we have made sure that it is safe to call it after creating a `badger` instance.
256+
257+
Note that `SYSTEM_TURBO` overclocks the RP2040 to 250MHz, and applies a small over voltage to ensure this is stable. We've found that every RP2040 we've tested is happy to run at this speed without any issues.
258+

0 commit comments

Comments
 (0)