Project site : https://kishima.github.io/family_mruby/
This was presented in RubyKaigi Takeout 2020.
mruby has been known as a good tool for supporting server applications and embedded softwares like an IoT application on a small CPU whose resource is limited. Now times are changing. mruby gets more power from recent micro processors. I believe now Ruby engineers can create their own computer as per their wish. Basic process and essential technique how to create an original (m)Ruby computer will be shown in the talk with a live demonstration of the computer.
8. WHO AM I?
Katsuhiko Kageyama
“kishima” @ twitter/github
• Embedded software engineer in a manufacturing
company
• Making mruby devices
• Personally, producing technical books about
mruby and original devices in TechBookFest,
Comic Market and Maker Faire(2020 Tsukuba).
10. Agenda
•How to create your computer
•Why mruby?
•Important technical things about mruby
11. GOAL OF MY DEVELOPMENT
•Creating my small
computer to run Ruby
scripts like “Family BASIC”
•I call it “Family mruby”
12. How to create your computer
DEFINE
REQUIREMENTS
FIND
COMPONENTS
MAKE A
SCHEMATICS
MANUFACTURING
THE DEVICE
IMPLEMENT
SOFTWARE
13. Define requirements
Find components
Make a schematics
Manufacturing the device
Implement software
Each steps are no so difficult for software
engineers
According to your idea
Find components which satisfy your requirements.
DigiKey is a good worldwide supplier
Digital signal schematics could be simple
We can use KiCAD
Chinese company offers 5$ / 5 boards
You need to implement basic software
14. Write application using Ruby!
•I love Ruby
•No one likes to wait for compiling C and flashing img
•Shorter code is nice for the small device
15. Why mruby?
•mruby can run on some small processors with
limited memory (>400KB RAM preferred)
•Simple implementation of mruby VM helps to port
it to your own hardware
16. FINDING THE CORE PROCESSOR
Board MCU ROM size RAM size
Arduino ATmega328p 32KB 2KB
ProMicro ATmega32U4 32KB 2.5KB
ESP32 dev board ESP32-WROOM-32 4MB 520KB
ESP32 dev board ESP32-WROVER-B 4MB 8MB
Raspberry Pi zero ARM1176JZF-S >1GB
(external)
512MB
(external)
*mruby requires >400kB memory
18. Implement basic software
•Small processor doesn’t support rich OS like Linux.
•C, C++ are common language
•Difficult to avoid C/C++ because low layer are
provided by C/C++ usually
19. My idea : System diagram
Dev host
ESP-IDF
my device
ESP32Arduino core
FabGL
mrbgem fro esp32
mruby compiler/VM
mruby user App
System
App
(C++)
family_mruby
Micro SD
xtensa tool chain
Serial communication
PS/2 key board
ESP32-WROVER-B
Updating software
Active speaker
VGA monitor
21. DIFFICULTY OF IMPLEMENTATION
•Limited memory
•Always need to take care of remaining memory
• Avoid creating so many Ruby objects
•Low performance
•Use HW function(Interruption, DMA etc.) as much as possible
22. INTERRUPTION
• Hardware interruption is good for receiving
HW event
CPU
Button
Electrical signal
Function A
(running)
Function B
(Interruption handler)
Interruption signal will change the program counter to
an interruption hander
23. MRUBY CANNOT HANDLE HW INTERRUPTION
• Cannot not touch mruby VM’s resource from the interruption handler
• The handler has higher priority
• Common solution is a polling method
loop do
if Input::available
if Input::keydown?(Key::K_UP)
my=-2
end
if Input::keydown?(Key::K_DOWN)
my=2
end
end
sp.move(mx*1,my*1)
end
Checking inputs in
a loop
• This is not the best in the limited CPU
performance condition
24. SOFTWARE-LAYER INTERRUPTION
• Compromised solution for handling interruption
• Similar idea is applied in eLua and MicroPython
https://github.com/kishima/mruby-interrupt
CPU
Button
Electrical signal
Function A
(running)
Function B
(Interruption handler)
mruby VM
mruby VM do polling
events
Storing int. event in the
handler
Example:
27. SUMMARY
•We can create our own device
•I have created Family mruby
•Software interruption is a good
tool for making devices
•Enjoy your maker life
https://kishima.github.io/family_mruby/