Go Down

Topic: Help with packetized serial on SyRen 10? (Read 1 time) previous topic - next topic

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...)
Code: [Select]

#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!!!!

retrolefty


Not sure if it's the problem or not, but the NewSoftSerial command should be in the setup function I believe.

Quote
void setup() {
  Serial.begin(115200);
  pinMode(txPin, OUTPUT);
  pinMode(rxPin, INPUT);
  mSerial.begin(9600);
  mSerial.print(0xAA,BYTE);
  NewSoftSerial mSerial(rxPin, txPin);
  delay(1000);
}




Not sure if it's the problem or not, but the NewSoftSerial command should be in the setup function I believe.



Interesting... it still seems to work, and some of the examples I saw online had it in the header...

Regardless though, the serial link doesn't seem to work even if I use the regular hardware serial (Serial.xx) interface and forget all about NewSoftSerial... Also, the scope shows that my NewSoftSerial pin (4) is outputting the wave packet I was expecting it to...

thanks though!

Graynomad

Are you waiting 2 seconds from powerup before sending the auto baud character?

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com


Are you waiting 2 seconds from powerup before sending the auto baud character?


yes

jraskell



Are you waiting 2 seconds from powerup before sending the auto baud character?


yes


Show the code that is doing this.  The code you originally posted is not.



Show the code that is doing this.  The code you originally posted is not.


For testing, I'm doing this physically. IE - start up the SyRen, then wait several seconds before turning on the Arduino. The code I have there should send the baud character during the setup portion of the Arduino boot process, I think?

Graynomad

#7
Mar 12, 2011, 01:43 am Last Edit: Mar 12, 2011, 01:47 am by Graynomad Reason: 1
I'd start by putting some Serial.print()s at the bottom of the writeTorque() func to ensure that your values are reasonable. You have to start eliminating possibilities.

Quote
then wait several seconds before turning on the Arduino.

This could produce garbage on the serial line that the SyRen interprets as the baud rate byte. Do you literally mean "turning on" or just resetting? If you are turning on then I'd try just holding the rest button while the SyRen powers up.
______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Go Up