Showing posts from January, 2017

A simple reaction timer in MicroPython on the micro:bit

The micro:bit continues to surprise and delight me. My project yesterday was to write a simple reaction timer in MicroPython . The timer application was really easy to code. I'll build up a subset of the code step-by-step, but the whole program is on GitHub . You can download it here . Here's how the code works: The program starts by displaying a clock image: Next, it picks a random time to wait, ranging from 500 ms to 4500 ms. (In other words, it will wait between half a second and four-and-a-half seconds.) sleep(random.randint(500, 4500)) When the time has run out it displays a happy face:   Then it checks every tenth of a second to see if the user has pushed button a (to show they have seen the image, keeping count while it waits. def time():     # returns the time until waiting is over, in 1/10 secs     count = 0     while waiting():         sleep(100) # 100 ms = 1/10 secs         count = count

MicroPython on the BBC micro:bit - easy as Pi

The BBC micro:bit really makes it easy for you to get hooked and get coding with MicroPython. Like Python, the micro:bit comes with batteries included. Plug in the battery and an irresistible introductory app launches. Many newcomers will use the Scratch-like block coding environments. If, like me, you prefer to program in Python, a couple of clicks on the micro:bit website will show you how to upload and run your own code. When you connect the the micro:bit via USB, it appears as a removable USB drive and you can just drop your code onto the drive to flash (install) and run your program. There's a browser-based interface to the compiler, but I'm using the mu editor on the Pi. That way I can maintain my source files on Github, and I'll be sharing them once I have something useful to show. I'm hoping to start coding the controller for C2Pi in the next few days. For now I'm working my way through the great examples available on the micro:bit website and

Raspberry Pi and BBC micro:bit for C2Pi

Right now the Raspberry Pi and the BBC micro:bit look like a winning team. If you're f ollowing this blog you will know that I am evaluating new hardware and software for C2Pi (the re-generated C3Pi, neé Trackbot). Over the weekend I discovered that the micro:bit now supports MicroPython. Since I am looking for a micro that supports a language with a REPL, I had to investigate. MicroPython on the pyboard I've been a fan of MicroPython for a while. It runs on several platforms, including a custom board (the pyboard). I first met the pyboard, and Damien George, (its designer, and the original implementer of MicroPython) at an Open Technology conference in Cambridge a couple of years ago. I learned that MicroPython is a full, optimised implementation of Python 3; the only difference lies in MicroPython's specialised libraries, which  focus on direct access to the hardware. At the time I felt that the pyboard and MicroPython had great potential but I couldn&#

Embedded development is faster with a REPL

In my previous post I mentioned that I was frustrated by the slow pace of Arduino-style development and that I was looking at using a language with a REPL (Read-Evaluate-Print loop). A REPL is just a fancy name for an interactive environment. You can type an expression and have the computer evaluate it; the computer display the result immediately. (If you've ever used Python interactively you'll know exactly what I mean). Why REPLs are great REPLs give you immediate feedback. If you've done something right, you get an immediate reward. If you've made a mistake, you get to fix it while everything is still fresh in your mind. I find it makes for much faster progress, particularly if I am using hardware or software I haven't used before. They also give you a chance to do some stunning demos. Here's a video of two Dyabots dancing, courtesy of Morten Kromberg (CXO of Dyalog). A tale of two REPLs  C3Pi and Dyabot have two computers on board; a Pi to do

C3Pi regenerates!

My old friend C3Pi, like Doctor Who, regenerates from time to time. He started life as Trackbot - a tracked robot, powered by an Arduino Nano, with fairly limited capabilities. Some years later he acquired a Raspberry Pi, and replaced the Nano by a Teensy 3.1. C3Pi has proved a good subject for experiments, as did the Dyabots - the mobile robots built by Dyalog to experiment with APL as a control language for robotics. But... The C3Pi and Dyabot designs had their limitations, and it's time to apply the lessons learned. Issues with C3Pi and Dyabot Several factors have stopped me achieving all I want to with the old version of C3Pi. I found it awkward to recharge or replace C3Pi's batteries. C3Pi’s limited room made it hard to add new capabilities. The Pi was a veteran model 2 B+; C3Pi would benefit from the processing power of the Pi 3. I found the Teensy disconnect-compile-upload-reconnect-test cycle frustratingly slow . The motor control