Help for servo question

Contakm lfs-arduino. Prima prova. - YouTube :slight_smile:

Nice vid Tommy!

You could always give it a shot!

Can I export rpm data for an other servo with python?

Can I export rpm data for an other servo with python?

This question does not make sense. RPM is a measure of speed. How can python, on the PC, know how fast something connected to the Arduino is turning?

This question does not make sense.

It does, if you watch the video :wink:

It does, if you watch the video

I watched the video. It still doesn't. The context in which it might make sense is missing. The python script and the Arduino code, to be specific.

Can i change this code for rpm data???

import time
import pyinsim
import serial

ARDUINO_PORT = 'com3:'

arduino = serial.Serial(ARDUINO_PORT, 19200, timeout=1)
time.sleep(3)

def outgauge_packet(outgauge, packet):
  speed_kmh = int(packet.Speed*3.6)
  speed_command = 'S {0}\r'.format(speed_kmh)
  arduino.write(speed_command)
  arduino.flushInput()


outgauge = pyinsim.outgauge('127.0.0.1', 30000, outgauge_packet, 30.0)

pyinsim.run()

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.