Hey all, fairly new Arduino programmer here doing a project that requires the use of two motor controllers. I got two SyRen 10's because they were recommended to me and seemed to fit my specs well. I know I could throw an RC filter on a PWM input from the Arduino and control it with an analog, but ideally I would like to get it up and running with packetized serial. I think I understand the concept pretty well, but I can't get it to work, either with my code or some examples I found on the internet. When I run this code, the LED status light on the SyRen dims as I would expect, but the motor never turns on. I looked at the S1 input using a scope and I can see the packets that Arduino is sending out, and they seem to look ok (to me at least), so I'm a bit at a loss as to what the issue is (I've quadruple checked the jumper setups on the SyRen board). Anyway, here's the relevant section of my code (it's part of a much larger project outputting data to a LabView VI, which is why I need the computer to keep the hardware Serial connection. But I tried running the SyRen off the regular Serial port for debugging and still had no luck, so I don't think that's the issue...)
#include <NewSoftSerial.h>
#define rxPin 3
#define txPin 4
/* Constants For Torque Serial Controller */
NewSoftSerial mSerial(rxPin, txPin);
const byte cmndChar = 128;
const byte torqueAddress = 0x80;
void setup() {
Serial.begin(115200);
pinMode(txPin, OUTPUT);
pinMode(rxPin, INPUT);
mSerial.begin(9600);
mSerial.print(0xAA,BYTE);
delay(1000);
}
void loop()
writeTorque(800, torqueAddress);
delay(2000);
}
/* Writes an 8 byte serial datapacket to write a torque command to the torque controller */
int writeTorque(int theReading, uint8_t theAddress) {
uint8_t strength;
uint8_t cmd;
uint8_t chkSum;
if (theReading < 1000) {
cmd = 0x01; // Drive motor backward
strength = map(theReading, 0, 999, 0, 255);
} else {
cmd = 0x00; // Drive motor forward
strength = map(theReading, 1000, 1999, 0, 255);
}
strength = constrain(strength, 0, 255);
chkSum = (theAddress + cmd + strength) & B01111111;
mSerial.print(theAddress, BYTE);
mSerial.print(cmd, BYTE);
mSerial.print(strength, BYTE);
mSerial.print(chkSum, BYTE);
return 0;
}
Any ideas?
Thanks!!!!