Pages: [1]   Go Down
Author Topic: Help with packetized serial on SyRen 10?  (Read 1199 times)
0 Members and 1 Guest are viewing this topic.
Salt Lake City, UT
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17293
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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);
}

Logged

Salt Lake City, UT
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8499
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Salt Lake City, UT
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

yes
Logged

New Hampshire
Offline Offline
God Member
*****
Karma: 17
Posts: 781
There are 10 kinds of people, those who know binary, and those who don't.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Salt Lake City, UT
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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?
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8499
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: March 11, 2011, 07:47:55 pm by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

Pages: [1]   Go Up
Jump to: