Two's Complement - Pictures and Candy with Arduino
Episode Date: April 26, 2021Join our hosts as they talk about hobby hardware projects, past and present. Matt explains how he's building a digital picture frame out of a Raspberry Pi Pico and E-Ink display. Ben talks about build...ing a Halloween candy dispenser using devices both serial and cereal. Matt and Ben discover they both liked MP3s in the early 00's.
Transcript
Discussion (0)
I'm Matt Godbolt.
And I'm Ben Rady.
And this is Two's Compliment, a programming podcast.
Hey, Ben.
Hey, Matt.
How are you doing?
Great.
Great to hear it.
So I know that one of the things that you do when you're not writing tests is build cool things.
I try to.
And you've shared with us at work a video of one of the coolest things I've ever seen, which is a...
Tell us what you built.
An automated candy dispenser.
Why would you build such a thing?
What on earth?
What's the reason for such a thing?
Yeah, well, so I used to live in a neighborhood in Chicago.
I still live in Chicago, but I live in a different neighborhood now.
But I used to live in a neighborhood that was absolutely bonkers on Halloween.
Is bonkers a word that you as an American would use,
or are you saying it because you've hung around with me too long?
No,
I'm saying it because I'm looking at you and I'm like,
what's the right word for it?
When I look at Matt,
Matt Godbolt,
I think bonkers.
So no,
it's because we,
this,
and it was like full size candy bars are like amateur hour in this
neighborhood.
If that's all you're doing, you're just way behind the curve.
And we knew this.
And so putting a bowl of candy out is not only an unacceptable solution if you want to go trick-or-treating with your kids, which we did.
Both my wife and I wanted to go trick-or-treating with our kids.
And this is when they were younger and much cuter.
And so, you know,
we wanted to go out. And so, I can't just put a bowl of candy
out there. What am I going to do? And I had been looking
for an excuse to use one of
the many Arduinos that I had just ordered only to have them and
just sort of assemble them and you know possess them collect them like i should put these things
to use um and so i built two versions of it one version was a candy dispenser and this little like led backlit for some reason super mario themed um you know game
the whole structure of it was like a carnival game i called it candy or death and it would
alternate between two possible outcomes you hit there's a giant button hit the button and it like
plays a song and it like alternates between these things candy or death like like
the sort of the skill game on a fruit machine yeah stop it on the right okay yeah except it
you know there was no skill to it it just it just almost like a like a like a roulette wheel in a
way oh okay so yeah exactly like that and then it would always land on candy and then it would
dispense candy and the idea behind this right yes and more on that later um oh okay uh but the idea behind this is it was sort of like
dinner and a show because i needed to have a hopper that would hold so much candy and i needed
to know approximately even with the ridiculous traffic if there was like a line around the
block of kids just hitting this button over and over and over again how long do i have
out trick-or-treating with my kids before i have to go back and refill the candy hopper replenish
right the hopper right got it exactly and so it would take a minimum of the first version i think
was like a minimum of like 50 seconds 55 seconds somewhere
in there to just to go through the whole thing and then eventually dispense the candy and so
and you know it wouldn't do it if it wouldn't do it if it was in the middle of doing it so you could
just sit there and literally just hit the button over and over and over again and it would have at
least like an hour to an hour and 15 minutes worth of candy so we can go to one piece of candy per
minute yeah like even with someone just hammering the button a couple minutes worth of candy so we can go to one piece of candy per minute yeah like
even with someone just hammering the button a couple of pieces of candy and you just know well
i can get 120 150 pieces of candy into the dispenser i'm good for an hour yeah got it yeah
yeah yeah and it was the candy was kind of random and then that was sort of like i think part of the
appeal is it almost always i had it i had it tweaked enough to where it would always give
you at least some candy but sometimes you get a bunch of candy sometimes it'd just be a little
and i thought that was just i i didn't want to fix that that wasn't a bug for me right
this is all part of the entertainment right uh but yeah and so the first version was just sort
of this backlit you know i basically like took some almost like i forget this paper
but like almost like rice paper and i built like like a shadow box type thing with an led in the
back and so it would sort of light up um and that was all controlled by the arduino and then the
second version was that plus i replaced the leds with a actual TV screen controlled by a Raspberry Pi that played an animation.
And this had a skeleton hand that would spin around and music that would play.
That's pretty serious an installation at that point, rather than a microcontroller and a couple of LEDs and a server.
But we need to talk about how you actually built the thing because that to me is like the really interesting part yeah yeah yeah yeah it was cool um the so the candy dispenser itself ran
on a arduino and the arduino had a uh stepper motor shield that you could put on it um all this
is on my like all the code for this is on my public GitHub, by the way,
which is BenRady.
So github.com slash BenRady.
And it had this really cool stepper motor that I found
and the Arduino shield that went with it.
What is the stepper motor compared to a regular motor?
What is the difference?
Yeah, so it's basically just like a super powerful servo.
So you can control with a regular servo usually,
and also with a regular servo usually there's like a range of motion
that you're limited to, right?
Sometimes they go, just keep going.
But a servo is like a thing where I can pick what orientation
I would like it to be pointing at between say like 0 and 45.
Yeah, yeah.
It's like a motor that you can basically just rotate as much
or as little as you want and to specific locations, to specific okay that's it yeah right so like if
you've got you know anybody that does anything in robotics there's a lot of servos going on right
because you're just like i'm going to rotate this motor 15 degrees to the left and then whatever
it's attached to also hopefully hopefully does the motor know which way it's facing or i guess
in your case it doesn't matter yeah in, in my case, it didn't matter.
Basically, the thing that I figured out is I did a lot of testing with different kinds of candy.
Testing, you said?
Yeah.
Always the testing with you.
What is it?
I mean, you know, you want things to work, you got to test them.
Maybe we'll call it experimentation.
No, I like it.
I like it i like it uh yeah the the so i had i had this like cereal dispenser that i had found that was like
basically these rubber fan blades and the cereal would sit in a hopper on the top and you'd spin
it and you've maybe seen this in cafeterias or in other places where it's just they fill
right a big plastic hopper full of breakfast bowls yeah and then you just twist it two portions yeah and so i had one of those and i had hooked that up to not directly it was through a
a little belt pulley system but i had hooked that up to the stepper motor
um a to get more gearing so that it could you get a bit more torque, but also to elevate it up
so that it could fall down and still hit the right spot in the window where the candy came
out.
Got it.
But I had hooked that up to the separate motor, and I figured out that you can't, if you just
turn it in one direction, it tends to jam.
And so what it would do is it would turn a little bit in one direction, and then it would
back off and turn in the other direction, and then it would back off and turn in the other direction and then it would back off turn in the other direction and it would basically
alternate back and forth to get out if there was anything that was yeah and so it wouldn't it was
much less likely to jam that way but then that also depended on the kind of candy so i tested
lots of different kinds of candy and that's onerous testing oh man yes that. I'd be ordering these five-pound bags of candy
off of Amazon,
and I'd run it for like two hours
and it would jam and be like, well, this is useless.
I can't use this candy for anything.
Except, you know,
eating it all, which I
definitely did.
At a certain point, I was like, maybe I should just do Tootsie Rolls
because then I won't eat them. Yeah, but then
neither does anybody else. Well, yeah, that's true. So point, I was like, maybe I should just do Tootsie Rolls because then I won't eat them. Yeah, but then neither does anybody else.
Well, yeah, that's true.
I did.
So eventually, I wound up with Jolly Ranchers.
Jolly Ranchers were a good combination of hard candy but with a wrapper that was flexible enough to where you wouldn't get this sort of like –
because I tried Starburst and Starburst would lock into position where the square blocks of the starburst would just like form a wedge
and like no matter how hard you turned it it just wouldn't it's not gonna move right yeah i got it
what an interesting thought yeah so like the little um tassels not the tassels like the plastic
wrapper yes forms like a spring on either side right and also a force that tends to when if
you've ever tried to squish and push it like twist it away so as they're kind of being squished
together they move around a lot yep as opposed to as you say something like a
starburst where essentially you're playing tetris except that the line does not disappear when you
got it completed exactly yep yep that's exactly right so yeah so so after some some some
experimentation and testing with that um you know i had the stepper motor working i had the candy that i wanted to use
and it was just you know sitting down and writing like a little arduino program to do this and i
love the arduino ide it's super fun i was gonna say we should really talk about that because if
if people i mean obviously there's physically building the stuff's cool and interesting we
should definitely get back and talk a little bit more about how you actually put it together but
the arduino programming experience is is pretty exciting and you should yeah tell us about it what all does it
look like how does it how do you do this oh yeah i mean it's so fun to be able to just you know
you could the id is really easy to use you just download it you plug in your arduino via usb
and you can you know run and you can run your
you can upload your code to the Arduino
super fast so you have a nice
feedback cycle and you can just be plugging
components into the thing
if you've, I think the first one I did
was one of the earlier models
so I didn't have it on a breadboard
I just had
basically just wires running
out of the thing.
I actually forget how those connected, if they were like little female connectors that you could put those wires into.
But it was really easy to plug stuff into.
So you could, you know, plug in LEDs, plug in like other, like the button, you know, I can control that.
And you can, with a pretty fast turnaround time, experiment it right just try things out right and you know like writing in in what language are you writing all this well it's like
it's sort of a weird c++ the arduino language right it's like you know not nearly as fully
featured but you have certain c++ language elements that are there um and it's you know it's if you've written any
programming language it's not hard to figure out right and presumably this is we're talking like a
page or two of code we're not talking like giant giant gobs of it not multiple files or are you i
mean i don't know if my own like led Yeah, I didn't split it into multiple files.
Actually, the most complicated thing that I did with the first version was...
You know the Mario Brothers flagpole fanfare?
Yeah.
That was the sound that it played when it dispensed the candy.
And I had basically hand-coded that into the program as frequencies.
Oh, yes.
And I had found a couple of places where it's like I thought i had the frequencies right and i my wife is very musically inclined she played piano for
years she played french horn she's a singer and i played it for the first time and she was like nah
she recoiled in horror she's like that's that note is that's wrong that's just you're not
you're off and i'm like if you say so, I can't tell the difference.
But yeah, so that was, honestly, most of the code in that file was taken up by that, just playing that fanfare.
And the rest of it was like, turn motor on.
Yeah, it was like, turn motor 180 degrees, wait two seconds.
Turn the motor 180 degrees the other direction, wait two seconds.
Got it.
You know, flash the lights, you know, for the thing for the thing but that was all that stuff was pretty straightforward that's that's awesome
and and so the feedback cycle is really really quick when it's like they're plugged in a usb
board into your computer and then presumably you've got wires dangling out and you've got like a
something constructed nearby with a stepper motor that's kind of at least just turning so you can
see how it's going to fit together at least while you're developing it how do you take that
that's sort of connected to a pc and then make it run elsewhere it just seems like you know hey how
do i install my software on it how do i deploy it right right well you screw it to a piece of wood
that's the that's the main thing that you do is it persists does it once you've
once you've copied the code onto that that little arduino you don't have to flash rammy type thing
or that's just it you kind of deploy it and then you unplug it and then you turn it off and then
put it somewhere else and turn it back on again and off it that's so cool yeah all you gotta do
is turn it on it'll run so there's it's it's really simple and um you know it's not that hard to write a little while loop to listen for inputs and wait for the state of a button or a pin to go high and then do something.
And so, you know, it's a really simple environment to work in and really rewarding, I think.
When something actually physically happens in the real world, there's definitely a warm feeling you get from, like, I'm controlling something in the real world yeah there's there's definitely a warm feeling you get from like i'm
controlling something in the real world i mean it feels like magic my kids do some like lego
mindstorm stuff and that's all like drag and drop things but that's it's still really cool to move
a motor around and kind of go oh yeah that's that's that's a real thing that happened because
you type some code in and but when you've actually built it yourself it's got to be even better yeah it was super fun so you've you've got this uh motor that's powering this uh serial dispenser
and you've kind of worked out the correct sequence of wiggles and the right candy to put into it the
right sweets to put into it for those listening in engb it's also a bit late to say this now but
like for those who don't realize quite how big a deal halloween is over here in the states um yeah our international audience are like what are they talking about it's
like no it really is crazy you have you have to leave tons we leave like a big bowl outside we
have the exact problem that you do which is that we come back and within like 30 seconds the bowl
was empty because someone's just emptied the whole thing into their bag and i'm gone on and then it's
like there's not really goodwill to your your uh the neighborhood kids if you if there isn't something for them so this is obviously a
very real problem in a real world problem that you're solving with this uh this this uh approach
but so anyway yeah you've built this thing it's all connected together do you put it outside and
just do people steal it i mean that would be my concern in this kind of thing is that someone
would go that that was also my concern i mean you know we live in a fine neighborhood but if you
give teenage kids access to a giant hopper full of candy they're gonna take it right it's the same
problem as the ball so we had the fortune of um our house having a window directly onto the front
porch right it's like kind of to the side of the front door and it
was kind of a narrow window it was only about two feet wide and it had these child locks built into
the window to where the window would only move up so far so that you could open the window and you
know be safe with kids so they're not going to like little kids so they're not going to like
push the window all the way open and fall out right Got it. And so I built it into that specific window
with those child locks.
So the way it would work is there was a faceplate
with the button and the speaker in it,
and then that was on top of a piece of MDF
that held the Arduino and the motor
and the assembly for the hopper and all that stuff and all
the you know power circuit you know all the power cables and all everything was just sort of screwed
into that piece of mdf and so you could set it in the window and then close the window and lock it
into place with the child locks i see and it would not only partially closed but yeah open it anymore
after that right right it was the faceplate was the exact height of the gap that was created by I see. robbing the candy because yes you're just breaking into my house actually breaking and entering sort of outside of the spirit of halloween yeah yeah even over here yeah um so yeah and then the cool
thing is i could pull the shade down behind the window so that i would prevent any light from
sort of leaking through because again it's like i want it to be dark on the front porch and i want
the light from the candy dispenser to be the only thing you really see right ghoulish illuminated by the flashing red and green yeah candy or death right
or the screen you know in the second version in the second one yeah so we should so you when i
mentioned death before you said there was a story is this the right time to tell that story yeah so
so the thing was is that you know my my wife and i it's not like we had another supply of halloween candy right so
when we came back from dispensing or when we came back from going trick-or-treating we would go in
our house i just leave the candy dispenser there and this was great because you get to hear the
reactions from the people we'd be just sitting in our living room so cool yeah and people would come
up and you'd get to hear their reactions and And by far, the thing that we heard most often was kids being disappointed that it didn't land on death.
Right?
They'd just be like, so they'd just do it over and over again.
And they'd be like chanting death, death, death, death, death, death.
And it would land on a kid and they'd go, oh, fine.
What is wrong with children these days?
Yeah.
Yeah.
So I don't know. so they went to death did you ever were you ever tempted to to meet out you know like one in a hundred deaths something like that i did have
the idea i did have the idea of having it look like it like glitched out and then switch to death
and then throw like a jump scare picture up on the screen you know something that's not too terrifying but
something from like a horror movie that would just you know the deserves like pop up on the screen
and scare you and what i wanted to do was put a webcam over the thing so as soon as it did that
it would take a picture and then post it to a twitter account and then i could have the candy
or death twitter account with people going like you know know. About five minutes before someone pointed out
you probably shouldn't be doing that without consent
and all those boring but very important things.
Again, Halloween.
Actually, you know, it's funny because like...
All bets are off, right?
You waived your rights when you walked up my front steps.
Disclaimer at the foot of the stairs.
It wouldn't be the craziest thing that has happened
in the neighborhood on Halloween, for sure.
Not even by a long shot.
There's pretty macabre things around here.
I've seen, like, bodies on spikes in the front garden.
I'm like, this is not...
That's not cool.
Yeah.
But, yeah, so...
But I never did that.
In fact, I don't own it anymore, because when we sold our house, that was part of the deal for the house.
Oh, my gosh. I sold it with the house, because it fits that one window. It house that was part of the deal for the house i oh my gosh i
sold it with the house because it fits that one window it's that window of course rebuild it
to do and we don't even have a window in our new house that it would that it would be you don't
have a window for this oh you don't do that it wouldn't be i was gonna say you just gave it a
brick brick cube i live we're done with looking it people. It's actually all window. I live in a giant glass cube. It's like an Apple store.
Right.
I mean,
from the webcam,
since you've moved,
I haven't seen a new house.
Like there may well be no,
no windows.
I can't see any windows.
So I assume it would make sense.
There's not,
there's no windows here,
but no,
we couldn't have used it.
You sold it with your,
your,
your,
your house because it doesn't fit the new house.
And did you leave them with like an owner's manual?
I made them an instructional video, actually.
That's so cool.
Yes.
And actually the presentation.
So you've seen my presentation that I did.
I have, which is what clued me into knowing about it.
Yeah.
I left that.
The reason I did it is because I was selling the house and I was like, oh, I'm not going to have this anymore.
And also the new owners need to know how to use it.
So I'm going to do a talk on it
and then I'm going to leave them the link to that talk
and some video so they can see some other things.
So is there a YouTube link
actually in the closing documents for your house?
That would be the legal documentation that says...
Sign the rights of the video over to them as well. be the legal documentation that says yes sign the
rights of the video
over to them as well
the seller represents
that this is how the
candy dispenser works
and yeah it's part of
the inspector was like
this this candy
dispenser is not up to
code there's yeah did
you show him the
tests did you write
any tests uh did i
write tests so i in
the arduino ide i had a test mode right so if you
um turn the thing off and turned it on and you held down the button and this made me think when
i was making this is like surely surely surely there are like old school coin-op video games and
vending machines and things where if you turn the thing off
and you enter in the right code in the vending machine
all the candy comes out.
All the food in the vending machine comes out.
That has to exist.
And doing this sort of reinforced that for me.
If you turned it off
and then turned it back on and you held down the button
so that the button was pushed when it started up
it would run a diagnostic.
And it was basically just me with a bunch of asserts
checking a couple of the functions that I had written.
And then it would go into this like auto dispensing loop
that I could use for stress testing, right?
So if I was testing out a new kind of candy,
I could just do this and leave it for three hours
or two hours or whatever and come back.
And if it had jammed, then okay, that candy was no good. That's, and come back and if it had jammed then okay that candy was
no good that's do you get uh feedback if it does jam is there like a readout from the motor that
says no it doesn't it's gonna be a fire soon because the motor oh okay yeah clicking horrible
thing actually what would happen is the belt would slip the motor was powerful enough but the the
teeth on the on the timing belt would just slip got it yeah
and so we haven't talked about the second version very much so that was more complicated than just
an arduino and some lights and and a and a while it had um it had a raspberry pi did he say and
a screen tv yeah yeah so the way i did this yeah tell us Tell us. The way I did this was I hooked up a Raspberry Pi to the Arduino over the same USB cable that you use to program it.
Right. And you can just, you know, talk over that serial connection and send bytes in both directions.
Right. Yeah.
And then on the Raspberry Pi side, I just, you know, opened up a serial connection to that device and read the bytes that it was sending.
And all I really needed was just the signal for when to play the animation.
So I don't know what message I sent.
It was probably just some like hello world string or whatever.
So the Arduino was the driver, driver effectively it was in control of the
whole show here and it was using the raspberry pi a full unix operating system on a small arm
many hundreds of megahertz arm chip as essentially a glorified graphics card yes on a wire yes
that's exactly right that's exactly right and so when it got the signal it would play it would play the animation i actually did it all
in chrome with svg so it was like serving up a the the thing running on the raspberry pi was
listening to the serial port and serving up a uh very very tiny web app that would play this animation and play the music right um and it would just do that in
response to getting the signal over the so it was a dynamic web page that was showing the content
yeah used that is i mean if we people talk about being a full stack developer but until until you you were writing an arduino like low level
um stepper motor driver talking over serial to a web browser and that's a whole product that then
you're not full stack yeah right right i don't know gatekeep what full stack is not at all you
know like it's it's that's just amazing to sort of have a fun project that touches so many different areas of problem solving and computing.
Yeah.
And yeah, it's like it's like that when you type something in your web browser, what happens when you push the button on this thing?
What happens?
Well, first, the Arduino sees that the pin has gone high.
Then it starts playing a song.
Did you use I'm going to have to bring up my favorite thing to talk about, which is, you know, when you're down at the low levels like this, First, the Arduino sees that the pin has gone high. Then it starts playing a song.
I'm going to have to bring up my favorite thing to talk about,
which is when you're down at the low levels like this and you're looking for edge events like a button being pressed.
You mentioned earlier you had a while loop,
but did you use an interrupt?
Tell me you used an interrupt and you just went to low power mode.
Oh, it's so disappointing.
You missed a golden opportunity.
Can you even do that on an Arduino?
Yeah. It's so disappointing. You missed a golden opportunity. Can you even do that on an Arduino?
Yeah.
Yeah.
There's some of the sort of like pigeon C++ extension-y type things that they've got allow you to tag stuff as interrupt handlers and set them as interrupt handlers and stuff.
So you can do some of that nonsense. Did not know that.
You didn't need to do it, so you didn't.
Because it turns out that if you're not battery constrained or anything like that, sitting in a tight loop going, while read this memory address is not equal to zero, sitting in a tight loop going while read this memory
address is not equal to zero sit in a tight loop works just fine it's just fine yeah but no i just
an opportunity to kind of get that end as well as a few just another rung down yeah well yeah
if i was running this thing off a battery that would have been a whole other deal. For sure.
A whole other world of consideration.
So the obvious next question is, what are you going to do in your new house?
What am I going to do in the new house?
You know, the thing I built in my new house is I built a golf simulator.
Because I like to play golf.
Oh, well, this has taken an unexpected turn.
But that's almost like a whole show unto itself
because man, once you have
simulator data that you can
export and analyze
there's a whole other level
of nerdery that happens.
Oh my gosh.
That is definitely a whole other episode.
That's another talk. Okay. You definitely piqued my interest there. I'd love to hear about what the heck that is oh my gosh yeah that's that is definitely a whole other episode that's another talk okay
yeah all right but you definitely piqued my interest there i'd love to hear about what the
heck that is but no no plans then for any halloween magic or for resurrecting something
similar to it is that you've kind of done that you've got the t-shirt the kids are more grown
up now baby yeah our kids like you know they don't you're allowed out of the house at all
obviously yeah right when when there isn't a pandemic going uh yeah they they
can go trick-or-treating by themselves now honestly if they want to and i think they did
last year or the year before it was snowing i remember but yeah it's it's sort of been there
done that you've you've you've got the t-shirt you've had your fun and now you've moved on to
more things that actually impact you directly.
I know how much golf means to you.
So a golf simulator is more in keeping with stuff that you're interested in rather than just service to the neighborhood kids.
Yeah.
Cool.
Well, I guess we'll talk about that another time.
And I'm disappointed that you didn't have an actual test framework for this
and you just have to hold down a button.
I did write tests for the web app that lived on the Raspberry Pi.
That had tests.
Okay.
But the Arduino code only had the diagnostic mode.
Although, in fairness, writing tests for web pages is about as difficult
as writing tests for embedded systems, right?
It's still awkward to do it most of the time.
It's much easier.
Is it?
Oh, it's so much easier.
We should not go back to testing just yet.
But at some point, you're going to have to explain to me
how to write decent web tests because I can't.
But yeah, that's another topic.
That's another topic.
Yeah.
Do you want to talk a little bit about your picture frame
that you've been working on? Oh, I guess we could. I would like to hear a little bit about your picture frame that you've been working on?
Oh, I guess we could.
I would like to hear a little bit more about that.
So, yeah, I saw a YouTube video from an acquaintance of mine
who had made a kind of joke present for his mom
where he built a picture frame into uh with with an e-ink paper uh into a into like a
little uh photo frame like a regular photo frame that you'd put a normal photo in and gave it to
his mum as a present but unbeknownst to her every day or every couple of days the picture would
change overnight and he was he was betting how long it would take her to notice and unfortunately
i think she realized something was up because it didn't look quite right and you know it was
she knows her son so it was it was it was under intense scrutiny but anyway it was inspirational
to me and i thought i've just been lucky enough to be sent a raspberry pi uh zero which is a
raspberry pi that doesn't run unix, unlike all the other ones.
It's just a chip on a board
and a very low power chip at that.
And I thought, hey, why don't I give this a go?
And I'm going to try and make it run off a battery
because Charles's setup was on an Arduino,
which I've also got an Arduino
knocking around somewhere as well.
They're great fun.
The IDE is just brilliant,
like we were saying before. I was just interested in using the raspberry pi uh sorry pico if i said zero before i meant pico i forgot what i said it's late in the day now
but yeah raspberry pi pico it's just nothing to it just a little board and so um i picked up the
same e-ink screen and this is a color e-ink screen so it's got seven colors which is a weird
number of colors to have as you can probably imagine eight would make more sense and so it's
four bits per pixel bizarrely the internals of this screen are very much like an actual crt display
like it has you have to set up timings and uh how many pixels across it is how many pixels down it
is how quickly the vertical refresh happens.
But it's clearly not updating 60 times a second or 50 times a second, right?
That seems to be the communication between the RAM on the board
and the actual physical screen itself.
This is a well-established way of addressing each pixel.
The best way of doing it is to sort of stream out the colors one after another
to some circuitry
that can then make sure the right color gets to the right pixel. That said, though, the way that
it works is that you kind of populate this memory and then you kind of say go. And then it starts
doing the kind of Kindle thing, if you know what I mean. If you've got a Kindle that's got an E-ink
display, it kind of flashes on and off and kind of has a real laborious time of it as it's kind of like reset the e-ink except it takes even longer because it's got multiple color cells to do it
and it seems to be there are just different cells with like colored lenticles over the top of them
to give you this the seven different colors and the seven colors like red green blue yellow brownie orange uh that's five um there's another but to be honest most
of them look brownish right it's not very good and so you and it's 600 by 448 so it's it's quite
high resolution so some dithering gets you some way but all the algorithms i've looked at for
dithering the standard ones um floyd steinberg
error diffusion is the one that i picked um they they work really well with luminance from a screen
but they don't seem to work as well with essentially a paper medium which is essentially
subtractive and i'm trying to wonder if there's some almost like newspaper style half toning that
used to happen you know like on printers versus the kind of thing
you do for a screen that i might look at but anyway the the code it runs on the little um
zero it talks over spi which is a standard serial protocol to the the display i've got a little
sense uh direction sensor on there as well which tell can tell whether it's up. Oh, that's neat.
So that, yeah,
if you can pick up the picture frame and put it on its side,
it'll only show portrait things
and you put it back in to show landscape photos.
And so there I use an interrupt handler.
So I can go into low power mode.
You see, I get it out in the end.
We're talking about interrupts.
So that it can go into low power mode
between essentially what would be a sleep for,
at the moment I've got it like five minutes, just because can see it see it go uh it's been a lot of fun um i plan on putting
the whole thing at the moment it's on my shelf in the other room but it's like if you to look at it
any further than um sorry any closer than like a couple of feet you'll notice that behind it is a
ton of breadboard and wires and batteries and things so it's not very good i'm i'd like to get it to the stage where um i can get a like a
breadboard an actual um you know copper track breadboard old school not like the pushy pin
ones but and solder onto it and get that um actually sort of fabbed enough to then get
everything into the little clip frame that i've got for it. Because the whole thing is only like, you know, a half a centimeter thick,
which is, I don't know, some 29 64ths of an inch or something.
I don't know.
Americans do a crazy set.
But yeah, five mil kind of thick thing.
But it's been an interesting experience.
The Raspberry Pi SDK, the Pico SDK, the it's been an interesting um experience the the raspberry pi sdk the the zero sorry i keep
saying zero the pico sdk is shipped as like a github project that you just get clone and then
you kind of just c make it in and it's all written in c and c plus plus they've done a really good
of documenting it the you kind of link the whole operating system such as it is it's just support libraries into your
executable and because it's you you have like a sibling directory with all the code and it builds
it as source so you change your compiler and it's going to pick up all the the whole operating
system and you just get like a dot a single image to deploy to the the app to the device
and the way you deploy is when you turn it on just like you were describing
before there is one button on the top of the thing if you hold down that button when you're
when it's powered on it goes into like a receive mode yeah and there it looks like it's a usb thumb
drive oh neat and you copy a single file onto it and as soon as you finish copying that single file
into it that's the image it's going to run from then on it just flashes that image and now it's that so i've got like a little watch
loop you know we've talked about the uh the watch sort of targets before now which look for the usb
drive to appear and when it does it copies the current version and then it waits for it and then
it gets the serial port debug interface up and just waits on so i've got a little like repl style
thing where i can just hit build the only annoying thing is i have to like press the button and until i wired in a reset
button myself as well it meant that i actually had to unplug and plug the whole thing back in
again which was a pain in the proverbials but um you can get an actual debug header for it
and then actually debug it but the easiest and best way to connect to the little
three pin debug uh system that it has is to use another raspberry pi zero as like the adapter
and these things are $3.99 each it's just silly so i just ordered 20 of them because
i'm gonna find you this is exactly like you and your arduinoinos on the shelves. That's why I have half a dozen BBC micro boards sitting on my shelf, right?
Exactly right.
So yeah, these cool things are, you use them as the adapter, the debug adapter.
And so unfortunately, because everyone has rushed off to buy them, they're out of stock everywhere.
So I'm waiting for more to come through, which is why I've sort of shelved it for now until I can i can uh debug it properly and and get my few other bits and pieces through but it's just great fun it's great fun to
have something uh and i'm hoping that it's inspirational for the kids to see that with
relatively straightforward code i mean again at the moment everything that i've done in my code
with the exception of the gzip library which i've kind of got hidden away somewhere else to compress the images and put them on uh into the like the image itself everything fits into
a single screen yeah or so and that included me me going slightly crazy and um wrapping
the screen driver that i had written in a nice c++ 17 objects that are all you know all the nice things all the
nice trimmings so which means it's more than one page of code it's one file i said it was one
screen i mean it's one file it's about two screens worth of code in as much as a screen is a decent
measurement of code but it's not much it's just fun and exactly as you say like hey when you when
you are just doing a relatively straightforward symbol thing, you don't need very much code.
Like while, you know, I go, hey, sleep in low power mode for five minutes.
Cool.
All right.
Now send this byte over the SPI to the display driver, which wakes it back up again from its slumber that I put it in.
And now stream 600 times 448 divided by two, because that's four bits per pixel, colors from an array that I just g-unzipped.
Okay.
And then let's sleep again for a bit.
You know, give it the magic command to say and go.
And now watch it do its screen changing.
And now I'm going back to sleep again.
But it's so cool.
It's so cool.
If you don't mind a very dull, slightly brown image of anything you wanted to put on it.
So my original hope was
to give this to my wife as a valentine's present oh yeah and uh i failed to deliver to her in time
next year next valentine but i but i told her about it and so i got almost as many kind of
reward point romance reward points for uh for the idea of it than the actual implementation
because i don't know how excited she would be really about a muddy picture of pictures of us they say that it is the thought
that counts they do say that it's the thought that counts and this is also uh not the first
time that she's had to put up with devices that i've wanted to make as either gifts for for her
or for me because i think for my 30th birthday i said to her
rather than getting anything i was gonna getting her getting me anything i should say i was gonna
buy a bunch of components and build my own mp3 playing system that could plug into my amp
i still have the parts this well 40 15 years ago i got it working but ultimately i ended up buying like a squeeze box
which was this commercial offering that did the same thing you know this is like pre sonos pre
yeah um that kind of stuff where i you know i had a server that was chock full of all my mp3s and i
couldn't play it on my nice hi-fi because there wasn't a way of connecting the two and so i thought
well i'll make one do you do you see i don't know if you can see this in the webcam you see the sort of steel
and plastic contraptions sitting on the top of my on the top shelf i have many times wanted to ask
you what that is that is a computer that i installed into my honda civic in around 2002
to play mp3s because you couldn't buy an mp3 player at the time and so
that one is voice controlled there's a little lapel mic that i wired through the car up to
the driver's seat and there was a push to talk button and you would push it and i it would use
the windows uh voice to text api we should talk sometime about the trials of trying to get a computer to shut down
reliably and not overheat in texas in a car in a car if it's a windows machine um but wow but you
could push a button and you could say the name of a song album or playlist and it would play that
song album or playlist that's amazing oh my god that's so cool you uh when was that i mean
obviously this was when you were in Texas.
It was immediately after I graduated school, and I'm like, I have money.
I can spend this money on whatever I want.
I'm going to build a computer into my car, right?
That's so cool.
That was my geek project.
Oh, my God.
MP3 players, man. I mean, as if we needed more reasons to say that we are similar.
We've taken, we took a different fork at the beginning,
but we have remarkably consistently done similar things about 15 years ago.
MP3s.
That's cool.
Well, there's lots more to talk about there.
And yeah, I definitely want to hear your your golf machine at some point and maybe we should record something and put it on a
you know a youtube for people when we talk about that we can do that then we can critique your
golf swing as well oh boy critique golf that'd be another that's embarrassing yeah you know we
could do maybe we should do like a youtube channel something and do some of these
you know we're talking about these presentations that we're given but we've given before we should
probably we could at least collect them in a playlist we've got a few things that we've talked
about that might be a good idea cool my friend yeah well let's think about that some more when
we're not recording for a podcast so we can actually talk about it yeah good call sort of
make ourselves promises that we won't be able to keep. Right.
And we've got tons more to talk about.
So I guess until next time.
Yeah.
Sounds good.
All right, mate.
Laters.
Later.
You've been listening to Two's Compliment, a programming podcast by Ben Rady and Matt Godwald.
Find the show transcript and notes at twoscompliment.org.
Contact us on Twitter at twoscp.
That's at T-W-O-S-C-P.
Theme music by Inverse Phasease. Inverse Vase.com