If you think that my LED tutorial is too complicated to program a simple LED, then this article might be of interest for you. Because there is an easy and basic way: And I mean it: really basic. And the name is the program(ming language) ;-).
One of my very first contact with computers was the Commodore C64: this was a very successful home computer system back in the 1980′s: a 8bit machine with 64 KByte of RAM and a built-in Basic Interpreter in ROM:
The great thing with the build-in BASIC ROM was that you immediately can start programming: no compiler or special IDE needed: simply type in your program and run it! Awesome simple and intuitive, especially for beginners. And of course there was plethora of software and game available too.
Now the cool thing is: there is the CoreBASIC interpreter for the FRDM-KL25Z Freedom board created by SolderCore.
Freedom MSD Bootloader
First, I need to load the MSD bootloader on my Freedom board to use OpenSDA as mass storage bootloader (skip this step if the MSD bootloader is already running):
- Plug in the board using the SDA USB port, with the reset button pressed
- Small green LED nearby of the OpenSDA K20 toggles
- Device enumerates as Mass Storage Device/Drive named ‘Bootloader’
- Drag&drop (or copy) the MSD_FRDM_KL25Z_Pemicro_v*.SDA from P&E’s OpenSDA firmware (latest and greatest, registration needed) or from Freedom Quick Start the to the Bootloader drive (:!: unzip the files first, and then copy!)
- Unplug the USB cable and power the board again with the USB cable
- Small green LED is on, and device reports as ‘FRDM-KL25Z’ device
- Now the Freedom board can be programmed with an application file
Programming the CoreBASIC application
Next step is to program the board with the BASIC firmware:
- Download the CoreBasic Freedom Board CoreBASIC firmware (binary file).
- Copy the freedom.bin file to Freedom board device (drive letter on your system)
- Be patient as it takes a while to flash the application
- Repower the board
Connecting with Tera-Term
Connect to the board with 115200 baud:
After connecting to the OpenSDA serial port, I press the reset button, and I get:
To print out something is easy, simply type in
print "Hello World!"
There are other cool things: turning on the red RGB LED is as simple as:
core.led = %red
And you guess it right:
core.led = %blue core.led = %green core.led = %black
turns the RGB led to blue, then to green and finally to black (well: off). Other colors are accepted too (see below or the CoreBASIC manual).
A LED Blinking Loop
Creating a program on the fly is simple: it is entered line by line.
Each line starts with a line number. To insert new lines, it is a good idea to increment line numbers by 10 (so I have enough lines as space in the program).
So I enter the following lines, one after each other:
10 for i = 1 to 5 20 print i 30 core.led = %magenta 40 pause 0.5 50 core.led = %black 60 pause 0.5 70 next i
Simply copy-paste the source lines into TeraTerm!
The list command lists my program:
Notice the %magenta in yellow color: here I have made spelling error. To correct a line I simply enter that line again.
to delete a line: I use the delete command followed by the line number.
The command to run a program is: of course run:
The video on the SolderPage shows the usage of the accelerometer.
Using the edit command opens an editor to edit multiple lines:
make sure the TeraTerm view is big enough, otherwise the top line(s) of the source might not be visible.
To exit the edit mode, use CTRL+D.
It is a great feeling: feels like I was young and programming with the Commodore C64. Maybe because of the blue background ;-). It is really fun to quickly type in something and to see how it goes. The only consideration is that there is not much RAM left, and that does not allow big things. SolderCore demonstrates on larger devices with more RAM that a BASIC system can work with file system, ethernet and all the other goodies an embedded systems offers. On the CoreBasic site there is a cool demo video, plus www.soldercore.com/manual/ for the documentation, plus code examples I can try out.
Happy Back to BASIC