Help for servo question

Can i change this code for rpm data???

In place of speed, or in addition to?

What is packet? It looks like some kind of struct. What is in packet? Does it have something analogous to Speed that contains rpm, instead?

Rpm in addition to speed with 2 servo: one for speed and one for rpm

The correct ratio is one answer per question.

What is packet? It looks like some kind of struct. What is in packet? Does it have something analogous to Speed that contains rpm, instead?

Excuse me... Packet of the game?

Since this no longer has anything to do with Arduino, I think you're on your own.

tommy27:
Rpm in addition to speed with 2 servo: one for speed and one for rpm

If you are able to modify the software that is sending the speed commands to also send RPM commands then I don't see anything stopping you. The Arduino side of things would certainly be possible.

with this code my servo is very crazy, why??? :~

#include <Messenger.h>
#include <Servo.h>

#define SPEED_SERVO_PIN 7
#define SPEED_SERVO_0_US 460
#define SPEED_SERVO_300_US 3000

#define RPM_SERVO_PIN 7
#define RPM_SERVO_0_US 460
#define RPM_SERVO_300_US 3000

Servo hand;
Messenger message;

void sendVersion()
{
  Serial.println(F("AD 01.12 ArduDash"));
}

void sendOK()
{
  Serial.println(F("OK"));
}

void sendERROR()
{
  Serial.println(F("ERROR"));
}

void setSpeedServo(int speed)
{
  int microseconds = map(speed, 0, 300, SPEED_SERVO_0_US, SPEED_SERVO_300_US);
  hand.writeMicroseconds(microseconds);
}
void setRPMServo(int rpm)
{
  int microseconds = map(rpm, 0, 10000, RPM_SERVO_0_US, RPM_SERVO_300_US);
  hand.writeMicroseconds(microseconds);
}

void setSpeed()
{
  int speed = message.readInt();
  if (speed < 0 || speed > 230)
  {
    sendERROR();
    return;
  }
  setSpeedServo(speed);
  sendOK();
}
void setRPM()
{
  int rpm = message.readInt();
  if (rpm > 100000 || rpm < 0)
  {
    sendERROR();
    return;
  }
  setRPMServo(rpm);
  sendOK();
}
void onMessage()
{
  switch (message.readChar())
  {
    case 'V':
      sendVersion();
      break;
    case 'S':
      setSpeed();
      break;
    case 'R':
      setRPM();
      break;
    default:
      sendERROR();
      break;
  }
}

void serialEvent()
{
  message.process(Serial.read());
}

void setup()
{
  hand.attach(7);
  Serial.begin(9600);
  message.attach(onMessage);
  
  setSpeedServo(0);
}
void setup()
{
  hand.attach(7);
  Serial.begin(9600);
  message.attach(onMessage);
  
  setRPMServo(0);
}

void loop()
{
}

That sketch won't even compile...

is this the error??

void setup()
{
  hand.attach(7);
  Serial.begin(9600);
  message.attach(onMessage);
  
  setSpeedServo(0);
}
void setup()
{
  hand.attach(8);
  Serial.begin(9600);
  message.attach(onMessage);
  
  setRPMServo(0);
}

yep...

If it didn't compile, why complain that the servo went crazy?

AWOL:
If it didn't compile, why complain that the servo went crazy?

with this

void setup()
{
  hand.attach(7);
  Serial.begin(9600);
  message.attach(onMessage);
  setSpeedServo(0);
  hand.attach(8);
  Serial.begin(9600);
  message.attach(onMessage);
  setRPMServo(0);
}
  hand.attach(7);
  hand.attach(8);

Which pin do you want the servo attached to?

  Serial.begin(9600);
  Serial.begin(9600);

In case the 1st one didn't work, do it again. Why do you then assume the 2nd one worked? Why not a thirst and a fourth?

  message.attach(onMessage);
  message.attach(onMessage);

Ditto.

It's really time that you stop blindly cutting and pasting code in the hopes that something will work, and read and understand what the code is doing.

hand.attach(7); //rpm servo
hand.attach(8); //speed servo

The comments now say one thing (wrong). The code still says something else.

There is NO relationship between rpm and hand or between speed and hand. Meaningful names make all the difference.

Is it ok??

void setup()
{
  SpeedServo.attach(7);
  Serial.begin(9600);
  message.attach(onMessage);
  setSpeedServo(0);
  RPMServo.attach(8);
  Serial.begin(9600);
  message.attach(onMessage);
  setRPMServo(0);
}

Is it ok??

No. Same reasons as before.

The complete code is

#include <Messenger.h>
#include <Servo.h>

#define SPEED_SERVO_PIN 7
#define SPEED_SERVO_0_US 460
#define SPEED_SERVO_300_US 3000

#define RPM_SERVO_PIN 8
#define RPM_SERVO_0_US 460
#define RPM_SERVO_300_US 3000

Servo SpeedServo;
Servo RPMServo;
Messenger message;

void sendVersion()
{
  Serial.println(F("AD 01.12 ArduDash"));
}

void sendOK()
{
  Serial.println(F("OK"));
}

void sendERROR()
{
  Serial.println(F("ERROR"));
}

void setSpeedServo(int speed)
{
  int microseconds = map(speed, 0, 300, SPEED_SERVO_0_US, SPEED_SERVO_300_US);
  SpeedServo.writeMicroseconds(microseconds);
}
void setRPMServo(int rpm)
{
  int microseconds = map(rpm, 0, 10000, RPM_SERVO_0_US, RPM_SERVO_300_US);
  RPMServo.writeMicroseconds(microseconds);
}

void setSpeed()
{
  int speed = message.readInt();
  if (speed < 0 || speed > 230)
  {
    sendERROR();
    return;
  }
  setSpeedServo(speed);
  sendOK();
}
void setRPM()
{
  int rpm = message.readInt();
  if (rpm > 100000 || rpm < 0)
  {
    sendERROR();
    return;
  }
  setRPMServo(rpm);
  sendOK();
}
void onMessage()
{
  switch (message.readChar())
  {
    case 'V':
      sendVersion();
      break;
    case 'S':
      setSpeed();
      break;
    case 'R':
      setRPM();
      break;
    default:
      sendERROR();
      break;
  }
}

void serialEvent()
{
  message.process(Serial.read());
}

void setup()
{
  SpeedServo.attach(7);
  Serial.begin(9600);
  message.attach(onMessage);
  setSpeedServo(0);
  RPMServo.attach(8);
  Serial.begin(9600);
  message.attach(onMessage);
  setRPMServo(0);
}

void loop()
{
}

void setup()
{
SpeedServo.attach(7);
Serial.begin(9600);
message.attach(onMessage);
setSpeedServo(0);
RPMServo.attach(8);
Serial.begin(9600);
message.attach(onMessage);
setRPMServo(0);
}

Why? If Serial.begin() fails (and I've never heard of a single instance of it failing), why do you assume that calling it again will work? If it worked, why do you need to call it again?

The same question applies to the call to attach().

I was wrong
Now i use this code. Arduino compile but he not work... why?
http://arduino.cc/forum/index.php/topic,8711.0.html

my code:
void setup() {
  // Speed needs to match INSIM - Outgauge Client Configuration setting
  Serial.begin(9600);
  Serial.flush();

  // Set all pins to Outut Mode
  int a;
  for(a=0;a < 13;a++){
      pinMode(a, OUTPUT);
   }
}

My serial begin is 9600