driving and floating serial signals???

I have an Arduino connected to a Basic Stamp 2px via serial, and the BS2 guys informed me that my arduino is ‘floating’ the serial connection during two functions, thus creating a double serial character from the BS2… I guess I’m not ‘driving’ the serial connection… How do I do this to create a stable serial communication channel?

If my code is needed please let me know. Thanks in advance!

What do you mean by “double serial character from the BS2”? For example, are you expecting “A” but receiving “AA”? Or is one character random and the other something you expect? Or are both random?

Yes, like you describe, a single ‘A’ should be sent, but instead an instantaneous ‘AA’ is sent. To give more details, the BS2 sends 4 types of commands, two of which are quickly responded to by the Arduino, the other two take about 10 seconds to get a response from the Arduino and those are the two that get the ‘AA’ from the BS2.

That sounds an awful lot like a software issue. Can you provide more details?

I hope you’re familiar with the Basic Stamp 2. When the BS2 is sending the signal for ‘left’ and ‘right’, the arduino communicates fine - RX’s good, processes and sends a reply which the BS2 RX’s fine. When the BS2 detects the ‘both’ and ‘front’ conditions is where the snafu occurs - the BS2 sends those two values as instant repeats to the Arduino, which the Arduino code happens to take about 10 seconds to finish it’s task before it replies to the BS2.

I really appreciate your help! Here’s the BS2 and the Arduino code:

Basic Stamp 2px:

' {$STAMP BS2px}
' {$PBASIC 2.5}

IRL VAR Byte
IRR VAR Byte
IRF VAR Byte
ard VAR Byte

main:
GOSUB IR_Left
GOSUB IR_Right
GOSUB IR_Front


IF (IRL = 0) AND (IRR = 0) THEN
  DEBUG "Both", CR
  SEROUT 0, 396, ["1"]
  DEBUG "Serial going Out for Both", CR
  SERIN 1, 396, [WAIT("@"), ard]
  DEBUG "Response from Both", CR
ENDIF

IF IRF = 0 THEN
  DEBUG "Front", CR
  SEROUT 0, 396, ["4"]
  DEBUG "Serial going Out for Front", CR
  SERIN 1, 396, [WAIT("@"), ard]
  PAUSE 50
  DEBUG "Response from Front", CR
ENDIF

IF IRL = 0 THEN
  DEBUG "Left", CR
  SEROUT 0, 396, ["2"]
  DEBUG "Serial going Out for Left", CR
  SERIN 1, 396, [WAIT("@"), ard]
  DEBUG "Response from Left", CR
ENDIF

IF IRR = 0 THEN
  DEBUG "Right", CR
  SEROUT 0, 396, ["3"]
  DEBUG "Serial going Out for Right", CR
  SERIN 1, 396, [WAIT("@"), ard]
  DEBUG "Response from Right", CR
ENDIF

IRF = 1
IRL = 1
IRR = 1
GOTO main
END

IR_Left:
FREQOUT 7,6,6385
IRL = IN6
RETURN

IR_Right:
FREQOUT 5,6,6385
IRR = IN4
RETURN


IR_Front:
FREQOUT 15,6,6385
IRF = IN14
RETURN

Arduino:

#include <NewSoftSerial.h>
#include <Servo.h>

Servo LeftServo;
Servo RightServo;
Servo pingServo;
Servo downServo;

int duration, i, inches, ppos, pingdata[4];
char BS2data;

NewSoftSerial BS2(2,3);

void setup()
{
  BS2.begin(9600);
  Serial.begin(9600);
  LeftServo.attach(9);
  RightServo.attach(10);
  downServo.attach(11);
  pingServo.attach(12);
}  


void loop()
{
  if (BS2.available() > 0)
  {
    BS2data = BS2.read();
    Serial.print("From BS2: ");
    Serial.println(BS2data);
    // Both IR Sensors Tripped or Front IR Sensor
    //if (BS2data == '1' || BS2data == '4')
    if (BS2data == '4')
    {
      Stop();
      i = -1;
      PingAroundArea();
    }
    // Left Sensor Tripped
    if (BS2data == '2')
    {
      MoveRight();
      Serial.println("Turned Right");
    }
    // Right Sensor Tripped
    if (BS2data == '3')
    {
      MoveLeft();
      Serial.println("Turned Left");
    }
  Serial.println("@Z to BS2");
  BS2.print(char('@'));
  BS2.print(char('Z'));
  delay(50);
  }
  MoveForward();
}


//****************************************
//*******      SERVO CONTROL      ********
//****************************************
// Servo Write Values:
//  90 = still
//  0 = full speed direction 1
//  180 = full speed direction 2
void MoveForward()
{
  LeftServo.write(180);
  RightServo.write(1);
}

void MoveRight()
{
  LeftServo.write(180);
  RightServo.write(180);
  delay(500);
}

Above the edit window, there is a button with a hash [#] that inserts “code tags”. If you don’t mind, please edit your post so the code is bracketed by these code tags.

The tags look like this (with the spaces removed)…

[ code ] [ /code ]

Does this…

IR_Front:
FREQOUT 15,6,6385
IRF = IN14

…have a RETURN after it?

What does WAIT("@") do?

Sorry about the formatting - the tools scared me, lol. There is a return after IR_Front, I didn’t copy it, my bad, I’ve added it.

The wait("@") waits until the @ character is read from the serial line and then saves what comes next to the ‘ard’ variable.

If IRL is zero, the Stamp side sends “1”, waits for the Arduino, sends “2”, then waits for the Arduino. Is that your intention? Is that the problem you’re seeing?

If IRR is zero, the Stamp side sends “1”, waits for the Arduino, sends “3”, then waits for the Arduino. Is that your intention?

When I use my hand to create each of the four conditions why does this happen:

Left
Serial going Out for Left
Response from Left
Right
Serial going Out for Right
Response from Right
Front
Serial going Out for Front
Front
Serial going Out for Front
Response from Front
Both
Serial going Out for Both
Both
Serial going Out for Both
Response from Both

Why does ‘Both’ and ‘Front’ not follow the same output as ‘Left’ and ‘Right’?

I can’t see anything in the code that would cause that to happen. My guess is that the Stamp is rebooting / losing power after “Serial going Out” is sent. But that’s just a guess.

and the BS2 guys informed me that my arduino is ‘floating’ the serial connection during two functions

Can you go and ask the guys what the mean by that because the arduino doesn’t float it’s serial connection.