Summarized using AI

mruby/c and data-flow programming for small devices

Kazuaki Tanaka • April 16, 2025 • Matsuyama, Ehime, Japan • Talk

In the presentation titled "mruby/c and data-flow programming for small devices", Kazuaki Tanaka, a faculty member from Kyushu Institute of Technology, discusses the application of data-flow programming in the development of software for small devices, particularly microcontrollers. The main focus is to demonstrate how this programming paradigm can enhance the efficiency and functionality of Internet of Things (IoT) systems.

Key Points Discussed:

  • Introduction to Microcontrollers: The presentation begins with an introductory note on microcontroller boards, which are core components in many IoT applications.

  • Data-Flow Programming Explained: Tanaka introduces data-flow programming as a method that emphasizes the flow of data generation and processing, contrasting it with traditional programming models. He draws parallels with Node-RED, a commonly used data flow programming environment.

  • Microcontroller Technologies: He describes various low-power wireless communication technologies that support IoT applications, particularly those tailored for local governments aiming to leverage cost-effective solutions for environmental monitoring and disaster prevention purposes.

  • MVC Architecture and Ruby Implementation: The talk elaborates on the MVC (Model-View-Controller) framework in the context of small devices. Tanaka discusses how mruby/c, a lightweight version of the Ruby programming language, is adapted for microcontrollers to optimize memory usage and processing efficiency, which is crucial for constrained environments. He compares memory requirements among Ruby, mruby, and mruby/c, highlighting their footprint sizes (from 1 MB for Ruby to around 20 KB for mruby/c).

  • Asynchronous Processing: The concept of asynchronous processing is emphasized, showcasing how it can effectively manage the limited resources of microcontrollers while facilitating more dynamic data handling in IoT applications.

  • Block Programming for Education: Tanaka notes the effectiveness of visual programming environments, such as block programming, in teaching junior high and high school students about programming concepts, which ultimately leads to the development of Ruby code without needing to understand the syntax initially.

  • Integration Discussion: The presentation concludes with discussions on integrating the mruby/c environment with data-flow programming for microcontrollers and explores future directions, such as enhancing dispatch performance and adapting to distributed systems for edge computing.

Conclusion and Takeaways:

  • Data-flow programming is a powerful methodology for IoT applications that can improve how devices operate and communicate through efficient data handling.
  • The presentation showcases the adaptability of Ruby-based frameworks to fit within the constraints of small, resource-limited devices, paving the way for innovative solutions in the IoT landscape.
  • Continued research and development in this area are essential for addressing the evolving needs of smart environments and disaster management applications.

Tanaka concludes by inviting interaction during the conference, indicating his openness to further inquiries on this emerging technology.

mruby/c and data-flow programming for small devices
Kazuaki Tanaka • Matsuyama, Ehime, Japan • Talk

Date: April 16, 2025
Published: May 27, 2025
Announced: unknown

In my presentation, I will show how data-flow programming can be used for software development of small devices. The effectiveness of the proposed method is demonstrated with a microcontroller implementation in mruby/c.

In IoT programming, we want to focus on the flow of data generation and processing. This is data flow programming, also known as the Node-RED development environment.

Data flow is processed asynchronously. I will explain how to implement this asynchronous processing in a reasonable manner using mruby/c and demonstrate its operation on a real microcontroller.

https://rubykaigi.org/2025/presentations/kaz0505.html

RubyKaigi 2025

00:00:04.880 okay Okay Thank you very much for coming uh my session So uh first uh please
00:00:10.480 remember this microcontroller board So later I des I explain this one uh microcontroller board Okay Okay
00:00:18.760 Later Okay Uh so let's start my session My topic is about MVC and data flow
00:00:26.240 programming environment So uh first of me I'm Tanaka from Kushu
00:00:33.440 Institute of Technology Japan I'm a faculty member Yes And I have a lecture
00:00:38.719 about data structure algorithm image processing sensors and so on And also
00:00:45.280 I'm researching about uh ML system so small microcontroller operating system
00:00:50.640 realtime operating system and so on and also IoT IoT systems and uh recently I
00:00:57.600 research about uh wireless communication low power wireless communication and also I have uh I
00:01:05.760 belongs to some uh association and some activities I am now doing uh Ruby
00:01:12.159 association thank you very much Ruby association and Ruby forum in Fukoka Mub forum in Fukoka and Ruby business
00:01:19.360 council that is named uh as as well known as uh Rubiko Yes And uh also MV
00:01:27.840 and MVC commit So uh before starting my topic uh
00:01:35.400 recent topic is the virus communication local virus communication Uh that's
00:01:41.600 stands for the LPWA virus communication I'm now researching uh this virus
00:01:46.720 communication is maybe opposite side of the 5G or 6G or next generation virus
00:01:53.360 communication very opposite side uh like uh zerog very very uh opposite side
00:01:59.680 because the band uh the the transmitting speed is very low about
00:02:08.000 one kilo bit per second or very low and uh but low power consumption And also
00:02:16.319 the wide range wide area is covered about 50 15 20 kilometer by one small
00:02:24.000 module Uh they very good good for the IoT devices Uh so I'm uh this technology
00:02:32.239 apply to the local government virus communication Uh because usually local government is no money So they want to
00:02:40.319 use such low cost virus communication for local government
00:02:45.560 monitoring Uh this uh activity is applying for the disaster prevention in
00:02:52.480 Japan You know the many many disasters uh strong rains landslide typhoon or
00:02:58.720 something something earthquake or something many things Uh so uh local government want to uh get a sensor value
00:03:05.760 from local area local government area field but uh no money So low cost virus
00:03:13.040 comation is applying to this area This is my mark p experiment of this work So
00:03:20.319 this is a W module and battery solar panel and so on and getting a sensor
00:03:27.360 value usually uh rain strength wind meter uh
00:03:32.680 temperature light sensor or something getting denser values and transmit to the uh local government office
00:03:39.599 headquarter local government office then the local staff analyze the sensor value
00:03:46.200 and next uh action uh They died This one this this explan
00:03:53.280 explanation is now ongoing in Fukuoka and Fukushima and Miyagi
00:04:01.080 prefecture Okay Uh so the topic uh the topic is about M Ruby and uh data flow
00:04:09.439 uh programming environment So this is a programming environment First uh I show you the
00:04:15.519 demonstration This one this one is a so this one is a just blinking LED two LEDs
00:04:22.160 red and green LEDs are blinking that's all uh that is interesting or not maybe
00:04:28.320 not interesting but uh I talk about this uh mechanism of this uh device and the
00:04:35.759 mechanism of the MB and data flow programming okay demo is okay so that's
00:04:42.639 blinking I then uh I talk about uh these topics Uh first what is MVC mv or MVC
00:04:50.800 this is a like Ruby language Yes And data flow programming What is data flow
00:04:56.479 programming uh next topic And uh finally I uh talk about integrating
00:05:02.840 MLBC execution environment and data flow programming Okay First uh first
00:05:10.919 is MVC So Mub MC is designated for the small
00:05:17.759 devices Uh Ruby language as you know languages are using in web application
00:05:23.840 web server or some computing server or some some places that they has many many
00:05:30.639 memories many processing powers that is a very uh rich environment uh but uh my
00:05:38.880 focusing point is uh that is small devices IoT devices that area that is
00:05:45.520 usually the memory processing server power power is processing power is
00:05:52.680 limited So uh we we m and mcg developer
00:05:58.320 uh uh how to adapt such a ruby language into small devices Then uh we uh
00:06:05.759 implement MB and MBC So MBC is a more smaller Ruby like
00:06:13.759 smaller V concept of MB uh is the uh so reduce the memory consumption memory uh
00:06:21.120 footprint in execution time That is a point uh the laptop developing
00:06:27.280 environment is a laptop or PC that is a very rich environment So no need to uh
00:06:32.319 such restriction no need to carrying about such memories and process powers
00:06:38.639 but in execution environment that are small devices So we must reduce the
00:06:45.120 memory and uh reduce the process power that is a concept in execution time only
00:06:51.360 execution time Okay And uh source code is developing in PC that is okay
00:06:58.479 Execution time is a compiled code Compiled code is the uh compiled in
00:07:05.039 development environment PC and generated by code should be transmitted to the
00:07:10.520 microcontroller Then uh the microcontroller is executed by this ber
00:07:15.919 machine MB batch machine and also MB has many many uh
00:07:21.759 libraries Uh MRB gem MRB M Ruby gem MB
00:07:26.880 gem uh C Ruby gem very similar but design are very different Uh MB gem we
00:07:34.960 have many many MB gem MRB gem libraries
00:07:40.880 Okay here is the compression with Ruby M Ruby M Rubyc Here Ruby is
00:07:48.840 a usually requires one megabyte or more memories maybe maybe and MV is more
00:07:56.240 smaller about 120 kilobyte that you needed kilo kilobyte and MVC is a more smaller uh
00:08:04.639 one uh 20 kilobyte or uh around that very smaller memory uh consumption The
00:08:11.440 targeting devices rubies of course that the server or PC laptop anything Uh MLB
00:08:19.440 is one board computer like a Raspberry Pi one board microcontroller and MVC is targeting to
00:08:27.560 targeting targeting MBC is one chip microcontroller one chip So memory and
00:08:34.399 processing unit and some other uh IOS are uh integrated in one circuit That is
00:08:41.599 a one chip microcontroller very small microcontroller So uh targeting is a
00:08:47.920 small devices uh low power low cost Low power is low cost and low power is low
00:08:55.680 memory uh sorry small memory consumption is long time uh operation Uh because the
00:09:03.800 uh you know the uh the CPU CPU and memory the
00:09:09.600 combination is the base of the uh processing computer microcontroller processing uh CPU is uh we can cut the
00:09:18.160 CPU power that that uh low power consumption or deep sleep mode or
00:09:23.680 something then CPU can uh stop we can stop the CPU uh processing
00:09:30.240 that is a very low power consumption that is okay but a problem is memory
00:09:35.440 memory is uh always always consume the powers uh electricity powers uh so
00:09:43.839 memory is S RAM or D RAM both memory is they are consuming always consuming
00:09:50.880 powers So small memory is good for the small devices and small uh IoT devices
00:09:59.279 So memory memory space equals to memory consumption in small
00:10:05.800 microcontroller Okay So uh MVC provides win features uh memory management uh in
00:10:13.519 this microcontroller we don't have operating system so uh bameal
00:10:19.839 implementation so memory management is inside MBC machine and also power
00:10:26.560 management of course power management uh cut the CPU power the PC CPU power and so on
00:10:34.519 controlling and also the uh realtime processing uh semi-real time processing
00:10:40.800 uh real time processing is required in this device is sometimes used for MVC is
00:10:47.120 sometimes using for the uh so controlling uh so machinery controlling
00:10:54.399 in such area the uh realtime processing is necessary so semi-realtime processing
00:11:00.480 is uh a available byc virtual machine so this This is a hardboard MLB
00:11:08.959 uh MC microcontroller This one is also uh this one is a very small memory You
00:11:16.000 see the SRAMM is 64 kilobyte kiloby very small uh flash memory is
00:11:23.720 256 kilobyte kilobyte very small and uh several iOS
00:11:31.399 here Okay Uh this is Mubc execution diagram So first we implement
00:11:40.000 Ruby code uh so MV code Ruby code M and Ruby code is the same M Ruby code and
00:11:46.000 compiled into by code By code is a binary code uh compiled by code but uh
00:11:51.760 but this B code is device independent independent device independent code So
00:11:57.760 uh this B code can transmit to the any uh microcontrollers any uh architectures
00:12:04.880 no problem and uh in the small devices transmitted m code is executed by a
00:12:11.200 virtual machine This virtual machine is uh already
00:12:16.600 implement deployed as a firmware like this Uh so hardware and
00:12:24.320 hard is hardware absoration layer is provided from MBC and MBC machine B
00:12:32.399 machine is a processing b machine and by code So by code is executed on uh MBC MV
00:12:41.120 and MBC virtual machine Okay So uh what is hard hardware social layer so uh we
00:12:48.240 want to uh port uh many many devices into many many devices Uh this one is
00:12:53.760 the one example but another devices devices we want to port deploy to many
00:13:00.560 devices So we also provide uh hard
00:13:05.600 hardware abstraction layer some libraries hardware accessible
00:13:10.800 accessing libraries is prepared provided the battery machine
00:13:17.200 and h so many several hub is available uh so ESP32 processing hardware
00:13:25.680 absorption layer libraries or uh several libraries uh MLBC is providing So you
00:13:33.040 can choose uh which library free is applied to the your virtual machine then
00:13:38.720 build then uh you can get uh your own virtual machine for your own
00:13:45.560 devices they available on GitHub Okay this is the MVC So uh
00:13:52.720 conclude about the MVC MVC is a Ruby language for small devices my small
00:13:59.160 microcontrollers and uh compiled on the laptop and by code generated by code
00:14:04.800 should be transmitted to the microcontroller then execute that all that is the MVC
00:14:11.560 environment Okay Next is uh data flow programming data flow So uh recently
00:14:19.360 some educ educational field like junior high school high school student want to
00:14:25.680 learn about the information uh subject uh in the high school uh junior high
00:14:31.519 school uh at at such uh schools uh sometimes visual
00:14:38.000 programming is using uh they they are popular visual programming environment uh the website
00:14:45.360 is block programming like a scratch or blocky or some some v
00:14:51.279 programming environment is we can use and right side is data flow programming
00:14:57.360 This is a node environment or some environment is available So they are
00:15:03.360 very uh useful for the education because they can understand by seeing the blocks
00:15:11.760 seeing nodes uh then then they can understand they will understand the
00:15:18.240 behavior or logics of the programs after that uh they uh code into the
00:15:25.880 coding Okay So uh first uh block programming this is named small Ruby Uh
00:15:32.240 so block programming environment for Ruby language is small Ruby Uh this is
00:15:37.600 mainly using at the educational environment schools and so on So this is
00:15:44.000 a very entry of the procedure programming procedure programming So step by step line by line that's a
00:15:50.720 procedure programming is the base of the uh recent programming language Ruby C
00:15:57.040 language Java anything anything they are procedure programming So uh like this
00:16:03.279 one uh this figure is showing about the blocks left side blocks block is this is
00:16:09.199 a repeating block and uh some uh sentence and delays or something is
00:16:17.120 here and uh directly convert it into the Ruby language here Then uh we we we uh
00:16:25.920 write a Ruby code without knowing the Ruby syntax Ruby uh grammars and so on
00:16:32.240 Uh so block is a very easy to uh understand easy to implement the uh some
00:16:39.680 programming program software Yeah like this But I I I know the uh
00:16:47.040 some some student in junior high school uh they are first uh they implement by
00:16:54.079 the block arranging block arranging the wrong program they want to write but as
00:16:59.279 soon uh they tired because many many blocks should be
00:17:04.679 dra many many places and uh so ordering change the ordering or some moving
00:17:10.480 moving or something something very uh tired They tired Then finally uh they
00:17:17.600 change to the coding just coding copy paste copy paste they easy to understand
00:17:25.039 but uh initial entry point is uh block is very good because the logic they
00:17:31.039 understand the student understand but that is very tired soon uh they uh go or
00:17:39.520 enter to the uh coding style copy paste like this So this is a is a one visual
00:17:46.240 programming environment block programming environment This is also popular and next one is a
00:17:59.200 environment data pro programming environment is a benefit fit uh to the
00:18:04.960 IoT programming because IoT is a sensing some some sensors sensing processing and
00:18:12.960 output uh storing uh the storage or actuating or something something sensing
00:18:19.919 processing uh actuate something something so that is the data flow data is created
00:18:28.440 generated process processing and pass to the uh so next node process process like
00:18:36.080 this this is the data programming is a very uh good for the such IoT programming then that's why so I I'm
00:18:43.440 researching about this uh topic this is a node environment in n environment we
00:18:50.400 have uh two items one is a node node is this uh block is a node called node and
00:18:59.200 wires wire is connected to the connected between the two nodes via connected So
00:19:06.559 some data is generated in the uh the left inject node that is the generating
00:19:13.760 creating generating the new data new data or a new packet at the first point
00:19:21.200 that is a data source then uh pass to the next node process pass to the next
00:19:28.000 node process that is a series of the node and node then that's a IoT problem
00:19:35.760 like I IoT programming like this Okay So uh how to how to implement uh
00:19:43.360 implementation okay Implementation is okay So that is arranging blocks and connecting the wire that is okay So how
00:19:49.919 to uh execute this program is the next problem Okay Uh this uh node environment
00:19:58.160 is on the browser We can execute that is okay and server side that is okay But uh
00:20:04.400 my target is small devices How to execute such program in in the uh
00:20:11.600 microcontroller is my topic my research topic So I am talking about uh talking
00:20:17.880 today about this topic Uh so how to how to uh execute this data flow design
00:20:28.200 implementation on the microcontroller The answer is very simple Answer is uh
00:20:35.280 that passing the data pass the data from the one node and second node first node
00:20:40.480 passing data data is stored in Q some Q
00:20:45.520 stored and uh NQ uh sorry the Q the Q from the Q and then analyze dispatch the
00:20:53.280 uh Q packet then next process So inject inject node that is a data source is NQ
00:21:00.880 into the queue global Q and uh the Q
00:21:06.159 from the queue and analyze uh this patch then uh process that's all so uh two
00:21:13.600 phases only two phases uh the inject that is a data source in Q to the global Q and second
00:21:22.400 is uh processing node other node other nodes are uh the queue from the global
00:21:28.480 queue and analyze dispatch execute that all so uh that repeating this uh sense
00:21:35.760 then uh this uh node or uh data flow programming environment uh data
00:21:41.679 discretion in the microcontroller that is uh realized by this uh
00:21:49.080 idea Okay So integrating integrating uh this MVC environment microcontroller and
00:21:56.080 data flow uh discretion how to integrate how to how to how to uh this answer is
00:22:02.720 very very simple this one So I already uh node to M Ruby So this uh script uh
00:22:10.720 can generate uh the uh m ruby code m code uh from the node uh data flow
00:22:19.440 discretion So input is a data flow discretion that is creating the node node node node v that is a discretion of
00:22:27.919 the node uh data flow description that is input and output is uh ruby code or
00:22:36.000 rub by bite code mv by code is generated this is node or data
00:22:43.440 description here first node this is a first node uh many many information is
00:22:50.400 uh listed But uh uh in execution time only this red line enough Other items
00:22:58.000 other properties they are placing the uh location size color or something
00:23:04.400 something that is no meaning in execution uh so uh we uh remove such
00:23:10.840 uh not necessary information entries properties and
00:23:18.679 uh so and and convert into the MV code So uh this is a demo program first
00:23:26.720 demo program This one first de program this de program is two series of the
00:23:32.640 data flow two data flows Uh first data flow is blinking green LED This one is
00:23:39.840 one second each blinking one second each this one So first node is uh creating uh
00:23:47.320 generating timing the injection data source data source data generated as the
00:23:53.600 first node and second node is this is like uh D flip-flop So you know the
00:24:01.919 flip pop is the signal is to trigger coming to the this triga node then uh
00:24:08.640 first time output one second time out of zero first third time out of the one so
00:24:14.960 one zero is a flipped this is this trigger node uh middle node that one
00:24:20.559 that is a work behavior is the same as D flip-flop and final case is LED green
00:24:29.440 LED the blinking And the second floor is uh 2.5 seconds
00:24:36.159 each The timing is 2 seconds 5 seconds to trigger and to is deep flip-flop flip
00:24:44.400 one zero flipping flipping flip flop Then finally uh blinking turn on and
00:24:50.159 turn off the red LED So this is a very interesting behavior uh because this
00:24:56.320 microcontroller is a single core of course single core and single program
00:25:01.520 only uh by the way MVC can uh MLBC is
00:25:06.880 supporting multiprogramming Okay But in this in this case only one program is executing on this micro microcontroller
00:25:15.120 But uh like asynchronous uh application like a asynchronous application two LEDs
00:25:22.400 linking so independently like independently but only one
00:25:28.520 program Okay This is a generated sh program uh like a sh program Uh so sorry
00:25:34.880 the the character is very small The point is that three point sorry three
00:25:40.080 point one point is a injection data injection that is a data source is a
00:25:45.120 generate one packet into the queue NQ NQ NQ each timing each timing 1.0 0 second
00:25:52.799 2.5 seconds and so injection and second node is uh second point is uh processing
00:26:00.559 so inq from the global queue and analyze dispatch uh which behavior sometimes
00:26:07.600 drip prop sometimes uh toga or sometimes threshold or something something Ruby
00:26:13.600 code is also okay Ruby implementation is also okay uh so some some behavior some execution in the second step and the
00:26:21.200 third One is uh so you can you see the the last line sleep
00:26:30.640 uh the sleep state uh statement is that is a sleeping as a as a Ruby has a sleep the
00:26:38.960 same as a sleep but uh but in microcontroller sleep sentence
00:26:45.000 is goes to the deep sleep model in CPU CPU goes to deep sleep mode and for a
00:26:53.120 while interval time after interval time then wake up the CPU then work again go
00:27:00.679 again So uh this one is also uh so asynchronous execution is done by this
00:27:08.400 mechanism and also uh the deep uh so power consumption low power consumption
00:27:13.600 is real by the final line three uh line So that is a h good for the IoT devices
00:27:22.080 Okay Uh I now conclude my uh topic Uh
00:27:27.840 this mark is now continuing not not uh closed not not completed now continuing
00:27:34.480 So future work and uh that's idea is the uh dispatching performance Dispatching
00:27:42.159 is a not so good performance the lower performance uh so so I want to uh adapt
00:27:48.559 or improve this processing and maybe IoT is something directed to the uh
00:27:55.279 distributing distributed systems like edge computing or central centralized
00:28:00.320 computing or some node computing or something that is very uh related to the
00:28:06.960 uh distributing system So uh this node or data flow programming is sometimes
00:28:14.080 adapt can be adapted to the such distributing distributed system So I
00:28:19.200 want to adapt uh or do something uh that idea and uh
00:28:26.080 deploying uh so in such distributed system so how to deploy each program to
00:28:31.200 the devices main devices how to deploy is another problem uh so recent program
00:28:36.960 another problem So I have no idea about that distributing system distributed uh
00:28:42.840 so bad distributing in the distributed system but maybe that is an interesting
00:28:48.799 topic of the uh my research I think so uh finally thank you very much for many
00:28:55.279 many persons related to the MLB and MBC mainly so MVC developers I'm thank you
00:29:02.320 for everything uh so Higan and Hashmission very very thank Thank you
00:29:08.240 for virtual machine implementation and uh I I talk that is a local government
00:29:14.799 research center is supporting this uh research and also QC is my my
00:29:21.360 institution Q students so student work some something sometimes student work is
00:29:27.320 related student work and also u national institute of technology mat professor
00:29:34.799 ski professor and also the student in there many many uh help is many many
00:29:41.600 supporting from the such student thank you very much and uh this references so
00:29:47.840 if you are interested in MVC please refer this GitHub site or uh I'm uh
00:29:54.640 after after I'm joined to the uh official party tonight so if any
00:29:59.760 questions or any advice to me please find me find me at the conference party
Explore all talks recorded at RubyKaigi 2025
+66