Arduino to Basic Stamp through Serin
billyb
Posts: 2
First post- apologize if it is not in the right location or other problems.
I'm having an issues with serial communication between an arduino and a basic stamp home work board. I get a good response out of the arduino in the editor's serial monitor, but the serial monitor on the stamp just gives nonsense data (usually a "v:" or a "w:" or "7w:"). Both the arduino and the stamp output LED and input LED light up at the 1 second increments, as does the serial monitors. I'm using com 5 and com 6 on the same computer, both through USB. Boards are connected Pin 1 (TX) from arduino to a 220ohm resistor to Pin 1 (RX) stamp. Ground wire is connected from GND on Arduino to Vss- on Basic Stamp. The arduino is doing what I expect it to do, although I can't rule it out as the problem. I did try different baud rates on the BS2 and other options, this was the best result. Baud 2400, Even Parity, 7 bits.
Here's the code for arduino:
Here's the code for BS2:
The LOW are just a precaution, I have heard that having an output pin of one board connected to an high output can burn out one or both of the boards. They can be removed.
My intent was to get this running, then use a simple RF transmitter like this:
http://www.rentron.com/remote_control/tws-434.htm
Then use simple if..then subprograms to use one board as a remote control for the other.
Unfortunately I can't even get a simple data to get from one to the other so I'm stuck. Can anyone help?
I'm having an issues with serial communication between an arduino and a basic stamp home work board. I get a good response out of the arduino in the editor's serial monitor, but the serial monitor on the stamp just gives nonsense data (usually a "v:" or a "w:" or "7w:"). Both the arduino and the stamp output LED and input LED light up at the 1 second increments, as does the serial monitors. I'm using com 5 and com 6 on the same computer, both through USB. Boards are connected Pin 1 (TX) from arduino to a 220ohm resistor to Pin 1 (RX) stamp. Ground wire is connected from GND on Arduino to Vss- on Basic Stamp. The arduino is doing what I expect it to do, although I can't rule it out as the problem. I did try different baud rates on the BS2 and other options, this was the best result. Baud 2400, Even Parity, 7 bits.
Here's the code for arduino:
/*
* Simple Transmitter Code
* (TX out of Arduino is Digital Pin 1)
*/
byte counter;
void setup(){
//2400 baud for the 434 model
Serial.begin(2400);
}
void loop(){
//send out to transmitter
Serial.print("1000000");
delay(1000);
}
All this does is transmit the same number once each second. The arduino editor serial monitor shows the correct output each second. The input on the serial monitor in the basic stamp editor changes when I change the number or put in letters, but not in a way I understand.* Simple Transmitter Code
* (TX out of Arduino is Digital Pin 1)
*/
byte counter;
void setup(){
//2400 baud for the 434 model
Serial.begin(2400);
}
void loop(){
//send out to transmitter
Serial.print("1000000");
delay(1000);
}
Here's the code for BS2:
' {$STAMP BS2}
' {$PBASIC 2.0}
LOW 1
LOW 2
LOW 3
LOW 3
LOW 4
LOW 5
LOW 6
LOW 7
LOW 8
LOW 9
LOW 10
LOW 11
LOW 12
LOW 13
LOW 14
result VAR Word
Main:
DO
SERIN 1, 24972, Bad_Data, 10000, No_Data, [DEC result]
DEBUG CLS, ? result
LOOP
Bad_Data:
DEBUG CLS, "Parity error"
GOTO Main
No_Data:
DEBUG CLS, "Timeout error"
GOTO MAIN
' {$PBASIC 2.0}
LOW 1
LOW 2
LOW 3
LOW 3
LOW 4
LOW 5
LOW 6
LOW 7
LOW 8
LOW 9
LOW 10
LOW 11
LOW 12
LOW 13
LOW 14
result VAR Word
Main:
DO
SERIN 1, 24972, Bad_Data, 10000, No_Data, [DEC result]
DEBUG CLS, ? result
LOOP
Bad_Data:
DEBUG CLS, "Parity error"
GOTO Main
No_Data:
DEBUG CLS, "Timeout error"
GOTO MAIN
The LOW are just a precaution, I have heard that having an output pin of one board connected to an high output can burn out one or both of the boards. They can be removed.
My intent was to get this running, then use a simple RF transmitter like this:
http://www.rentron.com/remote_control/tws-434.htm
Then use simple if..then subprograms to use one board as a remote control for the other.
Unfortunately I can't even get a simple data to get from one to the other so I'm stuck. Can anyone help?
Comments
I've interfaced the BS2 to other microcontrollers (but not the Arduino) and the PC. The issue is that the basic stamp is reading the input asynchronously from the output of the Arduino. So it can't tell where the start of the message is and only sees a bunch of bytes slammed together. What you need to do it pad the start of the message with a few unique bytes the BS2 can look for and then read a fixed length message after that. You couple this with the use of the WAITSTR on the BS2's serin.
I've been meaning to do some BS2 to Arduino interfacing because the Arduino libraries work with the ATTiny MCU which would make a great ADC for the BS2.
The BS2 baudrate for 2400 8N1 True is 396
On a related note, the stamp serial monitor automatically opens with 9600 baud as the default when using debug, and the pull down menu is greyed out. I had to close it, open the manual serial monitor manually, and set the baud rate. But it works fine from then on.
Martin- I think you are reffering to a handshake protocol? I know some of those words Probably something I need to learn down the road but for this project its not neccessary.
FYI- Next step is to prove out the RF transmitter can do the same thing as a wire connecting the 2 boards. Once I've done that, I will just be hooking up the arduino as a transmitter to an old joystick, and using the basic stamp to run my robot.
Thanks so much everyone!