I'm trying to send data from a Basic Stamp 2 to the Arduino via serial communication. I'm using the Serial.available and Serial.read functions, connected the BS2 serial out to the Arduino RX pin 0. When data is read it sets the LED on pin 13 high and delays a bit. The BS2 is looping forever sending a the byte 64. It never works. I made sure to upload the Arduino program, disconnect USB and go on 9V battery power, tried the SoftwareSerial library on pins 2 and 3, even changed the BS2 pins as well. Can anyone point me in the right direction??
Is the Basic Stamp code using inverted baud mode (e.g. 16468) or true baud (e.g. 84)? Try switching the baud mode and make sure that you are using the same baud rate (e.g. 9600) for the Arduino and the Basic Stamp.
I started with true, value 84 but when it didnt work I tried inverted 16468 which also did not work. 9600 baud is set for both the BS2 and the Arduino.
The BS2 was verified working with Hyperterminal, connected 9600, 8 bits, no parity, 1 stop bit. It shoots out the symbol @ (40h) forever just fine.
Another thing to try is using the NewSoftSerial and different pins on the Arduino. The UART is connected to pin 0 and normal serial comm is 12v while the Basic Stamp serout is 5v.
You could use a line driver like the Maxim MAX233a but it would be easier to use the NewSoftSerial library and different pins.
I connected a BS2 to an Arduino - BS2 pin 0 to Arduino pin 2 with a 220 ohm resistor and Vss to GND.
The BS2 sends the letters A thru F to the Arduino. It works fine.
Here is the code I used for the BS2
' {$STAMP BS2}
' {$PBASIC 2.5}
'TrueBaud mode for non-inverted 9600-N81
'InvBaud mode for inverted, 9600-N81
#SELECT $STAMP
#CASE BS2, BS2E, BS2PE
TrueBaud CON 84
InvBaud CON 16468
#CASE BS2SX, BS2P
TrueBaud CON 240
InvBaud CON 16624
#CASE BS2PX
TrueBaud CON 396
InvBaud CON 16780
#ENDSELECT
Ard PIN 0
i VAR Byte
PAUSE 1000
FOR i = 65 TO 70
SEROUT Ard,TrueBaud,[i]
PAUSE 500
NEXT
END ' Finished.
Thank you all for your help! Ron C, your code worked for me. I did not use a 220 ohm resistor in my original tests, perhaps that was the problem.
To carry on the project I was wondering how to allow bidirectional communication. Set the NewSoftSerial to pin 3 for TX, use BS2 pin 1 for RX, or is there a better/alternative method for this?
Trying to use the Arduino pins 0 and 1 was your problem since they are connected to a UART.
The 220 ohm resistor is probably not neccessary - just a precaution.
Your bidirectional solution is correct - change the NewSoftSerial BS2(2, 255); to NewSoftSerial BS2(2, 3); , add the additional wire and modify the code to transmit the other direction.