Hey folks!
I'm working on a project where an Arduino is connected to weighing scale with an RS232 interface.
I'm using a RS232 to TTL converter from DX.com.
My script reads the weight given from the interface and translates this to a servo angle.
This works perfectly, but when the servo should be at rest (servo.write is only called when the difference in weight is big),
the servo shakes/ticks at around 2.7 Hz. The problem cannot lie in the PWM timing, because the problem also exists when the Arduino isn't sending an angle to the servo.
Here comes the strange part; the problem only exists when I connect the RS232-to-TTL converter to the weighing scale. I think this has to do with an electrical problem? I made sure the Servo has a seperate Power Supply, and all grounds are connected.
Can someone help me out?
I also included my script.
#include <Easing.h>
#include <SoftwareSerial.h>
#include <Servo.h>
#define FUSTWEIGHT 6.50
#define LEEGFUST 0
Servo myservo;
SoftwareSerial mySerial(2, 3);
char cArray[17];
char number[5];
float weightFloat;
float ratio;
int degVal;
int prevDegVal;
void setup() {
// put your setup code here, to run once:
pinMode(2, INPUT);
pinMode(3, OUTPUT);
mySerial.begin(9600);
myservo.attach(11);
pinMode(7, OUTPUT);
digitalWrite(7, HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
if(mySerial.available() > 0)
{
delay(200);
for(int i = 0; i<17; i++)
{
cArray[i] = mySerial.read();
}
while(mySerial.available() > 0)
mySerial.read();
for(int i = 0; i<5;i++)
{
number[i] = cArray[i+8];
}
weightFloat = atof(number);
ratio = (weightFloat - LEEGFUST)/(FUSTWEIGHT - LEEGFUST);
prevDegVal = degVal;
degVal = ratio*180;
int sign = 1;
if(degVal < prevDegVal)
{
sign = -1;
}
if(abs(degVal - prevDegVal) > 10)
{
for(int i = 0; i< abs(degVal-prevDegVal); i++)
{
int pos = prevDegVal + i*sign;
myservo.write(pos);
delay(50);
}
}
}
}