My first Basic Stamp project (SERIN and Code Questions)
Hello, I am trying to create communication between a BS1 (Transmitter) and BS2 (Receiver) to do three simple functions: turn LED 1 on/off, turn LED 2 on/off, or turn both LEDs off from whatever state they are in.
To do this, I have 3 buttons attached to the transmitter to put a voltage across pins 1,2, or 3 on the BS1.
I'm currently using a TWS-434a and RWS-434 to transmit and receive. Unfortunately, I haven't had any success, and I am not sure if it is my wiring, or my code. I have not received any syntax errors, but I wonder if the following code would be good to perform the functions I have in mind? Thanks for your time and suggestions.
Transmitter:
Receiver:
To do this, I have 3 buttons attached to the transmitter to put a voltage across pins 1,2, or 3 on the BS1.
I'm currently using a TWS-434a and RWS-434 to transmit and receive. Unfortunately, I haven't had any success, and I am not sure if it is my wiring, or my code. I have not received any syntax errors, but I wonder if the following code would be good to perform the functions I have in mind? Thanks for your time and suggestions.
Transmitter:
' {$STAMP BS1} SYMBOL slowdown = B3 SYMBOL code = W4 'The code determines the receiver operation' SYMBOL synch = W5 'The synch is like the starting key' SYMBOL junk = B6 'Junk gets the receiver running' LET junk = 123 LET synch = 63158 DIRS = %00000001 LET code = 000 Start: PAUSE 30 slowdown = 1 IF PIN1 = 1 THEN Operation1 'Depending on which button is depressed' IF PIN2 = 1 THEN Operation2 'A different code is sent' IF PIN3 = 1 THEN Operation3 IF PINS = %00000000 THEN Pauser IF slowdown = 1 THEN Start IF code <> 000 THEN Transmit IF slowdown = 0 THEN CodeReset PAUSE 70 GOTO Start Operation1: LET code = 11013 RETURN Operation2: LET code = 21013 RETURN Operation3: LET code = 31013 RETURN Pauser: LET slowdown = 0 RETURN CodeReset: LET code = 000 RETURN Transmit: SEROUT 0,N2400,(junk,synch,code) 'This sends the junk, followed by the synch' RETURN 'and code'
Receiver:
' {$STAMP BS2} synch CON 63158 'This tells the receiver what to expect' BAUD CON 16780 code VAR Word DIRH=%11111111 Start: SERIN 0,BAUD,[noparse][[/noparse]WAIT(synch),code] IF code=11013 THEN Light1 'Depending on code values' IF code=21013 THEN Light2 'One of three operations will run' IF code=31013 THEN Light3 GOTO Start Light1: TOGGLE 14 'Turns the 1st set of lights on or off' RETURN Light2: TOGGLE 15 'Turns the 2nd set of lights on or off' RETURN Light3: LOW 14 'Turns all lights off' LOW 15 RETURN
Comments
You could also skip the use of "<next label>" and just do:
My questions still relate to SERIN/SEROUT Syntax, as well as actual circuit connections. I'm using a couple of 433 MHz transceivers presently.
For one, I assume I should use pull down resistors for on the TX-RX pins?
Furthermore, should I use pull down resistors on my data output/input pins?
When using SEROUT with a BS1 module, if I want to just store a number into a word variable, like 11013 in my first post, should I place a '#' before the variable name? (As seen in the code to follow)
To go along with that, when using SERIN, should I place DEC before the variable name on the BS2 Module?
Here are some pieces of code, so far I haven't gotten a response from the receiver, even when directly connecting the receiver and transmitter data pins.
BS1 Transmitter Excerpt:
BS2 Receiver Excerpt