Syren problem .. I think

I'm working on a self balancing unicycle using this http://www.instructables.com/id/Easy-build-self-balancing-skateboardrobotsegway-/ instructable as a guide and using a Syren 25a motor controller SyRen 25A regenerative motor driver - analog, R/C, and serial motor control.

When I finally wired everything up and tested my modified version of his code the motor went crazy and didn't do anything I expected. I tried various stuff to get some decent result out of the motor controller and failed.

So I tried to write a code to check the Syren is functioning properly and the motor is still not behaving as I expected.

From the Syren instructions it says

"Simplified serial mode uses TTL level RS-232 serial data to set the speed and direction of the
motor. This is used to interface the SyRen to a PC or microcontroller. If using a PC, a level
converter such as a MAX232 chip must be used. The baud rate is set via DIP switches.
Commands are single-byte, with 0 representing full reverse and 255 representing full forward.
There is also a Slave Select mode which allows the use of multiple motors from a single
microcontroller serial port."

Here is my sketch

#include <SoftwareSerial.h>

SoftwareSerial SaberSerial(8, 12);

void setup()  
{
  Serial.begin(9600);
 

 SaberSerial.begin(9600);

}

void loop() 
{ 
   
 Serial.println("start");
 SaberSerial.print (10, BYTE);
 delay (5000);
 Serial.println ("20");
  SaberSerial.print (20, BYTE);
 delay (5000);
 Serial.println ("40");
  SaberSerial.print (40, BYTE);
 delay (5000);
 Serial.println ("60");
  SaberSerial.print (60, BYTE);
 delay (5000);
 Serial.println ("80");
  SaberSerial.print (80, BYTE);
 delay (5000);
  SaberSerial.print (100, BYTE);
 delay (5000);
 Serial.println ("100");
  SaberSerial.print (127, BYTE);
  Serial.println ("FULL STOP");
 delay (10000);
  SaberSerial.print (150, BYTE);
 delay (5000);
 Serial.println ("175");
  SaberSerial.print (175, BYTE);
 delay (5000);
 Serial.println ("200");
  SaberSerial.print (200, BYTE);
 delay (5000);
 Serial.println ("225");
  SaberSerial.print (225, BYTE);
 delay (5000);
 Serial.println ("250");
   SaberSerial.print (250, BYTE);
 delay (5000);
 
 Serial.print ("loop");
}

Which should start at almost full speed in one direction slow down to zero and then speed up in the other direction sending it's progress to the serial window so I can see what it's doing and when.

I have the battery and motor connected to the battery and motor connections on the syren, S1 on the syren is connected to pin 12 on the Arduino and 0v on the syren connected to ground on the Arduino nothing else is connected except USB and power from the batteries through a converter for the Arduino.

Does that look ok? am I doing something basically wrong ? or do I actually have some faulty hardware somewhere.

When I apply power the motor instantly speed's up and then acts erratically it appears to be trying to do something ... but its certainly not doing what I expect. The figures in the serial window look right.

I've reached the point where I just want to get the motor to do ANYTHING I ASK it to just to confirm all my hardware is ok.

Thanks for any help you may be able to give.

So Ive been playing around some more.

Moved the S1 to the arduino TX pin and uploaded this sketch

void setup() {
  
   Serial.begin(9600);

}

void loop() {

Serial.print(200); // forward
delay (10000);
Serial.print(127); // idle
delay (10000);
Serial.print(50); //  reverse 
delay (10000)
}

and tried

void setup() {
  
   Serial.begin(9600);

}

void loop() {

Serial.write(200); // forward
delay (10000);
Serial.write(127); // idle
delay (10000);
Serial.write(50); //  reverse 
delay (10000)
}

Neither had the effect I was expecting .. the motor sped up and slowed down (almost but not completely to a stop) but didn't change direction.

I've distilled the code down to the bare minimum needed to test the hardware. I just need someone to confirm that I'm not doing something basically wrong. or connecting something wrong somewhere.

I'm tearing my hair out here. I'm so close to testing and I feel like either my stupidity or a silly hardware problem is holding me back.

If I'm having this much trouble just getting to motor to spin then I dont stand a chance getting everything else working =(

honestly, it looks correct to me, based on the BASIC that is provided as example. Maybe somebody else will find what we're missing.

for kicks and grins, try this. Should do the same, but you never know.

B11111111,BYTE

B01111111,BYTE

B00000000,BYTE

Thanks for the advice .. I'm not at home ATM but I will test that ASAP.

I'm going to be running the Syren through it's other modes as well to see how it performs with them . and of course pestering Dimension eng. for a reply .

Would that be

serial.print (B11111111,BYTE);
I presume ? or should it be serial.write or none of the above ?

I'm pretty new to programming and I'm very much "learning on the job" . It was all going so well until I tried to test it. lol

I've not played with IDE1.0 but i think it's serial.write there? On IDE 002x it's Serial.print. But yes the syntax is correct.

It's just providing the binary byte as upposed to the decimal byte. IIRC the compiler should convert the decimal to that binary but I could be wrong.

I had a brainwave earlier today ..now I have a second arduino board I could use that to read that serial coming out of the board and display it in the serial window.

Using a code like this

int incomingByte = 0;	// for incoming serial data

void setup() {
	Serial.begin(9600);	// opens serial port, sets data rate to 9600 bps
}

void loop() {

	// send data only when you receive data:
	if (Serial.available() > 0) {
		// read the incoming byte:
		incomingByte = Serial.read();

		// say what you got:
		Serial.print("I received Binary: ");
		Serial.println(incomingByte, BIN);
                Serial.print("I received ASCII: ");
		Serial.println(incomingByte);
	}
}

I might have to change the serial.read to a software serial ... but that should tell me exactly what the "problem" board is outputting right? In binary and ASCII ?

fish_man:
I might have to change the serial.read to a software serial ... but that should tell me exactly what the "problem" board is outputting right? In binary and ASCII ?

Nope .. that didn't work ... Either my arduino isn't sending anything , but the serial monitor works fine ... or that approach just doesn't work.

You are reading from and writing to the same serial port. Is that really what you intended to test? If the serial monitor is on the other end of the serial port, you've learned nothing about what the other Arduino is sending.

Thats why I changed the serial.read to software serial

Read the serial coming in from pin whatever and send it out to the serial monitor on the PC.

I don't have a copy of the code I tried last night but thats basically all I changed.

Of course I might just be completely misunderstanding how the software serial works.

I don't have a copy of the code I tried last night but thats basically all I changed.

It will be pretty hard to help you debug it, then.

Of course I might just be completely misunderstanding how the software serial works.

Just like hardware serial, except that you must make the physical connections correctly, instead of relying on the shape of a connector to make that happen.

PaulS:

I don't have a copy of the code I tried last night but thats basically all I changed.

It will be pretty hard to help you debug it, then.

Of course I might just be completely misunderstanding how the software serial works.

Just like hardware serial, except that you must make the physical connections correctly, instead of relying on the shape of a connector to make that happen.

I wasn't looking for help in debugging really just sharing results. I'm pretty sure the serial is working fine as I got exactly the same results across two boards. I just though it would be nice to have a definite "yes that is working fine".

I will see if I can re-create the code if you really want to have a look.

Something like this

int incomingByte = 0;	// for incoming serial data
#include <SoftwareSerial.h>
SoftwareSerial SoftSerial = SoftwareSerial (8, 9 );


void setup() {
  Serial.begin(9600);	// opens serial port, sets data rate to 9600 bps

  pinMode(8, INPUT);
  pinMode(9, OUTPUT);
  SoftSerial.begin(9600);
}

void loop() {



  // send data only when you receive data:
  if (SoftSerial.available() > 0) {
    // read the incoming byte:
    incomingByte = SoftSerial.read();

    // say what you got:
    Serial.print("I received Binary: ");
    Serial.println(incomingByte, BIN);
    Serial.print("I received ASCII: ");
    Serial.println(incomingByte);
  }
}

With the TX pin of the Arduino1 connected to Digital pin 8 of the Arduino2 ... and the Arduino2 Connected Via USB cable to the PC running the serial monitor.

Arduino1 being the one which was connected to the Syren Running the simple Serial.write(200) sketch.
Arduino2 Being the new one running the above sketch Connected to the PC with e USB cable.