Custom extension: Arduino code generation, include


#1

I’m working on an mBlock extension that would enable custom blocks for controlling a LED strip that’s attached to the Arduino Leonardo board.

I am using mBlock v4.0.4 on Ubuntu (64bit). I was forced to take this preview version because the only “production” linux version was for 32bit platform.

I have created the s2e file and put the myClass.cpp and myClass.h files in the src folder. The myClass.h has to be included when any of the extension blocks are used, so I have specified the “inc” property for every block definition in the s2e file.

The extension zip file imports without issues. The blocks are shown in the IDE. The Arduino code is generated correctly. However, the problem is that at upload there’s a “Compiling failed” error, and thers’s info in the log - “Fatal error: myClass.h: No such file or directory”

How to debug such error?In what path the ino file is verified/compiled? It appears that the extension files are not copied to that path prior to compilation.

Another, more general problem, is that code upload to Arduino fails with “Cannot communicate with the board” error, and after that it is not possible to connect via USB anymore, the first upload failure apparently messes up the port and/or conversation with the board, so any further attempts are futile until the board is disconnected and reconnected. It is also not possible to upload firmware to the board, when USB connection is established, I get the same “Cannot communicate with the board” error.


Creating custom extention - compiling problem
#2

Hi Passiday,

You may refer to this post have a try.
Besides, you may upload your extension file here.


#3

Here’s the extension zip file. It installs without issues, and I was using the pdf file for reference that is mentioned in that post.
The only deviation is that I did not include the js subfolder at all, as the extension will never be used in Scratch mode. But I’d expect an error message at install time, if that would be the problem.

LEDStar.zip (2.3 KB)


#4

Do you have any insight in this “fatal error … no such file” problem? I did further research and found that a similar error is thrown also for other extensions that can be found+installed in the extensions manager.

Basically the problem boils down to the fact that the extension files are not copied to the path where the cpp source is. I checked the /opt/makeblock/mBlock/resources/tools/arduino-server/compilerProcess.js file that is responsible for this process and found the problem:

this line #13

extensionArr&&extensionArr.length&&fs.existsSync(buildPath)&&fs.emptyDirSync(buildPath);

empties the build path if the path exists and there are any extensions to copy. However, this line #26 slightly below

if(!fs.existsSync(buildPath)) {

tells to initiate the extension copying only with the build path does not exist. So, as a result, the extension files are copied only the first time the code is compiled (the build path does not exist), but if I try to recompile, the build path already exists, it is emptied (but not deleted!) and the extension files are not copied. Hence, the “no such file or directory” error.

I fixed the problem by replacing the lines #26 to #29 with this:

if(!fs.existsSync(buildPath)) {
    fs.mkdirSync(buildPath);
}
if (extensionArr&&extensionArr.length) {
    this.copyExtensionFile(extensionArr,buildPath);
}

It’s kind of dirty fix, but it works.


#5

Good to hear you’ve found a solution.
The next major version (mBlock 5) will work on better extensions experiences.

BTW 32bit versions should work on 64bit systems.


#6

I am not sure why you say “should work”, because they totally don’t work. Of course, by default, there are no i386 architecture libraries installed, but even after meticulously installing every single library that was required to launch it, mBlock did not work properly.

So the extension problem is now fixed. The upload problem is another thing, and it seems to be related to the fact that the Arduino IDE included in the mBlock requires some kind of usb driver related 32 bit package. So it’s still the architecture issue. I hope that Arduino code compilation and upload works in mBlock 5 fine for both architectures.


#7

Hi Passiday
It seems that I have the same kind of problem with the extention I am trying to create
There is this message “fatal error: MotorDriver.h: No such file or directory” when I am trying to transfer the code to the Arduino board.
Unfortunatly I don’t manage to find the “compilerProcess.js” file on my computer and I am kind of stuck right now…