M5Stack-mruby

M5Stack-mruby is mruby runtime environment on M5Stack micro computer.
M5Stack-mruby provides mruby programming platform in below.

  • Execution of mruby application (binary).
  • Execution of mruby script in interactive mode.
M5Stack-mruby

How to setup

Preparation

Please install the following software required to build M5Stack-mruby.

Download M5Stack-mruby

Change to the directory where you installed esp-idf and get the source code of M5Stack-mruby.

1
2
cd ~/esp
git clone —recursive https://github.com/mimaki/M5Stack-mruby.git

Build and write to M5Stack

Connect M5Stack and PC with USB cable.
Type below command at M5Stack-mruby directory.

1
make flash

Execution of mruby application

M5Stack-mruby can execute mruby application (binary) compiled with mruby compiler (mrbc).
The mruby compiler (mrbc) is generated in the M5Stack-mruby/components/mruby_component/mruby/bin directory.
The sample program japan.rb and the compile procedure are shown below.

Sample program (japan.rb)

1
2
3
4
LCD.clear
LCD.fill_rect(50, 40, 219, 159, LCD::WHITE)
LCD.fill_circle(160, 120, 50, LCD::RED)
gets

Compile

1
M5Stack-mruby/components/mruby_component/mruby/bin/mrbc -o autorun.mrb japan.rb

Insert the microSD with autorun.mrb copied to the root directory into the M5Stack’s SD card slot and power on (or reset) the M5Stack to execute the mruby application saved on the microSD card.

Note:
  • The file name of the mruby application binary to execute should be autorun.mrb.
  • Copy autorun.mrb to the microSD card root directory.

Execution of mruby script in interactive mode

By using a terminal application such as CoolTerm, M5Stack-mruby interactive mode can be used.
The operation when using CoolTerm is shown below.

Setting of CoolTerm

Connect M5Stack to PC with USB cable, open CoolTerm Options, and set the following items.

Serial Port Options
Item Value Note
Port Mac: SLAB_USBtoUART
Windows: COMx
COMx number if different depending on the environment.
Baudrate 115200
Data Bits 8
Parity none
Stop Bits 1

If you can’t find Port, check if the VCP driver is correctly installed.

Terminal Options
Item Value
Terminal Mode Line Mode
Enter Key Emulation CR
Local Echo ON

Run interactive mode

  1. Click Connect on CoolTerm.
  2. Remove the microSD card and press the M5Stack RESET button.
  3. Ruby script is executed when Ruby script and Enter are input in the input box at the bottom of CoolTerm.