Go Down

Topic: [1/2SOLVED]Problems with Firmata, need help! (Read 3672 times) previous topic - next topic

zh32

Jan 08, 2011, 12:42 am Last Edit: Jan 08, 2011, 12:59 pm by zh32 Reason: 1
Hi,
a few days ago i got my arduino uno. i'm new to programming, electronics and stuff. ::) but i can learn fast.

i'm trying to build a RC LEGO-car at the moment with GUI,sensors....

i'm using processing and firmata to everything and it works fine. but a few hours ago i bought a servo and it's not working.

when i use StandartFirmata the motor controller works, but the servo is not doing wgat it should.

but when i use ServoFirmata the servo works perfect, but the motor controller is not working.

i use arduino IDE 0022, processing 1.2.1

does anyone know a solution for my problem?

btw: sry for my bad english skills


here's my processing code:
Code: [Select]

import net.java.games.input.*;
import processing.serial.*;
import cc.arduino.*;
import procontroll.*;
import java.io.*;

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

int LED = 7;
int speed;
int licht = 4;     //LDR
int motorpin1 = 9; //when motorpin1 HIGH motorpin2 LOW = forward....
int motorpin2 = 7;
int motorpwm = 11;
int standby = 8;
int geschw;
int richt;
int lichtval;
int steer;
int leucht;
int m;
int servoPin = 10;
int richtung;

String s = "Speed:";
String l = "Licht:";
String r = "Richtung:";

PFont myFont;

Arduino arduino;

void setup()
{
 size(400,400);
 arduino = new Arduino(this, Arduino.list()[1]);
 arduino.pinMode(LED, arduino.OUTPUT);
 arduino.pinMode(licht, arduino.INPUT);
 arduino.pinMode(motorpin1, arduino.OUTPUT);
 arduino.pinMode(motorpin2, arduino.OUTPUT);
 arduino.pinMode(motorpwm, arduino.OUTPUT);
 arduino.digitalWrite(standby, arduino.HIGH);
 arduino.pinMode(servoPin, arduino.OUTPUT);

 myFont = createFont("Arial", 20);
 textFont(myFont);
 
 controll = ControllIO.getInstance(this);
 device = controll.getDevice("Logitech Cordless RumblePad 2");
 device.printSticks();
 device.setTolerance(0.1f);
 device.printButtons();
 
 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);
 lichtval = arduino.analogRead(licht);
 text(s, 30,30);
 fill(0);
 geschw = int(-speed/2.55);
 text(geschw, 120, 30);
 text(l, 30, 60);
 leucht= int(-lichtval/4/2.55);            //my "GUI"
 text(leucht+100, 120, 60);
 text(r, 30, 90);
 richt = int(steer);
 text(richt, 120, 90);
 
 if(button.pressed()){
   arduino.digitalWrite(LED, Arduino.HIGH);
   }
 
 else
   {arduino.digitalWrite(LED, Arduino.LOW);
   }
 
 speed = int(stick.getY()*255);  // get right value for motor controller
 steer = int(stick1.getX()*90+90); // get right value for servo
 arduino.analogWrite(servoPin, 0);
 
 println(steer); //print different values for debuging
 if(speed > 0){                
   arduino.digitalWrite(motorpin1, arduino.LOW);
   arduino.digitalWrite(motorpin2, arduino.HIGH);        //forward
   arduino.digitalWrite(standby, arduino.HIGH);
   arduino.analogWrite(motorpwm, speed);
   }
 
 if(speed < 0){
   arduino.digitalWrite(motorpin1, arduino.HIGH);
   arduino.digitalWrite(motorpin2, arduino.LOW);        //back
   arduino.digitalWrite(standby, arduino.HIGH);
   arduino.analogWrite(motorpwm, speed*-1);
   }
 if(speed == 0){
   arduino.digitalWrite(standby, arduino.LOW);          //motor controller standby
   }

}

PaulS

Lots of people have trouble with Firmata. When it works, it works fine. When it doesn't, it doesn't.

It's not that hard to develop your own protocol, and have Processing write your commands to the serial port, and have Arduino read your commands, and react and reply appropriately.

zh32

#2
Jan 08, 2011, 02:22 am Last Edit: Jan 08, 2011, 02:26 am by zh32 Reason: 1
But the library is working, but only with two sketches... one(ServoFirmata) is driving the servo fine, but not the motor. the other one(StandartFirmata) is working fine with the motor, but the servo is doing noises and not the right postions.

and in both sketches LDR data receiving and pressing controllerbutton for LED is working.

i think that describes my problem in the right way

PaulS

The two firmata sketches do different things. Neither one does everything you need it to do. You might be able to combine the two sketches, and create one sketch that does everything right, if you are lucky.

Or, you can write your own protocol and learn something in the process.

zh32

mixed the scetches and got it working:)

if anyone is interested, i'll post the arduino and processing scetch.


PaulS

Quote
if anyone is interested, i'll post the arduino and processing scetch.

Sure. Post away.

zh32

#6
Jan 08, 2011, 01:16 pm Last Edit: Jan 08, 2011, 01:21 pm by zh32 Reason: 1
here's the link to TOF Firmata, it contains one library for processing and the firmware for arduino.
http://t-o-f.info/pmwiki/index.php?n=Arduino.Firmata

BUT theres one little problem left: every 10 seconds the servo vibrates for 1 seconds, maybe this gives a hint (from firmware):
Code: [Select]
/* SEND FTDI WRITE BUFFER - make sure that the FTDI buffer doesn't go over
    * 60 bytes. use a timer to sending an event character every 4 ms to
    * trigger the buffer to dump. */


as i said im new to these topics :P

btw: the processing code for my gamepad controlled lego-rc-car, with sending illumination data to "GUI" and turn LED on with button

Code: [Select]
/*  autonomous RC car project | Arduino UNO | zH32
   08.01.2011
*/

import procontroll.*;
import net.java.games.input.*;
import processing.serial.*;
import cc.firmata.*;
import java.io.*;

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

int LED = 3;
int licht = 4;     //LDR
int motorpin1 = 6; //when motorpin1 HIGH motorpin2 LOW = forward....
int motorpin2 = 7;
int motorpwm = 11;
int standby = 8;



void setup()
{
 size(400,400);
 println("Available ports:");
 println(Firmata.list());
 firmata = new Firmata(this, Firmata.list()[1], 115200);
 
 frameRate(20);
 
 PFont myFont;
 myFont = createFont("Arial", 20);
 textFont(myFont);
 
 controll = ControllIO.getInstance(this);
 device = controll.getDevice("Logitech Cordless RumblePad 2");
 device.printSticks();
 device.setTolerance(0.1f);
 device.printButtons();
 
 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 firmataSetup (Firmata f)
{
 
 println("Running setup function");
 f.pinMode(motorpwm,firmata.PWM);
 f.pinMode(9,firmata.SERVO);
 f.pinMode(LED, firmata.OUTPUT);
 f.pinMode(licht, firmata.INPUT);
 f.pinMode(motorpin1, firmata.OUTPUT);
 f.pinMode(motorpin2, firmata.OUTPUT);
 }
 
void draw()
{
 background(150);
 
 String s = "Speed:";
 String l = "Licht:";
 String r = "Richtung:";
 int speed = int(stick.getY()*255);                    // get right value for motor controller
 int steer = int((stick1.getX()*45)+90);               // get right value for servo
 int lichtval = firmata.analogRead(licht);
 int leucht= int(-lichtval/4/2.55);
 int richt = int(steer-90);
 text(s, 30,30);
 fill(0);
 text(speed, 120, 30);
 text(l, 30, 60);
 fill(leucht+100);                                      //my "GUI"
 text(leucht+100, 120, 60);
 fill(0);
 text(r, 30, 90);
 text(richt, 120, 90);
 
 if(button.pressed()){
   firmata.digitalWrite(LED, firmata.HIGH);
   }
 else
   {firmata.digitalWrite(LED, firmata.LOW);
   }
 
 //println(speed);                                       //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

}




this took me a night and lot of smokes, cheers!

zh32

#7
Jan 09, 2011, 02:51 am Last Edit: Jan 09, 2011, 05:42 am by zh32 Reason: 1
changed the motorstandby pin and now its working (changed from 12 to 2)


Go Up