Custom Blockly Block “does not know how to generate code”

March 8, 2016 at 10:56 pm (computers, kids) (, )

I’m playing around with my Espruino board (embedded board, programmed with JavaScript) as part of my quest to find a kid-friendly embedded controller.  One of the nice things about Esruino is that it comes with a Web-based IDE that provides a terminal console that allows you to write JavaScript directly onto the board or allows you to programme it using Blockly.

I want to write some custom blocks, so downloaded the source for the EspruinoWebIDE and did the following:

  • Created a new file “EspruinoWebIDE\blockly\blockly_myfile.js”
  • Included this file in a SCRIPT tag in the top of “EspruinoWebIDE\blockly\blockly.html”
  • Proceeded to create my blocks – initially as defined using the Google BlockFactory and then added to blockly.html to present them in the UI

There are already a few files defining extra blocks – blockly_espruino.js is the main one and blockly_robots.js is a simpler one, that actually makes quite a good example to follow if you are doing your own.

The basic idea is that there is a ‘toolbox’ definition for your block in the blockly.html file (which makes it appear in the menu of blocks in the user interface), supported with a block-definition file detailing the physical appearance of the block and what it needs to connect to within the user interface (Blockly.Blocks.mycategory_myblock) with an accompanying code-generation block.  In this case, generating JavaScript via Blockly.JavaScript.mycategory_myblock that uses the Blockly API to get what it needs from the user interface and returns a string that contains the corresponding generated code.

There is a setting in the EspruinoWebIDE – Settings->General->Overwrite JavaScript with Graphical Editor – which is quite handy at this point, as it means that every time you hit ‘Send to Espruino’ in the graphical editor, the JavaScript window is updated with the generated code.

Except when it isn’t.  There were no obvious errors, and the ‘Send to Espruino’ always said ‘Sent’ but there was no outward sign that anything had happened.

If you use the Inspect option of the Chrome browser then it was apparent that there was a JavaScript error:

Language “JavaScript” does not know how to generate code for block type “mycategory_myblock”

This hidden message indicates that there is a miss-match between the Blockly.Blocks.mycategory_myblock function and the Blockly.JavaScript.mycategory_myblock function and even though the block is available through the user interface, Blockly doesn’t know how to generate code for it.

Except in my case, no matter how it was written, generated, typed or checked, it was ignoring my code and I just could not spot what the error was.  Eventually, I changed the order of the SCRIPT statements in blockly.html, wondering if there was some kind of load-order issue and it suddenly started working.  Once I changed the order back again, it kept on working – so unfortunately I have no idea what was causing the problem, but just guessing some weird local caching issue or something not picking up my changes.

But if you are finding things aren’t working but there are no visible errors, definitely try Inspect and look for JavaScript errors and see if you can somehow force the application to re-load all files from scratch to make sure you aren’t working with an old version or something similar.  I still don’t know why it started working, but at least it works now.

The only reason I’ve written this is that Googling for various hints as to what might cause the issue was failing me – even once I knew what the error was.  So thought I’d write it down myself in case others have a similar issue – this might give someone else a clue.

Despite this rather irritating issue, I actually quite like Blockly.

In a future post, I’ll talk a bit more about what I’m actually doing with all this.





Permalink Leave a Comment

Codebugs, Glowbugs and DIY Tails

February 20, 2016 at 11:21 pm (computers, kids, maker) (, , , , )

We got a couple of Codebugs just before Christmas and have been having quite a good time playing with them so far.  You write code for them using an online IDE based on Google Blockly and the device itself has two buttons, a 5×5 grid of LEDs and 4 GPIO ports with nice croc-clip friendly contacts on it so you can straight away start playing with linking code to the physical world.   It also has an expansion connector (the ‘Tail’) and when you connect it to a PC via USB it comes up as a mass storage device and you drag code across to it to run it.

We’ve done the obligatory “scroll your name” across the LEDs, hooked up fruit to create a fruit ‘touch’ keyboard and have started exploring some of the projects available via the online community.

My only slight gripe is that the mechanism for getting code on it isn’t quite as intuitive as it might be.  We’ve largely got the hang of holding buttons down whilst powering it up.  although, when trying out code, it tends to stay plugged in, so we use the ‘reset’ then ‘hold’ technique designed for when it is powered by battery most of the time.  However sometimes the buttons aren’t held quite long enough for it to register.  Also, every time it comes up in mass storage mode, the previous programme is erased.  If you are not careful you end up with lots of “compiled” Codebug programmes lying around your browser’s download directory.  Seeing as all projects are managed by the online IDE it would be nice if there was a neater way to send the code straight to the Codebug without copying between directories.

That aside, its a great device and has generated lots of interest with the kids and I’ve recently purchased a set of Glowbugs.  These are WS2812 based RGB LEDs with simple croc-friendly (of course) contacts that you connect to the Codebug using the GPIO, configure and off you go.

For our next project however, we quite wanted to use all 4 GPIO as inputs and I know that the Glowbugs can be driven directly via the expansion header, so I set about seeing if I could create a DIY ‘tail’ connector to breakout the CS, +5v and GND connectors, as used by the Colourtail, to something that would accept croc clips.

I also have a cheap, purchased from China, 24-LED WS2812 pixel ring with the same +5, GND, DIN, DOUT interface as Neopixels and the Glowbugs that I wanted to use.  I’ve already connected this up via the Codebug Tail, but again wanted something croc-clip friendly that the kids could use.

So armed with a 20x80cm prototyping board and some right-angled headers, I set about making a simple DIY tail adaptor and connector for the LED ring.  Warning – massively dodgy soldering coming up.


As a major goal was to make this easy for the kids to use, I wanted the connectors to break out in the same order as the Glowbugs – so (with all boards face down) this means from left to right, GND, DIN, +5v.  However the tail connectors are CS, GND, three not required for this application, and VCC, so I needed a wire link to get CS (for the data) from the left-most pin to a central spot.


With a small portion of board cut and smoothed ready for headers, I decided to use crude solder blobs as a simple way to create croc-friendly pads and connections, as can be seen via the very dodgy soldering going on in the following!  In case you can’t quite make it out, the ‘circuit’ is highlighted in the last pic.


So after adding another three ‘pads’ on the other side, the final thing looks like this.


In order to be able to easily use the LED pixel ring, I decided on a similar approach to add some ‘pads’ to the ring.  Once again I wanted the pads in the same order as a Glowbug.  I could have added both an ‘in’ and ‘out’ connector, but decided for simplicity only to create an ‘in’ – so the ring will always be the last thing in the chain.  In the following, the wires are coloured as follows: green is GND, blue is DIN and red is VCC.


The biggest problem with just connecting the pixel ring directly to the Tail connector was the poor physical connection of the wires to the ring itself, so this time to give it a degree of kid-robustness, I used a hot-glue gun to stick the pads to the ring and protect the solder links.


With a final blob of glue over the top of the solder connections to the ring, everything is ready to go.


So to use the Glowbugs connected via the DIY tail, you have to use the configuration blog to enable the ‘Colourtail’ rather than ‘Glowbug’, but otherwise, everything else is just the same.  And of course, the ring is just treated as a set of additional 24 Glowbugs added on the end of the chain.

So crude, and soldering that will definitely not be winning any prizes, but it works, and passes first contact with the kids.




Permalink Leave a Comment

Wii fixed it (even though they didn’t want us to)

December 28, 2012 at 12:13 pm (kids, moan, odds) (, , , , , , )

Do you get fed up with today’s “the bonnet is welded shut” mentality to consumer electronics?  I do.

Part of the issue, is that the drive for compactness is making the designs optimised for size rather than maintenance – so you get circuit boards shaped and interleaved around larger components, small ribbon connectors and carefully routed cables and so on.  You also find that you need to know the exact order in which to unscrew things and pop them apart, and then work out if something is fixed by a clip, glue, screw or something else.

But it doesn’t need to be as hard as it is.  There is also an annoying trend for hidden screws (often behind rubber feet or blanking panels that pop or stick on/off), speciality screws and one-way plastic fixings which makes the whole thing a lot more complicated than it needs to be.

But there is some hope.  The excellent site has a massive range of guides for many popular consumer electronic devices.  It is practically the haynes manual for electronics.  Haynes themselves do have some computer related manuals, and a wide range of novelty manuals (sold ‘for kids’ – but they don’t say how big or small the kids have to be) – including Bob the Builder, Thomas the Tank Engine, the Millenium Falcon, Thunderbirds and a few others.

But the nice thing about the website is the community around it – you can see comments from fellow fixers and see how many people have rated and attempted the fix.  It also lists the tools you need, and if you don’t have any you can help support the site by buying tools through them.  You can also buy spare parts.

So, with a slight twist of irony, whilst my car is wide open to home mechanics, I’ve long since got fed up with getting my hands dirty, and seeing what look like simple steps in a haynes manual, which are performed on prestine, clean, non-rusted-up parts, turn into hours of frustration and finding out I’ve not got the right replacement washer or something.  So today, I rely on a local, small garage round the corner and pay for their expertise and collection of tools and parts.

However with consumer electronics, I have most of the tools, already have the ‘well if its broken anyway I have nothing to lose’ mentality and enough of a background in basic electronics and computers to challenge the consumer electronics industry attempts at stopping me having a go.  And the parts are rarely rusted shut or covered in oil (the odd exception being something whose last moments might have been spent left in a rainy sandpit!  That tends to be fairly terminal).  With a little dust to clear here and there and some basic static precautions I’m quite ready to have a go.  In fact the most risky part is keeping the kids away from the carefully laid out screws and fittings as the thing comes apart – especially if something has to be taken apart and then left until a new part is sourced and delivered from some speciality online store or ebay.

And so, courtesy of a new drive from ebay. a tri-wing screwdriver, a range of small phillips screwdrivers, the guide for replacing the drive on a Wii, and some peace and quiet from the kids, we have a functioning Wii again and can now try out some of the new games the kids got for Christmas.

It’s not as hard as you might think but naturally you will void warrenties and everything is done at your own risk – but as I said, if its broken, you can either pay for repair (cash for someone else’s time), just buy a new one (what a waste) or at least see how complicated it will be to have a go yourself.

Viva the maker culture of repair not replace!


Permalink Leave a Comment


June 9, 2012 at 9:28 pm (computers, kids) (, , , , , , , )

Blast from the past this one … and in some senses, a few months too late!

I stumbled across a spectrum emulator for the ipad (can’t remember how now …) and that let me to the World of Spectrum.  Whilst knowing about Spectrum emulators (I had a paid for copy of one courtesy of, was it Brian somebody?  I think I still have it on a floppy disk somewhere from around 10-12 years ago!) I haven’t touched one for a very long time.

Like many, I had a Spectrum in the 80s – the Spectrum+ was my first one, followed by a Spectrum 128 at some point.  I followed all the typical titles from Ultimate (Play the Game), Melbourne House, Quicksilva and the like … and whilst there are so many I could mention, for some reason one that always stuck out in my mind and that I really wanted another go on was Starquake.

Don’t really know why, other than I remember when Crash magazine published the map of the game as a centre page I spent quite a long time exploring, using the teleports and basically working on it until I had actually completed it.  Back in the time when maps were hand drawn and submitted to the magazines!

I wondered about getting the iPad emulator and having another go, but looking at all the instructions of how to get custom games onto an iPad, I didn’t get further than just downloading it .. but then I noticed a Java icon and sure enough, if you feel so inclined you can run games from World of Spectrum directly in your browser – so I had a few moments nostalgia running Starquake once again.

From the opening (always tinny, this being simple Spectrum sounds) jingle, through the in-game sounds and graphics and scarily, I actually remember a lot of how to play it and actually what you need to do at specific points – where you need to ride a platform here, but get off just there to go through this passage and collect this whatsit over here …

I wonder how much of my memory is taken up with trivial paths through games from that era … only to be reawakened via a Java emulator some 30 odd years later …

Its very interesting to note how those simple graphics often hid a simple, but very addictive gameplay.  Something that gets forgotten a little with some of the large franchise titles these days, but something we perhaps are seeing a bit of a return to with some of the addictive mobile and social games.

Curiously, I still have my Spectrum 128 in the loft (along with my Atari 2600) … but I would be absolutely amazed if any of those tapes (assuming I still have a few) play any more.

But that will do for now, I have to go and find Sabre Wulf (with its colourful fauna and orchids), On the Run (more colourful fauna and very distinctive sound effects and puffy graphics), Atic Atac (‘ware the ghosts, find the keys and watch that bizarre roast chicken drain down!)  and a few other real classics from the time and re-live this electronic part of my teens.



Permalink Leave a Comment