# Project by Michael; PiicoDev Sketcher - An interactive sketching toy!

**URL:** <https://forum.core-electronics.com.au/t/project-by-michael-piicodev-sketcher-an-interactive-sketching-toy/15369>\
**Category:** Projects\
**Created:** [13 October 2022 23:14 UTC](https://forum.core-electronics.com.au/t/project-by-michael-piicodev-sketcher-an-interactive-sketching-toy/15369 "2022-10-13T23:14:35Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/michael/32/3545_2.png) [@Michael](https://forum.core-electronics.com.au/u/Michael)\
**Post date:** [13 October 2022 23:14 UTC](https://forum.core-electronics.com.au/t/project-by-michael-piicodev-sketcher-an-interactive-sketching-toy/15369/1 "2022-10-13T23:14:35Z")

</div>

I’ve just shared a new project: “[PiicoDev Sketcher](https://core-electronics.com.au/projects/piicodev-sketcher-an-interactive-sketching-toy/)”

The PiicoDev Sketcher is a fun, interactive toy reminiscent of sketching toys from my childhood. The user draws an image using the two knobs - one for X-control and the other for Y. Turning one knob at a time produces horizontal or vertical lines. The real magic is when you turn both together - creating diagonal or curved lines. Clear the sketch by shaking it!

[![PiicoDev Sketcher Project Thumbnail](https://canada1.discourse-cdn.com/flex028/uploads/core_electronics/original/2X/d/dedb74f165b35430ef67e4715ea2cb6e8c9eb689.jpeg)](https://core-electronics.com.au/projects/piicodev-sketcher-an-interactive-sketching-toy/)

“[Read more](https://core-electronics.com.au/projects/piicodev-sketcher-an-interactive-sketching-toy/)”

---

<div class="post-metadata">

**Author:** ![Rooppoor212784](https://avatars.discourse-cdn.com/v4/letter/r/278dde/32.png) [@Rooppoor212784](https://forum.core-electronics.com.au/u/Rooppoor212784)\
**Post date:** [17 October 2022 08:24 UTC](https://forum.core-electronics.com.au/t/project-by-michael-piicodev-sketcher-an-interactive-sketching-toy/15369/2 "2022-10-17T08:24:32Z")

</div>

Is it possible to draw any specific human face using the Picodev sketcher?

---

<div class="post-metadata">

**Author:** ![Robert93820](https://avatars.discourse-cdn.com/v4/letter/r/ac91a4/32.png) [@Robert93820](https://forum.core-electronics.com.au/u/Robert93820)\
**Post date:** [17 October 2022 08:32 UTC](https://forum.core-electronics.com.au/t/project-by-michael-piicodev-sketcher-an-interactive-sketching-toy/15369/3 "2022-10-17T08:32:30Z")

</div>

Hi Roo  
I would imagine that would depend on your artistic talents.  
Cheers Bob

---

<div class="post-metadata">

**Author:** ![Steven](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@Steven](https://forum.core-electronics.com.au/u/Steven)\
**Post date:** [17 October 2022 13:15 UTC](https://forum.core-electronics.com.au/t/project-by-michael-piicodev-sketcher-an-interactive-sketching-toy/15369/4 "2022-10-17T13:15:05Z")

</div>

New piicodev modules!

---

<div class="post-metadata">

**Author:** ![Rooppoor212784](https://avatars.discourse-cdn.com/v4/letter/r/278dde/32.png) [@Rooppoor212784](https://forum.core-electronics.com.au/u/Rooppoor212784)\
**Post date:** [24 October 2022 10:48 UTC](https://forum.core-electronics.com.au/t/project-by-michael-piicodev-sketcher-an-interactive-sketching-toy/15369/5 "2022-10-24T10:48:02Z")

</div>

I see. I’d love to make Elon musk’s face. Thanks.

---

<div class="post-metadata">

**Author:** ![Michael193054](https://avatars.discourse-cdn.com/v4/letter/m/b5ac83/32.png) [@Michael193054](https://forum.core-electronics.com.au/u/Michael193054)\
**Post date:** [27 October 2022 22:12 UTC](https://forum.core-electronics.com.au/t/project-by-michael-piicodev-sketcher-an-interactive-sketching-toy/15369/6 "2022-10-27T22:12:14Z")

</div>

Awesome !  
Where’s the “add BoM to cart” button ?

---

<div class="post-metadata">

**Author:** ![Michael](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/michael/32/3545_2.png) [@Michael](https://forum.core-electronics.com.au/u/Michael)\
**Post date:** [27 October 2022 22:33 UTC](https://forum.core-electronics.com.au/t/project-by-michael-piicodev-sketcher-an-interactive-sketching-toy/15369/7 "2022-10-27T22:33:09Z")

</div>

Thanks! For now you’ll have to add them separately - but if there’s enough interest we could put together a bundle to make things easier 😃

---

<div class="post-metadata">

**Author:** ![Michael193054](https://avatars.discourse-cdn.com/v4/letter/m/b5ac83/32.png) [@Michael193054](https://forum.core-electronics.com.au/u/Michael193054)\
**Post date:** [31 October 2022 09:22 UTC](https://forum.core-electronics.com.au/t/project-by-michael-piicodev-sketcher-an-interactive-sketching-toy/15369/8 "2022-10-31T09:22:23Z")

</div>

I wasn’t suggesting a new SKU, just a single button that adds all those parts to your cart with a single click. Then you could still delete individual items if you didn’t need to buy them.

---

<div class="post-metadata">

**Author:** ![Beau219629](https://avatars.discourse-cdn.com/v4/letter/b/e495f1/32.png) [@Beau219629](https://forum.core-electronics.com.au/u/Beau219629)\
**Post date:** [11 February 2023 06:22 UTC](https://forum.core-electronics.com.au/t/project-by-michael-piicodev-sketcher-an-interactive-sketching-toy/15369/9 "2023-02-11T06:22:25Z")

</div>

I am running the sketcher-code.py script that you posted for this and I am getting the following in return:

```auto
Traceback (most recent call last):
  File "<stdin>", line 6, in <module>
  File "PiicoDev_Potentiometer.py", line 6, in <module>
  File "PiicoDev_Unified.py", line 1
SyntaxError: invalid syntax

```

I have tried the PiicoDev\_Potentiometer.py file on the Potentiometer guide page as well as the this page. Same with the PiicoDev\_Unified.py file. I noticed they are different file sizes. I had a similar message for the accelerometer that I fixed by doing the above.

Any help will be great. This is the first project, still feeling good about this.

Cheers

---

<div class="post-metadata">

**Author:** ![Michael](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/michael/32/3545_2.png) [@Michael](https://forum.core-electronics.com.au/u/Michael)\
**Post date:** [14 February 2023 22:35 UTC](https://forum.core-electronics.com.au/t/project-by-michael-piicodev-sketcher-an-interactive-sketching-toy/15369/10 "2023-02-14T22:35:02Z")

</div>

Hey @Beau219629 - weird that you’re running into this issue.  
I re-downloaded the source files and they seem to work fine - albeit I had to also download `PiicoDev_LIS3DH.py` separately (I forgot to include this in the original file upload. fixed now)

Are you working with a Raspberry Pi Pico?  
Can you share a photograph of your setup?

It appears there is a syntax error in your copy of `Unified`. Have you modified this file at all?

---

<div class="post-metadata">

**Author:** ![Ezra224017](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/ezra224017/32/8344_2.png) [@Ezra224017](https://forum.core-electronics.com.au/u/Ezra224017)\
**Post date:** [11 March 2023 22:52 UTC](https://forum.core-electronics.com.au/t/project-by-michael-piicodev-sketcher-an-interactive-sketching-toy/15369/11 "2023-03-11T22:52:32Z")

</div>

Hey! Awesome project. Will this exact code and setup by any chance work with the microbit v2?

---

<div class="post-metadata">

**Author:** ![Michael](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/michael/32/3545_2.png) [@Michael](https://forum.core-electronics.com.au/u/Michael)\
**Post date:** [12 March 2023 22:23 UTC](https://forum.core-electronics.com.au/t/project-by-michael-piicodev-sketcher-an-interactive-sketching-toy/15369/12 "2023-03-12T22:23:51Z")

</div>

Hey @Ezra224017, welcome to the forums 🙂 I haven’t tested this project on a microbit. It’s possible, but won’t be as pleasing as on a Pico.

The framerate will be significantly slower. What’s more, the microbit as very little spare memory so we distribute “minified” versions of the device modules (`PiicoDev_SSD1306.py`, `PiicoDev_Potentiometer.py`) on each tutorial page. Even with the minified files the micro:bit usually only supports a couple of PiicoDev Modules. This project may overwhelm the microbit’s memory.

---

<div class="post-metadata">

**Author:** ![John136772](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/john136772/32/5416_2.png) [@John136772](https://forum.core-electronics.com.au/u/John136772)\
**Post date:** [11 December 2023 00:37 UTC](https://forum.core-electronics.com.au/t/project-by-michael-piicodev-sketcher-an-interactive-sketching-toy/15369/13 "2023-12-11T00:37:42Z")

</div>

I made a version of this using a nano and the Arduino IDE! The problem was recording the points continuously meant I ran out of storage after about 100 points. So I added a button to record the current position to the array. Fun Challenge.  
Here’s a picture with some fabulous art work. 😉

![IMG_3919 Medium](https://canada1.discourse-cdn.com/flex028/uploads/core_electronics/original/2X/e/e51339be9be8e5b90e4e0b40cf8c597c52711495.jpeg)

---

<div class="post-metadata">

**Author:** ![Michael](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/michael/32/3545_2.png) [@Michael](https://forum.core-electronics.com.au/u/Michael)\
**Post date:** [11 December 2023 05:52 UTC](https://forum.core-electronics.com.au/t/project-by-michael-piicodev-sketcher-an-interactive-sketching-toy/15369/14 "2023-12-11T05:52:21Z")

</div>

Nice remix @John136772 !  
Yeah keeping a long list of points is problematic. For the PiicoDev Sketcher I just write points/lines to the screen and _never_ clear it. So the code only needs to know the last point and the current point. The rest of the drawing just persists on the screen 😃

---

<div class="post-metadata">

**Author:** ![John136772](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/john136772/32/5416_2.png) [@John136772](https://forum.core-electronics.com.au/u/John136772)\
**Post date:** [11 December 2023 07:04 UTC](https://forum.core-electronics.com.au/t/project-by-michael-piicodev-sketcher-an-interactive-sketching-toy/15369/15 "2023-12-11T07:04:29Z")

</div>

Of course…  
I’m so used to changing things on the screen as opposed to a cumulative effect of adding lines/points.

---

<div class="post-metadata">

**Author:** ![John136772](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/john136772/32/5416_2.png) [@John136772](https://forum.core-electronics.com.au/u/John136772)\
**Post date:** [11 December 2023 07:22 UTC](https://forum.core-electronics.com.au/t/project-by-michael-piicodev-sketcher-an-interactive-sketching-toy/15369/16 "2023-12-11T07:22:16Z")

</div>

So then I thought because I have stored the points I can erase them.  
So now the left button erases the last line by decreasing the point index by one.  
Here’s the code in case anyone wants to have a go themselves…

```auto
/ **************************************************************************

  Nano Sketcher (Etch a Sketch) by John Wegner

  Monochrome OLEDs based on SSD1306 drivers

  Simple version with button to record change. 
  
  Move pots to alter x and y position and press right button to record a point
  Lines are drawn between points
  Left button erases the last line

 ************************************************************************** /

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Button.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
// On an arduino UNO: A4(SDA), A5(SCL)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C //Check this - might be 0x3D
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

/*
   Variables
*/

#define PositionGridSize 100
int positionIndex = 0;
byte xPosition[PositionGridSize];
byte yPosition[PositionGridSize];

byte potX, potY;

Button buttonErasor(4);
Button buttonPlot(9);

void setup() {
  Serial.begin(9600);
  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;); // Don't proceed, loop forever
  }
  buttonErasor.begin();
  buttonPlot.begin();
}

void loop() {
  checkPots();
  checkButtons();
  display.clearDisplay();
  showCursor();
  showLines();
  display.display();
  delay(50);
}

void checkButtons() {
  if (buttonErasor.pressed()) {
    positionIndex--;
    if (positionIndex < 0) positionIndex = 0;
  }
  if (buttonPlot.pressed()) {
    positionIndex++;
    if (positionIndex > PositionGridSize - 1) positionIndex = PositionGridSize - 1;
    xPosition[positionIndex] = potX;
    yPosition[positionIndex] = potY;
  }
}

void checkPots() {
  potX = map(analogRead(A2), 0, 1023, 0, 127);
  potY = map(analogRead(A0), 0, 1023, 0, 63);
}

void showCursor() {
  display.fillCircle(potX, potY, 2, SSD1306_WHITE);
}

void showLines() {
  for (int i = 2; i <= positionIndex; i++) {
    display.drawLine(xPosition[i - 1], yPosition[i - 1], xPosition[i], yPosition[i], SSD1306_WHITE);
  }
}

```

---

<div class="post-metadata">

**Author:** ![Michael](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/michael/32/3545_2.png) [@Michael](https://forum.core-electronics.com.au/u/Michael)\
**Post date:** [12 December 2023 00:51 UTC](https://forum.core-electronics.com.au/t/project-by-michael-piicodev-sketcher-an-interactive-sketching-toy/15369/17 "2023-12-12T00:51:58Z")

</div>

> [@John136772](#):
>
> because I have stored the points I can erase them

Yes! the advantage of your approach is that you can clear the screen systematically if you like. Similar to a ctrl+z undo tool. Or from the earliest drawn line like your method. It’s a pretty cool feature 🕶

In my version of the project where I do not know the lines that make up the drawing, I can’t do this. I clear the screen by sprinkling black dots at random until the screen is eventually cleared - that’s all an attempt to simulate shaking an Etch-a-Sketch and having your drawing disappear gradually.

---

<div class="post-metadata">

**Author:** ![John136772](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/john136772/32/5416_2.png) [@John136772](https://forum.core-electronics.com.au/u/John136772)\
**Post date:** [12 December 2023 01:28 UTC](https://forum.core-electronics.com.au/t/project-by-michael-piicodev-sketcher-an-interactive-sketching-toy/15369/18 "2023-12-12T01:28:18Z")

</div>

I like your idea of the random points. Very cool!
