Go Down

Topic: serial communication via NewSoftSerial library with sabertooth 2*5A motor driver (Read 631 times) previous topic - next topic

NearCZ

Hi Arduino folks,
I have a question regarding the NewSoftSerial library.
I have a sketch which should help me to communicate with my sabertooth Motor Driver over Serial:
Code: [Select]
#include
int x, r, l, s, f, xa, xb, xc;
#include <NewSoftSerial.h>

//serieller transmitter
#define SABER_TX_PIN  13
//Serieller empfänger
#define SABER_RX_PIN  12
//baudrate zur übereinstimmung mit den dip einstellungen
#define SABER_BAUDRATE  9600
NewSoftSerial SaberSerial = NewSoftSerial (SABER_RX_PIN, SABER_TX_PIN );

void initSabertooth (void)  {
   //kommunikation mit sabertooth
pinMode ( SABER_TX_PIN, OUTPUT );
SaberSerial.begin( SABER_BAUDRATE );
}

void setup()                   
{
   initSabertooth();
   
     Serial.begin(9600); 
}

void set_motor()   {
   x = analogRead(0);       

//x winkel ist  270-400 astabil bei 330
       

xa = x;
delay (20);
x = analogRead(0);     
xb = x;
delay (20);
x = analogRead(0);     
xc = x;
x= (xa +xb + xc)/3;

         
//SABER_right_FULL_FORWARD 127
//SABER_right_FULL_REVERSE 1
//SABER_left_FULL_FORWARD 255
//SABER_left_FULL_REVERSE 128


s = 1.8  ;

f = 5;


//stabilitätspunkt bei 330
if ((x > 325) && (x < 335)) {
r = 62;
l = 194;
}
//leicht nach vorne 310 > x < 330
if ((x > 310) && (x < 326)) {
r = 45;
l = 167;
}
//schneller nach vorne 279 > x < 311
if ((x > 279) && (x < 311)) {
r = s * x - 278 + f;
l = s * x - 148 + f;
}
//stark nach vorne x < 280
if ((x > 250) && (x < 280)) {
r = 6;
l = 133;
}
// laicht nach hinten 334 > x > 349
if ((x > 334) && (x < 349)) {
r = 78;
l = 208;
}
//schneller nach hinten fallen 348 < x < 390
if ((x > 348) && (x < 391)) {

r = s * x - 270 + f;
l = s * x - 140 + f;
}
//stark nach hinten 390 < x
if ((x > 390) && (x < 410)) {
r = 122;
l = 250;
}

//zum sabertooth senden
SaberSerial.write(byte(r));
SaberSerial.write(byte(l));

}

void loop ()  {
 
float level = 0;

int u;

   set_motor();
 
}

when trying to compile this I get the following error message:
NewSoftSerial does not Name a type
I think the error occurs because of this Statement, which I'm not able to fix:
NewSoftSerial SaberSerial = NewSoftSerial (SABER_RX_PIN, SABER_TX_PIN );
Maybee it's a thumb question but I really don't get if I have to insert a type Definition an if so which..
Thanks in advance,
NearCZ

p.s Sorry for bad spelling(auto-correction)
and please excuse me for doing things wrong as this is my first post in the Forum.. :~


Go Up