Arduino to BasicStamp 2 Single Wire Serial Communication
simlc
Posts: 8
I am trying to use an Arduino to send 0,1,or 2 to my Stamp 2. I have the Arduino pin 1 (TX) going to the Stamp pin 2 (SIN) via a 220 ohm resistor. I have the Stamp pin 1 (SOUT) going to my laptop's COM1 pin 2 (RX) in an attempt to see what the Arduino is sending the Stamp. Here is the Stamp's code:
And here is the Arduino code:
On my laptop I have a serial monitor running that is looking at COM1. What I hoped to see was some version of 0,1, and 2 (hex, decimal, binary, ASCII, something!)
What I consistently saw, in decimal, was 6, 103, 51. Not even close to 48, 49, 50.
Anyone have any ideas as to what I am doing wrong? The only thing I can think of is the level translation circuitry on the Stamp. The Arduino is sending out 0-5v (space = 0v). Supposedly, the BAUDMODE should be able to handle that.
I have spent 2 days tweaking various things and haven't figured it out.
Any thoughts would be appreciated!
Thanks.
' ($STAMP BS2) ' (PBASIC 2.5) Image VAR Byte Setup: Image = 0 Main: SERIN 16, 396, 20 Face_Image, [Image] SEROUT 16, 416, [Image] 'I read somewhere that you needed to add 20ms to the BAUDMODE number. Didn't make any difference in what I saw in my serial monitor. GOTO Main END
And here is the Arduino code:
void setup() { Serial.begin(2400, SERIAL_8N1) } void loop() { Serial.print("0"); delay(1000); Serial.print("1"); delay(1000); Serial.print("2"); delay(1000); }
On my laptop I have a serial monitor running that is looking at COM1. What I hoped to see was some version of 0,1, and 2 (hex, decimal, binary, ASCII, something!)
What I consistently saw, in decimal, was 6, 103, 51. Not even close to 48, 49, 50.
Anyone have any ideas as to what I am doing wrong? The only thing I can think of is the level translation circuitry on the Stamp. The Arduino is sending out 0-5v (space = 0v). Supposedly, the BAUDMODE should be able to handle that.
I have spent 2 days tweaking various things and haven't figured it out.
Any thoughts would be appreciated!
Thanks.
Comments
Start first by getting the Arduino to talk to the laptop. I think the Arduino pin 1 is at ttl levels and not what the Stamp pin 16 or laptop are expecting. If you can confirm that, then you can set the Stamp to use another pin at ttl levels. You can also see if the Stamp can talk to the laptop by setting the Stamp in a loop to print out a known string, say "test". The Stamp Helpfile in the IDE has several sample programs. Look under SERIN or SEROUT.
Now connect the Arduino to the Stamp pin (no, you don't have to add 20mS to the baud number)
I am concerned about connecting the Arduino directly to the laptop. As you pointed out, the Arduino is using TTL levels, while the laptop serial port will be using normal RS232 levels, +/- 12 volts. I do not want to fry my Arduino. I am using all the other pins on the Stamp to drive an 8x8 LED matrix, so I have no extra pins to play with, outside the SERIN and SEROUT pins.
For testing, you won't damage the Arduino if you connect it to the laptop through some 1K resistors. But, the Arduino will have to be set to an "inverted" baudmode to talk to the laptop's "real" rs-232 logic. I know Stamps can set the general pins to true or inverted mode but I am unsure about the Arduino.
If you're scarce on Stamp pins and must use the pin 16 serial on the Stamp , you can run the Arduino ttl serial through a rs-232 interface chip MAX233 or ST232 to shift the levels to what the laptop expects.
You're very close now!
A MAX232 is unnecessary.
If you are using the BoE/HWB D-Sub connector (pin 3) then all you need is a simple transistor-based inverter (invert the Arduino output.)
If you need a sketch of that then Reply ("PJ, how about a sketch of that circuit?")
If you SERIN using 0-15 then a "direct connection" is fine (add a 2K for "mistakes".)
Either way, use a True BAUDMODE.
I have verified all of this, using:
To make things clear(er) --
The module on the left is the Arduino and that on the right is the Stamp.
I used 1Ks because they were right there at the time. The transistor is a "you pick it" NPN.
Not sure how to mark this as resolved. The original problem has been resolved. Frying my Stamp wasn't part of that problem.
Lynn
PJA
[If you go back to your original post and press the Edit button you can then change Un/Resolved etc.]
I went back to my original post, edited it, but could not see anyway there to change the status to Resolved.
Thanks for your responses!!
Lynn
Sorry we can't get your situation squared away.
Otherwise, look for the little gadget labelled "Prefix", just north of "Title". There's a dropdown with 3 options: (none), Solved, and Unresolved.
[I think it's there either way, but you may have to bop that "Go Advanced" button.]
Edit Post then Go Advanced gets you access to the Prefix dropdown.
And, it's PJ.
Found the "solved" prefix. Thanks for all your help and patience.
Lynn