UrbiOpenSourceContestProjects

Noonv

Arduino with taste of URBI

Goal of this project is implementation URBI for Arduino

http://urbiduino.googlecode.com/files/Urbiduino-001.zip

sorry for bad video quality

Arduino

Arduino is a single-board microcontroller and a software suite for programming it. The hardware consists of a simple open hardware design for the controller with an Atmel AVR processor (mostly ATMega168 or ATMega328) and on-board I/O support. The software consists of a standard programming language and the boot loader that runs on the board.

Implementation

Arduinos are 8bit microcontrolers with no more than a few kilobytes of RAM (ATMega168 - 1Kb RAM). URBI is too big to run it. So URBI is not embeddable in the Arduino.

However, we could use Arduino boards controlled by urbiScript on URBI-server running on a PC connected to the Arduino via a USB/Serial interface (or wireless technology: XBee, Bluetooth).

Protocol

To communicate with the controller we are need some protocol. For example, if we write in the serial symbol H, the controller must be installed on its pin HIGHT voltage and LED light on, and if we write L, then the opposite - installs LOW voltage and the LED goes light off.

Here you can see an example of using this type of home-made protocol for the management of ports Arduino:

http://robocraft.ru/blog/algorithm/108.html (rus)

To know the controller to which port it should work - in front of the symbol H or L is transmitted port number: 13H or 13L for 13 Arduino pin:

serial.write("13H", 3);
serial.write("13L", 3);

Note: The digital ports 0 and 1 used a microcontroller to communicate with a serial port, so you cant change their status ;)

Arduinos sketch to work with this simple protocol:

/*
 * Reads data from the port and sets the appropriate level on the port
 * 00H - set high on the 0-th port
 * 01L - set a low level on the 1 st port
 * 
 */

char val = 0;       // variable to store the data from the serial port
char port1 = 0;
char port2 = 0;
int p=0;

void setup() {
  Serial.begin(9600);        // connect to the serial port
}

void loop () {
  if( Serial.available() ) {
    port1 = Serial.read();     // read the  port 
    port2 = Serial.read(); 
    val = Serial.read(); 
    Serial.print(port1); Serial.print(" "); Serial.println((int)port1);
    Serial.print(port2); Serial.print(" "); Serial.println((int)port2);
    Serial.println(val);
    int p1=(int)port1-48;
    int p2=(int)port2-48;
    p=p1*10+p2;
    pinMode(p,OUTPUT); 
    if( val == 'H' || val == 'h' ) 
    {
      digitalWrite(p, HIGH);
    } 
    else
    {
      if(val=='L' || val == 'l')
      {
        digitalWrite(p, LOW);
      }
    }
  }
  delay(10);
}

But using such a protocol does not allow full control of the controller ports. Change their status to the INPUT or OUTPUT, work with analog ports, steer servo, etc. And anyway, why reinvent the wheel - if you already have a ready protocol, which can do all this? And the name of this protocol - Firmata.

Firmata

Firmata is a generic protocol for communicating with microcontrollers from software on a host computer. Basically, this firmware establishes a protocol for talking to the Arduino from the host software. The aim is to allow people to completely control the Arduino from software on the host computer. The protocol is quite simple.

http://firmata.org/wiki/Protocol

/* This protocol uses the MIDI message format, but does not use the whole
 * protocol.  Most of the command mappings here will not be directly usable in
 * terms of MIDI controllers and synths.  It should co-exist with MIDI without
 * trouble and can be parsed by standard MIDI interpreters.  Just some of the
 * message data is used differently.
 *
 * MIDI format: http://www.harmony-central.com/MIDI/Doc/table1.html
 * 
 *                              MIDI       
 * type                command  channel    first byte            second byte 
 *----------------------------------------------------------------------------
 * analog I/O message    0xE0   pin #      LSB(bits 0-6)         MSB(bits 7-13)
 * digital I/O message   0x90   port       LSB(bits 0-6)         MSB(bits 7-13)
 * report analog pin     0xC0   pin #      disable/enable(0/1)   - n/a -
 * report digital port   0xD0   port       disable/enable(0/1)   - n/a -
 *
 * sysex start           0xF0   
 * set pin mode(I/O)     0xF4              pin # (0-127)         pin state(0=in)
 * sysex end             0xF7   
 * protocol version      0xF9              major version         minor version
 * system reset          0xFF
 *
 */

Code

http://urbiduino.googlecode.com/files/Urbiduino-001.zip

google code: http://code.google.com/p/urbiduino/

Usage

  • upload Arduino.dll and Arduino.u into your engine directory
  • upload into your Arduino board StandardFirmata sketch
  • run Arduino.u
  • use it!
=>var a = Arduino.new(19, 57600); // 19 - USB Serial of Arduino, 57600 - rate of StandardFirmata
#[0004240062] object_561
=> a.pinMode(13, OUTPUT); // set 13 pin led L as OUTPUT
=> a.digitalWrite(13,HIGH); // set pin HIGH
=> a.digitalWrite(13,LOW);

Lets URBI it!

http://code.google.com/p/urbiduino/

Options: