John Fletcher
S06:E47

John Fletcher

Episode description

In the kickoff of season 6, John Fletcher joins the show. John shares how he ported CircuitPython to web assembly, how it works, and how using Claude Code helped.

Follow the show on Mastodon and Bluesky.

Show Notes

00:00 Intro

00:23 John’s start with computers

4:07 John’s Discord nickname

5:05 CircuitPython and web assembly

6:43 How CircuitPython works in the browser

7:46 Advantages to using CircuitPython in the browser

9:25 Windows Subsystem for Linux

10:25 Using Claude Code

10:49 Managing the prompts

12:48 How to test CircuitPython in the browser

13:33 Where to learn more

Download transcript (.srt)
0:05

Welcome to the CircuitPython Show. I'm your host, Paul Cutler.

0:08

This episode, I welcome John Fletcher to the show.

0:11

John is a self-taught programmer who holds a Master's in English Literature

0:15

and a Master of Fine Arts in Writing from the University of Alaska, Fairbanks.

0:19

John, welcome to the show.

0:21

Hi, Paul. Thanks so much for having me.

0:23

How did you first get started with computers and electronics?

0:26

Well, I share a lot of commonalities with other folks that you've had on the show before.

0:31

My father, he worked in the insurance industry, and his office at home had a Commodore 64

0:38

that my brother and I were allowed to use.

0:41

So on that machine, I really learned to be frustrated with the command plane.

0:45

Otherwise, the influence came from kind of stereotypical dad stuff, guy stuff from the

0:51

80s.

0:53

My father had home stereo, home theater type equipment.

0:57

He had dual VCRs.

0:59

He was big into re-recording and editing home videos,

1:04

especially things for my brother and I to watch.

1:08

And he was the one that got the Nintendo

1:10

and brought it into the house.

1:11

I grew up a gadget guy,

1:13

firmly in the generation of thought that opening scene

1:16

and back to the future, fiddling with the amplifier,

1:20

one of the coolest things ever,

1:22

as well the interior of the Batcave from Tim Burton's '89 Batman

1:27

with all of the monitors set up.

1:30

That's a drool-worthy setup.

1:32

I think John Park is doing his best

1:34

to sort of recreate it in his workshop.

1:38

But the rest of it, you can blame Pokemon for.

1:40

And I love the fact that we sort of have this shared lineage

1:45

where it was video games that got us into programming.

1:49

with you was EverQuest, with me it was Pokémon. But the first generations of Pokémon required a

1:56

connection, connection cables and things for doing the trading. But they also had hacking.

2:03

And so trying to catch them all really was what provided my first exposure to

2:09

trying to understand and work with any sort of a code base.

2:14

How did you discover CircuitPython?

2:19

I discovered Adafruit before I discovered CircuitPython.

2:23

What I mean by this is I'm an avid DIYer.

2:27

I've got fundamental skills for pretty much all areas of home improvement.

2:32

I'm a pretty skilled amateur woodworker as well.

2:35

So I found Adafruit a little more than five years ago

2:39

while I was looking for some simple, practical electronics and things

2:43

that I could integrate into some of my home projects.

2:48

So we're not even talking at the microcontroller level here.

2:50

We're talking about motors, actuators, et cetera,

2:54

for really basic mechanisms.

2:56

But again, it was Pokemon that brought me back

2:58

and back to stay.

3:01

So kind of a long story short, and if you know, you know,

3:04

I was looking for a way to recombine power and data

3:10

from power over ethernet splitter

3:13

And because I remembered Adafruit,

3:15

I went back to the website, ordered a couple of things

3:18

to try to do that.

3:19

But I also added a couple of extras into my cart

3:23

because such is the nature of Adafruit,

3:26

things are priced so reasonably that it's, well,

3:29

while I'm making the order, I might as well.

3:31

So I picked up a QTPY, a SamD21, a time of flight sensor

3:36

to play around with.

3:38

Long story short, I never got the power and the data

3:41

to recombine.

3:42

But the time of flight sensor, I integrated

3:45

into a nighttime stairway illumination project

3:50

that's now in its maybe second kind of version.

3:54

And yeah, really writing the code

3:56

for that time of flight sensor was definitely

3:58

an aha moment for me.

4:01

So I knew that working with CircuitPython

4:04

was something that I wanted to do.

4:05

- Very cool.

4:07

One of the fun questions I sometimes like to ask

4:09

is about your Discord nickname.

4:10

It's spelled J-O-H-N-N-H-O-J, John and then John backwards.

4:16

Set the record straight, what is the correct pronunciation?

4:19

BF: Yeah, to me, there's no end of comedy for me with this.

4:28

When I wrote the name, I didn't have any pronunciation in mind.

4:33

I mentioned to Tim Foamyguy on one of his live streams that it should perhaps be pronounced

4:41

like "you know".

4:43

And so as a result of that, he's got this kind of Northern European Scandi-influenced

4:49

take on it that I like.

4:51

John Park always goes much more British sounding with "John Nodge", which I think is maybe

4:57

more appropriate for considering my own name's heritage.

5:02

I tend to think of it as John O.

5:04

Yeah.

5:05

- CircuitPython has the online code editor

5:07

at code.circuitpython.org.

5:09

You forked that repository

5:11

and created a port of CircuitPython

5:12

that runs in the browser using WebAssembly.

5:15

First, what is WebAssembly or Wasm

5:18

and what led you to create a WebAssembly port

5:20

of CircuitPython?

5:22

- Yeah, so I won't claim to be completely familiar

5:24

with WebAssembly myself.

5:27

So anybody who is expert in this

5:29

will probably find this a little painful

5:31

please reach out and correct me if I'm wrong. But in essence, the same way that CircuitPython

5:36

is compiled in order to run on microcontrollers, the C code can be compiled to run wherever

5:42

JavaScript runs. So that compilation process sort of breaks down the higher order C language

5:49

into something friendlier for machines, much less friendly for people. For CircuitPython,

5:53

the target is the assembly language or the instruction set for a given chip, your RP2040s,

6:01

your CMT21s, and so forth, so that your code can work in tandem with the hardware. And as its name

6:08

suggests, WebAssembly or WASM, however you want to pronounce it, runs on virtual machines in the

6:16

JavaScript runtime environment. And since CircuitPython is C code, by using a different compiler,

6:23

we can break down the CircuitPython code to work in those JavaScript virtual machines,

6:28

and instead of the physical hardware. CircuitPython is normally compiled using CMake,

6:34

but for WebAssembly we use Emscripten or EMSDK, which I think uses LLVM or Clang under the hood.

6:43

So what led you to create a WebAssembly port of CircuitPython?

6:46

Yeah, so creating the WebAssembly port really grew out of a larger, long-term project,

6:53

working on an extension for VS Code, and really thought that it would be beneficial to use

7:01

WebAssembly within that extension. One of the, not necessarily issues, but potential sticking

7:08

points of working with CircuitPython and Python in general is the need to create virtual environments.

7:18

And I thought having something more portable, since VS Code is a web browser basis based on

7:25

a Chromium browser, why not be able to have a portable Python interpreter that wouldn't need

7:33

the creation of virtual environment because it's already pre-compiled. It's more or less a closed

7:39

system. And then you can sidestep some of the issues inherent there. So the biggest advantage

7:48

to the WebAssembly port, it gives folks access to CircuitPython interpreter in the browser

7:55

without needing a physical board. In that case, the browser in some sense is the board. And

8:03

to create a port of CircuitPython specifically,

8:07

MicroPython, for example, has its own WebAssembly port.

8:11

PyScript is a well-known variant of the MicroPython WebAssembly

8:17

port.

8:18

The issue with that is, even though it's

8:22

based on MicroPython, there are certain things

8:24

in CircuitPython that we'd like to have specifically.

8:28

And for the PyScript, PyScript has a very specific goal in mind,

8:35

which is to provide a Python interpreter in the browser and very little more.

8:43

And that causes a problem for anyone who is interested in integrating more of the hardware awareness.

8:51

And so the CircuitPython port was able to add back in some sense of board, pin, these sorts of protocols.

9:02

So how does CircuitPython work in the browser? Does it drop you right into a REPL?

9:07

Yes, it should. After you spool it up, very, very quickly, it should drop you right into a REPL.

9:15

Of course, in the webpage that needs the intermediary program of having a pseudo terminal to work

9:22

just as a UI.

9:25

So when you ported it over, you used the Windows subsystem for Linux, WSL, and branched off

9:31

of CircuitPython from there.

9:33

Any challenges working with the Windows subsystem for Linux?

9:36

I know folks have sometimes run into problems compiling CircuitPython itself in WSL, but

9:41

how was your experience in using it?

9:43

I didn't really run into any issues in using the subsystem for Linux. I had used it before.

9:53

I tried building the Unix port of CircuitPython, and of course I used the subsystem for Linux in

10:00

that regard as well. And so it was, I found it to be very straightforward to use.

10:08

The biggest problem I found was interoperating between the Windows subsystem for Linux and

10:13

Windows itself in order to keep my files straight.

10:19

And I suppose that's more of a workflow issue on my part than anything else.

10:25

How did using Claude Code help in porting this over to WebAssembly?

10:30

At base, the WebAssembly port would not exist without Claude Code. I simply don't have the

10:36

skills. It certainly wouldn't have happened within the month or so that it took. Maybe

10:43

but it really was essential to getting this off the ground.

10:49

- Any challenges with the prompts?

10:51

I know there's not a lot of CircuitPython code

10:52

out in the world for the LLMs to learn from.

10:56

How did you work with the prompts

10:58

to get it to do what you wanted it to do?

11:01

- That was a large learning curve,

11:03

and I think that's true for anyone who first comes

11:07

to using anything like Claude Code.

11:11

And as to figuring out some of the quirks,

11:14

I tend to think that Claude works very well

11:19

to work on a code base

11:21

as opposed to working with a code base.

11:24

In this case, because it was C code and not CircuitPython,

11:28

it was a little bit more, I guess,

11:30

straightforward on Claude's behalf.

11:34

But nevertheless, it still wanted to default

11:37

to always be adding something to the code base

11:44

rather than working within the confines

11:48

of what was already there.

11:49

That quickly became a source of annoyance.

11:53

There are workarounds you can leverage agents

11:57

and things to kind of keep the Claude on track

11:59

and give it a little bit more of a direction.

12:02

The other issue was the context window management.

12:08

While I was working on it,

12:10

Anthropic kind of kept bumping up the context window,

12:16

but certainly there were sessions in working with Claude

12:21

where we'd come to the end of the context window,

12:24

we'd need to compact the conversation,

12:27

and I should have just called it a day at that point

12:30

because it really was sort of like working in Groundhog Day,

12:37

where we're starting all over again.

12:40

Nobody has any knowledge of what came before.

12:43

So also a source of frustration.

12:47

- How can folks test out

12:49

running CircuitPython in the browser?

12:51

- So if they are able to navigate to the repository,

12:56

the repository has instructions

12:58

for being able to spin up a local server.

13:03

They can self-host the webpage.

13:06

They can get in, select the virtual workflow,

13:11

and that will drop them right into a CircuitPython REPL.

13:16

Not an emulation of it,

13:18

or sort of under the hood,

13:22

kind of clever text-based thing,

13:26

but the REPL itself.

13:29

- I'll make sure I link to your repository

13:31

on GitHub in the show notes.

13:34

John, if anyone wants to learn more about you

13:35

and your work, where should they go?

13:38

- Yeah, I've got a couple of other

13:40

CircuitPython related repositories through my GitHub,

13:44

so people can feel free to poke around there as well.

13:49

If folks really wanna learn more about my work,

13:52

I'm looking to make a career change.

13:53

So if you or anyone you know and love

13:56

looking for someone, I'd love to do that.

13:59

Good to know. Last question I ask each guest.

14:03

You're going to start a new CircuitPython or microcontroller project.

14:06

Which board do you reach for to prototype or build with?

14:10

Probably a QTPY or Trinkey

14:13

with an RP2040. I mostly work

14:16

on a Surface tablet convertible,

14:19

so something small and light that I can plug in

14:22

that doesn't weigh down the side. I do wish the

14:25

the Trinkey had some exposed ports or pins, so kind of in a pinch I've resorted to using

14:32

WaveShare's variant. Sorry, Adafruit. I do hope that we can see some of the RP2350

14:38

versions in those form factors soon, once the new stepping becomes available. But of course,

14:44

if I'm just looking to play around with the CircuitPython interpreter itself,

14:49

there's a handy WASM port that I can use.

14:52

There absolutely is.

14:54

John, thanks so much for coming on the show.

14:56

Thank you so much, Paul.

14:57

I hope I can do something else cool soon and come back.

15:00

I look forward to it.

15:03

Thank you for listening to the CircuitPython Show.

15:05

For show notes and transcripts, visit www.circuitpythonshow.com.

15:10

To follow the show on Mastodon or BlueSky, check out the links in the show notes.

15:13

And if you're enjoying the show, I'd be grateful if you could leave a review.

15:17

Until next time, stay positive.