Home Home Astronomy Chemistry Electronics Mathematics Physics Field Trips Home  

Arduino Block Coding

 

Sorry, I cannot guarantee all information is correct or current. (Email link at bottom of page.)

 

Overview

Arduino microcontrollers are normally programmed in a slimmed-down (or more user-friendly) version of C++ using the Arduino IDE. However, there are also several ways for beginners to program them using block programming.

Some of these methods use something called Firmata, a ~12 kB Arduino program which is uploaded to an Arduino and allows a computer to communicate with the Arduino in realtime. This has the advantage that the code does not need to be compiled, and is implemented instantly. This setup can be a very convenient way of interfacing a computer with the world around it, employing the Arduino to handle the sensing and switching that microcontrollers do so well. (The interface could even be wireless, using a Wi-Fi or Bluetooth connection to the Arduino.)

Firmata can be found in the Arduino IDE sample programs: File > Examples > Firmata > StandardFirmata. It can be uploaded to the Arduino using the Arduino IDE the same as any other program.

However, Firmata has the drawback that the Arduino programs are not persistent – they don't last after the Arduino is disconnected from the computer. For an embedded application we need to be able to compile the code and upload it to the Arduino.

Scratch is a popular block programming tool, available with a web browser interface or a stand-alone program which comes with Raspberry Pi. It's very easy to use, but Scratch doesn't itself cope with Aduino. Most of the options below are extensions of Scratch to add Arduino functionality, and each provides a handful of Arduino-specific code blocks in addition to the standard Scratch code blocks.

 

 

Realtime Coding

These programming tools do not produce persistent code. The program is lost when the Arduino's power is turned off.

 

ScratchX

ScratchX is a web browser interface and uses Firmata to provide realtime changes in programming. To enable Scratch to support Arduino requires the Scratch Extensions Browser Plugin, and another extension to provide the actual functionality for the Arduino. Extensions for other hardware are also available.

  1. Install the ScratchX browser plugin. It's available for Mac and Windows only.
    • I was not able to install it on Mac OS 10.11. Although it seemed to install OK in Mac OS 10.6.8 it gave no sign that it was working.
  2. Use the ScratchX Arduino extension.
    • I have not been able to get this working.

Being unable to get it working I'm unable to recommend this option.

 

Snap4Arduino

http://snap4arduino.rocks/

Snap4Arduino is a web-based modification of Snap, which itself "is an extended reimplementation of Scratch". Snap4Arduino uses Firmata so any programs are not persistent.

There is no Raspberry Pi version but Snap4Arduino 5.1.0 is available for several other platforms:

  • By web browser: http://snap4arduino.rocks/run/
  • Mac OS 10.10+ (it would be nice if the minimum required version was mentioned on the site).
  • Linux 32 bit and 64 bit.
  • Chrome OS.
  • Windows 32 bit and 64 bit.
  • Source code.

This doesn't look as nice as other options, although that probably doesn't affect its performance at all. It is compatible with Arduino Nano but gives slightly inconsistent results when reconnecting the Arduino (for example, the Arduino program doesn't restart by itself).

If you really want to do some realtime programming, this is your best option.

 

S4A

http://s4a.cat/

S4A is a Scratch modification using a custom firmware apparently similar in function to Firmata.

Untested; limited board support, too many hoops to jump through to get it working.

Before starting programming, the firmware will need to be uploaded to your Arduino using the Arduino IDE or some other method.

S4A app is available for Linux, Mac, Raspberry Pi, and Windows.

"S4A works with Arduino Diecimila, Duemilanove and Uno. Other boards haven't been tested, but they may also work." No mention of it working with the CH340G USB controller on many clone boards.

 

 

Persistent Coding

These are the block programming tools I'm most interested in because the programs are compiled and thus persistent; you end up with an Arduino which can be plugged in and used for its programmed purpose when needed.

I regard block programming as a tool to help learn programming, and so an important feature is being able to see the code as blocks are placed, and to instantly see changes in the code when blocks are modified.

 

Ardublockly

https://ardublockly.embeddedlog.com/demo/

Web interface.

I only gave this a partial test; some features depend on it running at the same time as the Ardublockly app – for example, uploading a program to an Arduino. The app (untested) is available on the GitHub repository for Linux, Windows, and Mac (listed with a build error). https://github.com/carlosperate/ardublockly

Nice appearance with source code (visible the whole time) updated in realtime.

There are a few missing features. All code from blocks is put into void loop() and the user cannot set code specifically to run in void setup(). This is an annoying limitation, although it could be regarded as a bug. (It can be worked around using an if statement which sets a boolean to prevent it running a second time.) Pins cannot be referenced using variables (or constants).

It has not been updated since October 2016. For a descendent which is being updated see Edukits Code Kit.

 

ArduinoBlocks

http://www.arduinoblocks.com/web/project/editordemo

ArduinoBlocks is a block programming web interface.

I was only able to give it a partial test – "Demo mode! Login for complete editor"; not nice.

A feature breakdown:

  • Blocks.
    • Separate default blocks for setup() and loop(); nice.
    • There are two versions of commands to read or write pins – one with pin numbers only, selectable from a pop-up menu, and the other allows the pin reference to be a variable (or constant); nice.
    • Using the second type of block introduces a new function which sets the pinMode every time the pin is written to; not nice.
    • There are a LOT of extra blocks covering using the EEPROM, Bluetooth, LCD screens, RTC, GPS, SD card, addressable LEDs, MP3 files and many other things; very nice.
    • A downloadable library pack is available.
    • The block display sometimes gets confused, and continues to display a block that has been deleted, or doesn't correctly resize a block based on the length of the number inserted into it.
  • Source code viewing.
    • No option for a live view of the source code; not nice.
    • A pop-up menu at the top left has an option for a pop-up window showing the source code, which is plain text (not coloured).
  • Code download.
    • Gives options for downloading a .ino file by itself, and a zipped folder containing the .ino file (ready to go for the Arduino IDE).
    • A camera button offers a PNG snapshot of the blocks; nice. This could save a lot of time cropping screen shots.
  • Code upload.
    • No way to upload block code to the interface. To reuse block code, programs apparently have to be stored on the site; very not nice.
    • An Upload button cannot be clicked, so I don't know what it does (uploads the block program to an Arduino?) or if it works.
    • To upload code to an Arduino apparently requires a plugin or something to be installed on your computer – pretty common for web interfaces which offer the feature.
  • Code compiling and upload to Arduino.
    • This is done by the program ArduinoBlocks-Connector v4 which "connects ArduinoBlocks to your Arduino board".
    • Available for Linux 32 bit & 64 bit, Mac, Raspberry Pi "Raspbian Buster (10)", Windows "Tested on XP, 7, 10 (32/64 bits)". Other minimum OS version requirements unknown.
    • The downloads for these platforms are significantly different sizes: RPi = 101 MB, Linux 64 bit = 117 MB, Mac OS = 212 MB (zip file; 692 MB expanded). Why are they so different?
  • Documentation.
    • The only documentation I could find that I could actually view was in Spanish, which is rather less easy to read than I'd prefer.
    • Elsewhere I found a mention that it "used the Google Blockly development code to create a block-based interface for the Arduino. Currently, it supports the Arduino UNO, NANO and MEGA."

All up, the demo mode which I tested is a strange mix of good and bad which end up canceling each other out. The incredible range of blocks is very impressive and should allow some complicated projects to be programmed but not being able to load saved programs is too big a limitation.

 

BlocklyDuino

https://blocklyduino.github.io/BlocklyDuino/blockly/apps/blocklyduino/

BlocklyDuino is a web interface for block programming an Arduino based on Blockly from Google (https://developers.google.com/blockly/). The interface itself can run offline in a web browser. The block code can be saved to a computer and loaded to the web interface, both using an XML file.

As explained in the BlocklyDuino Git repository wiki, it does not provide the ability to upload code to an Arduino, but does allow Arduino code to be saved to a local drive, pasted into the Arduino IDE and uploaded manually. However, it is possible to "run a mini webserver that uses the Arduino IDE to upload the code to a connected Arduino board on Windows, Mac OS X and Linux systems." That's more complicated than most beginners are looking for; I didn't even attempt to get it working.

I found BlocklyDuino hard to use; for block programming it was strangely non-intuitive. Blocks can be deleted by dragging them to the rubbish bin at the bottom right corner (which took surprisingly long for me to figure out). It's easier to just highlight blocks and hit Delete on my keyboard.

There is no infinite loop block, and its source code gets everything put in void loop() without the option to put setup code in void setup(). There is no way to view the source code in realtime, as the code view tab is separate from the block coding tab.

This option is not high in my preferences.

 

Edukits Code Kit

https://edukits.co/code/

Edukits Code Kit is a block programming web interface inspired by Ardublockly. Code Kit creates code on the fly and allows the code to be copied or downloaded; the downloaded file includes a containing folder, so is ready to go in the Arduino IDE. Saved programs can be uploaded to the web interface.

The Arduino IDE (or an app like ArduinoDroid on Android) is used to upload programs to an Arduino, but there are app versions of Code Kit for Mac and Windows which can upload directly to an Arduino (untested).

I initially only gave it a partial test because I found some bugs and missing features which meant it wasn't suitable for what I would consider "normal" use. However, an email I sent to Edukits was very quickly answered, and very impressively answered with a list of all but one of the problems I had mentioned which had been fixed. Further to that, new blocks to support WS2812 addressable LEDs have been added, along with a dark mode.

The main missing feature that I'd really like to see is that it cannot reference pins using constants (or variables). I'm told this has been almost fixed. Code has been written but it'll be added later, probably with an Advanced Mode, because of potential problems such as new users not knowing which pins are PWM capable.

Code Kit is easy to use, and mostly produces clean, uncluttered code. (Some blocks such as the sense gesture block and WS8212 block add a lot of extra code so that no external libraries are needed – the program is all self-contained.) The genuinely usable interface has great potential and I plan on doing much more testing.

 

mBlock

mBlock is also based on Scratch. It makes some big claims (like being trusted by 10,000,000 users) but it has limitations, most annoying of which is probably the lack of parity of hardware support between different platforms.

mBlock 5.

  • mBlock 5.2.0 for Mac needs Mac OS 10.12+.
    • It'll sort-of run on 10.11 but it won't save files and seems to have several other issues.
    • Extra hardware blocks need to be opened for each program.
  • mBlock 5.2.0 for Windows needs Win 7 or Win 10.
    • It does not support Arduino Nano clones with the old or new bootloader.
    • It's oriented to be used online, and the standard Open and Save commands are linked to an online account instead of the user's own computer.
  • mBlock 5 for Android and iOS does not support Arduino. This is a big failing. Where's the platform parity?
  • mBlock 5 is also available by web browser, and requires the mLink plugin to make it work.
    • mLink MacOS 10.10+, Linux 64 bit, or Windows 7 or later. mLink is not available for ARM (eg, Raspberry Pi, Android).

mBlock 3.

  • mBlock 3.4.12 is available for Mac, Windows, Linux and Chromebook.
    • The Windows version cannot be found on the website when using Windows.
  • The web version is no longer available because it used Flash.
    • The website says it'll stop at the end of 2020.
  • The Mac version gives a very nice fully coloured code preview, with a button for editing in the Arduino IDE. It uses Arduino IDE 1.6.5 for uploading and code editing (which is older than the version I actually use).

From what I've seen, mBlock 3.4.2 is easier and nicer to use than mBlock 5.2. That's not a great endorsement for what should represent a significant improvement.

The download page on the website is rather curious. It changes depending on... something. Perhaps it's the platform being visited from, but it seems to change randomly, and often doesn't present the file(s) actually wanted. Or even any files. There is simply no fixed list to download any particular version wanted. This is very non-standard. (For example, old versions of the Arduino IDE are easy to find and download!)

mBlock can be used to upload compiled code (using the Arduino IDE), so can be used for programming embedded applications.

 

Sketchware for Arduino

https://play.google.com/store/apps/details?id=com.sketchware.arduino

Sketchware for Arduino is an Android app, and requires Android 5.0+.

This app provides drag and drop block coding, and compiling and uploading, but to an Arduino Uno only. This is very sad because it seems to do a very good job – at least what I've been able to test without having an Arduino Uno. For example, the code it creates is quite straight forward and not really convoluted like some interfaces produce.

The main program screen has two tabs: Logic and Serial Monitor. The Logic tab allows access to two separate screens for the setup() and loop() functions – very nice – and also a subtly colourised source code preview screen. The Serial Monitor tab provides a serial monitor with two way communication, along with an option to save the content of the serial monitor.

While the Uno bootloader can be loaded on a Nano clone this app still can't cope with the CH340G USB chip. Without compatibility with more than that one board its usefulness is rather limited, and the promised support of more supported boards and libraries has not eventuated.

However, there is a workaround. The app stores its saved programs in numbered folders, not named folders, so finding a particular .ino file can be tricky, but the file can be opened with ArduinoDroid (see below) and uploaded to a wide range of Arduino boards.

The app wants permission to access the users' contacts. Why!? That's almost as dodgy as any permission I've ever seen. Deny permission for the app to access your contacts! I've also seen Sketchware display some rather dodgy ads.

 

ArduinoDroid

https://play.google.com/store/apps/details?id=name.antonsmirnov.android.arduinodroid2

ArduinoDroid allows code to be edited and uploaded to a wide range of Aduino boards, including a Nano clone (ie, CH340G USB controller) with old bootloader. At times it's a bit awkward to use, mostly because of screen size, and has extra features which can be bought. It's the best Arduino IDE available on Android.

ArduinoDroid also wants permission to access your contacts, along with being able to use the telephone. Do not allow either.

 

Others

The options listed above are not exhaustive. There are many other options. These are some that should not even be considered for block coding.

 

CodeBlocks Arduino IDE

  • http://arduinodev.com/codeblocks/
  • Untested; I can't see anything to indicate this has anything to do with block programming. Even the screenshots don't show any blocks.
  • "CodeBlocks-Arduino contains added functionality for Code::Blocks to allow Arduino software development. Code::Blocks is a more advanced IDE than the ArduinoIDE, yet is still fairly straightforward."
  • So it's an IDE, not for block coding. I can't say how good it is as a programming IDE compared to the Arduino IDE.
  • Available for Linux and Windows.

 

MAKE with Arduino IDE

  • https://play.google.com/store/apps/details?id=com.CEREALLAB.FruitsLoop
  • Android app.
  • Untested; requires a login when launching, either with Google or MAKE. This is extremely dodgy.
    • I can think of absolutely no reason why I should supply my Google account login to anyone, let alone this particular company.
    • I have no idea how the app or company would use my Google login details – even if I could remember the details.
    • I have no idea why the app or company would want a Google login at all (other than as an excuse to get my Google account details).
    • Many users will be children and social media accounts require a certain minimum age. Google account holders are supposed to be 13 to manage their own accounts. For getting kids to start coding, why have a login barrier at all?
  • Neither of the two websites displays on my laptop. One of the links has a Somalia country code – strange for a company apparently in South Korea. What and who is this company which is asking for Google account details?
  • One of the permissions is to know the users approximate location.
  • For security reasons, do NOT use this app.

 

ScratchDuino

 

Conclusion

None of the stand-alone options are good enough to get a strong recommendation. They all have significant problems and I have not found any that support Arduino Nano clones – which means they can't actually be used stand-alone.

mBlock is probably the best complete package for desktop computers, but more work is needed to fill in gaps in its platform support.

Sketchware for Arduino has great potential for Android. What it has is actually rather good, but it desperately needs to support more boards and the CH340G USB chip, and to not have "sketchy" ads and permissions. Use ArduinoDroid to compile and upload code to many Arduino boards that Sketchware for Arduino doesn't support. Security warning: Do not let either have access to your Contacts.

I have not tested it but I expect either of those programs will work with this Arduino Uno clone, because it uses an ATMEGA16U2 for the USB controller, not a CH340G.

The web version of Edukits Code Kit is not stand-alone (it needs other software to upload code to an Arduino) but it gets my vote for best web interface. It's very easy to use with existing programs and cellphone apps which can do that. I'm looking forward to seeing what I can do using it with addressable LEDs.