Interactive BASIC for Arduino and STM32

This project was developed for classes with schoolchildren - so that in the lesson you could program controllers, including via Bluetooth from a phone - with an interactive mode.

It includes a simple homemade BASIC interpreter with firmware versions for AtMega328 (arduino) and STM32F103, an emulator so you can try/practice online - and a Bluetooth terminal for Android (in case of programming from a phone and not via cable).

The thing is more or less working - we played with it for a semester - but still I am not very satisfied with the result (I will explain why) - and in the following years I tried other ideas in this direction (also quite wild).

Background

Teaching electronics as a hobby at a local school, of course, every year I tried to include a few lessons with microcontrollers. It would seem that there is nothing to it - hand out arduinos to everyone and go - but this option faces problems:

  • the classes are held in a regular classroom, not equipped with computers - and the option "let everyone bring a laptop" is also doubtful - so I wanted to use mobile phones

  • the kids are not taught C (some classes study programming in Python, others in Java) - so although they can type and modify basic examples, slightly more complex ones inevitably face a lot of problems (in the lessons, I don't want to spend time thoroughly explaining the language)

In general, there are many options for how to arrange the interaction of the phone with the controller, especially now - there are environments for Arduino, and more intricate things (and I will tell you about a couple of my own later) - all of them, however, turn out to be inconvenient when you are not entertaining yourself alone but trying to organize the work of a class of 20 people.

So - the Miskatino project

The name is probably a bit silly - I didn't bother with it, I was just reading Lovecraft's fairy tales at that moment - and it was inspired by the name of the fictional university.


Interactive BASIC programming interface for Arduino and STM32 microcontrollers, displaying code and connected devices.

Here is the project on GitHub https://github.com/Miskatino/miskatino-basic - there is a fairly detailed description of the commands - there is also an emulator, so those who read this article from a computer can try it right away - open it and enter the command

PIN 2; 1

and, oh miracle, you will see that the LED drawn on pin 2 "lit up". Try to type the "program" - for this we enter commands with line numbers:

10 PIN 2; 1
20 DELAY 300
30 PIN 2; 0
40 DELAY 700
50 GOTO 10
RUN

Note - the last command without a line number. It is not added to the program but starts it for execution. The LED will blink.

If you take an Arduino - you can assemble and upload the project - and program it from a regular console via cable (for example, from the same Arduino Serial Monitor - a window in the Arduino IDE). As a basic model, I used those with controllers on AtMega328 - but in general, almost any will do, although since the program lives in RAM, the more RAM, the better.

For programming via Bluetooth, I bought a handful of HC-05 modules and soldered suitable connectors to them and to the Arduinos so that they could be plugged into each other. But it turned out that a convenient "terminal" for interactive work on the phone is not so easy to find - so soon I wrote my own (in particular, to send characters immediately and not accumulate them by lines). It is available there on GitHub, but since it has not been updated for several years, it is unlikely to run on a modern phone - and you will need to choose something else.

In general, you can admire the video (although I probably recorded the demo in English for Reddit), study the documentation, play with the emulator, or flash it into a live controller. The program in the controller is saved (although on Arduinos this was done in EEPROM, which is not very convenient) - and after restarting, if the controller does not receive any commands, it starts itself. That is, this thing can be used in simple crafts to reprogram and test them "on the go".

Conclusion

As mentioned at the beginning, I was not very satisfied with the results of the classes with the students. We tried to light LEDs, get the voltage value from the variable resistor engine, work with a seven-segment indicator. Below are the impressions on which I decided to move on and try other options.

  1. Technical - two dozen poor Bluetooth modules in one room, with unreliable power supply - all this makes the connection not very reliable on a scale of 20 people - every now and then someone's controller reboots or something else happens. However, on the scale of a whole class with any crafts, everything is always not smooth, even with ordinary Arduinos ("and my port disappeared", etc.)

  2. Technological - in this implementation, only relatively small programs fit into the Arduino memory - and their capabilities are of course limited by the functions provided in the interpreter. The performance is sufficient for a temperature controller or, say, a simple robot - but in general it is clear that the interpreter is an order of magnitude slower than compiled code. On ARMs, everything is of course much more fun - but making and soldering 20 boards with STM32 for the class seemed too laborious to me.

  3. Ideological - as I complained above, C is too difficult for the guys - and Basic, of course, is too simple. Well, not counting the process of mastering with an interactive set of programs. This is not the level for grades 9-11. In the following years, I already try to torment the children with assembler for AVR - their brains leak a little from this, but it seems more useful in terms of expanding their horizons. They are still able to learn Arduino C at this age without me (well, I help those who take it up as part of individual projects, they cope with the instructions without difficulty).

Comments