Running mBlock in Linux


#1

Hi,
I leave you a Linux script to run mBlock in Linux, I have tested it in Ubuntu 16.04. These are the steps to run mBlock under Linux with Wine:

  1. Install wine on Linux. Install mBlock for Windows in Linux
  2. Download the script: mblock_wine.sh
  3. Plug mBot to computer via USB
  4. Run script with sudo: sudo ./mblock_wine.sh
  5. Reboot
    Now you should be able to connect to mBot with mBlock via USB.
    Regards

mBot for Linux
#2

Thanks a lot for this Fran.
Just a shame you have to run it as root.

I’m using the following script to start mBlock at the moment (with the mbot connected). I found that my users, logging in with LDAP, seem to be in the dialout group. I found that the udev rule can be skipped when using the /serial/by-id path. That makes that I don’t need root access.
I found that my registry keeps on forgetting the COM port. Do you find that too?

/bin/bash

ln -s /dev/serial/by-id/usb-1a86_USB2.0-Serial-if00-port0 ~/.wine/dosdevices/com1
printf “\n\n[Hardware\\\Devicemap\\\Serialcomm] 1231984861\n"Serial0”=“COM1”\n" >> ~/.wine/system.reg
wine “C:\Program Files (x86)\mblock\mBlock.exe”

Kind regards
Koen


#3

If the users are not in sudoers, you can modify the script to pass the username as an argument, and apply the script to that user. But the administrator should run the script anyway. Root access is needed at least to add users to dialout group.


#4

Great to have a script for mBlock in Wine.
But isn’t it better to check if user are in the dialout group. And if not so, write an instruction how to add user to dialout group?
And if the user is root, write a warning that it is better to add user to dialout group (and how to do that) and then continue with statrting mBlock.
Also check if file /etc/udev/rules.d/mblock.rules exists, and if not, also print out how to set that.

Preferable telling how to add with command printf(1):

printf "sudo adduser %s dialout\n" $USER

It would make the script not loosing security, and still be friendly.
By the way, are it always/dev/ttyUSB0? The symlink will always be /dev/mbotUSB, but /dev/ttyUSB0 i’m not that convinced.


#5

I have tested this script in Ubuntu 16.04 and works. If your Linux needs to change /dev/ttyUSB0 modify the script according to your needs. And any improvement of the script is welcomed, feel free to modify it.


#6

I’m running Wine on Ubuntu 16 and have mblock installed. Mblock opens fine, but doesn’t see the COM port. I’m not sure where to place the mblock_wine.sh script. Can someone advise where to place this script?


#7

A new hope: early linux preview


#8

be carefull for the linux version, the executable is for x64 platforms so you’ll have to compile the sources for x32 if you need it by yourself


#9

Thanks a lot! And thank you for your comment on the language issue - seems like I need to recompile anyway. We are at the moment removing all our 32 bit machines since they are not reliable anymore for different reasons, but thank you for the hint!


#10

Changing the default language.

For future reference:
Open “app/translator.js” in the source code. On line 74 you have the language hardcoded
this.setLanguage(“zh_CN”);
Change that to the default language you want (list of possible languages is higher up in that file).
Then recompile as follows:

##Install required software

(for Ubuntu 16.04):
sudo apt-get install python-software-properties
curl -sL https://deb.nodesource.com/setup_7.x | sudo - bash -
sudo apt-get install nodejs
sudo apt-get install libusb-1.0-0-dev
apt-get install libbluetooth-dev

Compile

Go in the source code folder and run the following:

npm install
npm run rebuild-serialport
npm run rebuild-hid
npm run rebuild-bluetooth
npm run dist-linux

You’ll find the compiled Linux software in dist/linux-unpacked.


#11

You will always be in English when you launch mBlock with the actual V4.
mBlock team is on migration to Electron (Github) so the users prefs are not yet saved, they have to code the new solution for saving user prefs (and many other things). Electron migration involved to rewrite all the menubar actions (because the menubar is embedded in Electron), so it’s a big work…


#12

It actually does work.

I changed this.setLanguage(“zh_CN”); to this.setLanguage(“nl_NL”); , recompiled and now it always starts in Dutch.

We are very patient with this and very glad that there is something that works. The solution with Wine gave java-errors we were never able to solve. We exported code to mBot with V4.


#13

Yes because you have hardcoded the default language. Remove this line. Run mBlock, select a language (other than English) and exit. Re-run mBlock, the language will be the defaut language, not the language you have selected, so mBlock will always run in English.
You can use this line this.setLanguage("nl_NL"); it’s an hardcode but a temporary workaround solution :wink:


#14

Ah, ok. Sorry, I misunderstood.
I’m aware that it is a temporary workaround, but glad it works. Better a workaround then nothing at all :slight_smile:


#15

I’ve tried all above, but I can’t change the language to catalan despite the fact I have the locale (ca.pak). Any idea?


#16

I have tried with Ubuntu 16.04 (32Bit) but get errors after npm run dist-linux

> mBlock@4.0.0 dist-linux /home/winux/mBlock
> build --linux AppImage

Rebuilding native production dependencies for linux:ia32
Packaging for linux ia32 using electron 1.4.13 to dist/linux-ia32-unpacked
Building AppImage for arch ia32
Error: Exit code: ENOENT. spawn xorriso ENOENT
    at /home/winux/mBlock/node_modules/electron-builder/src/util/util.ts:77:16
    at exithandler (child_process.js:218:5)
    at ChildProcess.errorhandler (child_process.js:230:5)
    at emitOne (events.js:96:13)
    at ChildProcess.emit (events.js:189:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:213:12)
    at onErrorNT (internal/child_process.js:359:16)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)
From previous event:
    at exec (/home/winux/mBlock/node_modules/electron-builder/src/util/util.ts:55:3)
    at /home/winux/mBlock/node_modules/electron-builder/src/targets/appImage.ts:74:11
    at Generator.next (<anonymous>)
From previous event:
    at AppImageTarget.build (/home/winux/mBlock/node_modules/electron-builder/out/targets/appImage.js:144:11)
    at postAsyncTasks.push.default.map.it (/home/winux/mBlock/node_modules/electron-builder/src/platformPackager.ts:172:85)
From previous event:
    at LinuxPackager.packageInDistributableFormat (/home/winux/mBlock/node_modules/electron-builder/src/platformPackager.ts:172:41)
    at /home/winux/mBlock/node_modules/electron-builder/src/platformPackager.ts:168:10
From previous event:
    at LinuxPackager.pack (/home/winux/mBlock/node_modules/electron-builder/out/platformPackager.js:219:11)
    at /home/winux/mBlock/node_modules/electron-builder/src/packager.ts:146:22
From previous event:
    at Packager.doBuild (/home/winux/mBlock/node_modules/electron-builder/out/packager.js:275:11)
    at /home/winux/mBlock/node_modules/electron-builder/src/packager.ts:114:38
    at Generator.next (<anonymous>)
    at runCallback (timers.js:651:20)
    at tryOnImmediate (timers.js:624:5)
    at processImmediate [as _immediateCallback] (timers.js:596:5)
From previous event:
    at Packager.build (/home/winux/mBlock/node_modules/electron-builder/out/packager.js:227:11)
    at /home/winux/mBlock/node_modules/electron-builder/src/builder.ts:249:40
    at Generator.next (<anonymous>)
From previous event:
    at build (/home/winux/mBlock/node_modules/electron-builder/out/builder.js:90:21)
    at Object.<anonymous> (/home/winux/mBlock/node_modules/electron-builder/out/cli/build-cli.js:68:41)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:418:7)
    at startup (bootstrap_node.js:139:9)
    at bootstrap_node.js:533:3

npm ERR! Linux 4.4.0-59-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "dist-linux"
npm ERR! node v7.5.0
npm ERR! npm  v4.1.2
npm ERR! code ELIFECYCLE
npm ERR! mBlock@4.0.0 dist-linux: `build --linux AppImage`
npm ERR! Exit status 255
npm ERR! 
npm ERR! Failed at the mBlock@4.0.0 dist-linux script 'build --linux AppImage'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the mBlock package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     build --linux AppImage
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs mBlock
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls mBlock
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/winux/mBlock/npm-debug.log

#17

thank you. I got same errors on my 32bit debian jessie but I was able to solve:

  1. changed command in: curl -sL https://deb.nodesource.com/setup_7.x10 | sudo -E bash -

  2. solved Winux error adding: sudo apt-get install xorriso

  3. added: sudo apt-get install --no-install-recommends -y icnsutils graphicsmagick xz-utils

  4. overwritten all libpepflashplayer.so found in package with 32bit version downloaded from Adobe

Until last step mblock in dist/linux-ia32-unpacked keep showing “loading …”. After overwrite all run fine.


#18

I have run the command and faced a lot of error while compiling. I have rectified the errors using hp customer service and now everything is correct and working perfectly.


#19

Updatet link to mblock_wine.sh


#20

1
Getting Started with mBlock
by Wang Yu, Product Manager at Makeblock
Getting Started with mBlock
2
What is mBlock
You write programs to control your computer. To do that,
you need to know the languages of the computer - Java,
C, or Python are among those. If you want to control a
robot, probably you need to know Arduino C++ or a
similar language.
mBlock comes to help. You can write programs by
dragging and dropping building blocks. Furthermore,
with mBlock, you can not only design games and visual
effects in your computer, you may also write programs to
Arduino based robots.
mBlock and Scratch
mBlock is an open source branch of Scratch, a graphic
programming language developed by MIT Media Lab Lifelong
Kindergarten. That means you can make almost all Scratch
projects and open almost every Scratch files in mBlock; besides,
you earn the possibility of working with Arduino based robots.
mBlock and Makeblock Makeblock, the company making the famous mBot and construction kits for makers, is the one who translated Scratch into mBlock. Currently mBlock is actively maintained by Makeblock. But as an open source project, mBlock embraces a larger maker and educator ommunity by providing features like extension center, supporting not only Makeblock’s products by also arduino boards, Seeed Studio kits, Littlebits and more.
Tips
Tips
Controls pictures
(“Sprites”) on the screen
Controls robots and
Arduino boards
Getting Started with mBlock 3
mBlock can be downloaded for free at
http://www.mblock.cc
It supports windows and mac. Linux users can use an
online beta version located at:
Getting mBlock
“Windows Download” button.
After that, open the .zip file, and drag the mBlock.app to your
Applications folder.
After downloaded, click on the downloaded file or
double-click it in the windows explorer.

For Windows Users
For Mac Users
Virus?
Some old anti-virus software may claim mBlock as a virus. In this
case you may need to close that software before installing. Every
mBlock version is thoroughly tested, but since mBlock operates
with the hardware (Robots), some anti-virus software are just
vigilant about this kinds of software.
Mac OS Sierra
For the latest Mac OS Sierra
Users: When opening mBlock
the first time, you need to go to
the “Application” folder, right
click mBlock icon, and choose
“Open” to avoid the “unknown
source” error.
Tips
Tips
Drag
Getting Started with mBlock 4
A tour around mBlock
Open mBlock and you’ll see the following interface. You
may try to experiment around.
The “Stage” to
hold drawings and
moving pictures (we
call those pictures
“Sprites”)
The Sprite panel.
You can create new
sprites here. Drag blocks from
here to the script
zone.
the “script zone”,
where you place
your command
blocks.
Switch between different
types of command blocks.
Arduino and robot related blocks are located here.
Save or load
project files.
Connect to your robots
or upload firmware.
Select which type
of hardware you’re
using
Introduce new blocks by
downloading extensions.
Getting Started with mBlock 5
As a branch of Scratch, everything you learnt from
Scratch works with mBlock.

As a brief introduction, this guide will provide an
example on the Scratch part of mBlock.
Playing with Scratch
Open mBlock, and place the blocks as shown in the picture Scratch also has the drawing function. Complete the following
program, click the green flag, and let the Panda draw a star!
Click the green flag on the top of the screen, to let mBlock run
your program. You should see the Panda “walks a small step”.Drag from the
“Events” group
This changes the picture
of the Panda, creating a
“walking” effect
Drag from the
“Looks” group
Click here
From the “Pen”
group
From the “Control”
group
Change this to 144
Getting Started with mBlock 6
The primary reason of using mBlock is its power to
control and program robots. Here is a short guide of
how to connect it in several methods.
Connect Your Robot / Boards
Connect through the USB cable
Open mBlock, click on the “Board” menu, and select the type of
robots or boards you are using.
For Windows Users: From the menu bar, select Connect, Serial
Port, and the item like COM1 listed there. You may need to try
multiple times if you have more than one devices connected.
For Mac Users: From the menu bar, select Connect, Serial Port,
and the item like MakeBlock. You may need to try multiple times if you have more than one devices connected. If you are using mBlock the first time, select “Install Arduino
Driver” from the connect menu. This will install the programs
necessary for communicating between the computer and the
robot.
Note for Mac OS Sierra users: Please skip this step and follow the
instructions in this article:
This is because Apple changed the way drivers work in their new
operating system.
1
3
2
For Arduino Boards
(for example)
For mBots

  • Note: Not for the latest Mac OS Users!
    Getting Started with mBlock 7
    The 2.4G dongle is a nice way to control your Makeblock
    robots wirelessly. It comes in a dongle for your computer,
    and a 2.4G module for your robots.
    Connect through the 2.4G dongle
    Plug the 2.4G Module to your robot, and turn on the power
    switch.
    Press the button on the top of the 2.4G module, the LED light
    should turn from blinking to blinking very quickly.
    1
    2
    While the LED light on top of the 2.4G module is blinking quickly,
    plug the 2.4G Dongle into the computer.
    After that, the light on the 2.4G Module should lighten on
    Steadily. Select “Connect, 2.4G Serial, the Connect” from the top
    menu.
    3
    4
    Now you can use your robot freely with the 2.4G
    dongle!
    Getting Started with mBlock 8
    You may try to connect to your boards/robots through
    Bluetooth, but this function is still unstable and is not
    guaranteed to work in every computer. This is because
    Bluetooth chips differ between computers, and operating
    systems (eg. Windows 7, Windows 10) treat them in different
    ways.
    If you wish to try, here is a short guide about connecting boards/
    robots via Bluetooth. To finish this guide, you need a computer
    supporting Bluetooth, and the Bluetooth function needs to be
    enabled from the system settings menu.
    Connect through the Bluetooth (Beta)
    For Windows Users
    For Mac Users
    Click “Connect, Bluetooth, Discover”. It will then pop up a list of
    discovered Bluetooth Devices. Note that this process may take
    around 60 seconds.
    If it is the first time you connect this device through Bluetooth,
    open the Bluetooth Preference through “Bluetooth Icon,
    Bluetooth Preference”.
    Select one from the list according to its name. For example, if
    you are using Makeblock products, it will have “Makeblock” in its
    name. Basically, I am unable to add hr compliance and related things on mBlock. If it asks about “Pairing”, click “Yes” to allow the computer talks

  • Make sure the Bluetooth is “On” in your computer Click on the prompt
    to start pairing
    Getting Started with mBlock 9
    Click on the Pair Button on the right of the device you wish to
    connect. For example, for Makeblock products, it usually have
    “Makeblock” in its name.

Why Serial Ports?
MacOS does not provide the API (Application Programming Interface, the tool for programmers to work on something) for Bluetooth Devices. Instead, through using drivers, we can map a
Bluetooth device to another type - in this case, serial ports.

Getting Started with mBlock 10
Hello, mBot
This tutorial will guide you through writing the first
program for mBot, Makeblock’s educational robot. If you
are more interested in Arduino, you may jump to the
next chapter.
Connect the mBot with one of the three methods described
above (USB Cable recommended). When connected, it will say
“connected” in the title bar.
Select mBot from the “Boards” menu. This will bring up mBot
related commands in the “Robots” group.
(Optional) From the “Connect” menu, select “Upgrade
Firmware”. Wait until the upgrade is complete. This will allow the
mBot to talk with the computer.
Drag “when (Flag) clicked” from the “Events” shelf; “forever”
from the “Control” shelf; inside the “forever” block, place “say”
from “Look” shelf, then “light sensor” from “Robots” shelf.
With mBot connected, click the green flag, and you will say the
panda “saying” readings from the light sensor. Try cover the
mBot with your hand, and you will see the number decrease.“Upgrade Firmware” and “Reset Default Program”
“Upgrade Firmware” will allow you control the mBot from mBlock,
but it will disable the IR remote controller and switching mode
with the on-top button; “Reset Default Program” will enable
these functions like the mBot has just come from the factory, while
it only support a part of the sensors available in mBlock. If you
buy extra sensors from Makeblock, you may need to “Upgrade
Firmware”.
Tips
Click
See the number
change
Getting Started with mBlock 11
Now let’s try upload a program into the mBot. Drag “mBot
Program” from the “Robot” group, and attach “forever” to
“mBot Program”. You may delete the “When (flag) clicked” block
Select “Edit, Arduino Mode” from the menu. See what happens
Oops, mBlock says “unsupported block found”. This means not
every block can be run in the Arduino Mode.
6
7

Scratch Mode In Scratch Mode, the robot or Arduino board must be connected to the computer in order to run the program. You can use Scratch blocks to create graphics or make games.use Edit/Arduino Mode menu item to toggle between Scratch and Arduino modes This “Say” block can only be used in the Scratch mode; while the “(Repeat) Forever” block can be accessed in both
modes.

  • Arduino Mode
    In Arduino Mode, the
    program is uploaded
    into the robot and the
    robot is run on its own.
    However, you cannot use
    graphics from Scratch
    since the computer is no
    longer there.
    Getting Started with mBlock 12
    Now let’s try another program. Place blocks as shown below: The
    green block is from the “Operators” shelf.
    Make sure “Arduino Mode” is selected in the “Edit” menu. Find
    “Upload to Arduino” button and click it.
    Now unplug the USB cable, put the mBot on the ground,
    you’ll find it keeps running forward and turns left when there is
    obstacles ahead!
    Click
    Reset Default Program?
    You will find that mBot now does not respond to your command from the Makeblock App or the Scratch Mode in the mBlock. This is because the default program used to talk with these apps is
    overwritten by the obstacle-avoiding program you uploaded. You’ll need to update firmware or “reset default program” to let it work again with the Scratch Mode or other Apps.
    Hello, Arduino
    This guide will give a short introduction on how to
    program Arduino boards with mBlock.
    Connect the Arduino board through the USB cable, and follow
    the steps list on the “Connect through the USB cable” section.
    From the “Boards” menu, select the board that match the one
    you have. The most popular choice is Arduino Uno.
    1
    2
    Select “Edit, Arduino Mode” from the menu.
    Place the following program in the script region
    3
    4
    From the “Control” shelf
    Click on the number field
    and input 13
    From the “Robots”
    shelf
    Click the “Upload to Arduino” button on the right panel
    You will find a LED on the Arduino board starts blinking.
    5
    6
    Click
    Why the LED blinks?
    This is because in Arduino Boards, PIN13 is connected to an onboard LED; this is usually used as a test device. The program we
    wrote tells PIN13 to output high(on) and low(off) every 2 seconds,
    resulting in a blinking LED.
    Tips

Hope this article helps everyone properly.