Making mruby/c library for Wio LTE Arduino
Japanese version is here.
I have done a LT in 60th anniversary kawasaki.rb.
https://docs.google.com/presentation/d/15-78GUJtlWsIcS6HThrWswXMGcyIbfPntIaUzqqXSvU/edit?usp=sharing
I’d like to keep my presentation on this blog.
Summary
- I could run mruby/c on Arduino IDE environment of WioLTE
- I made a github repository of this Arduino library. (This is a just experimental project at this moment)
https://github.com/kishima/libmrubycForWioLTEArduino
Motivation of this project
recently making electrical things is my fan. I’ve been thinking nice project about such electrical things.
For my problem, I lost my self sometimes in late night when I drank much and I was so sleepy… This is very bad situation.
OK, let’s track and control myself by connected GPS tracker device.
(I don’t care making a smart phone app, I want to make a kind of HW!)
(Of course, I should not drink much any way.)
Devices with a modem
I was wondering there are many devices which have a modem. However variation of these devices are limited in Japan. I guess this comes from strong regulation in Japanese row and no-GSM network condition.
I picked some devices up.
Particle Electron
This is made by Particle they are a start up company in USA.
Small and Useful SIM chip with roaming.
Unfortunately it looks like this does not have a certification in Japan telec.
Sakura IO module
This is provided by Sakura Internet. Price is less than 10k yen, however we need a optional board to use this module and this schematic is not opened.
https://sakura.io/product/module_lte.html
Wio LTE (JP version)
This is made by Seed Studio in China.The micro controller of the board is STM32 which is major one. And schematic is opened. One more important thing is that this has a Japanese certification. That supports Grove interface which is provided by Seeed Studio. It is easy to hack it.
I thought this is good for personal project, so I decided to use this.
I also use a SORACOM Air SIM card. I guess it’s the cheapest SIM regarding personal use in Japan.
Picture of the system
I’m wondering following system.
It’s aware that we need to consider the way of power supply when we want to use it with a battery. I’ll add a small power supply circuit. It will consume 2A in peek. I should consider capacity of power supply as well.
Language?
Seeed Studio Japan provides Arduino library for Wio LTE with nice documents. It is very easy to start a project.
https://github.com/SeeedJP/WioLTEforArduino/wiki/Home-ja
It’s OK for me, but I wanted to add some special things. So I though to use mruby on the board.
However STM32F405RGT6 has only 200KB RAM, it is impossible to run mruby on it without modification.
I found out “mruby/c”. This is made for more limited resource condition. Sounds nice to use it for my project. I tried it.
http://www.s-itoc.jp/activity/research/mrubyc/
https://github.com/mrubyc/mrubyc
Result of building
It was easy to port mruby/c to Arduino. I could compile it on Arduino IDE with minor modifications.
I’ve uploaded my source code on github. I put a short explanation on README.
https://github.com/kishima/libmrubycForWioLTEArduino
I’m updating it now.
Arduino source
Wio LTE APIs are defined in mrbc_define_wiolte_methods() as Ruby methods.
#include
#include
extern const uint8_t code[];
// byte-compiled Ruby script by mruby
const uint8_t code[] = {
0x52,0x49,0x54,0x45,0x30,0x30,0x30,0x34,0x7e,0x45,0x00,0x00,0x01,0x4d,0x4d,0x41,
(snip)
};
#define MEMSIZE (1024*30)
static uint8_t mempool[MEMSIZE];
void setup() {
delay(1000);
SerialUSB.println("--- begin setup");
mrbc_init(mempool, MEMSIZE);
mrbc_define_wiolte_methods();
if(NULL == mrbc_create_task( code, 0 )){
SerialUSB.println("mrbc_create_task error");
return;
}
SerialUSB.println("--- run mruby script");
mrbc_run();
}
void loop() {
delay(1000);
}
Ruby script before byte-compile
r=0
g=0
b=0
while true
r=b/2
g=b/3
puts "mruby/c example: control LED B="+b.to_s
Wio.control_led(r,g,b)
sleep(1)
b=b+10
b=0 if b>60
end
Good points of mruby/c
This footprint is very small! However the functionality is limited.
I've measured footprint of mruby/c.
- usage of ROM: 100KB + byte-compiled script
- usage of RAM: 5KB + heap memory
We can modify memory usage of VM by editing vm_config.h.
It is more easy to understand behavior of the system because of the minimum and simple implementation.
Why I should use mruby/c
At this moment, every time I need to copy and paste byte-compiled Ruby script to ino source. I believe mruby programming should be done without any C/C++ code modification.
I'm thinking to implement small second boot loader for running mruby/c bytecode. Over The Air update could be implemented. It will happen after implementing major functions.
Additional thoughts
- I want to achieve this product!
- I was facing an error of modem initialization (this was an Arduino lib issue and solved)
- I got feeling I could implement all function which I need by mruby/c.
- In EPS32, mruby is ported as PoC but it is not common.
- It looks MicroPython is getting users now. https://github.com/micropython/micropython/tree/master/ports
- I think mruby/c can be another good choice. mruby/c with Arduino lib is a good entry environment to web application engineers.
- In Wio LTE, Espruino is also supported officially. If you like JavaScript, this is the best choice.
- It's very easy to port mruby/c to any IoT project. I want to try another case.
I'll keep in touch with mruby/c.
ディスカッション
コメント一覧
まだ、コメントがありません