blockly for arduino

881 views
Skip to first unread message

Kzooo Hori

unread,
Oct 31, 2017, 2:10:13 PM10/31/17
to Blockly
Hello. Please let me know if you do not mind.

In ios application, I'd like to convert blockly blocks to Arduino code.

I could convert it to JavaScript code using "javascript_compressed.js" with reference to 'https://developers.google.com/blockly/guides/configure/ios/code-generators'.

However, using "blockly_compressed.js" and "arduino_compressed.js" obtained from github of ArduBlockly or BlocklyDuino will give an error.
Perhaps I think that there is a problem with the contents of these files. What is the relationship between these two files?
Should I have to rewrite these files myself to realize generation of Arduino code?

Incidentally, such an error has come up.
"Could not evaluate JavaScript resource files: Error Domain=WKErrorDomain Code=4 "A JavaScript exception occurred" UserInfo={WKJavaScriptExceptionLineNumber=2034, WKJavaScriptExceptionMessage=TypeError: undefined is not a constructor (evaluating 'new Blockly.StaticTyping'), WKJavaScriptExceptionColumnNumber=103, WKJavaScriptExceptionSourceURL=about:blank, NSLocalizedDescription=A JavaScript exception occurred}"
Message has been deleted

Victor Ng

unread,
Oct 31, 2017, 3:33:55 PM10/31/17
to Blockly
I'm not too familiar with ArduBlockly or BlocklyDuino, but I'll do my best to answer your question.

blockly_compressed.js: This is the Blockly engine/library
arduino_compressed.js: This should contain the methods for generating Arduino code

In your case, the error is complaining that the type "Blockly.StaticTyping" is undefined, which seems to be specific to those Arduino projects (it's not an object defined in Blockly). You'll need include any extra JS dependencies by adding it to `jsCoreDependencies` when initializing the `CodeGeneratorService`.

As a side note, because the code generator actually runs in a webview, you can debug it outside of Xcode using Safari.
Enable "Developer Mode" in Safari, and then when your iOS app is running, open Safari and select Develop > Simulator (or device) > about:blank. Then you can see the console for any errors that may occur.

Kzooo Hori

unread,
Nov 1, 2017, 12:57:56 AM11/1/17
to Blockly
Thank you for your response.
I will refer to your opinion.

2017年11月1日水曜日 4時33分55秒 UTC+9 Victor Ng:

Maziarser

unread,
Nov 1, 2017, 11:47:58 AM11/1/17
to Blockly
Hi Kzooo,

I will really appreciate if you share with me the solution (if you find it).

thank you

Victor Ng

unread,
Nov 1, 2017, 5:03:34 PM11/1/17
to Blockly
To follow up, I did a quick test to see how this could be done. There is a solution for both open-source libraries, but it will require a bit of effort.

BlocklyDuino

This is an older library and does not have generators for many of the core default blocks. However, you can get up and running immediately with it.

1) From the Blockly repo (https://github.com/google/blockly), copy "blockly_compressed.js" and "msg/js/<language of your choice>.js" (eg. "en.js") into your Xcode project.
2) Then copy "arduino_compressed.js" from BlocklyDuino into your project
3) Specify these files into CodeGeneratorService and you should be able to generate code (unfortunately, for very few blocks).

With this solution, you'll most likely need to create generators for many blocks (or copy them from ArduBlockly).

ArduBlockly

This one is more well-maintained and has generators for many of the core blocks. Unfortunately, it is out-of-date and needs to be merged with the Blockly core library in order to work with Blockly iOS (which assumes a version of Blockly master from the past year). So here's what you'll have to do:

1) Merge the latest version of Blockly into ArduBlockly's version, by following the instructions under "Git Configuration" in the README. This will probably result in conflicts, which need to be resolved.
2) Once merged and resolved, run the build script ("build.py") to generate updated versions of "blockly_compressed.js" and "arduino_compressed.js".
3) Copy "blockly_compressed.js", "arduino_compressed.js", and "msg/js/<language of your choice>.js" into your Xcode project.
4) Specify them into the CodeGeneratorService and generate the code.

This is probably the preferred approach to go with. It's a bit of work to setup, but should be relatively simple to use afterward.

Kzooo Hori

unread,
Nov 3, 2017, 12:45:50 PM11/3/17
to Blockly
thank you for the advice.So it will be helpful.

I will consider it from now.
Thank you very much.

2017年11月2日木曜日 6時03分34秒 UTC+9 Victor Ng:

Maziarser

unread,
Dec 19, 2017, 8:39:16 AM12/19/17
to Blockly
Hi Victor,

First of all Thanks for your explanation. It was very helpful for me and I am currently working on BlocklyDuino to make more blocks available for it.

My work leads me to a question which is:

Is there any possibility to make "Serial Monitor" of Arduino IDE available in my web-based app which is based on BlocklyDuino ?

Any help will be appreciated

Maziar

Andrew n marshall

unread,
Dec 19, 2017, 12:29:48 PM12/19/17
to blo...@googlegroups.com
It looks like the Arduino Web Editor uses plugins.  The source of the plugin is here: https://github.com/arduino/arduino-create-agent. It appears that is just the serial port communication to the arduino, and while critical, I don't see any hint that it includes any frontend UI such as the serial monitor. I haven't found any hint that the Arduino Web Editor is open source anywhere, which might be a deal breaker for your goals.

I would reach out to the Arduino developers (there are two active contributors from Arduino to the above project). Explain what you are trying to do and see if they provide you any leads.

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Evan Cole

unread,
Jun 18, 2018, 6:12:07 PM6/18/18
to Blockly
Hi Maziar,

How is your project coming along? I am looking to do some Arduino projects with my students and would love to have access to an updated BlocklyDuino, if you are willing to share out your work.

Cheers,
-Evan

Maziarser

unread,
Jun 19, 2018, 11:40:59 AM6/19/18
to Blockly
Hi Evan,

It is still in developing process. I will share my work as soon as it gets finished, so others can use it in as easy way.

Regards,
Maziar

alittl...@vlacs.org

unread,
Jun 25, 2018, 1:45:11 PM6/25/18
to Blockly
I am experimenting with mBlock http://www.mblock.cc/ It also supports Python and based a version of Scratch...
Reply all
Reply to author
Forward
0 new messages