#240 Time to Say Goodbye to Arduino and Go On to Micropython/ Adafruit Circuitpython?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Python seems to be the fastest-growing programming language it is also widely used to program raspberry PI's and it is on the verge to become available on our small microcontrollers has the time come to leave the arduino ide and go on time for a closer look gritty youtubers here is the guy with the Swiss accent with a new episode and fresh ideas around sensors and microcontrollers if we trust this Stack Overflow post Python is a growing language and Adafruit invests a ton of money into their dialect of micro Python a typical makers perspective is he currently uses Arduino wants to have fun with programming but also wants to know about trends after this video you should be able to have a solid opinion first thing I hope we will not continue religious wars I firmly believe there is no right or wrong programming language everybody can choose and be happy with his favorite by the way if you know Python you can skip small parts of the video maybe you are interested in how Adafruit implemented the programming interface to these small boards it is quite interesting in my opinion I will cover these three topics and compare them with the current Arduino IDE environment the language itself parts of the hardware and programming interface libraries documentation and community fun for me means challenges but not too much hassle and this is why I use a de fruits implementation tools and ports for this comparison to make it clear from the beginning I bought the port's myself and never had any contact with either fruit up till now let's start with the languages there are two significant differences between Python and C++ the language used in the arduino ide if you look at the code python looks more like an english text and c++ used in the arduino ide looks more cryptic python often is considered to be a higher-level lang and C++ a language closer to the machine the second big difference is on how these two languages are translated into executable binary commands which are understandable by our microcontrollers the sketch in the Arduino IDE is stored on our PC and it uses a compiler which also runs on our PC every time we hit upload it takes some time to create a binary file which then is uploaded by a serial connection to the microcontroller the flash memory of the MCU is completely overwritten every time we upload new code as we all know this takes time especially if we forgot to choose a high speed for serial micro Python on the other hand runs on the microcontroller itself not on the PC it has to be installed before we can start and it stays there as soon as we change our code micro Python takes it translate it into a bytecode and stores it in RAM also on the MCU micro Python then executes this bytecode from RAM this is why the size of RAM is far more critical for micro Python than for C++ does all of that make a difference yes a big difference Micro Python behaves very much like an interpreter language you enter a statement and it immediately executes it no formal compiling needed if I want to set the neopixel to green I key these two commands and as soon as I hit enter the pixel screen with Arduino we would have to compile and upload the code every time we want to change the color for me as a maker this is a very nice feature at the beginning of a project where I want to play around with hardware much faster and more convenient how does it work if we want to use a program a set in Arduino the sketch always stays on the PC and only the binary file is uploaded to the flash of the micro in micro Python the code is stored on the microcontroller which has advantages and this advantages the advantage is that you lose your coat if you mess with your micro this was often the case when I played with Mongoose a JavaScript environment for microcontrollers and it was the main reason I never presented it on this channel I lost my newest code several times during the day this was the main reason I choose Adafruit environment for a start they use a some D 21 or 51 chip which offers native USB connectivity for my today's tests I use a feather M 0 Express port if you plug it in it shows up as a disk drive on your PC with the name circuit pipe the drive already contains some files and we will see this drive is a great idea and makes our work enjoyable you properly work with the board we also need software on our PC Adafruit recommends mu I hope I pronounced it right for that purpose by the way mu is free open source and also be used for other processes and is also written in Python mu has a code selection and a serial monitor in one window similar to the Arduino IDE to get you an impression on the two languages I use a standard blink program we all know the C++ code it consists of a setup and a loop part in setup we define the pin mode and in the loop we write to this pin and wait for a period how does that code locate Python we first have to import some libraries that we can use the hardware of the board then as without you we'll know we define the pin and the pin mode here called direction there is no setup or loop this wild statement creates a indefinite loop and we do not have any curly braces Python reads the code as we would read a text all intended code belongs to the while loop we also need for statements in the loop one thing we do not need in Python the declaration of variables in C++ we first have to declare a variable as int float etc Python does not require this step this might be easier for beginners for me there is no significant difference between these two examples I can live with both for a beginner it might be a little more comfortable without the curly braces in my opinion there are more important differences as we will see later the name of the code is code dot py because this is the code circuit Python starts after boot as soon as we press save the LED starts to blink much much faster than without we know if we change the timing and press safe again it is immediately applied cool if we want the debug message we enter a print statement and hit safe and it immediately shows in serial monitor extremely cool all this is possible because of this small disk which is created by the feather Express port move only saves the file on the disk and python on the board restarts with a new sketch as soon as it is changed the libraries and everything else stays on the MCU for the whole project we cannot discuss micro python without mentioning ripple this is the abbreviation of read eval print this is the normal user interface for micro python and with other boards we would have started with this ripple because they do not offer a disk on these ports the code is uploaded to the board using ripple we get to rebel if we press control C and we get back to program execution by pressing control D in ripple we work directly with the board and can as shown before directly execute commands for example we can import the board's library and then display all available pins with a command tear port for sure this is faster than the Arduino programming cycle where we always have to compile and upload whole coat one of the worst chapters of C++ in the arduino ide especially for beginners is string handling dealing with strings is hard for non-programmers like me especially if you have to deal with libraries which are written by real programmers and where pointers come into play string handling was not important in the old days when we wrote code to manage pings but today with all the user interfaces and the connectivity we more and more have to deal with strings even when we call web services and decode the answer for me this is definitely easier in Python it does more or less what you expect similar to the string type in Arduino let's be T equals one two three four five six seven eight nine if we want a substring we only write this command if we want to find the number three the command is like that we can combine the two and type this command which returns -1 because 3 does not appear in position 4 to 8 let's take a more complicated string and define T equals gear port we can print it without Sprint F conversions and if we print t5 we get a surprising result Python did not store the pins as a string it saved it as a list interesting of course there are much more differences and details to be mentioned for example also that python has a garbage collector which frees unused memory but this is stuff for other channels and maybe even for another video on this channel the next big thing is libraries a big plus for the arduino platform because we find a library for most of our devices quite a few of the well-known libraries come from Adafruit and they did an excellent job in porting many of those libraries to circuit Python for the moment I do not know if micro Python libraries are compatible with circuit Python but you also find a lot of libraries for micro Python but still Arduino is ahead and you have to check for the needed libraries before you start your project by the way on the Express sports you can load all available Adafruit libraries including all example files on the board and keep it there for the whole project there is enough space available like that you do not lose any time to search for or upload if you need a new library in your code what about documentation and support the documentation of circuit Python and its hardware is excellent it only took me a few minutes to get everything up and running when I started I downloaded the wrong initial file for my board and just got a disk space of 50k this gave me the opportunity to test the support I went to Adafruit a skort channel and got help in less than five minutes this channel seems to be very active with lots of users summarized the decision of Adafruit to use this m.d processors with native USB support increases the usability of Python on micro processors especially for beginners and it raises the comfort and development speed for the rest of us the most significant difference between circuit Python and the Arduino IDE is the fact that Python behaves like an interpreter language people in my age might be reminded at our beginnings with basic just without the go-to statement and without line numbers Python is considered to be a higher-level language than C++ which means that it has some powerful commands which have to be explicitly programmed in C++ on the other hand circlet Python needs more resources and runs slower than C++ especially Ram can become an issue this is why I would not run it on an esp8266 I would start with an ESB 32 with PS run a version of micro Python exists which can use PS Ram the code structure in both languages is very similar Micro Python reminds me more of English C++ looks more like code Arduino has much more available libraries Arduino IDE supports many ports especially the esp8266 and the ESP 32 circuit python for the moment melee runs on a de fruits hardware they ported it to the esp8266 and planned to port it on the Nordic NRF 52 platform may be expressive looks at these Sam D chips and adds a USB interface to their ESP 32 chips as well who knows micro Python is also ported to a few other platforms the documentation of circuit Python is proper and the support on this court was good for me the main reason for starting this endeavor was the announcement that Adafruit wants to port circuit Python on the Nordic platform viewers know that I am disappointed about the ble performance of the ESP 32 with the arduino ide i will closely monitor the development of this branch as these nordic chips are very good on ble and I'm still interested in this technology most probably this was not the last time you heard of micro Python on this channel what is your experience with micro or circlet Python do you use it and on which platform or do you have plans to use it in the future I hope this video was useful or at least interesting for you if true please consider supporting the channel to secure its future existence you find the links in the description thank you bye you
Info
Channel: Andreas Spiess
Views: 847,366
Rating: 4.8286271 out of 5
Keywords: wemos, hobby, ttgo, circuitPython, esp8266, ESP32 project, iot, adafruit feather m0, how to, electronics, micropython, adafruit Feather, eevblog, esp32 project, esp32, arduino project, guide, LORAWAN, beginners, project, do-it-yourself, adafruit feather m4 express, esp32 weather station, diy, arduino, smart home, wifi, NRF52, greatscott, adafruit feather, esp8266 project, simple, hack, Adafruit, Acafruit circuitpython, esp32 tutorial, nodemcu
Id: m1miwCJtxeM
Channel Id: undefined
Length: 15min 26sec (926 seconds)
Published: Sat Nov 17 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.