language:English/日本語

Ruby

For Ruby classes supported by mruby/c, see the official URL below.
https://www.s-itoc.jp/activity/research/mrubyc/mrubyc_docs/library

GPIO

new(pin)

pin:0~20

setmode(mode)

Configure pins to act as inputs or outputs.
mode:0(output),1(input)

write(value)

Write a 1 or a 0 value to a pin.
3.3V for 1, 0V (ground) for 0.
value:0(OFF),1(ON)

read()

Reads the value from a specified pin, either 1 or 0.
return value:0(OFF),1(ON)

pull(mode)

Internal resistance selection.
mode:-1~1
-1(pull down) , 0(not pull) , 1(pull up)

ADC

new(pin)

pin:0~20

read

Reads the value from the specified analog pin.
It is output as a voltage value.(0V~3.3V)
return value:0~3.3

read_v

※same as [read]
Reads the value from the specified analog pin.
It is output as a voltage value.(0V~3.3V)
return value:0~3.3

I2C

new()


write(sl_addr, addr, data1, data2,,,,)

Write data to the slave device using I2C communication.
sl_addr:slave address
addr:data address
data:data

read(sl_addr, size, addr)

Read data from slave device using I2C communication.
sl_addr:slave address
size:read size
addr:data address

PWM

new(pin)

pin:0~20

frequency(n)

frequency setting. Specify 0 to stop output.
n:integer(Hz)

duty(n)

Specify the duty ratio from 0 (all off) to 1023 (all on).
n:0~1023

period_us(us)

Specifies the cycle in microseconds.
us:integer[microsecond]

duty_us(us)

Specifies the duty cycle in microseconds.
us:integer[microsecond]
If (period_us) is 100 microseconds and (duty_us) is 50 microseconds, on:off will be 1:1.

UART

new( ch, baud )

ch :UART Channel(1 or 2)
 1=>Channel used by USB
 2=>Channel used by GROVE
baud:baud rate value(sample value:19200)

set_modem_params("baud"=>baud,"parity"=>parity,"stop_bits"=>stop_bits,"txd"=>txd,"rxd"=>rxd)

baud:baud rate value(sample value:19200)
parity:parity bit(0~2)
stop_bits:stop bit(1 or 2)
txd:TX pin number
 Channel 1->(0,8,9,12,20)
 Channel 2->(3,5,14,15,19)
rxd:RX pin number
Channel 1->(2,4,7,11,18)
Channel 2->(1,6,10,13,16)

gets

Receives a string. Returns bytes up to "\n".
return value:String

write(text)

Send a string.
text:String

read(n)

Receives a string. Receives only the specified number of characters.
Returns nil if the specified number of bytes of data has not arrived.
n:integer(word count)
return value:String or nil

read_nonblock(n)

Receives a string. Receives only the specified number of characters.
If the specified number of bytes of data has not arrived, it returns the data that has arrived.
n:integer(word count)
return value:String

puts(text)

Send a string.
※same as [write]
text:String

clear_rx_buffer

Initialize received string buffer

clear_tx_buffer

Initialize transmission string buffer

Math

https://github.com/YoshihiroOgura/pic32mx170_mrubyc/blob/a0542f4fb76b2f3e1ba6e5078c9e3fc3a7164865/src/c_math.c#L240

Additional features of RBoard

leds_write(byte)

onboard led control.
byte:integer
led Decimal Number binary
1 1 0b0001
2 2 0b0010
3 4 0b0100
4 8 0b1000

sw()

Read state of onboard switch
Switch with pull-up resistor
return value:0(switch on) or 1(switch off)

pinInit

Reset all pin settings to default.

puts(txt)

string output
Terminal software settings:link
txt:string