Easy & Powerful Arduino Alternative? #4 Pyboard (MicroPython) Beginner's Guide

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
I recently browed through the shop of my favorite Chinese EBay seller and noticed a rather interesting microcontroller development board. It was this PyBoard based around the STM32F405 that you can get for around 13$. At first sight I pretty much ignored that it made for MicroPython programming language and instead I immediately googled the datasheet of the microcontroller and oh boy it is quite a beast if I compare it to the previous 3 microcontroller boards of my Arduino Alternative series. It surpasses them in almost all important categories and yes you can download this chart through the link in the video description. I especially like its high clock speed, big memory and 32-bit timer; its only disadvantages are its high power consumption even in sleep mode and its comparable low bit analog to digital converter. But nevertheless I was sold on those specs and thus I of course ordered myself such a PyBoard. After connecting its Micro USB port to my computer though, it opened up as a flash storage device in which a boot and main.py file was resided. That should not have been a surprise for me though since such files are common for the Python or MicroPython programming language but only at this point I started to realize that I would have to learn a bit of MicroPython programming in order to properly use this development board. So in this video let’s go on a learning adventure together to explore what this board is all capable of and at the end I will tell you whether I think it is actually a good Arduino alternative for beginners. Let’s get started! This video is sponsored by JLCPCB! Feel free to visit their website JLCPCB.com to not only find out what awesome PCB and Assembly services they offer but also to easily upload your Gerber files and thus order affordable and high quality PCBs quickly. One way to use the PyBoard is by simply opening its main.py file with your favorite text editor, for which I would recommend Notepad++, then add the lines of code you want the microcontroller to execute, save the file, eject the flash storage safely and hit the reset button on the board and just like that we got a blinking LED. But I have to warn you that you should always eject the device safely because by only pushing the reset button you can easily damage the file system. In such a case you will have to do a factory reset to restore the original files. You can of course find more information about this process on the MicroPython website. But anyway besides this programming method there is actually another more beginner friendly way to interact with the board. To use it we simply have to open Putty, choose the correct serial port and click open. As you can see we can now send commands to the board but I quickly realized that the firmware version of my board came with pretty much the oldest one. To update it, I firstly downloaded the newest firmware for the Pyboard v.1.1 which is hopefully the hardware version of my board. Then I downloaded the files the manufacturer of my board provided, which not only comes with a pretty hand pinout diagram along with lots of example codes that we can partly later test but also with a tool which is called DfuSe Demo. After installing it, I created a solder bridge between the boot pin of my board and 3.3V in order to get it into the DFU mode, hooked it back up to the computer and started the software. There it immediately recognized my board and after choosing the right firmware file it was time to flash it. And after undoing the solder connection and once again creating a serial connection it seems like the update worked out just fine. So the first thing the board recommended me to do and what I also typed in was help, which spat out a list of commands that I could enter to let the board do certain things. And as you might already have noticed, those commands and the syntax of this programming language is not quite the Arduino language that I and probably you are used to. Like already mentioned it uses MicroPython which is basically an abridged version of Python. If you want to learn a bit more about the subject then I would recommend you to watch my video in which I used a Raspberry Pi to do some simple electronics related tasks. To learn more about MicroPython programming though I visited the MicroPython website and I have to say that all functions of the board and how to use them with the language was pretty well and straightforward explained; so I felt confident in writing some code on my own. To start simple though I sent two commands to the board via Putty which turn on and off the first onboard LED and as you can see the board executes the commands as soon as it receives it. This live programming function is pretty handy when you want to test out the features of the board. And you can also write your complete code this way but for such a case I would rather stick to the more traditional method of writing to the main.py file. So for a proper first code example I wanted to display the state of pin X10 on the serial monitor. As you can see I declared the pin as a simple input but you can also configure it as an input with pull up or pull down resistors or as an output with push-pull or an open drain output. But anyway after saving the code and resetting, we can open up putty as our serial monitor and as you can see the board spits out a 1 or 0 depending on whether we connect 3.3V or GND to the pin. It is noteworthy that most pins of the microcontroller tolerate 5V but definitely have a look at its datasheet before trying anything. Ok, let’s continue by outputting a PWM signal on pin Y1 of the board which uses the timer 8 channel 1. As you might already have guessed we have to configure this timer but in comparison to Arduino programming for which it can be quite complicated, this MicroPython timer configuration was super simple to do. The reason is that firmware calculates and sets the complicated values by itself and as you can see by hooking up the pin to the oscilloscope we get a PWM signal with 60% duty cycle and a frequency of 10 kHz just like I programmed it. Even setting higher frequencies like for example half a MHz was no problem for the board. And since we are already at the subject of timers, we can also easily configure them to execute a function at a certain frequency like toggling the onboard LED number 3. As you can see that also works just fine which means precisely timed task are easily doable with this board. For my next example I created a bit of code that outputs the mathematical values of a sine wave through the PWM pin I set earlier. As you can see on the oscilloscope it kind of seems to work but we can only truly confirm this by adding an LC low pass filter to the board which gets rid of the high PWM frequency. Now the great thing is that we actually do not need to use such a filter since the board also comes with a 12-bit Digital to Analog Converter. By simply feeding the sine wave values into it instead of the PWM timer, we can see on pin X5 that we get a beautiful 12-bit sine wave. Of course we can do such a conversion also the other way around with ADC of the board. For that I wrote a bit of code that uses the ADC to sample the voltage on pin X12 which it then outputs through the serial monitor. And after connecting the DAC created signal to the analog input, we can read in the values the board mathematically calculated. Last but not least I also added an external interrupt into this already busy code in order to toggle the onboard LED number 3 when the built on tactile push button is being pushed. And as you can see while still outputting and sampling the sine wave, the LED turns on and off just like expected but there were some problems with debouncing for which there would have been a solution given by another programming tutorial on the MicroPython site. Now at this point I could continue testing all the other features of the board like the real time clock, the build in and easy to use accelerometer, or the communication protocols but even without going into full detail here I can say that this board and MicroPython is a joy to work with. Yes, the board is quite a bit bigger than an Arduino and also costs 10$ but it packs so many more useful features and is so simple to program that I would highly recommend it to anyone looking for an Arduino alternative. The only real downside is that not all available Arduino libraries are ported over yet but there is already a long list of functioning libraries. And if you got question you can always have a look at the MicroPython forum which seems rather active. And with that being said it is clear to me that buying this board was definitely not a mistake. As always thanks for watching. Don’t forget to like, share, subscribe and hit the notification bell. Stay creative and I will see you next time!
Info
Channel: GreatScott!
Views: 151,987
Rating: undefined out of 5
Keywords: pyboard, micro, python, micropython, arduino, alternative, guide, beginner, beginners, make, project, tutorial, explain, program, programming, language, syntax, board, feature, compare, comparison, first, time, setup, input, output, digital, analog, putty, serial, monitor, pwm, pulse, width, modulation, dac, converter, adc, sample, voltage, current, firmware, flash, upgrade, update, notepad, code, price, power, performance, clock, timer, interrupt, accelerometer, axis, loop, greatscott, greatscott!, electronics, sine, wave, led, blink
Id: CyrgzzxQPzk
Channel Id: undefined
Length: 11min 29sec (689 seconds)
Published: Sun Nov 29 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.