Tiny Sketcher works just fine and demonstrates the basic idea of how the sketcher works. However, that tiny screen and those tiny knobs can be a little tricky to work with. And the only way to start a new sketch is to restart the program.

The Bigger Sketcher improves on Tiny Sketcher by using a larger screen, larger pot knobs, and adds a button that will erase the screen and start over.

In addition the the ItyBisty M4, the Bigger Sketcher uses these parts.

Animation of lines drawing on a Monochrome 2.42" 128x64 OLED Graphic Display.
If you've been diggin' our monochrome OLEDs but need something bigger, this display will delight you! These displays...
Out of Stock
Breadboard Friendly Panel Mount 10K potentiometer linear.
This potentiometer is a two-in-one, good in a breadboard or with a panel. It's a fairly standard linear taper 10K ohm potentiometer, with a grippy shaft. It's smooth and easy...
$0.95
In Stock
Top-down shot of 15 colorful round tactile button switches in green, yellow, red, blue, and white.
Little clicky switches are standard input "buttons" on electronic projects. These work best in a PCB but can be...
$5.95
In Stock
Angled shot of full sized breadboard.
This is a 'full-size' premium quality breadboard, 830 tie points. Good for small and medium projects. It's 2.2" x 7" (5.5 cm x 17 cm) with a standard double-strip...
$5.95
In Stock

The connection uses SPI, which is covered in the guide for the OLED, so be sure to read that first.

Read the OLED guide to make sure the display is configured for SPI.

And here's the code for the Bigger Sketcher.

import board, busio
import adafruit_ssd1306
from simpleio import map_range
from analogio import AnalogIn
from digitalio import DigitalInOut, Direction, Pull

# Create SPI bus
spi = busio.SPI(board.SCK, board.MOSI)

# Create the display
WIDTH = 128
HEIGHT = 64
DC = DigitalInOut(board.D7)
CS = DigitalInOut(board.D9)
RST = DigitalInOut(board.D10)
display = adafruit_ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RST, CS)
display.fill(0)
display.show()

# Create the knobs
READS = 5
x_knob = AnalogIn(board.A0)
y_knob = AnalogIn(board.A1)

# Create the clear button
clear_button = DigitalInOut(board.D12)
clear_button.direction = Direction.INPUT
clear_button.pull = Pull.UP

def read_knobs(reads):
    avg_x = avg_y = 0
    for _ in range(reads):
        avg_x += x_knob.value
        avg_y += y_knob.value
    avg_x /= reads
    avg_y /= reads
    x = map_range(avg_x, 0, 65535, 0, WIDTH - 1)
    y = map_range(avg_y, 0, 65535, 0, HEIGHT - 1)
    return int(x), int(y)

while True:
    while clear_button.value:
        x, y = read_knobs(READS)
        display.pixel(x, y, 1)
        display.show()
    display.fill(0)
    display.show()

As before, this code is largely setup. One big difference from Tiny Sketcher is how the knob values are determined. In order to smooth out possible noise in the analog readings, several readings are made and averaged together. This is all taken care of in the new function read_knobs().

The other change is the addition of the button used to clear the display. This is handled with a simple modification of the previous loop.

while True:
    while clear_button.value:
        x, y = read_knobs(READS)
        display.pixel(x, y, 1)
        display.show()
    display.fill(0)
    display.show()

There is still the outer loop that runs forever - while True:. But now the pixel drawing is done in a new nested loop - while clear_button.value: . The way the button is wired, it will read True when it is not pressed. So this loop will keep running as long as the button is left alone. This is when you are drawing. Anytime you want to clear the current display, just hit the button. clear_button.value will return False, and the drawing loop will exit. The display is cleared by the last two lines, but then it starts all over again and you are back to drawing.

Be careful not to accidentally hit the clear button. There's no UNDO.

This guide was first published on Dec 30, 2018. It was last updated on Dec 30, 2018.

This page (Bigger Sketcher) was last updated on Dec 29, 2018.

Text editor powered by tinymce.