We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

TinyGo: Fast, Small, Concurrent: Choose Three

00:00

Formal Metadata

Title
TinyGo: Fast, Small, Concurrent: Choose Three
Subtitle
TinyGo on microcontrollers
Title of Series
Number of Parts
490
Author
License
CC Attribution 2.0 Belgium:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal purpose as long as the work is attributed to the author in the manner specified by the author or licensor.
Identifiers
Publisher
Release Date
Language

Content Metadata

Subject Area
Genre
Abstract
This talk will show using live demos why TinyGo the Go compiler for "small places" is a excellent choice for next generation IoT and embedded devices.
MicrocontrollerComputer programInfinityWritingBuildingSet (mathematics)ArchitectureCompilerProjective planeIntermediate languageSingle-precision floating-point formatSystem callLibrary (computing)MicrocontrollerOpen sourceStandard deviationComputer programmingNeuroinformatikMultiplication signSoftware frameworkPoint cloudCompilerRun time (program lifecycle phase)Machine visionCompilerNormal (geometry)Fluid staticsCodeInformation technology consultingPhysical systemSource codeExpert systemComputer architectureCovering spaceFormal languageComputer animation
Concurrency (computer science)CubeRevision controlComputer hardwareMultiplication signWhiteboardFormal languageVirtual machineComputer programmingMereologyLibrary (computing)CoprocessorFunction (mathematics)2 (number)Functional (mathematics)Standard deviationPersonal identification numberSlide ruleComputer animationLecture/Conference
CodeFlash memoryRevision controlSpacetimeWeb pageFunction (mathematics)ParsingRead-only memoryComputer animation
FirmwareRevision controlSpacetimeWeb pageFunction (mathematics)Read-only memoryCodeFlash memoryView (database)Physical systemComputer fileVirtual machineBootingVirtual machineCodeBitMicrocontrollerElectronic mailing listFile formatFunction (mathematics)Line (geometry)Software developerDifferent (Kate Ryan album)Personal identification numberReal numberAbstractionView (database)Computer hardwareComputer fileNeuroinformatikPhysical systemDirection (geometry)Descriptive statisticsComputer animation
EmailDevice driverDevice driverWrapper (data mining)Configuration spaceDemo (music)Type theoryElectronic visual displayLevel (video gaming)Virtual machineInterface (computing)Address spaceComputer animation
Order (biology)Assembly languageComputing platformImplementationCodeHydraulic jumpQuicksortMicrocontrollerComputer programmingDevice driverLecture/Conference
FirmwareRevision controlSpacetimeWeb pageFunction (mathematics)Read-only memoryCubeCodeFlash memoryFile Transfer ProtocolParsingElectronic signatureDemosceneComputer animation
CubeCodeFlash memoryRevision controlElectronic signatureSpacetimeWeb pageFunction (mathematics)Read-only memoryFirmwareParsingHash functionDemo (music)BootingBitFlash memoryComputer fileForm (programming)Computer animation
Booting
Computer hardwareAdventure gameHash functionElectronic visual displayBitArmLibrary (computing)Computer hardwareMultiplication signRight angleCodeMulti-core processorAdventure gameElectronic visual display32-bitFlash memoryArmTwitterComputer animationLecture/Conference
Read-only memoryWeb pageSpacetimeFunction (mathematics)Revision controlElectronic signatureParsingAtomic nucleusFirmwareCodeMicrocontrollerWhiteboardCodeComputer programmingCuboidReal numberComputer animation
GoogolBoltzmann equationInterrupt <Informatik>Semiconductor memoryDemo (music)Electronic visual displayPower (physics)Process (computing)Interrupt <Informatik>MicrocontrollerGoodness of fitGame controllerImplementationCodeCubeOrder (biology)Matrix (mathematics)Frame problemComputer clusterProjective plane
FirmwareRevision controlElectronic signatureSpacetimeFunction (mathematics)Read-only memoryCubeWeb pageCodeFlash memoryDemo (music)Video game consoleMoment (mathematics)Pattern languageComputer animation
Revision controlFirmwareElectronic signatureWeb pageFunction (mathematics)Read-only memoryDenial-of-service attackCubeSineSpacetimeCodeFlash memoryParsingCorrelation and dependenceAtomic nucleusElectronic visual displayCodeCubeDemo (music)MicrocontrollerMultiplication signField programmable gate arrayComputer animationLecture/Conference
Host Identity ProtocolElectronic signatureSpacetimeWeb pageFunction (mathematics)ParsingRead-only memoryCorrelation and dependenceCubeFirmwareRevision controlFlash memoryCodeEmailCoprocessorMultiplication signJoystick
Electronic signatureSpacetimeWeb pageFunction (mathematics)ParsingRead-only memorySineCubeRevision controlFirmwareCodeFlash memoryComputer programmingJoystickGoodness of fitComputer animation
BootingJoystickReal numberCode
Electronic signatureSpacetimeWeb pageFunction (mathematics)Read-only memoryCubeRevision controlFirmwareParsingFlash memoryCodeAtomic nucleusComputer multitaskingSocial classGoodness of fitGame controllerJoystickMultiplication signCodeElectronic visual displaySerial portComputer animationLecture/Conference
CubeError messageRevision controlMachine visionPhysical systemArchitectureRobotConnected spaceCodeFlash memoryVideoconferencingJoystickQuicksortService-oriented architectureServer (computing)Message passingCountingWrapper (data mining)Computer programmingSoftware protection donglePattern languageCartesian coordinate systemMachine visionDemo (music)NumberNeuroinformatikComputer animationLecture/Conference
CubeRobotConnected spaceCodeFlash memoryRadio-frequency identificationArtificial neural networkPattern recognitionMultiplication signOrder (biology)Message passingTrailComputer clusterComputer animation
NeuroinformatikDemo (music)WhiteboardMultiplication signJoystickCodeComputer programmingWebsiteComputer animationLecture/Conference
CubeError messageRevision controlWhiteboardComputer programmingComputer animation
CubeError messageRevision controlLatent class modelNormed vector spaceR-ParitätCone penetration testWindowFirmwareMusical ensembleComputer fileHexagonComputer animation
CubeError messageRevision controlEmailComputer programmingComplete metric spaceWeb browserGraph coloringComputer animation
Open sourcePoint cloudDemo (music)Computer animation
Transcript: English(auto-generated)
Next speaker is Ron Evans. He's talking about TinyGo. Can you guys hear me okay? Is the audio coming through okay? All right, excellent. So, hello everyone. I am dead program.
In the real world, some people call me Ron, a couple of people call me dad, but don't call me dead, not yet. I am a technologist for hire. I've been told to be very subtle about these things. So I run a consultancy called The Hybrid Group, where we are all technologists for hire. So we've done work for many clients. The most recent one that is quite interesting
is a company called Northvolt. You may have heard of them. They're a lithium ion battery manufacturer based in Sweden. Very cool company. Check them out. But we are here to talk about some of our open source projects. GoBot, that I did a talk three years ago. GoCV, which is computer vision in Go. I did a talk two years ago.
And then TinyGo, which we actually introduced last year. And now, as of today, we can announce that TinyGo is sponsored by Google. So thank you Google. So everything knows that Go is big in the cloud, right? I mean, you know, it's really, really big in the cloud.
The thing is, Go is really big. And by that, I mean Go programs are very large. Hello World in Go is 1.1 megabytes. What? I know, crazy, isn't it? You know, it includes the whole runtime. It's statically linked. But, you know, that's no problem because clouds are infinitely scalable, right?
You know, just keep expanding. Cover the whole planet. But what about the small places, right? What about those tiny little places? Like, for example, microcontrollers. That's what TinyGo is for. To take Go where no Go has gone before. And, of course, WebAssembly.
But we'll get to that. So how TinyGo works, very quickly since we're all experts in embedded systems and the IoT, where this is going to be going kind of fast. So Go is written in Go. And then we use Go to talk to TinyGo to then talk to LLVM. So what do I mean by this? The Go compiler itself is written in Go.
You know, that's kind of the cool thing about all languages, that they can compile themselves. And LLVM, who here has ever heard of LLVM? Oh, of course. LLVM is a framework for writing compilers. It's used by a few little projects you may have heard of, like Swift and another very cool language called Rust. So this is the TinyGo compiler architecture.
We take the source code and then Go's normal, built-in standard libraries convert it to the Go single static assignment form, which is basically the most reduced form of code. It's like an intermediate. TinyGo then takes that and converts it into LLVM intermediate representation. And then we can compile that with Clang and LLD,
the normal LLVM tools, to target microcontrollers and other very, very small places. So let's get right to some demos, because time is short. So let's start with the Hello World of Things, which is of course a blinky light. And for that we're going to use a DigiSpark plus an LED. So a DigiSpark is based on the ATtiny85.
So as you might guess, I like it just because it's named Tiny. So this is one right here. It basically plugs into your USB port. That's the ATtiny85. It's an 8K processor that has 8-bit.
It's very, very small. Let's go back to the slides here. That's what I told you. 16 MHz processor with 8K of RAM. 8-bit processor, 8K of RAM. Because of all the pleasures, we're going to start with the smallest and gentlest. So here is some code. This is your basic Hello World in TinyGo.
Anyone here actually done the Go programming? All right, a few people. So a quick refresher for those of you who know Go, and a quick intro for those who don't. So Go has a package main. That's like the main program. You import, which is the same as import in Python or require in JavaScript or Ruby.
So we import the machine package, which is part of TinyGo. That's how we talk to the hardware. The time package, which is one of the Go standard built-in libraries for time. And then we have a function main, just like other languages, Python, C, other languages you've seen. First thing we do is we say that LED equals machine.LED.
That would be the built-in LED on most boards that you have. Usually have at least one built-in LED. Then we configure that pin as an output pin. That way we can actually turn the LED on and off. And then forever, which is how we do things repeatedly in Go. Go has no while. You just forever.
We're going to set the LED low, turning it off. Sleep for 500 milliseconds, half a second. Turn the LED back on and then sleep. So it will blink on and off very rapidly. So let's go here to... And so if I say make DigiSpark,
and I... So it's compiled the Blink program, which you may know. This is 398 bytes in size, and I'm going to plug it into my USB port. All right, so now it's done. Oh, I forgot my battery. I need my battery. I have a battery in here somewhere.
So let's plug it in. Turn it on. Let's go back to the camera. And after a five-second boot-up period, so that the bootloader can kick in now, blinking LED in 300 bytes compiled by Go. Yes.
All right. We're off to an excellent start. So that was neat, but let's get serious. So how TinyGo knows about hardware real quick? We have to go inside the chip. I mean way inside the chip. I mean way, way inside the chip. To the registers.
So for me, a register is kind of like a valve that you turn on and off, and it makes like little wheels spin. Like that's the way I like to think of it. I just try to explain it that way to little kids like myself. So there's a kind of file called system view description files, and it's created by the different vendors of chips. It's originally an ARM-based standard,
but some other chips have been using it. It's this really staggering XML format that actually contains a complete list of all of the different peripheral registers on any particular microcontroller. In this case, it's the port that's used for the general purpose IO. So we use the SVD files to generate Go code.
That's a technique that's used by Python, and that's what Rust embedded also does. Ours is written in Go, and kind of does the same thing in a different way. And that's how we create the TinyGo device package. The device package is a very, very low-level package, which takes in that same XML that we saw. It's converted to a Go type, port type,
and then we have the different individual registers within that, for example, turning which direction it should go, whether it should be cleared or set, and these are all of a type volatile because these are not safe types. I mean, you can't do type-safe computing when you're actually talking to hardware registers. So we take that,
and that's how we do very low-level stuff. Like this line of code would turn on bit three of the output of the port. So it would turn on whatever thing was connected to that pin. That's really low-level, though. That's why we've created the machine package. So the machine package is our hardware abstraction layer. It's a little bit higher level,
and it sits on top of the device package, and that's how we can do things like we can know which pin it is, and we can set it. If it's less than 32, which on the particular target here, it separates them by banks of 32 pins. Then if it's high, then that's the code you saw before of setting it.
So this way, it's a lot easier for normal developers to use GPIO. They can just say what we saw in that first demo. Pick the LED, configure it to an output, and turn it on and or off. All right. So we have machine package wrappers for the UART, for the SPI interface,
for the I2C interface, basically for all the interfaces. So now let's do something interesting that's both small and fast. I promised you for this talk, we were going to get small, we were going to get fast, and we were going to get concurrent. So we saw small. Let's see small and fast. So for that, I'm going to introduce the TinyGo drivers package.
The TinyGo drivers package is where we have our higher level wrappers around individual types of sensors and displays. So this code, let's just take a very quick look. We have a driver for what are popularly known as NeoPixels, but are actually WS2812
individually addressable RGB LEDs. And so in this code, we're going to blink both the built-in LED and we're going to connect to a pin that we're going to put that strip of LEDs to. Let me jump to the camera so you can actually see it real quick. So this is a different DigiSpark, and this is my little
Homebrew NeoPixel strip. They're not real NeoPixels. Sorry, I had these around. I don't like to cut real things up, so I just cut up this sort of thing. All right. So let's jump back to our presentation. So we're going to
basically turn each of the LEDs either red or green, alternatingly, and then we're going to call WriteColors to then send that to the LED strip. So the thing that's interesting is in order to do this sort of coding, it's well known that these LEDs
are extremely time-sensitive. You need to send them their signals at a very, very rapid pace. Generally too fast for nearly any programming language, except, of course, assembly language. So luckily, TinyGo can handle that quite nicely. This is a little piece of the implementation for the WS2812 driver.
In this, we're taking advantage of the fact that we have both Go code and we can emit assembly code. In this case, it's AVR assembly. Remember, this particular microcontroller is based on the AVR. It's the old-school Arduino platform. So we can basically emit assembly and embed that right into our Go code
that we were going to compile all together and put onto this chip. So, without further ado, what's this one called? I don't think so. I forgot why they called it. Oh, actually,
it is DigiSpark. I was supposed to show blank before, but that's alright. So if we make DigiSpark, again, that one also blanked the LED. That's why it fooled me. So we compile it.
Where did I just put it? Too many cables, not enough time. I know, exactly. It was too tiny. Just make sure it actually worked before I unplug it.
Oh, what's it saying? How rude. Must have forgotten to put my demo code in here. Well, let's take a wild guess. I think it's something like TinyGo
Flash Target DigiSpark You don't need an equal. You can't put one there if you prefer. And we'll see demo and it's NeoPixels. Yes, there we go. Thank you.
I'm glad someone can see. I have to just compile the whole package, not just one file. I also have to replug it in so that the bootloader detects that. Alright, that's a bit more like it. Oh, I forgot to say the size of it.
Size small actually outputs the size in a small form. Not makes it small. It's already small. It didn't output it, but that's alright. We don't have much time.
So let's go back to the camera. So here's the DigiSpark. And here's the battery. And let's turn on the battery. And then after our little five second wait for the bootloader then voila!
It's kind of amazing what you can do with an 8-bit device these days, isn't it? So retro. So hot right now. Alright, so back to the Presso. So this is the time to mention our ever popular choose your own hardware adventure. Choose your own hardware adventure means
that you can actually win some cool hardware to take home to play with TinyGo. So I brought with me some cool toys. All you have to do is go into the Twitterverse and tweet something using the hashtags TinyGo and FOSDEM. You can win a DigiSpark, I brought a few, an Arduino Nano 33 IoT, or
an Adafruit PiPortal. So start tweeting. Oh, by the way, tweet something nice. Otherwise we just won't give you anything. Now back to the show. Alright, so time for a bouncing ball. So for this we're going to use the PiPortal that you could win one of. And it uses the ILI9341
TFT display. So the PiPortal uses a microchip ATSAM D51, which is an ARM Cortex-M4 chip. It's a 32-bit processor. We're in the 32-bit world now. 120 MHz with 256K of RAM. Like, for us, that's like huge.
We can like stretch out and relax. So it also has a built-in Wi-Fi chip. It's got a ublox Nino 102, which is the same as an ESP32 under license. It's a dual-core extensa with 32-bit processor that actually is quite fast at 240 MHz with 16 MB of flash.
That's just so you can do SSL at all, basically. And so this is where the code is for the PiPortal, because I don't have time to show all that stuff. But let's look at the portal itself. So it's this little tiny itsy-bitsy board.
You can see on the back of it this is the microcontroller. This is the ublox chip. So let's go back to the code. So if I say made ball and I plug in
and I turn on this is how you know it's real. It's a little too real. This one's new in the box. I never flashed it before, so I'm really playing with fire.
So you see it's a 27K program. Now it's running. Yeah, for TinyGo it's really large. So here you see a bouncing ball display run entirely with TinyGo. So pretty good, right? Pretty good for a microcontroller?
Well, it's pretty good, but it's not that good. Let me tell you why. As good as that looks, we can get so much better. Right? Why? Because in that particular demonstration... Oh, I've got to plug in. I'm running out of power.
I really do have to plug in because this next demo uses a lot of juice. This is why I need more than zero minutes to plug in
and prepare. Oh yeah, it's really not happy now. It's really mad at me. So for this I'm going to show the LED cube, aka the cube of fire. Cube of fire. So the cube of fire uses an Adafruit Itsy Bitsy M4, which is the same chip as we saw in the previous demo,
and it uses six hub 75 displays. So this is the cube of fire, just so you can sort of see it. It's kind of large for this camera. And I don't want to take it apart just because bad things generally happen when you do that.
So let's plug it in. Let's go to the code first real fast. So it's got these hub 75 LED panels, which are basically 32 by 32 matrix LED displays. In order to do this ultra-fast stuff, we're going to use direct memory access, which allows the
peripheral controllers on the microcontroller to actually send the data without having to use the main microcontroller, so it's not using all of the processing power. And then we're going to use interrupts. That way, when the processing is done, it sends an interrupt, which will immediately tell our TinyGo program, yes, you need to send the next frame of data.
And so to do that, we have implementation in TinyGo for interrupt support. So this is just kind of a brief... We configure the interrupt code, which then sets the register to turn on the interrupt for, in this case, it's for the UART. We then, in our Go code, declare that it's a new interrupt. We set the priority, and we enable. So then when this interrupt
is triggered, it will call this Go routine, handle interrupt, which will then do the magic. So if you want to see the code for the kubefire, the code was written by one of our other contributors and actually the project original creator, Ike Van Latem. He's not here right now because he's getting ready for a talk over in the Go dev room.
So let's take a look at the demo. So I'm going to go to my console. I'm going to say make cube. So let's plug it in. So this is running the previous demo.
This is not the fire. You can't really see it that well through the camera. Sorry about that. It's a little too close because it looks so cool, doesn't it? Is there another camera? Other camera? All right. But that's not the fire. That's just a really cool pattern whose name escapes me at the moment.
So now let's put the code on the cube. So now we're loading the 20k worth of DMA and Awesome. Oh wait, I forgot to change the code to the other demo. My bad. Oh, Radiance, that was the name of that one. Let's put the fire on.
I mean, I don't know about you, but I need to bring the fire. All right, this one's a whole 21k. And there's the fire. FPGA was used in this demo.
None whatsoever. This is nothing but a very inexpensive and yet powerful 32-bit microcontroller. Imagine what we could do with FPGAs. That will be coming in the not too distant future. Forever in the not too distant future. All right. We have very little time left.
So let's keep going. A lot of people, you've seen me rocking this tiny Go-powered badge. You may have seen that while I've been wandering around. It's pretty cool. So I'm going to use this badge for something else now entirely. So this is the badge.
What happened? Oh, it went with the badge. It really got stuck on there. These mics really hang on to whatever they're attached to. I forgot to tell the AV person, who's very nice, that
I would be taking the badge off in the middle. He didn't realize that. Can you still hear me? Good enough. We are really running out of time. My fingers are clumsy. Anyway, here's the badge. It's just another
ATSAM D51 processor with a battery, a bunch of peripherals, trying to tell you to come to this talk right now that you are already at. So you took the instructions. I'm used to cameras that go upside down. Alright. So what we're
going to do with this is we're going to turn it into a joystick. We have six minutes left. We almost have literally just enough time maybe if I'm really fast. Alright, so let's unplug the battery. Let's plug in the joystick. I brought the joystick with me. I just want to fly a drone
with a badge. I think that's worth seeing, don't you guys? You're supposed to say, yes, we really want to see that program. Thank you. That was the right answer. Very good. Wow. We've got to lead people to the you're used to this. You work with management. Alright.
So I plugged in my joystick. Too many workspaces. So I've got the joystick plugged into the back of my badge. And I just have to flash the joystick code real fast.
Hey Danielle, are you here? Can you turn on the drone, please? That way you can boot while I do this. If I don't actually fly this drone today, I'm not leaving the stage. The drone will see that.
Everybody always thinks I'm joking. So I'm going to load the flight badge. As long as it's on, it's good. Thank you. I just want to make sure it boots. So now we are actually running the code that lets us use this joystick that lets us use this joystick
to be able to push the buttons and you can see the controls changing. So it's basically sending along the UART. If we go back to our quick diagram, that's what's the specs of it. We're using USB CDC, so it's like serial over USB. We've got the buttons and the joystick
communicating with the display and the USB. So we don't really have time to look at this code, but it's all online. You've seen the data coming from it. Or no, you actually haven't. So here's the data coming from the joystick. As I move the joystick, you see the number X and Y change.
So it's very, very simple. Let's get out of there. Four minutes. Alright, so B0. So for this, I have to go and turn off the camera because I need the camera
port now to plug in my other antenna. I bring a special antenna for this purpose. I have learned that little dongles are really cool, but you can't count on them for this sort of thing. Alright, so we are connected to...
So the flight application is using the flight stick along with a Go program also running on my notebook, which is communicating with this Tello drone over there and an MQTT server that is also running locally to avoid problems. Typical pattern would be to use a local broker and then forward those messages to your remote broker cluster.
So for this, we're going to bring in GoBot, the DJI drone, which has got a built-in Intel Movidius 2 chip, and we're going to use GoCV, which is our Go wrappers around OpenCV. So we're going to use the flight stick to talk to the GoBot program, which is going to communicate both with the MQTT server and the drone and the computer vision.
It's everything all at once in one massive demo. So let's take the drone and let's put it here. Real quick, before we start that, let's go to the... That way we can see the MQTT messages come through.
And if I make a tiny drone, it will compile it, it will connect. Once the video feed starts coming in, you can see the video from the drone. I'm kind of clumsy. That's one way to do it.
So let's go back to the MQTT so we can see that. You can see it's actually sending messages already. Alright. Are we ready for takeoff? Let's do this. There's a human now.
This place is full of them. So we're actually running a deep neural network that's based on CAFE in order to do facial recognition and tracking. I promised I wasn't going to fly over the crowd. But some people will be sad if I don't.
I still have 62% battery, 61. I think the people in the back... No, it's shutting down. It's like your insurance person has a shutdown button remotely. Alright.
You see the MQTT messages have stopped. Alright. So I don't have time to show you all the rest of my demos. But I will tell you very quickly what they are. The future of edge computing is of course RISC-V and WebAssembly. How about combining them both together into one demo, the TinyGo Playground.
So if you go to play.tinygo.org that is where we have the TinyGo Playground. It's a website that lets you compile TinyGo programs. And if I switch over here to the Hi5-1 Rev B The Hi5-1 Rev B is a RISC-V board from Sci-5.
And if I unplug my joystick I will use that same cable to plug in. I don't have the camera but you can see it. This RISC-V board here. I'm going to plug it in. Actually I can plug in the camera at the same time that I run the code. Because I'm now at time.
Let's just see if we can make it work. Make camera. There's the camera that we are seeing. This is the RISC-V board. Let's plug this back in.
Because I don't need to make a program I just need to download it from the website. So we go back to the TinyGo Playground. We also have a simulator. You see it's blinking because this knows about that. So I'm going to flash, which will then compile and download the firmware. So then if I just go to any window that has a...
So in my downloads along with a bunch of music from Mixcloud I'm going to drag this hex file onto the Cy5. That's how you flash it. It reboots. Go to the camera.
And now you'll see it's alternating through the three colors of the built-in LED. So we just downloaded a complete RISC-V program from play.tinygo.org and flashed it onto this with nothing but a web browser. Pretty much that's all we have time for. No questions.
Sorry. But I hope you've been tweeting like mad. So the future is already here. Go to thecinygo.org. I have stickers. I have cool things to give away. We will actually do the give away after the next talk. So you can keep tweeting during the talk and also you don't have to race out from this nice person who's going to give a very interesting and important talk as well. Questions?
Sorry. No time. Thank you. Thank you Rod. Lots of demos. We like that.