in Japanese
[ArduinoConf][ArduinoMonitor][iArduino]

iArduino: a C Interpreter for Arduino

Abstract

The iArduino is an interpreter which runs on Arduino board. Interpreted language is a programming language in which programs are 'indirectly' executed ("interpreted") by an interpreter program (see Wikipedia.)

The iArduino interprets a language which resembles to the Arduino language. It can

Preparation

First, download iArduino's sketch and upload to Arduino with Arduino IDE. You also need a terminal program like TeraTerm.

Execute the terminal program and connect to Arduino with the spped of 38400bps. You will see `OK' message printed in the terminal window sent from iArduino.

Touching iArduino

When you are ready, type
pinMode(13, OUTPUT)
in the terminal and hit Enter key (you need to hit enter key after you input something). Then, you see
pinMode(13, OUTPUT)
0
OK
in the window. This means iArduino evaluated pinMode(13, OUTPUT) function and the result was 0. The iArduino accepts another command after it shows OK in the terminal. If you input
digitalWrite(13, HIGH)
Then, you see
digitalWrite(13, HIGH)
0
OK
and lit the LED on the Arduino. If you input
digitalWrite(13, LOW)
Then the LED turns off. In the above, you executed a sketch
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
digitalWrite(13, LOW);
by inputing each expression with your hand. It shows ``Syntax error'' as
piMode(13, OUTPUT)
Syntax error
OK
if the iArduino could not analyze your input.

The iArduino supprts abs, analogRead, analogWrite, delay, digitalRead, digitalWrite, max, millis, min, rand, and pinMode functions as the Arduino languge does. It also evaluate an expression like:
analogRead(0)/2
which shows half of the current value on the pin 0 of analog input. It supports operators like +, -, *, /, and so on.

The iArduino supports the use of variables. The name of the variables are fixed to one character of alphabet, e.g. from a to z. A declaration is unnecessary. Type of the variables is short int (16bits int.) For example, if you input

a=1
b=2
c=a+b
and
c
You will see
c
3
OK
One of the feature of the iArduino is such a reflective evaluation as you see in the example above.

Running a program

Let us input a program bellow with the prog command.

pinMode(13, OUTPUT);
for(;;) {
    digitalWrite(13, HIGH);
    delay(500);
    digitalWrite(13, LOW);
    delay(500);
}
You need to input end after the end of the program. If you input run command, it runs the program which blinks the LED. The iArduino does not show OK when it is running a program.

It stops execution of the program when you hit a key and shows

Paused
>
Put `c' and the program resumes. Put `d' to show currently executed statement. You will notice that the execution of the digitalWrite function finishes imedeately, but delay(500) takes 0.5 seconds.
>d

: true
digitalWrite(13, HIGH)
delay(500)
digitalWrite(13, LOW)
delay(500)

: true
digitalWrite(13, HIGH)
delay(500)
digitalWrite(13, LOW)
delay(500)

: true
digitalWrite(13, HIGH)
delay(500)
Put some key and input `S' to abort the program.
>S
Stopped
OK
The prompt `OK' means that the iArduino accepts a next command. Type
save
to save the program in Arduino's EEPROM and type
autorun
Reset you Arduino after that. You see
Tiny C language interpreter for Arduino
(c) 2012 N.M.
Starting program
and the program is running. To abort the program, hit some key and input 'S'. You can use
noauto
to disable auto execution of the saved program.

Commands

The iArduino supports following commands after it shows OK prompt.

animate	Runs the program. It shows currently executed statement and pauses 0.5 seconds 
	after each execution.
autorun Runs the program in the EEPROM when the Arduino is reset.
debug	Runs the program. It shows currently executed statement (no pause.)
edit < line number >
	Replace the line specified by the line number. You input the new line 
	following the edit command.
list	Shows the program list. It appends the line number at the beggining 
	of each line.
noauto  Do not run the program in the EEPROM when the Arduino is reset.
prog	Accepts a new program. You input the new program following the prog 
	command and ``end'' after the last line of the program. 
run	Runs the program.
save    Saves the program to Arudino's EEPROM.
step	Does stepwise execution of the program stepwise. It pauses the execution 
	after each evaluation of a statement. 
expression	Evalutates the expression. You do not need a semicolon since 
	it is not a statement.

Commands when a program is paused

The iArduino accepts following command when it is paussing a program. You see '>' prompt when it accepts them.

a	Continues the program. It shows currently executed statement and pauses 
	0.5 seconds after each execution.
c	Continues the program.
d	Continues the program. It shows currently executed statement (no pause.)
r	Continues the program. It does not show statement and no pause is added.
S	Aborts the program.
< Enter >	Executes the next statement.
expression	Evalutates the expression. You do not need a semicolon since 
	it is not a statement.

Grammars and formats

Basic grammars are as same as the C language and the Arduino language. It does not support declaration of a new function nor a new variable. It runs a program from top of it (no main function.) Supported statements are if, while, for, break, continue, and expression statement. The maximum length of the program is about 800 bytes.

You can use monominal operators: +,-,~, binomial operators: +,-,*,/,%, bit operators: &,|,^, logical operators: &&,||, comparative operators: <, <=, >, >=, ==, !=, shift operators: <<, >> . The iArduino accepts literals in decimal, hexadecimal, and binary format. It also accepts constans LOW, HIGH, false, true, INPUT, and OUTPUT as the Arduino language does. The all operation are done in 16 bit integer.

You can use 26 variables which have names from a to z. The type of them is int (16bit int.)YYou donot need declarations to use them. You cannot declare a new variable.

The iArduino supports abs, analogRead, analogWrite, delay, digitalRead, digitalWrite, max, millis, min, noTone, rand, pinMode, servo?.attach, servo?.write, and print functions. The tone function has two arguments. Put the number 0 to 11 at the ? of servo?.attach, servo?.write functions. You can use them as if you declared as

Servo servo?;
in the Arduino IDE. The servo?.attach supports only one argument (pin number only.) The print function accepts an integer argument and shows the value in decimal format.

Summary of the iArduino language and the interpreter

Name of variables: a to z (16bits int aka. short)
Control statements: if, else, for, while, break, continue
Constans: LOW, HIGH, INPUT, OUTPUT, true, false
Operators: +, -, *, /, %, &, |, ^, &&, ||, <, <=, >, >=, ==, !=, >>, <<
Literals: decimal, hexadecimal, binary digit (16bits int only)
Functions: abs, analogRead, analogWrite, delay, digitalRead, digitalWrite, max, millis, min, noTone, rand, pinMode, servo?.attach, servo?.write, tone, print

Commands: animate, autorun, debug, edit, list, noauto, prog, run, save, step

Files

iArduino with iAduinoTerminal

A terminal and debugging software iArduinoTerminal is available. You can monitor variables and pin status as the figure below. Please use with iArduino-0.6 which has debugging interface for iArduinoTerminal. Note that program size is limited to 600bytes.

After downloading and extracting iArduino-0.6a.zip, put iArduino folder into Arduino's libraries folder. Then you will find iArduino in example list in Arduino IDE. Please upload iArduino-> iArduino to your Arduino.

You also can monitor pin status without iArduino interpreter. Please check Examples-> iArduino-> iArduinoTerminal.


iArduinoTerminal for Android

This iArduinoTerminal is an apprication for Android. Recommended minimum display resolution is 1280x800. It is tested on Acer ICONIA TAB A200 (Andriod 4.0.3). It should run under Android 3.1 or later. The app uses FTDriver by ksksue.

History


back
(c) 2012-2014 N. Mitsunaga (mnoriaki (at mark) gmail.com)