Let’s make a world that won’t fit on our screen. A city, a mountain range, a forest—something you can travel through. The OLED will show a moving window onto that larger picture. When we reach the end, we’ll come around to the beginning.
You already know the pieces: drawing tools from Phase 5, pages and masks from Phase 3, and the draw–show sequence from Phase 4. This detour puts them to work in a project of your own. We are still using the borrowed SSD1306 driver; investigating and rebuilding it comes afterward.
What You Will Be Able to Do
- Map a screen position into a larger world, including across its boundary.
- Build and animate a scrolling scene using two frame buffers.
- Measure drawing and transfer time separately, then verify a faster renderer.
- Convert your own artwork into display bytes and check it by decoding those bytes.
This is a project for several sittings. First get the temporary world scrolling. Then measure and improve it. Save the original-artwork stage for another sitting if you need one.
Get Ready
Download the Pico landscape lab . Only display and world-buffer setup run. Write your experiments beneath it; the function prompts are comments, not a finished program.
Keep ssd1306.py in the same folder on the Pico, using the Phase 1 kit if needed. Wiring remains GP0 → SDA, GP1 → SCL, 3V3(OUT) → VCC, GND → GND. Run the whole file through Thonny or MicroPico in VS Code. Keep functions that later problems need and replace earlier experiment calls. No input() pauses or preserved Python session are required.1
Later, Q6 uses a different file on your computer: the desktop image lab
. It needs Pillow, not the Pico’s machine or framebuf modules. We’ll introduce that tool when we reach the artwork.
Without hardware, use the two browser models and work through the coordinate and byte tests. The desktop artwork stage can also be completed without a Pico.
A Small Window onto a Bigger World
Imagine looking through a train window. The landscape appears to move past you because your viewpoint changes. Our world is a stored picture; our window is the portion we choose to copy onto the OLED. Moving the window doesn’t require changing the world.
The model uses 24 × 16 world pixels and an 8 × 16 screen. It has the same vertical-byte layout as our OLED, at a size where we can inspect the columns. Gold outlines mark the world columns currently visible. A brighter outline follows one selected screen column back to its source.
Before moving the slider, predict what screen column 0 will show at offset 5. Then try offset 22. Where will the picture come from after world column 23?
Move the window, keep the world
World: 24 × 16
Screen: 8 × 16
world_x = (offset + screen_x) % 24Here 24 is the world width. The remainder brings an out-of-range column back into 0–23. The screen width decides how many columns we copy.
No auto-play: predict the next frame, then step. The model displays each prepared window immediately; your Pico program must call show().
A screen coordinate describes a position in the small output picture. A world coordinate describes a position in the larger stored picture. The offset says which world column goes into screen column 0. Both coordinate systems start at zero; changing one doesn’t resize the other.
Python’s remainder operator, %, can help with the boundary: 24 % 24 is 0, and 25 % 24 is 1. With a positive world width, it brings an integer position into the valid column range. The next problem asks where that operation belongs in our mapping.
Q1 Where does each screen column come from?
On paper, list the eight source columns for offsets 5 and 22 in the toy. Check with the model. Write a rule that works for every screen column, including when the window crosses the world boundary. Then apply it to a 384-wide world and a 128-wide screen at offset 300: which columns appear, and how many come from each end?
Show hints Hide hints
- Start with offset plus screen x. World column 24 is past the toy’s last column, 23.
- Wrap using the world width, 24, rather than the window width, 8.
- Count columns inclusively, or subtract the starting position from the width.
Show answer Hide answer
At offset 5: 5, 6, 7, 8, 9, 10, 11, 12. At offset 22: 22, 23, 0, 1, 2, 3, 4, 5.
In Python: source_x = (offset + x) % image_width. We keep y unchanged because our window only moves horizontally.
At offset 300, the screen shows world columns 300–383, then 0–43. There are 384 - 300 = 84 columns in the first part and 128 - 84 = 44 in the second. The screen’s last x is 127: (300 + 127) % 384 = 43.
Wraparound makes the stored picture a loop. The world can stay fixed while the chosen window moves.
Give the World Its Own Memory
The starter creates these two pictures. Neither is a list of saved animation frames.
| Picture | Dimensions | Storage | Purpose |
|---|---|---|---|
world | 384 × 64 | world_data | The complete landscape. |
oled | 128 × 64 | oled.buffer | The current window, ready to send. |
Here is the world setup from the starter:
import framebuf
VIEW_WIDTH = 128
VIEW_HEIGHT = 64
WORLD_WIDTH = 384
world_data = bytearray(WORLD_WIDTH * (VIEW_HEIGHT // 8))
world = framebuf.FrameBuffer(
world_data, WORLD_WIDTH, VIEW_HEIGHT, framebuf.MONO_VLSB
)
FrameBuffer interprets the existing world_data array; it doesn’t make a second copy of its pixels. It provides familiar methods such as world.line(...), world.fill_rect(...), and world.pixel(...). Both pictures use MONO_VLSB: one byte for eight vertical pixels, lowest bit at the top. See the FrameBuffer constructor and pixel operations.
Q2 Build a world you can recognize
First calculate the storage for the world and for the two pictures together. Henry says: “world.fill_rect(...) should make a building appear on the OLED, because the two objects use the same drawing methods.” Correct his explanation.
Then write this function in the Pico lab. Make a temporary landscape with a ground line and at least six landmarks spread across the whole width. Use a loop; vary a height or shape so the sections are easy to distinguish. It may be rough—we are building a test picture.
def build_world(world, width, height):
"""Clear and draw a recognizable world. Do not call oled.show()."""
pass
Show hints Hide hints
- Eight pages times the picture’s width gives its bytes.
- The methods act on the object receiving the call.
worldandoledhave separate storage. - Keep a building’s last occupied row above the ground; use the Phase 5 size-minus-one rule.
Show answer Hide answer
The world needs 384 * 8 = 3072 bytes. The OLED picture needs 128 * 8 = 1024. Together their raw pixel arrays need 4096 bytes, plus Python objects and other program storage.
Henry has confused shared tools with shared storage. world.fill_rect(...) changes world_data; oled.show() sends oled.buffer. We haven’t copied anything between them yet.
One test world:
def build_world(world, width, height):
world.fill(0)
ground = height - 4
world.hline(0, ground, width, 1)
for number, x in enumerate(range(0, width, 32)):
building_height = 8 + (number % 4) * 8
world.fill_rect(x + 4, ground - building_height,
20, building_height, 1)
world.pixel(x + 8, ground - building_height + 3, 0)
build_world(world, WORLD_WIDTH, VIEW_HEIGHT)
The buildings end at row 59; the ground is row 60. Each group of four varies in height, and the dark pixel gives us another alignment clue. Later, choose more varied landmarks for your artwork.
A frame buffer can hold a picture that has never been displayed. The world is data we can draw into and sample, independent of the physical screen.
Copy One Window Before Animating
Our first renderer will copy every screen pixel, including dark ones. Reading world.pixel(x, y) returns 0 or 1; passing a third argument to oled.pixel(x, y, color) writes that state. If you copy only the lit pixels, dark parts of the new frame cannot erase old landmarks.
Keep show() outside the renderer. That gives us two separately testable operations: prepare the window, then display it.
Q3 Make the window travel
Implement these two functions in the Pico file. Use nested pixel loops for the renderer, even if you can imagine a faster approach. The optional dimensions let you test tiny pictures as well as the OLED.
def draw_window(world, target, image_width, offset,
view_width=128, height=64):
"""Copy a horizontally wrapped window, including dark pixels.
Pictures have equal height; image_width >= view_width > 0.
Write only target's pixels. Leave world unchanged. Do not show().
"""
pass
def advance_offset(offset, image_width, speed):
"""Return (offset + integer speed) wrapped into 0..image_width-1.
image_width is positive. Negative speed is allowed.
"""
pass
assert advance_offset(383, 384, 1) == 0
assert advance_offset(382, 384, 5) == 3
assert advance_offset(2, 384, -5) == 381
Test single windows at offsets 0, 100, 256, 257, 300, and 383 before animating. Predict the first and last source columns. Why is the pair 256/257 a useful test?
Then translate this plan into a finite animation: build the world once; start at offset zero; repeat 384 times: render, show, advance by one, pause 30 ms. Why does increasing the offset make a landmark move left? What changes if the pause becomes 150 ms? If the speed becomes five?
Show hints Hide hints
- Q1 supplies the source x; y is the same in both pictures.
- Use the returned pixel value as the written color, including zero.
- The final 128-column window that doesn’t wrap starts at
384 - 128.
Show answer Hide answer
def draw_window(world, target, image_width, offset,
view_width=128, height=64):
for y in range(height):
for x in range(view_width):
source_x = (offset + x) % image_width
target.pixel(x, y, world.pixel(source_x, y))
def advance_offset(offset, image_width, speed):
return (offset + speed) % image_width
| Offset | First source column | Last source column | Wraps? |
|---|---|---|---|
| 0 | 0 | 127 | No |
| 100 | 100 | 227 | No |
| 256 | 256 | 383 | No |
| 257 | 257 | 0 | Yes, just one column from the start |
| 300 | 300 | 43 | Yes |
| 383 | 383 | 126 | Yes |
256/257 catches a boundary error: exactly reaching the final world column is different from crossing it.
With the functions above your experiment code:
build_world(world, WORLD_WIDTH, VIEW_HEIGHT)
offset = 0
for frame in range(WORLD_WIDTH):
draw_window(world, oled, WORLD_WIDTH, offset)
oled.show()
offset = advance_offset(offset, WORLD_WIDTH, 1)
sleep_ms(30)
This displays offsets 0 through 383, then stops. The next stored offset is 0; the final displayed window is still 383. Once testing works, replacing the for line with while True: makes the sequence repeat until you interrupt it with Stop or Ctrl+C in the Pico terminal. Keep finite runs while developing.
A landmark at world x = 100 appears at screen x = 100 when offset is 0 and at x = 99 when offset is 1: our viewpoint moves right, so the scenery appears to move left. A longer pause reduces frames per second; it doesn’t change distance per frame. Speed five changes distance per frame and can skip intermediate positions. Neither changes the stored world.
You don’t need to clear first: this renderer replaces all destination pixels. Removing show() would keep preparing new windows while leaving the physical OLED unchanged.
Animation can change which data we select, rather than changing the data itself. One world and one reusable output buffer are enough.
Measure Before Making It Faster
A bottleneck is a part of the process that limits its overall speed. A slow renderer and a slow transfer can both delay a frame, but they need different improvements.
ticks_us() reads a timer in microseconds. Its counter can wrap, so use ticks_diff(end, start) to find a short elapsed interval. The starter imports both. See MicroPython’s timing functions.
The scaffold below times rendering and show() separately. It keeps printing outside the measured sections and collects five samples. There is no animation pause in these samples.
Q4 Which part is taking the time?
Before running, calculate the screen pixels copied per frame and the image bytes sent by show(). Add this block below your functions and world-building call:
render_times = []
transfer_times = []
for offset in (0, 100, 256, 300, 383):
start = ticks_us()
draw_window(world, oled, WORLD_WIDTH, offset)
rendered = ticks_us()
oled.show()
sent = ticks_us()
render_times.append(ticks_diff(rendered, start))
transfer_times.append(ticks_diff(sent, rendered))
print("Render samples (us):", render_times)
print("Transfer samples (us):", transfer_times)
Repeat the measurement. Which operation takes longer on your setup? To understand a transfer’s scale, assume eight data clocks plus one acknowledgement clock per byte. At 400,000 clocks per second, how long would just 1024 image bytes take? What about our starter’s 200,000? Does either calculation predict the complete frame time?
Show hints Hide hints
- A pixel has one bit here, but the slow renderer makes two method calls for each pixel: one read and one write.
- Divide required clocks by clocks per second to get seconds; multiply by 1000 for milliseconds.
- Commands, addresses, control bytes, software work, and pauses are additional costs.
Show answer Hide answer
We copy 128 * 64 = 8192 pixel states using 16,384 pixel-method calls. The driver sends 1024 image bytes per show(), even if only one screen column changed.
At 200,000 clocks/s, the same image clocks take 46.08 ms. The corresponding optimistic ceilings are about 43.4 and 21.7 full frames/s, before other costs. These are calculated bounds under the stated clock assumptions, not measurements or recommended speed settings. Real transfers may take longer. The I²C specification, byte and acknowledgement sections explains the ninth clock.
Your timing results decide which stage to investigate. Report the sample range, rather than inventing one “correct” benchmark. If drawing dominates, increasing bus speed cannot remove that drawing work. If transfer dominates, faster drawing still helps, but doesn’t remove the transfer cost.
With a 30 ms pause, a frame takes roughly render time + transfer time + 30 ms, plus loop overhead. The pause alone is not the frame period.
Correct output and fast output are different questions. Keep the working renderer as a reference while improving the part you measured.
Let the Memory Layout Do Some Work
Phase 3 gives us a useful shortcut. In MONO_VLSB, one byte is a column of eight vertical pixels. Our pictures have the same height and y alignment; moving horizontally doesn’t change the bit positions. We can copy those bytes intact.
The model below uses the same tiny world as the first model. Select a page and try offset 22. The window takes two bytes from the end of that source page, then six from its beginning. It must wrap within the page, not continue into the next page of the flat array.
The same window, one page at a time
World: 24 × 16
Screen: 8 × 16
Gold cells belong to the window. Brackets below use flat array indices with exclusive stops. Changing the page adds a different starting index in each picture.
For a real 384-wide source and 128-wide destination:
Each picture needs its own width in the index calculation. At offset 300, page 1 starts copying from source index 384 + 300 = 684 into destination index 128.
Python slices use an exclusive stop: destination[0:4] = source[8:12] copies source indices 8–11 into destination indices 0–3. For a bytearray, unequal slice lengths can resize the destination. Here every replacement must have exactly the length it replaces: the driver still expects a 1024-byte picture.
Moving vertically by one pixel is different. The new vertical groups would contain bits from neighboring source bytes. Our shortcut relies on horizontal movement with unchanged y.
Make It Your Landscape
Once the temporary world works, draw an original one. You can keep using drawing primitives or use a pixel-art editor such as Piskel. For the PNG route, export one still image, exactly 64 pixels tall and at least 128 pixels wide; 384 is a useful starting width. Use opaque black and white pixels only. Avoid a sprite sheet, transparent background, or smoothing.
Think about the seam: place the right and left edges beside each other while designing. Modulo guarantees that we continue at the beginning; it can’t make mismatched mountains meet. The world repeats—it isn’t storing infinite new terrain.
A PNG is a file format with its own encoding. Neither FrameBuffer nor our SSD1306 driver decodes PNG files. We’ll use Pillow on the computer to inspect pixels, then write our own MONO_VLSB bytes. The raw .bin file will contain only pixels; width and height must be supplied separately.
Install Pillow in the desktop Python environment used to run the image lab:
python -m pip install Pillow
The image lab supplies the file-opening and validation helper. read_artwork(filename) returns an RGBA image, with each pixel reported as (red, green, blue, alpha). It rejects anything except opaque black (0, 0, 0, 255) or opaque white (255, 255, 255, 255), and requires a height divisible by eight. Width 128 and height 64 are requirements of the final project; tiny converter tests use smaller pictures. See Pillow’s image operations.
Load the Verified Picture
After converting and checking your artwork in Q6, you’ll move back to the Pico lab for Q7. Upload landscape.bin onto the Pico using Thonny’s device file view or MicroPico’s upload command. Saving it in a laptop folder alone doesn’t put it on the board. Keep the file beside your program on the Pico.
File loading isn’t our main puzzle, so use this supplied function. It also appears as commented scaffolding in the Pico starter:
def load_image(filename, width, height):
if width < 128 or height != 64:
raise ValueError("Use a world at least 128 wide and exactly 64 high")
expected_size = width * (height // 8)
with open(filename, "rb") as file:
pixels = bytearray(file.read())
if len(pixels) != expected_size:
raise ValueError("Unexpected image size; check the dimensions and file")
image = framebuf.FrameBuffer(pixels, width, height, framebuf.MONO_VLSB)
return pixels, image
We return both views of the same storage: the bytearray for direct copying and the FrameBuffer for drawing or pixel reads. They aren’t two copies of the world.
The loader catches a wrong byte count. It cannot identify the wrong picture if another file has the same size, and the hardware doesn’t know which dimensions you intended. Checking the conversion before involving the hardware gives us fewer possible causes to investigate.
Homework
Explain yourself
Explain the terms with the definitions closed. Trace one screen pixel into the world, then trace its containing byte. How do coordinates, pages, wraparound, and rendering fit together? Explain why changing the renderer needn’t change the artwork or the driver.
World
Example: A 384 × 64 image stored in world_data.
Window / viewport
Example: 128 consecutive world columns, wrapping when necessary.
World and screen coordinates
Example: At offset 300, screen column 0 comes from world column 300.
Offset
Example: Increasing offset by one makes a fixed landmark appear one pixel farther left.
Modulo (%)
Example: (383 + 1) % 384 is 0.
Renderer
Example: draw_window() writes pixels into oled.buffer without showing them.
Page alignment
Example: Horizontal movement at unchanged y permits whole-byte copying in MONO_VLSB.
Slice
Example: source[8:12] contains indices 8, 9, 10, and 11.
Bottleneck
Example: Faster rendering cannot eliminate the time spent transferring the frame.
Benchmark
Example: Time both renderers at the same five offsets, separately from show().
Encoding and decoding
Example: Pack PNG pixels into MONO_VLSB bytes, then reconstruct an RGB preview from those bytes.
Seam
Example: Correct modulo arithmetic can still join a mountain to an unrelated sky edge.
Exercises
Keep your working version before replacing a function. These project exercises can each take a sitting. ★ Challenging · ★★ Very challenging.
Q5 Copy pages, then prove the pictures agree ★
Write the faster renderer in the Pico lab. Normalize the offset first. Find how many columns fit before the source page ends and how many must come from its beginning. Apply those two slices separately to every page.
def draw_window_fast(source, destination, source_width, offset,
view_width=128, height=64):
"""Copy a horizontal MONO_VLSB window without showing it.
Distinct arrays, default stride, equal height divisible by 8.
source_width >= view_width > 0; height > 0.
Array lengths exactly match their dimensions.
Preserve source and destination length. Copy dark bits too.
"""
pass
Work through offset 300 by hand first. For page 1, give the exclusive source and destination ranges for both parts.
Then test offsets 0, 100, 256, 257, 300, 383, 384, and −1. For each, render the slow version, save expected = bytes(oled.buffer), render the fast version, and compare every byte. Assert that the destination length stays 1024 and the world hasn’t changed. Then time the fast renderer with Q4’s same offsets and compare results. Does show() now send fewer bytes?
Show hints Hide hints
- After
offset %= source_width, usefirst = min(view_width, source_width - offset)andsecond = view_width - first. - Add each picture’s page start to its slice coordinates. The wrapped part starts at the same source page’s beginning.
- Preserve the old result as
bytes(...), not another name for the mutable buffer.
Show answer Hide answer
For page 1 at offset 300, copy source [684:768] into destination [128:212], then source [384:428] into destination [212:256]. Those lengths are 84 and 44, totaling 128.
def draw_window_fast(source, destination, source_width, offset,
view_width=128, height=64):
if not (source_width >= view_width > 0 and height > 0
and height % 8 == 0):
raise ValueError("Invalid picture dimensions")
pages = height // 8
if (len(source) != source_width * pages
or len(destination) != view_width * pages):
raise ValueError("Unexpected buffer length")
if source is destination:
raise ValueError("Use separate source and destination arrays")
offset %= source_width
first = min(view_width, source_width - offset)
second = view_width - first
for page in range(pages):
src = page * source_width
dst = page * view_width
destination[dst:dst + first] = source[src + offset:src + offset + first]
if second:
destination[dst + first:dst + view_width] = source[src:src + second]
The contract uses distinct backing arrays; don’t pass overlapping views of one allocation. Keep the slow function for this check:
world_before = bytes(world_data)
for offset in (0, 100, 256, 257, 300, 383, 384, -1):
draw_window(world, oled, WORLD_WIDTH, offset)
expected = bytes(oled.buffer)
draw_window_fast(world_data, oled.buffer, WORLD_WIDTH, offset)
assert bytes(oled.buffer) == expected
assert len(oled.buffer) == 1024
assert bytes(world_data) == world_before
print("Both renderers agree")
For timing, replace only the draw_window(...) call in Q4 with draw_window_fast(world_data, oled.buffer, WORLD_WIDTH, offset). Compare measured samples; no particular speedup is guaranteed. We now copy 1024 bytes in at most 16 slice assignments rather than making 16,384 pixel-method calls. Slice copies allocate temporary data too; this simple optimization isn’t allocation-free.
show() still sends 1024 image bytes. We changed how we prepare the picture, not the driver or connection.
A useful optimization preserves the answer while changing the work. Byte-for-byte agreement is stronger evidence than “it looks about right.”
Q6 Encode the artwork and read your bytes back ★★
Work in the desktop image lab. Uncomment its supplied read_artwork() helper before your own functions. Write these functions. White means lit; black means dark. Decode into a new image using only the data and dimensions—don’t reopen the original PNG to make the preview.
def convert_image(filename):
"""Return (bytearray, width, height) in MONO_VLSB order."""
pass
def preview_converted(data, width, height):
"""Return a new Pillow RGB image decoded from the supplied bytes.
Validate dimensions and byte count. White = lit, black = dark.
"""
pass
Start with a 3 × 16 opaque black test image. Set only (0, 0), (1, 7), (2, 8), and (0, 15) white. Predict all six output bytes before converting. Why do these points test more than four dots in the top-left corner would?
Verify those expected bytes independently. Then convert your artwork, save landscape.bin, decode it, and compare the decoded RGB pixels with the original. Save an enlarged nearest-neighbor preview so individual pixels stay square. The desktop starter includes test calls to uncomment after implementing the functions.
Show hints Hide hints
- Phase 3 gives
index = (y // 8) * width + xand bit positiony % 8. - OR the mask into the existing byte; assignment alone could erase another lit pixel.
- Decode with AND against the mask. A matching round trip alone can hide the same mistake in both functions; the six known bytes are a separate check.
Show answer Hide answer
The expected bytes, page by page, are 01 80 00 | 80 00 01 in hex. We test top and bottom bits, different columns, and both sides of the page boundary.
def convert_image(filename):
image = read_artwork(filename)
width, height = image.size
data = bytearray(width * (height // 8))
for y in range(height):
for x in range(width):
if image.getpixel((x, y)) == (255, 255, 255, 255):
index = (y // 8) * width + x
data[index] |= 1 << (y % 8)
return data, width, height
def preview_converted(data, width, height):
if width <= 0 or height <= 0 or height % 8:
raise ValueError("Invalid picture dimensions")
if len(data) != width * (height // 8):
raise ValueError("Unexpected byte count")
image = Image.new("RGB", (width, height), "black")
for y in range(height):
for x in range(width):
index = (y // 8) * width + x
if data[index] & (1 << (y % 8)):
image.putpixel((x, y), (255, 255, 255))
return image
After your definitions, run the tiny fixture first:
tiny = Image.new("RGBA", (3, 16), (0, 0, 0, 255))
for point in ((0, 0), (1, 7), (2, 8), (0, 15)):
tiny.putpixel(point, (255, 255, 255, 255))
tiny.save("tiny-test.png")
data, width, height = convert_image("tiny-test.png")
assert data == bytearray([0x01, 0x80, 0x00, 0x80, 0x00, 0x01])
assert preview_converted(data, width, height).tobytes() == tiny.convert("RGB").tobytes()
Then convert your full image in the same desktop file:
data, width, height = convert_image("landscape.png")
if height != 64 or width < 128:
raise ValueError("Use a world at least 128 wide and exactly 64 high")
decoded = preview_converted(data, width, height)
assert decoded.tobytes() == read_artwork("landscape.png").convert("RGB").tobytes()
with open("landscape.bin", "wb") as file:
file.write(data)
decoded.resize((width * 3, height * 3), Image.Resampling.NEAREST).save("landscape-preview.png")
print("World width:", width, "Bytes:", len(data))
For a 384 × 64 world, expect 3072 bytes. Correct size alone doesn’t prove the orientation, bit order, or pixel values are right. A headerless binary file also cannot tell the loader its dimensions.
Test an encoding by decoding it—and include examples whose correct bytes you know independently. That combination catches errors a convincing-looking output file can hide.
Q7 Take a trip through your own world ★
Replace the temporary world with your verified artwork. Set WORLD_WIDTH to the exact exported width. Replace the starter’s world allocation with the loader call, remove build_world(...) calls that would overwrite the loaded pixels, and keep your renderers.
Run one full-width, speed-one trip with the fast renderer. Show the wrap at the seam and explain any visible jump. Demonstrate that the slow renderer produces the same picture at one ordinary offset and one boundary-crossing offset. Record before/after rendering times and transfer times; explain what improved and what didn’t.
Finish by explaining which parts of your program had to change when the artwork changed, and which didn’t. Your evidence should include the original PNG, raw file, decoded preview, and the working Pico program.
Show hints Hide hints
world_data, world = load_image("landscape.bin", WORLD_WIDTH, VIEW_HEIGHT)supplies both objects the rest of your code expects.- Remove the original allocation rather than keeping two large worlds alive. Prepare and show the new window before pausing.
- Check both the mapping and the artwork. A correct wrap can still join two unrelated edges.
Show answer Hide answer
Place the supplied loader above this call, replacing the two original world-allocation statements. Set the width constant earlier in setup to your actual image width:
world_data, world = load_image("landscape.bin", WORLD_WIDTH, VIEW_HEIGHT)
After your renderer definitions, use:
offset = 0
for frame in range(WORLD_WIDTH):
draw_window_fast(world_data, oled.buffer, WORLD_WIDTH, offset)
oled.show()
offset = advance_offset(offset, WORLD_WIDTH, 1)
sleep_ms(30)
Check offset WORLD_WIDTH - 1 followed by 0 explicitly. A displaced or missing column suggests a renderer error; a correctly mapped but abrupt change in scenery suggests the artwork seam. Use Q5’s byte comparison to distinguish them.
The data source and possibly its width changed. The renderer, offset update, draw–show order, and SSD1306 driver didn’t need new artwork-specific logic. Timing results belong to your board: report the measurements rather than promising a frame rate.
Separating artwork, rendering, and display transfer makes each part easier to change and investigate. You have built a small graphics system using the same memory ideas we will find inside the driver.
A Further Detour, If You Want One
Try parallax: a distant mountain layer moves more slowly than nearby trees. Decide how to combine lit and dark pixels before showing the completed frame. Or generate new terrain instead of repeating a stored image. Both are new design problems; get one verified layer working first.
What’s next
You can now choose a view of a larger image, explain its bytes, and measure the work of turning it into a frame. Throughout this project, the borrowed driver kept handling show(). What does that method actually call, and where do the drawing tools come from?
Continue to Phase 6: The SSD1306 Driver → · Back to Phase 5 ← · Project roadmap
Optional, for VS Code users: If you prefer short experiments at
>>>and names such asoleddisappear, see Phase 4’s grey Python-session note. Whole-file runs avoid that dependency. ↩︎