I think the world is ready for a good Firmata Tutorial

As far I know Firmata is now know for quite a while but a lot of people ( including me ) don't really know how to use this awesome programm/sketch.
I really looked for a lot of time through the net and didn't find anything helpfull there...
There is a testprogramm for Firmata on their mainpage and it is really neat and I would like to be able to do the same comads over, for example, Processing.
The interface is not needed.
http://firmata.org/wiki/Main_Page
I don't really get how to propperly read and understand the arduino reference to do that.

The Servowrite function is quite important for me.
I know there is an arduino libruary for processing but this one does just support analog read, write and pwm.

the essancial quaestions from me are:
Is there someone who would do a nice and understandable firmata tutorial so that the not so good programming people know what to do ? :slight_smile:

What do I need to send to trigger a specific firmata function on the arduino?
and how do I read proberly the firmata-arduino output data (sensors) ?

(this is somewhat in the first question included)

I hope my spelling is not to bad ^^

Greetings from Germany,
Florian

I found this forum link and I guess It couldn't be continued because of the forum change.
Does someone know how to fix the latest probleme there?
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1294833227
I would be really interessted in the solution.

try this one:

http://t-o-f.info/pmwiki/index.php?n=Arduino.Firmata

its a modded firmata (servo only 9 & 10) and a processing library (dont use arduino library).

what i cant translate fast:

funktioniert wunderbar. nur da ich jetzt xbees als "kabel" nehme, hab ich selber was ohne firmata geschrieben. firmata wartet immer auf antwort, was bei mir zu keiner verbindung mit xbees führt. aber sonst sahne.

hier noch mein letzter kabel-sketch in processing mit tof-firmata

/*  RC car project | Arduino UNO | zH32
    08.01.2011
*/
import processing.serial.*;
import cc.firmata.*;
Firmata firmata;
import controlP5.*;


Serial myPort;
ControlP5 controlP5;
import procontroll.*;
import net.java.games.input.*;

import java.io.*;


ControllIO controll;
ControllDevice device;
ControllStick stick;
ControllStick stick1;
ControllButton button1;
ControllButton button;

int LED = 13;
int licht = 4;     //LDR
int motorpin1 = 6; //when motorpin1 HIGH motorpin2 LOW = forward....
int motorpin2 = 7;
int motorpwm = 11;
int standby = 2;
int ledState;
  int val;
long previousMillis = 0;
long interval = 200;    
void firmataSetup (Firmata f) 
{
  
  println("Running setup function");
  f.pinMode(motorpwm,firmata.PWM);
  f.pinMode(9,firmata.SERVO);
  f.pinMode(LED, firmata.OUTPUT);
  f.digitalWrite(LED, firmata.LOW);
  f.pinMode(licht, firmata.INPUT);
  f.pinMode(motorpin1, firmata.OUTPUT);
  f.pinMode(motorpin2, firmata.OUTPUT);
  f.pinMode(standby, firmata.OUTPUT);
  
  }
  
void setup()
{

  
  size(1024,600);
  
  println("Available ports:");
  println(Firmata.list());
  firmata = new Firmata(this, Firmata.list()[4], 115200); 
  String portName = Serial.list()[3];

  frameRate(20);
  
  PFont myFont;
  myFont = createFont("Arial", 20);
  textFont(myFont);
  controlP5 = new ControlP5(this);
  controlP5.addSlider("Lenkung in %",-100,100,50,10,50,400,40);
  controlP5.addSlider("Power in %",-100,100,100,30,150,40,400);
    controlP5.addSlider("Licht",0,100,25,200,150,40,400);
  controll = ControllIO.getInstance(this);
  device = controll.getDevice("Logitech Cordless RumblePad 2");
  
  device.setTolerance(0.07f);
  
  
  ControllSlider sliderX = device.getSlider("Z-Achse");
  ControllSlider sliderY = device.getSlider("Z-Rotation");
  ControllSlider sliderX1 = device.getSlider("X-Achse");
  ControllSlider sliderY1 = device.getSlider("Y-Achse");
  
  stick = new ControllStick(sliderX,sliderY);
  stick1 = new ControllStick(sliderX1,sliderY1);



  button = device.getButton("Taste 0");
  button1 = device.getButton("Taste 2");
 }

void draw()
{
  background(150);


     
 
  int speed = int(stick.getY()*255);                    // get right value for motor controller
  int steer = int((stick1.getX()*40)+90);               // get right value for servo
  int lichtval = firmata.analogRead(licht);
  float li = map(lichtval, 1024, 0, 0, 100);
  
  controlP5.controller("Lenkung in %").setValue((steer-90)*2.5);
  controlP5.controller("Power in %").setValue(-speed/2.55);
  controlP5.controller("Licht").setValue(int(li));
   if(button.pressed()){
  long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED 
    previousMillis = currentMillis; 
  if (ledState == firmata.LOW)
      ledState = firmata.HIGH;
    else
      ledState = firmata.LOW;

    // set the LED with the ledState of the variable:
    firmata.digitalWrite(LED, ledState);  
  }
  else 
  firmata.digitalWrite(LED, firmata.LOW); 
  }

  //println(lichtval);                                       //print different values for debuging

  if(speed > 0){                
    firmata.digitalWrite(motorpin1, firmata.LOW);
    firmata.digitalWrite(motorpin2, firmata.HIGH);        //forward
    firmata.digitalWrite(standby, firmata.HIGH);
    firmata.analogWrite(motorpwm, speed);
    }
  
  if(speed < 0){
    firmata.digitalWrite(motorpin1, firmata.HIGH);
    firmata.digitalWrite(motorpin2, firmata.LOW);        //back
    firmata.digitalWrite(standby, firmata.HIGH);
    firmata.analogWrite(motorpwm, speed*-1);
    }
  if(speed == 0){firmata.digitalWrite(standby, firmata.LOW);
    }
 
 firmata.analogWrite(9, steer);                          //steering
 

}

Interessting thing :slight_smile:
sadly I need at least 24 Servos XD
I am using a Seeduino mega.

I know it is off topic but would you be so kind and send me the xbee sketch you talked about?
Because I am gonna switch to Xbee soon.

Best regards,
Florian

i sent u a message, but i also post it (maybe its useful for anyone).

processing:

/*  RC car project | Arduino UNO | zH32
   
*/
import processing.serial.*;
import controlP5.*;
import procontroll.*;
import net.java.games.input.*;
import java.io.*;

ControlP5 controlP5;
ControllIO controll;
ControllDevice device;
ControllStick stick;
ControllStick stick1;
ControllButton button1;
ControllButton button;

Serial myPort;
void setup()
{
  println(Serial.list());
  
  size(1024,600);
  myPort = new Serial(this, "COM32", 57600);
 

  frameRate(20);
  
  PFont myFont;
  myFont = createFont("Arial", 20);
  textFont(myFont);
  controlP5 = new ControlP5(this);
  controlP5.addSlider("Lenkung in %",-100,100,50,10,50,400,40);
  controlP5.addSlider("Power in %",-100,100,100,30,150,40,400);
  controlP5.addSlider("Licht",0,100,25,200,150,40,400);
  controll = ControllIO.getInstance(this);
  device = controll.getDevice("Logitech Cordless RumblePad 2");
  
  device.setTolerance(0.05f);
  
  
  ControllSlider sliderX = device.getSlider("Z-Achse");
  ControllSlider sliderY = device.getSlider("Z-Rotation");
  ControllSlider sliderX1 = device.getSlider("X-Achse");
  ControllSlider sliderY1 = device.getSlider("Y-Achse");
  
  stick = new ControllStick(sliderX,sliderY);
  stick1 = new ControllStick(sliderX1,sliderY1);

          // get right value for servo
  button = device.getButton("Taste 0");
  button1 = device.getButton("Taste 2");
 }


void draw()
{
  background(150);

  String n1;
  String n2;
  String sending;
  int speed = int(stick.getY()*-255+255); // get right value for motor controller
  int steer = int((stick1.getX()*45)+90);
  n1 = Integer.toString(steer);
  n2 = Integer.toString(speed);
  // if n1 or n2 is less than 4 digits add a zero to the front of them
  while (n1.length() < 4){
    n1 = '0' + n1;
  }
  while (n2.length() < 4){
    n2 = '0' + n2;
  }
  //combine the two 4 digit long strings into one 8 digit long one
  sending = n1 + n2;
  //write this to the serial port.
  myPort.write(sending);
  println(sending);
  controlP5.controller("Lenkung in %").setValue((steer-90)*2.5);
  controlP5.controller("Power in %").setValue(map(speed, 0, 510, -100, 100));
  fill(0);
  text("Sendestring: "+ sending, 800, 580);
  delay(20);

}

arduino:

#include <Servo.h>
String readString, servo1, speed2;
Servo myservo1;  
int motor1 = 6;
int motor2 = 7;
int motorpwm = 5;
int standby = 4;


void setup() {
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  Serial.begin(57600);
  myservo1.attach(9);  

 
}

void loop() {

  while (Serial.available()) {
  
    if (Serial.available() >0) {
      delay(2);
	char c = Serial.read();  
	readString += c; 
    }
  }

  if (readString.length() >0) {
	Serial.println(readString); 

	// expect a string like 07002100 containing the two servo positions
	servo1 = readString.substring(0, 4); 
	speed2 = readString.substring(4, 8); 

	Serial.println(servo1);  //print ot serial monitor to see results
	

	int n1;
	int n2;

	char carray1[6]; //magic needed to convert string to a number
	servo1.toCharArray(carray1, sizeof(carray1));
	n1 = atoi(carray1);

	char carray2[6];
	speed2.toCharArray(carray2, sizeof(carray2));
	n2 = atoi(carray2);

	myservo1.write(n1); //set servo position
	
    readString="";
    int power = map(n2, 0, 510, -255, 255);
    if (n2 > 255){
      digitalWrite(motor1, HIGH);
      digitalWrite(motor2, LOW);
      digitalWrite(standby, HIGH);
      
    
       analogWrite(motorpwm, power);
    }
     if (n2 < 255){
      digitalWrite(motor2, HIGH);
      digitalWrite(motor1, LOW);
      digitalWrite(standby, HIGH);
      
       
       analogWrite(motorpwm, power*-1);
    }
    if (n2 == 255){
      digitalWrite(standby, LOW);
    analogWrite(motorpwm, 0);}
      
   
 
  }

}