Difference between revisions of "Micropython"
(39 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
== '''Micropython is a hype!''' == | == '''Micropython is a hype!''' == | ||
− | Micropython is a programming language, like C, C++, Code Blocks. | + | Micropython is a programming language for microcontrollers, like C, C++, Java, Code Blocks. |
In principle all the languages can do the same sort of thing. In principle all languages have the same type of complexity. | In principle all the languages can do the same sort of thing. In principle all languages have the same type of complexity. | ||
− | Micropython can be seen as "a conversation with the microcontroller". | + | Why MicroPython???? Micropython can be seen as "a conversation with the microcontroller". |
You can send it command using code, and it will immediately talk back. You can change a line of code in a program and the change is immediately incorporated. | You can send it command using code, and it will immediately talk back. You can change a line of code in a program and the change is immediately incorporated. | ||
+ | |||
+ | So you can test sensors directly. Look at the values coming out of the sensor without a program. | ||
+ | |||
+ | Maybe this is why everybody wants micropython, why it seems to be a hype. | ||
Micropython needs disk space on the microcontroller (or around on the board): 60K | Micropython needs disk space on the microcontroller (or around on the board): 60K | ||
− | + | == Arduino == | |
+ | The Arduino doesn't "talk" micropython. Its memory is too small. | ||
+ | |||
+ | You can also say: Micropython is too big! | ||
+ | |||
+ | Uploading to the ATmega328, or comparable always cost time, even for the slightest change in code: compiling and flashing. The memory is always first erased, before putting the new code in. | ||
+ | |||
+ | The code stays on the board. | ||
− | == | + | The file is nicely saved in the Arduino Sketch folder |
+ | |||
+ | == Micropython - circuit python == | ||
Officiel versions | Officiel versions | ||
Line 26: | Line 39: | ||
https://learn.sparkfun.com/tutorials/micropython-programming-tutorial-getting-started-with-the-esp32-thing/all | https://learn.sparkfun.com/tutorials/micropython-programming-tutorial-getting-started-with-the-esp32-thing/all | ||
− | + | The program is not always saved on the microcontrollers. It is when you drag the file into the disk visible in your laptop. | |
+ | |||
+ | In the MAIX dock editor you have to specifically tell the editor to store the code on the microcontroller. | ||
== Editors == | == Editors == | ||
Line 33: | Line 48: | ||
Mu editor for Adafruit, also microbit https://codewith.mu Errors are displayed in the REPL window. | Mu editor for Adafruit, also microbit https://codewith.mu Errors are displayed in the REPL window. | ||
+ | |||
+ | The MAIX dock has its own editor: https://maixpy.sipeed.com/en/ | ||
+ | |||
+ | OpenMV has its own editor: https://openmv.io | ||
You can also use a text editor and drag the file into the micropython disk | You can also use a text editor and drag the file into the micropython disk | ||
− | + | == Microcontrollers talking Micropython (or CircuitPython)== | |
− | |||
− | == Microcontrollers talking | ||
''I have bought and tested these boards myself.'' | ''I have bought and tested these boards myself.'' | ||
Line 45: | Line 62: | ||
*Adafruit circuit playground express (29,95) https://www.adafruit.com/product/3333 | *Adafruit circuit playground express (29,95) https://www.adafruit.com/product/3333 | ||
− | *Adafruit feather M0 adalogger (22,93 euro) | + | *Adafruit feather M0 adalogger (22,93 euro) https://learn.adafruit.com/adafruit-feather-m0-adalogger/ |
*Adafruit Itsy Bitsy M0 (12,04 euro) | *Adafruit Itsy Bitsy M0 (12,04 euro) | ||
*Adafruit Itsy bitsy M4 express (15,70 euro) https://learn.adafruit.com/introducing-adafruit-itsybitsy-m4 | *Adafruit Itsy bitsy M4 express (15,70 euro) https://learn.adafruit.com/introducing-adafruit-itsybitsy-m4 | ||
Line 52: | Line 69: | ||
*Maix Dock one (30,95) https://www.antratek.nl/sipeed-m1w-ai-dev-board-with-lcd-and-camera | *Maix Dock one (30,95) https://www.antratek.nl/sipeed-m1w-ai-dev-board-with-lcd-and-camera | ||
*BBC Microbit (22,95) https://www.floris.cc/shop/en/home/1848-microbit-go-bundel-microbit.html | *BBC Microbit (22,95) https://www.floris.cc/shop/en/home/1848-microbit-go-bundel-microbit.html | ||
− | *OpenMV7 (75 euro) https://www.antratek.nl/openmv-h7-camera | + | *OpenMV7 (75 euro) https://www.antratek.nl/openmv-h7-camera, https://openmv.io |
*Sparkfun Artemis Thing Plus (25,35) https://www.antratek.nl/artemis-thing-plus | *Sparkfun Artemis Thing Plus (25,35) https://www.antratek.nl/artemis-thing-plus | ||
Line 59: | Line 76: | ||
*Sparkfun Edge (18,09) https://www.antratek.nl/edge-development-board-apollo3-blue | *Sparkfun Edge (18,09) https://www.antratek.nl/edge-development-board-apollo3-blue | ||
− | All these boards can also be programmed using the Arduino IDE | + | All these boards can also be programmed using the Arduino IDE, except for the microbit |
+ | |||
+ | == Memory space == | ||
+ | |||
+ | Micropython asks for memory space. | ||
+ | |||
+ | For example the Adafruit Feather M0 and the Adafruit Trinket M0 have only a little bit of space. | ||
+ | |||
+ | When you load too many libraries on the micro python "disk", you get this error: | ||
+ | |||
+ | [[File:mcDISKerror.png]] | ||
+ | |||
+ | This means that for a real micropython program two sensors can be too much, while if you program the same thing in Arduino IDE on these boards it only is 22% of the memory space. | ||
+ | |||
+ | [[File:disk22.png]] | ||
+ | |||
+ | These two images are for the same purpose: connecting a BME680 and a LIS3DH sensor to the Feather M0 datalogger. | ||
+ | |||
+ | Adafruit Itsy Bitsy M0, Adafruit Itsy Bitsy M4, Adafruit Itsy bitsy M4 express, have 2MB. | ||
+ | |||
+ | With these last boards you can add two sensors without any problem. | ||
+ | |||
+ | == Sensors == | ||
+ | |||
+ | For Arduino finding the library for sensors is easy, the sensor is practically sold - with the library. | ||
+ | |||
+ | Micropython libraries for Adafruit boards: https://learn.adafruit.com/welcome-to-circuitpython/circuitpython-libraries | ||
+ | |||
+ | I have used these libraries also for Sparkfun sensors if the sensor type is the same, for instance the LIS3DH. | ||
+ | |||
+ | == Special Boards == | ||
+ | Because the disk space must be bigger anyway, the boards come with extensions, like LCD screens and camera's, or extra programming facilities like micro AI: TensorFlow. | ||
+ | |||
+ | MAIX Dock has a mic array, a ring of six microphone and neopixels, which can indicate the direction of the sound: https://www.seeedstudio.com/Sipeed-6-1-Microphone-Array-for-Dock-Go-Bit-p-2875.html | ||
+ | |||
+ | At the same time the display which comes with the MAIX Dock displays also the direction of the sound: https://www.flickr.com/photos/contrechoc/49403059642/in/dateposted/ | ||
+ | |||
+ | The Adafruit Circuit Express comes with 8 neopixels and a microphone, acceleration sensor. | ||
+ | |||
+ | The BBC Microbit comes with a 5 x 5 pixel display, acceleration sensor, temperature sensor, BLE. | ||
+ | |||
+ | The Sparkfun Edge comes with tensor flow. It can do speech recognition, although the results are poor... | ||
+ | |||
+ | These advanced boards - compared to the Arduino board with only the built in LED 13 are really different ''personalities'', they can do different things, use different built in possibilities. | ||
+ | |||
+ | More about special boards on this page [[SpecialBoards]] - talking about boards independent of the language. | ||
+ | |||
+ | |||
+ | == Example BBC Microbit: micropython Speech == | ||
+ | Join a microbit with a sound board in 1 second (you have to buy this sound board): | ||
− | + | and using Code Blocks Programming: | |
− | == Arduino == | + | You can make sounds, tones, a melody |
− | + | ||
+ | [[File: CodeBlocks1.png| 500px ]] | ||
+ | |||
+ | But using microphyton: You can use speech. | ||
+ | https://microbit-micropython.readthedocs.io/en/latest/speech.html | ||
+ | Just insert 1 line of code: import speech and start talking. | ||
+ | |||
+ | [[File: Mupy1.png ]] | ||
+ | |||
+ | Sure, this is a poor machine voice, but still... | ||
+ | And you can edit your program in the mu-editor and upload it without dragging the file in the micropython disk. | ||
+ | |||
+ | I don't think this can be beaten using an Arduino and a self soldered speaker, although it can be done (for instance: https://www.youtube.com/watch?v=krFOc7AwaKI) | ||
+ | |||
+ | == Other languages == | ||
+ | Of course there are also other way to program these boards, Arduino IDE was already mentioned. | ||
+ | |||
+ | BBC Microbit can also be programmed in C++ using the online embed editor: https://ide.mbed.com/compiler/#nav:/microbit-proximity-heart/main.cpp | ||
+ | |||
+ | BBC Microbit and Adafruit Circuit Express can be programmed using the online Code block Editor: https://makecode.adafruit.com/#editor, which then can be changed in JAVA easily within this editor. | ||
+ | |||
+ | == Concluding == | ||
+ | So... Arduini IDE or MicroPython? | ||
+ | |||
+ | For me that depends. | ||
+ | |||
+ | To get the mic_array working, giving me a direction of sound, I will use the 13 lines of code in MicroPython (- but where can I get the setting changed?) | ||
+ | |||
+ | To get the speech machine voice: yes immediately the micropython speech! | ||
+ | |||
+ | For making the sensor networks, with cheap Pro Minis I will use the Arduino IDE. | ||
+ | |||
+ | For exploring other languages and sometimes study deeper structures, or get a vague idea of Makefiles, I will use C++ environments. | ||
+ | |||
+ | [[File: sensor_network.png]] | ||
+ | |||
+ | A kite with four networks of sensors attached to Pro Mini's with LCD's, reporting their data to a 5th Pro Mini (the boss microcontroller). All programmed in the Arduino IDE. In the background a kite with neopixel, currently programmed in the Arduino IDE using a ATmega328 board with RF12 - wireless, but this could be done even with an Adafruit Circuit Express, ItsyBitsy M4, BBC Microbit (BLE for sending and receiving data). | ||
+ | |||
+ | [[File: MaixMIC.png]] | ||
+ | |||
+ | The mic_array, with the Maix Dock, display and camera, conveniently programmed with MicroPython | ||
+ | |||
+ | More about the special boards like the Maix Dock in [[SpecialBoards]] | ||
+ | |||
+ | [[Category:Circuit Python]] |
Latest revision as of 15:10, 28 November 2022
Micropython is a hype!
Micropython is a programming language for microcontrollers, like C, C++, Java, Code Blocks.
In principle all the languages can do the same sort of thing. In principle all languages have the same type of complexity.
Why MicroPython???? Micropython can be seen as "a conversation with the microcontroller".
You can send it command using code, and it will immediately talk back. You can change a line of code in a program and the change is immediately incorporated.
So you can test sensors directly. Look at the values coming out of the sensor without a program.
Maybe this is why everybody wants micropython, why it seems to be a hype.
Micropython needs disk space on the microcontroller (or around on the board): 60K
Arduino
The Arduino doesn't "talk" micropython. Its memory is too small.
You can also say: Micropython is too big!
Uploading to the ATmega328, or comparable always cost time, even for the slightest change in code: compiling and flashing. The memory is always first erased, before putting the new code in.
The code stays on the board.
The file is nicely saved in the Arduino Sketch folder
Micropython - circuit python
Officiel versions http://micropython.org https://circuitpython.org
Adafruit version: https://www.adafruit.com/micropython
Sparkfun version: https://learn.sparkfun.com/tutorials/micropython-programming-tutorial-getting-started-with-the-esp32-thing/all
The program is not always saved on the microcontrollers. It is when you drag the file into the disk visible in your laptop.
In the MAIX dock editor you have to specifically tell the editor to store the code on the microcontroller.
Editors
Online code editor in python for the BBC Microbit: in Chrome (not in Safari or Firefox): https://python.microbit.org/v/2.0. Errors are displayed on the microbit.
Mu editor for Adafruit, also microbit https://codewith.mu Errors are displayed in the REPL window.
The MAIX dock has its own editor: https://maixpy.sipeed.com/en/
OpenMV has its own editor: https://openmv.io
You can also use a text editor and drag the file into the micropython disk
Microcontrollers talking Micropython (or CircuitPython)
I have bought and tested these boards myself.
(prices for Dutch shops, Antratek.nl, KIWI-electronics)
- Adafruit circuit playground express (29,95) https://www.adafruit.com/product/3333
- Adafruit feather M0 adalogger (22,93 euro) https://learn.adafruit.com/adafruit-feather-m0-adalogger/
- Adafruit Itsy Bitsy M0 (12,04 euro)
- Adafruit Itsy bitsy M4 express (15,70 euro) https://learn.adafruit.com/introducing-adafruit-itsybitsy-m4
- Adafruit Trinket M0 (8,40 euro) https://circuitpython.org/board/trinket_m0/
- Maix Dock one (30,95) https://www.antratek.nl/sipeed-m1w-ai-dev-board-with-lcd-and-camera
- BBC Microbit (22,95) https://www.floris.cc/shop/en/home/1848-microbit-go-bundel-microbit.html
- OpenMV7 (75 euro) https://www.antratek.nl/openmv-h7-camera, https://openmv.io
- Sparkfun Artemis Thing Plus (25,35) https://www.antratek.nl/artemis-thing-plus
- Sparkfun Artemis Nano (19,30) https://www.antratek.nl/redboard-artemis-nano
- Sparkfun Edge (18,09) https://www.antratek.nl/edge-development-board-apollo3-blue
All these boards can also be programmed using the Arduino IDE, except for the microbit
Memory space
Micropython asks for memory space.
For example the Adafruit Feather M0 and the Adafruit Trinket M0 have only a little bit of space.
When you load too many libraries on the micro python "disk", you get this error:
This means that for a real micropython program two sensors can be too much, while if you program the same thing in Arduino IDE on these boards it only is 22% of the memory space.
These two images are for the same purpose: connecting a BME680 and a LIS3DH sensor to the Feather M0 datalogger.
Adafruit Itsy Bitsy M0, Adafruit Itsy Bitsy M4, Adafruit Itsy bitsy M4 express, have 2MB.
With these last boards you can add two sensors without any problem.
Sensors
For Arduino finding the library for sensors is easy, the sensor is practically sold - with the library.
Micropython libraries for Adafruit boards: https://learn.adafruit.com/welcome-to-circuitpython/circuitpython-libraries
I have used these libraries also for Sparkfun sensors if the sensor type is the same, for instance the LIS3DH.
Special Boards
Because the disk space must be bigger anyway, the boards come with extensions, like LCD screens and camera's, or extra programming facilities like micro AI: TensorFlow.
MAIX Dock has a mic array, a ring of six microphone and neopixels, which can indicate the direction of the sound: https://www.seeedstudio.com/Sipeed-6-1-Microphone-Array-for-Dock-Go-Bit-p-2875.html
At the same time the display which comes with the MAIX Dock displays also the direction of the sound: https://www.flickr.com/photos/contrechoc/49403059642/in/dateposted/
The Adafruit Circuit Express comes with 8 neopixels and a microphone, acceleration sensor.
The BBC Microbit comes with a 5 x 5 pixel display, acceleration sensor, temperature sensor, BLE.
The Sparkfun Edge comes with tensor flow. It can do speech recognition, although the results are poor...
These advanced boards - compared to the Arduino board with only the built in LED 13 are really different personalities, they can do different things, use different built in possibilities.
More about special boards on this page SpecialBoards - talking about boards independent of the language.
Example BBC Microbit: micropython Speech
Join a microbit with a sound board in 1 second (you have to buy this sound board):
and using Code Blocks Programming:
You can make sounds, tones, a melody
But using microphyton: You can use speech. https://microbit-micropython.readthedocs.io/en/latest/speech.html Just insert 1 line of code: import speech and start talking.
Sure, this is a poor machine voice, but still... And you can edit your program in the mu-editor and upload it without dragging the file in the micropython disk.
I don't think this can be beaten using an Arduino and a self soldered speaker, although it can be done (for instance: https://www.youtube.com/watch?v=krFOc7AwaKI)
Other languages
Of course there are also other way to program these boards, Arduino IDE was already mentioned.
BBC Microbit can also be programmed in C++ using the online embed editor: https://ide.mbed.com/compiler/#nav:/microbit-proximity-heart/main.cpp
BBC Microbit and Adafruit Circuit Express can be programmed using the online Code block Editor: https://makecode.adafruit.com/#editor, which then can be changed in JAVA easily within this editor.
Concluding
So... Arduini IDE or MicroPython?
For me that depends.
To get the mic_array working, giving me a direction of sound, I will use the 13 lines of code in MicroPython (- but where can I get the setting changed?)
To get the speech machine voice: yes immediately the micropython speech!
For making the sensor networks, with cheap Pro Minis I will use the Arduino IDE.
For exploring other languages and sometimes study deeper structures, or get a vague idea of Makefiles, I will use C++ environments.
A kite with four networks of sensors attached to Pro Mini's with LCD's, reporting their data to a 5th Pro Mini (the boss microcontroller). All programmed in the Arduino IDE. In the background a kite with neopixel, currently programmed in the Arduino IDE using a ATmega328 board with RF12 - wireless, but this could be done even with an Adafruit Circuit Express, ItsyBitsy M4, BBC Microbit (BLE for sending and receiving data).
The mic_array, with the Maix Dock, display and camera, conveniently programmed with MicroPython
More about the special boards like the Maix Dock in SpecialBoards