This document outlines an upcoming workshop on embedded systems and mruby programming. The workshop will be held from September 11-15, 2023 at Kyushu Institute of Technology in Japan and led by Associate Professor Kazuaki Tanaka. Participants will learn about mruby, a small embedded Ruby implementation, controlling circuits with a microcontroller board, and using sensors like a brightness sensor. Hands-on exercises include blinking LEDs, reading sensor values to control LED brightness.
3. About Me
? Kazuaki TANAKA┐燭覆 かずあき
? Kyushu Institute of Technology, JAPAN
Associate Professor
? Ph. D in Information Science
? Research topics: embedded systems, IoT,
mruby, wireless communication
6. Research topic:
mruby and mruby/c
? Ruby language for small devices
? OO Programming Language
? Target: one-chip microcontroller
PIC, ESP32, STM32, etc.
? Small memory footprint
minimum 20KB
? Open-Source Software
https://github.com/mruby/mruby
https://github.com/mrubyc/mrubyc
7. What is Ruby language?
? Object Oriented Programming Language
C Scripting language
C Web application, Ruby on Rails
? Matsumoto has said that Ruby is designed
for programmer productivity and fun.
led1 = GPIO.new(0)
while true do
led1.write 1
sleep 0.5
led1.write 0
sleep 0.5
end
Ruby code example:
9. LPWA
? Long range wireless communication
C ~10km by small wireless module
C Using 920MHz band
24mm
17mm
Low power
Tx: 43mA
Rx: 20mA
Sleep: 1.7μA
Speed:
1kbps
16. Blinking LED
? program1
? First, run this program
led1 = GPIO.new(0)
while true do
led1.write 1
sleep 0.5
led1.write 0
sleep 0.5
end
17. Microcontroller board
? RBoard
? Features
C Execute program
C Store data
C I/O of Pins
C Input= Measure voltage
C Output= Set voltage
HIGH(1) or LOW(0)
Pin
18. Onboard LEDs
? 4 LEDs, each LED is connected to Pin
C LED 1: Pin 0
C LED 2: Pin 1
C LED 3: Pin 5
C LED 4: Pin 6
? Set pin voltage to HIGH, then turn on LED
Set to LOW, then turn off LED
19. Program
? GPIO General Purpose Input and Output
led1 = GPIO.new(0)
while true do
led1.write 1
sleep 0.5
led1.write 0
sleep 0.5
end
Pin0 is assigned to variable led1
Iteration
write: set voltage
sleep: stop execution
20. Exercises
? Blink two LEDs alternately
? Blink four LEDs
LED 1: Pin 0
LED 2: Pin 1
LED 3: Pin 5
LED 4: Pin 6
21. LED
? Light Emitting Diode
Current flows from Anode to Cathode
Longer: Anode
Anode Cathode
22. LED Circuit
? Make LED on
C Current flowing through the LED
? Rboard feature
C Set voltage of Pin
C Set HIGH or LOW
30. Implement your code
led1 = GPIO.new(15)
led1.setmode(0)
while true do
led1.write 1
sleep 0.5
led1.write 0
sleep 0.5
end
Set pin mode
0: Output voltage
1: Input voltage
Pin 15
33. PWM
Analog output
? Output of microcontrollers: Digital
C HIGH or LOW voltage
C In LED, ON or OFF
? We want: Analog
C Change voltage
C In LED, ON´bright´dark´OFF
34. Pseudo analog output
? PWM, pulse width modulation
? Control HIGH and LOW rapidly
C 1000 times a second
0.1 msec.
50% HIGH 50% LOW
35. Change brightness
? Change brightness => Change duty ratio
Time
1 msec.
Duty=1
Duty=2
Duty=1023
Duty=1022
Duty=1
Duty=0
Duty=0
36. PWM example
led1 = PWM.new(15)
led1.frequency 10000
while true do
for i in 0..1023 do
led1.duty i
sleep 0.001
end
for i in 0..1023 do
led1.duty 1023-i
sleep 0.001
end
end
duty: 0 to 1023
0: 0% HIGH
1023: 100% HIGH
41. ADC
? ADC: Analog Digital Converter
C Read voltage at Pin20
C Voltage v
0 < v < 1.5
adc = ADC.new(20)
v = adc.read
42. CdS example
led1 = GPIO.new(0)
adc = ADC.new(20)
while true do
v = adc.read
if v<0.5 then
led1.write 1
else
led1.write 0
end
sleep 0.1
end
Read voltage
from Pin20
Voltage: 0 < v < 1.5
Pin20 for ADC
43. Exercises
? Brightness sensor
? LED changes by brightness
C Green: bright
C Yellow: a little dark
C Red: dark
? adc.read returns around 0.2 in dark, and
returns around 0.9 in bright