Mis-communication??

First off, I am not sure about support in these forums for BASIC Stamps, but I need to interface one to the Arduino. I am having trouble, though. I am trying to get the Arduino to read an analog value, convert it to digital, then send the result over a serial line to the BS2e (Basic Stamp 2e). The BS2e then stores the result in a variable, and displays it in a debug terminal (aka “serial monitor” according to the Arduino software). Here’s the Arduino code:

//int txPin = 7;
int micPin = 0;
int val = 0;

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

void loop()
{
  val = analogRead(micPin);
  Serial.print(val);
  //digitalWrite(txPin, val);
  delay(200);
}

Ignore the commented out parts (with the “//”).

…And here’s the PBASIC code (again, ignore the commented out stuff with a " ’ ")

' {$STAMP BS2e}
' {$PBASIC 2.5}

value           VAR     Word(3)

'Tx              PIN     0
Rx              PIN     1
Baud            CON     1200

DO

  'value = 0
  SERIN Rx, Baud, [value]
  'IF value > 0 THEN
    DEBUG HOME, DEC value
  'ENDIF

LOOP

Maybe someone has experience with BASIC…? Thanks!

I am not familiar with the Stamp but guess that it needs something like a carriage return and/or line feed to discriminate between SERIN values. Try replacing your arduino print statement with Serial.println(val);

Your baud constant for the BS2e is wrong – the BS2 does use the actual rate as the value, but an integer constant (you can find the formula in the PBASIC help file) based on the baud rate, mode, parity, etc… For 1200 baud, true mode (what the Arduino spits out), the correct constant is 813.

Hmmm…It’s still not returning proper values. did you mean that the constant was supposed to be just “813” or “$813”? I tried both, and the debug window on the BS2 program is still giving me improper values. I know I have everything else right; the Arduino is set for 1200bps, all the connections are right…I also tried the carriage return on both the BS2e ("DEBUG CR, …) AND the Arduino (Serial.Println …). What could be wrong?