I'm trying to control a SaberTooth 2x12 connected to my Pi3. Based my Google research it seemed the best method was Simple Serial. I configured the Pi for Serial in raspi-config. Set the dip switches on the SaberTooth for simple serial and 9600 baud. I added a Level Shifter between the Pi and SaberTooth.
According to the Sabertooth documentation, with simple serial 1-127 controls the speed and direction of M1 and 128-255 speed and direction of M2. "0" shuts the motors off. When I run the code motor1 moves in one direction and one speed and will continue until power is removed.
As long as I'm sending a "number" of any value the same results: Motor 1 one speed and one direction. One thing the original code I was basing this off of use "ser.writeString". When I ran the code with that format it said Serial Object does not have "String". Can you advise what I'm doing wrong?
#! /user/bin/env python
# _*_ coding : utf-8 _*_
import time
import serial
ser = serial.Serial('/dev/serial0', 9600)
def main():
print("Program Start")
time.sleep(5)
x=0
while x < 4:
ser.write("M1: 1\r\n")
ser.write("M2: 128\r\n")
time.sleep(2)
ser.write("M1: 64\r\n")
ser.write("M2: 192\r\n")
time.sleep(2)
ser.write("M1: 127\r\n")
ser.write("M2: 255\r\n")
time.sleep(2)
ser.write("M1: 0\r\n")
ser.write("M2: 0\r\n")
time.sleep(2)
x = x + 1
if __name__ == '_main_':
main()
Here's the traceback of the error I was getting:
Traceback (most recent call last):
File "MotorTest.py", line 27, in <module> main()
File "MotorTest.py" , line 16 in main
ser.writeString("M1: 1\r\n")
AttributeError: 'Serial' object has no attribute 'writeString'
------------
Program exited with code: 1