Arduino with Ping Sensor w/ LV DSMC Problems

Hi,

I’m using a Arduino Duemilanove along with a Parallax Ping Ultrasound Sensor with a Low-Voltage Dual Derail Motor Controller.

I have two motors hooked up per the recommend schematic. Digital Pin 1 (labled TX) sends info from the Arduino to the Motorcontroller. Digital Pin 2 is the reset pin. A 4x AA battery holder provides the power (batteries are fresh). It operates perfectly by itself. However the problem comes in when I add the Ping Sensor. The ping sensor is on Digital Pin 15 and receives power from the same battery pack. Everything is on the common ground from the battery pack. Again, the Ping sensor works perfect by itself. The problem is that the Motor Controller is sending out some kind of signal to the serial port. When I open the Serial Monitor I see “EE6” where EE is from the motor controller and the 6 is the distance reading from the sensor. I have everything operating at 9600 Baud. What is the “EE” and how do I get rid of it. Attached is a screen shot of my serial monitor.

Thanks for any help

my code

[code]int motor_reset = 2;
const int pingPin = 15;
int distance = 0;
int ledpin = 14;

void setup()
{
pinMode(motor_reset, OUTPUT);
Serial.begin(9600
);
digitalWrite(motor_reset, LOW);
delay(50);
digitalWrite(motor_reset, HIGH);
delay(50);
}

void loop()
{
motorforward();
ping();
}

void distancecheck()
{
if (distance <= 1)
{
motorstop();
ledwarning();
delay(1000);
motorreverse();
delay(1000);
motorstop();
delay(1000);
rotateccw();
delay(2000);
motorstop();
delay(1000);
}
}

void ping()
{

// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches, cm;

// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);

// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);

// convert the time into a distance
distance = microsecondsToInches(duration);

Serial.println(distance);
//Serial.print("in, ");
//Serial.println();

delay(100);
}

long microsecondsToInches(long microseconds)
{
// According to Parallax’s datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 74 / 2;
}

void ledwarning()
{
digitalWrite(ledpin, HIGH);
delay(1000);
digitalWrite(ledpin, LOW);
}

//subroutine motor forward
void motorforward()
{
//left motor
unsigned char buff1[6];
buff1[0] = 0x80; //start byte - do not change
buff1[1] = 0x00; //device type byte - do not change
buff1[2] = 0x01; //Motore number and direction byte; motor one = 00,01
buff1[3] = 0x45; //Motor speed “0 to 128” in hex
for(int i=0;i<4;i++) {Serial.print(buff1[i], BYTE);}

//right motor
unsigned char buff2[6];
buff2[0] = 0x80; //start byte - do not change
buff2[1] = 0x00; //device type byte - do not change
buff2[2] = 0x03; //Motore number and direction byte; motor two = 02,03
buff2[3] = 0x45; //Motor speed “0 to 128” in hex
for(int i=0;i<4;i++) {Serial.print(buff2[i], BYTE);}
}

//subroutine motor reverse

void motorreverse()
{
//left motor
unsigned char buff3[6];
buff3[0] = 0x80; //start byte - do not change
buff3[1] = 0x00; //device type byte - do not change
buff3[2] = 0x00; //Motore number and direction byte; motor one = 00,01
buff3[3] = 0x35; //Motor speed “0 to 128” in hex
for(int i=0;i<4;i++) {Serial.print(buff3[i], BYTE);}

//right motor
unsigned char buff4[6];
buff4[0] = 0x80; //start byte - do not change
buff4[1] = 0x00; //device type byte - do not change
buff4[2] = 0x02; //Motore number and direction byte; motor two = 02,03
buff4[3] = 0x35; //Motor speed “0 to 128” in hex
for(int i=0;i<4;i++) {Serial.print(buff4[i], BYTE);}

//subroutine motor all stop
}

void motorstop()
{
//left motor
unsigned char buff3[6];
buff3[0] = 0x80; //start byte - do not change
buff3[1] = 0x00; //device type byte - do not change
buff3[2] = 0x00; //Motore number and direction byte; motor one = 00,01
buff3[3] = 0x00; //Motor speed “0 to 128” in hex
for(int i=0;i<4;i++) {Serial.print(buff3[i], BYTE);}

//right motor
unsigned char buff4[6];
buff4[0] = 0x80; //start byte - do not change
buff4[1] = 0x00; //device type byte - do not change
buff4[2] = 0x02; //Motore number and direction byte; motor two = 02,03
buff4[3] = 0x00; //Motor speed “0 to 128” in hex
for(int i=0;i<4;i++) {Serial.print(buff4[i], BYTE);}
}

void rotateccw()
{
//left motor
unsigned char buff3[6];
buff3[0] = 0x80; //start byte - do not change
buff3[1] = 0x00; //device type byte - do not change
buff3[2] = 0x01; //Motore number and direction byte; motor one = 00,01
buff3[3] = 0x40; //Motor speed “0 to 128” in hex
for(int i=0;i<4;i++) {Serial.print(buff3[i], BYTE);}

//right motor
unsigned char buff4[6];
buff4[0] = 0x80; //start byte - do not change
buff4[1] = 0x00; //device type byte - do not change
buff4[2] = 0x02; //Motore number and direction byte; motor two = 02,03
buff4[3] = 0x40; //Motor speed “0 to 128” in hex
for(int i=0;i<4;i++) {Serial.print(buff4[i], BYTE);}
}

void rotatecw()
{
//left motor
unsigned char buff3[6];
buff3[0] = 0x80; //start byte - do not change
buff3[1] = 0x00; //device type byte - do not change
buff3[2] = 0x00; //Motore number and direction byte; motor one = 00,01
buff3[3] = 0x40; //Motor speed “0 to 128” in hex
for(int i=0;i<4;i++) {Serial.print(buff3[i], BYTE);}

//right motor
unsigned char buff4[6];
buff4[0] = 0x80; //start byte - do not change
buff4[1] = 0x00; //device type byte - do not change
buff4[2] = 0x03; //Motore number and direction byte; motor two = 02,03
buff4[3] = 0x40; //Motor speed “0 to 128” in hex
for(int i=0;i<4;i++) {Serial.print(buff4[i], BYTE);}[/code]

Your program contains 10 lines of code like the following:

Serial.print(buff4[i], BYTE);

That’s probably where the extra characters are coming from. Your problem is that the Arduino only has one hardware TX line and you are using it for two purposes: to command the motor controller and to send data to the computer. Any command you send to the motor controller will get seen by the computer. Arduino has a software serial library (NewSoftwareSerial?) that you could use to send commands to the motor controller which should let you use a different IO line.

-David

excellent thank you. I’ll look into it.

yeah that did it thanks

http://arduiniana.org/libraries/NewSoftSerial/

The sensor is on hardware serial and the motor controller is on the software serial. Works perfect.