Program an Arduino from any browser, even from a tablet, even a cell phone? Of course, and there are several options available for makers and other learners who want to develop embedded applications using Wiring code and the Arduino IDE.
Architecture & programming by Göran Krampe
The Craftbot for Arduino tether project came about as part of the eCraft2Learn project within a EU-backed Horizon 2020 programme. It’s meant to run as a service on a Raspberry Pi or similar single-chip computer (i.e. the Raspbian ‘Stretch’, released Aug 2017), while it should run fine on any Linux by following the build instructions.
So, what is the big deal? What can I do once I have it?
Well, now you can program your Arduino remotely – in a plain web browser – using a computer, tablet or phone. You’ll need a Raspberry Pi or other Linux computer and some open source software, including the Arduino IDE which is used headless. For our current web based example editor, we use the CodeMirror text editor. The editor works out of the box in most browsers, and you don’t need to tether your computer with a serial cable, the Raspberry takes care of the serial connection.
We started off supporting only the Arduino Uno, but we aim to expand the Craftbot for Arduino API to support both choosing among standard Arduino boards as well as adding other boards and libraries, as they are both exposed CLI calls.
Below, you’ll find a schematic of how the parts are glued together. The tablet on the far left could just as well be a stationary computer, laptop, phone or anything with a browser. When we demo on the fly, we’ll use a power bank and tether WiFi off a cellphone, to further free the Raspi from unnecessary cables!
So, we’re sending the source in base-64 encoded text over MQTT or REST to the Raspi, and it compiles there using a headless installation of the Arduino IDE, and then flashing the firmware to the Arduino. We’ve already thought of multiple users targeting multiple devices, one per USB port. And here the server uses a thread pool allowing several jobs to run concurrently. You’ll get any compilation error messages back, typically via an MQTT topic subscription. The messaging broker normally also runs locally on the Raspberry Pi, we use Eclipse’s Mosquitto, a popular open source MQTT broker service. Third parties can also subscribe to the various topics, for example, to collect common coding errors users are making. This has proven to be interesting for a learning context like the eCraft2learn project we’re currently involved in.
Ok, so now we have another ‘thing’ in the chain, what’s wrong with the computer I already use?
As if keeping track of the Arduino hardware wasn’t enough, and you might reason that there are Arduino boards already with a Linux processor on-board, isn’t this more like a step backwards? Our take is rather to focus on the possibilities, being able to serve multiple single-board computers, to be somewhere else than the target device, to be able to have many kids program Arduino boards using just tablets and to optionally be able to do all of this without the need of an Internet connection to cloud resources which may be a true reality in many educational scenarios. The MQTT broker also opens up possibilities for other things like sending serial monitor data, sensor readings, and affect actuators depending on “outside” parameters like weather conditions, temperature, movement, stock tickers or sending data for third-party cloud-side crunching.
Speaking of possibilities, what about industry-strength applications?
Using standard technologies already out there today, it’s piece of cake to go reasonably secure, both MQTT and REST APIs can easily be lined up in their secure incarnations, and fret not at cost issues, as you know a free cert can nowadays be generated from our friends site at the Linux Foundation’s service Let’s Encrypt.
Again, the Pi computer is merely an example, the code should run on most Linux installations and can be hardened to the strength required, currently, it’s listening on two open ports; 8080 (http) and 1884 (mqtt). The Raspberry Pi was used for convenience and as a very interesting price point, and we also had access to them with our target audience (learners, at 13-18 yrs), there are many other more powerful and ruggedized edge devices.
We could also easily picture scenarios where the Craftbot for Arduino (including the Arduino IDE) runs in the cloud, and only the ‘last step flashing operation’ is carried out with the actual hardware in place, using more controlled environment which obviously compiles many times faster. This is like a distant cousin to the ‘web editor’ hosted by Arduino, but the difference is that this is a slightly more open solution that can be integrated into other development tools and also hosted by anyone and anywhere.
Ok, this all sounds fine, I want one!
Excellent, we hope you’ll like it. Don’t be a stranger, and feel free to tell us what you think! Instructions on how to make your own, shiny Craftbot for Arduino can be found on our Github.
And for the lazy, there is a ready-baked SD card image available (approx. 900 MB download) too here, although building from source is recommended as the project will continue to evolve over the next few months. Don’t forget to do apt-get update and apt-get update, if you’re running a RPi 3 B+ to upgrade the bootloader. You’ll also need to fix the wifi though, for it to be discoverable when running headless. Those specific instructions are found in this readme
For usage, the Raspberry Pi is usually called (or calls itself using zeroconf) raspberry.local on your local network, and you call it typically from a browser using raspberrypi.local:8080/index.html
. Each sketch is saved as a retained message over MQTT, and by calling the sketch parameter, you can work on several projects concurrently. Every sketch you create, starts with a default blink pin 13 sketch, e.g. raspberrypi.local:8080/index.html?sketch=baloothebear
.
The next steps
The Craftbot for Arduino as seen today is a first step, in a direction well-known to some, somewhat radical to others and it is our hope that with this development effort, we are able to inspire others to do new things based on the underlying ideas, both within the Horizon 2020 programme and far beyond. This code is released under the MIT license to the effect of that you as a developer can use, modify, distribute and sell solutions containing this code and libraries free of choice.