Traditional way of making arduino application
The normal procedure of making arduino program is to

wirte code in IDE –> compile to verify –>connect USB to Board –> upload code –> code execute

Typically, programing the arudino needs the developer to have the knowledge of developing embedded system and in the development process  developer have to write the program, compile and upload it. The program is compiled statically and not able to execute in the run time.  Every time we program the arduino needs us to repeatably go though the compiling and uploading process with the help of the avr-gcc compiler and the avrdude uploading tool.

 

Using the interpreter as a alternative for ease development and deployment

For the ease development and deployment of WRT program, we can figure out a possibility that the webino developer can write the webinos application in javascript, once the webinos application is deployed on the PZP platform, the javascript application can also run on the arduino without compiling the arduino application.

The advantage of this approach is the webinos developer doesn’t need to have knowledge about how to develop embedded system such as the arduino, the developer can use the javascipt code to manipulate the resource on the arduino board, such as reading / writing a pin. Moreover the application can be easily deployed and run on the arduino at the run time.
In order to build the platform, we need to build a javascript interpreter that can evaluate the javascript based application and this interpreter can be ported to the avr based arduino platform.
In other words,  a  interpreter is written specific to a arduino programming language instead, and the interpreter will be uploaded to the arduino board.    With the interpreter on board, the program can be developed through javascript, and sent to the interpreter through a serial command line or web interface, or combination of keyboard, LCD screen  as a input source. The interpreter then  evaluate the javascript language  and execute it to perform arduino tasks, such as read/ write a analog/digital value to a pin.

To make a javascript interpreter, we have to face two primary questions, the first one is how to make a low footprint javascript interpreter based on c, the second one is how to port the interpreter to the arduino board. Also in building the javascript interpreter on c, we also face the choice whether to build it based on avr-c or wiring library.

 

Arduino Programing language in avr-c and wiring library
Playing with Arduino programming is much easier than ever. To conclude,   there are 2 primary  reasons.  
The first is because of its graphical development environment, which is based on the Java IDE rather than using the compiler directly from the command line.
And the second is to use arduino based wiring library (a simplified set of libraries that are built over C ), previously writen code is turned into LIBRARIES  which can be reused in diffrent programs. These libraries allow you to say things like "printf(a num is %d, 200)" to print a string with a number or "Serial.prinln("hello world") for Arduino.So that  the invoice user no longer need to understand complexities of micro-controller oriented programming like avr-c. (Wiring libraries are only compatible with the micro-controller that is inside the Arduino board (Atmel ATMega). )
If you ever program in arduino, you will get started with the wiring library provided in the Arduino development environment. This wiring library is based on the standard c, but note that is not pure c language. The library provides many useful functions, which accomplishes 80% functionalities in ordinary arudino projects.
Those functions are more semantic, hiding the low level knowledge of microchip programming, so it is easy to understand and use:
• pinMode() – set a pin as input or output
• digitalWrite() – set a digital pin high/low
• digitalRead() – read a digital pin’s state
• analogRead() – read an analog pin
• analogWrite() – write an “analog” value
• delay() – wait an amount of time
The following are examples of making arduino programing in wiring library and avr-c.
Arduino programming with wiring library:
void setup() {                
// initialize the digital pin as an output.
// Pin 5has an LED connected on most Arduino boards:
pinMode(5, OUTPUT);     
}
void loop() {
digitalWrite(5, HIGH);   // set the LED on
delay(1000);              // wait for a second
digitalWrite(5, LOW);    // set the LED off
delay(1000);              // wait for a second
}
Arduino programming without wiring library:
#include <avr/io.h>
#include <util/delay.h>
enum {
BLINK_DELAY_MS = 1000,
};
int main (void)
{
/* set pin 5 of PORTB for output*/
DDRB |= _BV(DDB5);
while(1) {
/* set pin 5 high to turn led on */
PORTB |= _BV(PORTB5);
_delay_ms(BLINK_DELAY_MS);
/* set pin 5 low to turn led off */
PORTB &= ~_BV(PORTB5);
_delay_ms(BLINK_DELAY_MS);
}
return 0;
}

Build a interpreter based on pure c
To build a interpreter on pure c with avr-c would be advantageous, that we have a lot of internal micro-processor control. ( The AVR compiler is complemented with a C library: avr-libc, which contains useful functions and headers to develop for AVR chips without using assembly language.)  
For example,
  • The required bootloader takes up space, which is quite limited on the smaller atmegas.
  • Removing the bootloader will make the board start executing your code faster after a reset.
  • Pin operations are faster using avr, and can act on an entire port instead of acting on the pins one by one.
  • In some cases the arduino language may interact poorly with interrupts.
  • Optimise in the memory usage

But that would lead to more complexities in the development.
Not only we need to get in touch with low level avr-c programing, at the same time, compiling and loading the program to microchips are much harder, because we only work on the command line rather the understandable graphical Java IDE.
1. Tiny -js
Tiny-js is extremely simple (~2000 lines currently) JavaScript interpreter, meant for inclusion in applications that require a simple, familiar script language that can be included with no dependencies other than normal C++ libraries. It currently consists of two source files – one containing the interpreter, another containing built-in functions such as String.substring.
Currently TinyJS supports:

  • Variables, Arrays, Structures
  • JSON parsing and output
  • Functions
  • Calling C/C++ code from JavaScript
  • Objects with Inheritance (not fully implemented)

Tiny-js looks very promising as a javascript interpreter built on c.

Build a interpreter based on wiring library

To build a interpreter with the wiring library means we can build it faster with the advantages of arduino developing environment. The side effect would be on the memory since the wiring libraries are not optimised enough.
Fortunately, there are 2 case studies of arduino interpreter for the basic and c language.

2. iArduino  a C Interpreter for Arduino

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
The iArduino interprets a language which resembles to the Arduino language. It can

  • evaluate an expression refelctively,
  • do stepwise executtion of a program,
  • run a program slowly,
  • stop and resume a program.

Source:  iArduino-0.2.zip

3. Arduino Basic  a Basic Interpreter for Arduino

A port of a BASIC interpreter that fits on an Arduino. The code is meant to be a faithful port of Tiny BASIC for the 68000, and true to Tiny BASIC form, it fits in the very limited RAM of the Arduino.  The BASIC interpreter eats up around 600 bytes in the Arduino RAM, leaving about 1.4 kB for BASIC code. Not much, but more than the lowest-end BASIC Stamp.
source: Tinybasic_source

Advertisements