Since its debut of April, 2020, LEGO Spike Prime has attracted much attention and many wonder if it will replace LEGO MindStorms sometime in future. In today’s post, I would like to show our first experience of LEGO Spike Prime programming environment, and have a brief comparison with LEGO MindStorms EV3 programming.
Drag-and-drop Coding Language
Quoted from LEGO Spike Prime introduction:
The SPIKE App uses an intuitive drag-and-drop coding language that’s based on Scratch. Some of the blocks are identical to the ones that are used in Scratch 3.0, while others have been specially developed to interact with the SPIKE Prime hardware.
If you are familiar with Scratch 3.0 programming, it would be a breeze to understand how to drag and drop those blocks and snap them together to make your project run.
In the following example, the program first sets motors to E and F ports. When the force sensor (which is attached to port A) is pressed down, the model will stop running and hub’s center button light turns to Red. When the force sensor is not pressed, the model will turn at the speed proportional to the reflective light intensity and hub’s center button light turns to green. Meanwhile, the model will play music till the program stops. The final effect is shown in the following video.
Writing the above program is not difficult once you get familiar with Scratch 3.0 programming techniques. Many blocks in Control, Operators, Variables tabs, etc. are the same as that in Scratch 3.0. Using parallel code segments as shown above, the program could conduct multiple tasks at the same time. Through broadcasting and receiving messages, a program could realize more complicated logic relationship.
Quoted from LEGO Spike Prime Introduction:
The Python editor in the app uses MicroPython, which is an efficient and and commonly used version of the Python language that’s optimized to run on microcontrollers or small computers. The majority of Python’s language features are found iin MicroPython. However, MicroPython doesn’t contain the entire Python library by default.
An advantage of LEGO Spike Prime is that you could create a Python project right through Spike App, and the Python project could show side by side with those projects created with block language.
This design is advantegous to Python coding in LEGO MindStorms EV3. When developing Python program for LEGO MindStorms EV3, we need to use Visual Studio Code to write and run Python code. We might also encounter issue when trying to connect computer with EV3 via Bluetooth.
The following is a sample Python project which implements the same functionality as the above block based project.
Using Python Editor in LEGO Spike brings same experience as using Visual Studio Code for LEGO MindStorms EV3. However, it is not issue free. One problem is that the console information could not get refreshed in time. Therefore, the historical error information always shows in the console window, even though the code has gotten updated and runs successfully. To work around this problem, I will close the Python project and reopen it, just to ensure clearing up the Console window.
Code Comparison with LEGO EV3
The following is the EV3-G code implementing the similar function as above. Due to the design constraint of EV3 programming blocks, there are lots of wires connecting different blocks, making the program look complicated for beginners.
Although EV3-G is a good starting point for kid to learn LEGO programming, block-based language of LEGO Spike Prime seems a better choice since it is easier for kid to understand, edit their code, use variables and different control structures.
That is my initial experience of LEGO Spike Prime. Stay tuned and more topics about LEGO Spike are on the way!
Note: All the analysis articles are copyright products of http://www.thecodingfun.com. Anyone re-posting them should credit author and original source. Anyone using them for commercial purposes or translating them into other languages should notify TheCodingFun and get confirmation first. All Rights Reserved.