Kernal Class

Syntax Overview Argument Return Value
pinMode(pin, mode) Pin mode setting pin: Pin number
mode: Set the following values:
0 (INPUT)
1 (OUTPUT)
2 (INPUT_PULLUP)
3 (OUTPUT_OPENDRAIN)
Version
digitalWrite(pin, value) Set pin output to 0 or 1 pin: Pin number
value: 0 or 1
None
digitalRead(pin) Check whether pin input is 0 or 1 pin: Pin number 0 or 1
analogRead(pin) Confirm analog value of pin pin: Pin number (14, 15, 16, 17) 0 to 675 (3.3V)
Input mode can be specified in analogReference, as described below.
analogReference(mode) Specify analogRead input mode mode: Select from the following:
0: 5.0V ref.
1: 1.1V ref. (built-in voltage)
2: 3.3V ref.
3: 3.3V ref., 12-bit resolution (0 to 4096)
None
pwm(pin, value) PWM output from pin (490Hz) pin: Pin number
value: PWM rate 0 to 255
None
initDac() Initialize DA converter None None
analogDac(value) Output analog value from DAC pin 0 to 4096 (3.3V) None
led(value) Set LED output value: 0(OFF) or 1(ON) None
delay(value) Wait for specified time value: Time ((ms)) None
millis() Count time period in millisecond from system startup. Overflows and returns to 0 after about 50 days. None Milliseconds
micros() Count time period in microseconds from system startup. Overflows and returns to 0 after about 1 week. None Microseconds
tone(pin, frequency[, duration) Output tone signal used for piezoelectric sounder, etc. pin: Pin number, frequency, duration, output time (option) None
noTone(pin) Stop tone signal output pin: Pin number None
randomSeed(value) Set random seed value: The value to be used as the random seed None
random([min,] max) Get random count min: Minimum value (option),
max: Maximum value
Random

System Class

Syntax Overview Argument Return Value
System.version([R]) Get system version Any value Version
System.exit() End program. If the program was set by System.setrun, that program will be executed. None None
System.setrun(file) Set next program to be executed. file name: mrb None
System.push(address, buf, length) Store value in flash memory. The value will not be erased even when the power is turned off. address: Start address (0 to 255)
buf: Write data
length: Data length (Max. 32 bytes)
0: Failure, 1: Success
System.pop(address, length) Get value from flash memory address: Start address (0 to 255)
length: Data length (Max. 32 bytes)
Amount of data retrieved
System.useSD() Set to enable use of SD card None 0: Invalid, 1: Valid
System.useWiFi() Set to enable use of WA-MIKAN (ESP8266 board) None 0: Invalid, 1: Valid
System.getMrbPath() Get file path of mrb now running None File path (file name)

Serial Class

This class generates and uses an instance for each communication port.

Syntax Overview Argument Return Value
serial.new(num,bps) Serial communication initialization num: Communication port to be initialized (TX/RX)
0: USB, 1: 0/1, 2: 5/6, 3: 7/8, 4: 12/11
bps: Baud rate
Serial instance
serial.print([str]) Output to serial port str: Output string None
serial.println([str]) Output to serial port with line break
Line break: \r\n
str: Output string
When omitted, only line break
None
serial.write(buf, len) Data output buf: Output data string, len: Data count Output data count
serial.flush() Wait until transmission is completed None None
serial.available() Check if receive data is available None Number of bytes of data
0: No data
serial.read() Get data None String or receive data

I2C Class

This class generates and uses an instance for each communication port.

Syntax Overview Argument Return Value
i2c.new(num) I2C communication initialization num: Communication port to be initialized (SDA/SCL)
0: 18/19, 1: 0/1, 2: 5/6, 3: 7/8, 4:12/11
I2C instance
i2c.begin(address) Start I2C write preparation address: Device 7-bit address None
i2c.lwrite(data) Write to I2C write buffer data: Data None
i2c.end() Execute prepared I2C write communication None None
i2c.request(address, count) Execute a read request to the device address: 7-bit address
count: Data count
Receive data count
i2c.available() Check if receive data is available None Receive data count
0: None
i2c.lread() Get receive data None Receive data
i2c.write(address, reg, data) Write 1 byte to the device specified address (execute begin, lwrite, end) address: 7-bit address
reg: Write address in device
data: Data
Always 0
i2c.read(address, regL[, regH]) Read data from device specified address (execute write, request, read) address: 7-bit address
regL: Read lower address
regH: Read upper address (option)
Read data

Servo Class

Syntax Overview Argument Return Value
Servo.attach(ch, pin [, min, max] ) Assign output pin to servo motor to specified channel ch: Any channel (0 to 9)
pin: Any pin
min: Pulse width at 0 degrees (default = 544µs) (option)
max: Pulse width at 180 degrees (default = 2400µs) (option)
I2C instance
Servo.write(ch, angle) Set angle ch: Channel (0 to 9)
angle: 0 to 180
None
Servo.read(ch) Get current angle ch: Channel (0 to 9) Angle
Servo.us(ch, us) Set angle with pulse width ch: Channel (0 to 9)
us: 0 to 19999
None
Servo.attached(ch) Check if servo is assigned to channel ch: Channel (0 to 9) 0: Not assigned
1: Assigned
Servo.detach(ch) Release servo assignment ch: Channel (0 to 9) None

Rtc Class

Syntax Overview Argument Return Value
Rtc.init() Start real time clock None 0: Failure
1: Success
Rtc.deinit() Stop real time clock None 0: Failure
1: Success
Rtc.setTime(array) Set time array: year (0000-9999), month (1-12), date (1-31), hour (0-23), minute (0-59), second (0-59) 0: Failure
1: Success
Rtc.getTime() Get time None The following array:
year: (2000-2099)
month: (1-12)
day: (1-31)
hour: (0-23)
minute: (0-59)
second: (0-59)
weekday: (0-6) 0: SUN, 1: MON, 2: TUES, 3: WED, 4: THUR, 5: FRI, 6: SAT

SD Class

System.useSD() must be called before using this class.

Syntax Overview Argument Return Value
SD.open(number, filename[, mode]) Open the file number: Any file number (0 or 1)
filename: File name (8.3 format)
mode: 0: Read, 1: Append, 2: New Create
File number
-1 = Failure
SD.close(number) Close the file number: File number None
SD.seek(number, byte) Move to the position in the file to be read number: File number
byte: Move toward end of file for the number of bytes (-1) required by seek
0: Failure
1: Success
SD.read(number) Read from the file number: File number Data (bytes)
If position is the end of the file, -1 is returned.
SD.write(number,buf,len ) Write to the file number: File number
buf: Data buffer
len: Data count
Number of data written
SD.flush(number) Wait for write operation to complete number: File number None
SD.size(number) Get file size number: File number Size
SD.position(number) Get read/write position number: File number Position
SD.mkdir(dirname) Create directory dirname: Name of directory to be created 0: Failure
1: Success
SD.rmdir(dirname) Delete directory dirname: Name of directory to be deleted 0: Failure
1: Success
SD.remove(filename) Delete file filename: Name of file to be deleted 0: Failure
1: Success
SD.copy(srcfilename, distfilename) Copy file srcfilename: Name of source file to be copied
distfilename: Name of destination file to be copied to
0: Failure
1: Success
SD.exists(filename) Check if file exists filename: Name of file to be checked 0: No file
1: File exists

WiFi Class

Syntax Overview Argument Return Value
WiFi.setMode(mode) Set station mode mode:
1: Station
2: SoftAP
3: Station + SoftAP1
ESP8266 return value
WiFi.ipconfig() Display IP address and MAC address None ESP8266 return value
WiFi.connect(SSID, Passwd) Connect to WiFi access point SSID: WiFi SSID
Passwd: Password
ESP8266 return value
WiFi.multiConnect(mode) Set mode for multiple connections mode:
0: Connect 1 only1
1: Connect up to 4
ESP8266 return value
WiFi.disconnect() Disconnect WiFi None ESP8266 return value
WiFi.httpGetSD(Filename, URL[, Headers]) Store http GET results on SD card Filename: Name of file to be stored
URL: URL
Headers: An array of character strings to be added to header
0: Failure
1: Success
2: SD card use invalid
3: Couldn’t open transmit data file
4: Couldn’t read transmit data size
5: Couldn’t read transmit data file
6: Couldn’t open receive data file
7: Failure to create received file
WiFi.httpGet(URL[, Headers]) Transmit http GET protocol.
Only transmit, do not receive.
URL: URL
Headers: An array of character strings to be added to header
0: Failure
1: Success
WiFi.httpPost(URL, Header, Body) Transmit http POST protocol URL: URL
Header: An array of character strings to be added to header
Body: An array of character strings to be added to body
0: Failure
1: Success
WiFi.httpServer([port]) Start http server; SD card is required port: The number of the port waiting for data; if -1 is specified, the server stops. One of the following values is returned depending on access availability:
0: No access
1: Access available
2: Cannot use SD card
3: Failed to access SD card

For access from client:
GET: Path
Other than GET: First line of header
WiFi.udpOpen(number, IPAddress, SendPort, ReceivePort) Start UDP connection number: Connection number (1 to 4)
IPAddress: Communication destination address
SendPort: Communication port number
ReceivePort: Receive port number
ESP8266 return value
WiFi.send(number, Data[, length]) Transmit data to specified connection number number: Connection number (1 to 4)
Data: Data to be transmitted
length: Size of data to be transmitted
Transmit data size
WiFi.recv(number) Receive data from specified connection number number: Connection number (1 to 4) Array of received data; must be 256 or less
WiFi.cClose(number) Close TCP/UDP connection number: Connection number (1 to 4) ESP8266 return value
WiFi.bypass() Direct serial connection between USB port and ESP8266.
Processing does not return until reset occurs.
None None
WiFi.serialOut(mode[, serialNumber]) Set serial number for serial output to ESP8266 mode:
0: No output
1: Output
serialNumber: Serial number of output destination
None
WiFi.at(command[, mode]) Transmit AT command to ESP8266 command: AT command string
mode:
0: Automatically add 'AT+'
1: Do not automatically add 'AT+'
ESP8266 return value