Author Topic: How to assign pins to sabertooth  (Read 1347 times)

reinier

  • Newbie
  • *
  • Posts: 10
    • View Profile
How to assign pins to sabertooth
« on: September 23, 2014, 12:04:58 PM »
Hi,

I would like attach my sabertooth to a pin of the balanduino.
for example : ST.attach( pinnr, 1000, 2000);

Now is the pin numbers  assigned in avrpins.h

balanduino.h looks like
#define leftPWM P18

How can I define a pin in balanduino.h which I can use to assign it to sabertooth code?


Reinier

Lauszus

  • Administrator
  • Full Member
  • *****
  • Posts: 131
    • View Profile
Re: How to assign pins to sabertooth
« Reply #1 on: September 23, 2014, 08:49:12 PM »
@Reinier
You can still use the Balanduino main board as any normal Arduino.  So in order to send a servo input to the sabetooth you simply use the standard servo library: http://arduino.cc/en/reference/servo.

I only use the pins assigned in avrpins.h in order to write directly to the registers which is faster than using Arduino's digitalRead/Write functions.

Regards
Lauszus

reinier

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: How to assign pins to sabertooth
« Reply #2 on: September 23, 2014, 11:24:25 PM »
I understand but I will explain it with an example.

This is my code:

#include <servo.h>

#define rightPWMST P3  // connected to sabertooth motor controller
#define leftPWMST P4  // connected to sabertooth motor controller

I can't write the code:

  leftST.attach( rightPWMST, 1000, 2000);
  rightST.attach( leftPWMST, 1000, 2000);

but only this code will work:

  leftST.attach( 3, 1000, 2000);
  rightST.attach( 4, 1000, 2000);

I don't want to use hardcode pinnumbers.
How can you help me to use the same notation?

Regards, Reinier

Lauszus

  • Administrator
  • Full Member
  • *****
  • Posts: 131
    • View Profile
Re: How to assign pins to sabertooth
« Reply #3 on: September 23, 2014, 11:26:58 PM »
@Reinier
Simply define it them like so:
Code: [Select]
#define rightPWMSTPin 3  // connected to sabertooth motor controller
#define leftPWMSTPin 4  // connected to sabertooth motor controller

Notice that I added the Pin subfix, so it is consisted with the existing code: https://github.com/TKJElectronics/Balanduino/blob/master/Firmware/Balanduino/Balanduino.h#L79-L82.

Regards
Lauszus