readadc pin, variable
select variable
case < a: do this
case < b: do that
case < c: do the other (a<b<c)
...
endselect
DIP Switches come in multi-switch packages. I have 2, 4 and 8 switch sets. The DIP stands for Dual Inline Package. Each switch uses one pin/contact in each row of the Dual Inline connections.I strayed away from the dip switch because I don't have any experience with them and have no idea how they work or how to write the program to use one. Would the switch you are talking about have three pins/switches and you would use a combination of switches to set the "channel" you are on? Meaning switches that say 1,2,3 and possible combinations of 100, 010, 001, 110, 101, 001. Which would give you the 6 different "channels?"
' Transmitter code
if pinC.2 = 0 and pinC.4 = 0 and pinC.1 = 0 then
let b4 = 1
endif
if pinC.2 = 0 and pinC.4 = 0 and pinC.1 = 1 then
let b4 = 2
endif
if pinC.2 = 0 and pinC.4 = 1 and pinC.1 = 0 then
let b4 = 3
endif
if pinC.2 = 1 and pinC.4 = 0 and pinC.1 = 0 then
let b4 = 4
endif
if pinC.2 = 0 and pinC.4 = 1 and pinC.1 = 1 then
let b4 = 5
endif
if pinC.2 = 1 and pinC.4 = 1 and pinC.1 = 0 then
let b4 = 6
endif
if pinC.2 = 1 and pinC.4 = 0 and pinC.1 = 1 then
let b4 = 7
endif
if pinC.2 = 1 and pinC.4 = 1 and pinC.1 = 1 then
let b4 = 8
endif
main:
if pinC.3 = 1 then
SEROUT 0,N4800,("UUUUUUUUUUUUUUUUUUUUUUUUU")
pause 50
SEROUT 0,N4800,("ABC", b3)
pause 150
end if
goto main
' Receiver code
if pinC.2 = 0 and pinC.4 = 0 and pinC.1 = 0 then
let b4 = 1
endif
if pinC.2 = 0 and pinC.4 = 0 and pinC.1 = 1 then
let b4 = 2
endif
if pinC.2 = 0 and pinC.4 = 1 and pinC.1 = 0 then
let b4 = 3
endif
if pinC.2 = 1 and pinC.4 = 0 and pinC.1 = 0 then
let b4 = 4
endif
if pinC.2 = 0 and pinC.4 = 1 and pinC.1 = 1 then
let b4 = 5
endif
if pinC.2 = 1 and pinC.4 = 1 and pinC.1 = 0 then
let b4 = 6
endif
if pinC.2 = 1 and pinC.4 = 0 and pinC.1 = 1 then
let b4 = 7
endif
if pinC.2 = 1 and pinC.4 = 1 and pinC.1 = 1 then
let b4 = 8
endif
main:
SERIN 3,N4800,("ABC"), b1
if b1 = b4 then
let b2 = 0
do
high C.0
pause 100
low C.0
pause 100
inc b2
loop while b2 < 20
end if
pause 1000
goto main
' Transmitter code
;First read all pins and reorgansie so pinC.1 is in variable bit0, pinC.2 is in bit1 and pinC4 is in bit2
Init:
LET b0 = pins /2
LET bit2 = bit 3 ; now the status of all three switches are in bits 0, 1 and 2
b0 = b0 AND $07 ; keep only bits 2,1,0 and clear the others
; now you have a value from 0 to 7 - you can increment this by 1 (INC b0) if you want 1 to 8 as the values.
main:
if pinC.3 = 1 then
SEROUT 0,N4800,("UUUUUUUUUUUUUUUUUUUUUUUUU")
pause 15
SEROUT 0,N4800,("ABC", b0)
pause 150
end if
goto main
I have just started to read up on PICAxe and it's use, I have have only just come across this thread. "Please ignore, if I'm mistaken""I am going to be putting a tilt switch on the TX" <snip> " "I am using the DIP switches on both sides to figure out which "channel" to operate on by taking the inputs from the switch"
If a person wanted to add a second or third XTMR, would it be reasonable to assume that the SEROUT command might be DEF or ABC1, ABC2 etc. with a corresponding test for each on the SERIN command for the RCVR?You could use RFIN and RFOUT except that's not supported by the 08M2, though you could use the NKM2401 to achieve the same.
If you add a preamble the code will look something like in the http://www.picaxe.com/Circuit-Creator/Miscellaneous/RF-Radio-Transmitter example, like -
Code:do if pinC.3 = 1 then SEROUT 2,N4800,("UUUUUUUUUUUUUUUUUUUUUUUUU") Pause 2 SEROUT 2,N4800,("ABC", 1) end if loop
Thanks for the reply.Coding a multiple point communications system is not a simple task. I think you're planning to use wireless links, which will add to the complexity. You don't indicate whether your primary communication is one-to-many or many-to-one.
The simpler arrangement is one-to-many, where a single master controller 'speaks' to one slave at a time and expects a reply. The reply is required to confirm that the slave has received the instruction, even if it may not have to respond with data. The code in the master must cater for the situation where, for any reason, the response is not received. Eg the comms are corrupted and not recognised or the slave is powered down. You don't want the whole system to lock up if just one slave is not responding.
More difficult is the many-to-one or, worse, many-to-many. What happens if two controllers 'speak' at once? You need a fancy routine to ensure that the system can recover and operate correctly as soon as possible.
The way I read into your idea, your master will have a series of different SerIn commands, each with its own hard-coded qualifier string. What will happen if the master is executing the SerIn command that is searching for "ABC1" when an "ABC2" data packet arrives? It gets ignored.If a person wanted to add a second or third XTMR, would it be reasonable to assume that the SEROUT command might be DEF or ABC1, ABC2 etc. with a corresponding test for each on the SERIN command for the RCVR?
As long as only one XTMR is functioning at the same time, it should be possible to identify which transmitter sent the info, right?
Thanks
Doug
Ah, but you could search for "ABC" and then examine the next character for "1" or "2" etc.What will happen if the master is executing the SerIn command that is searching for "ABC1" when an "ABC2" data packet arrives? It gets ignored.
Would resetting the receiver after each event be practical?>I had hoped that this could be done with a time out on SERIN and careful timing of the polling.
Timeout on serin is not useful with raw wireless, since ambient noise on the frequency will abort the timeout, even tho a qualifier is not matched within the timeout period.
I understand that the PICAXE startup/initialization is on the order do 50ms or less. I'd a transmitter is sending out its conditioning/qualifying string, wouldn't the newly reset receiver (and the associated PICAXE) "sync" with the transmitter that was active? Afterward, once the transmitter ID was receiver, the receiver could be powered down and restarted, ready for the next transmitter.>Would resetting the receiver after each event be practical?
>The XTMRs won't be turned on until they are activated individually.
I'm not certain what you mean. In any case, I wouldn't feel confident that serin timout would work with raw 315/433mhz receivers in any circumstances unless Rev-ed modifies the firmware so that the timeout occurs when a qualifier is not found within the timeout period (rather than as now, when anything which is identified as a character apparently resets the timeout clock).
Can you explain, in simple terms how the 2401 will sort out the noise problems that seem inherent with this solution? I understand that the PIC does Manchester Encoding/decoding and the second PICAXE seems to be able to ?reset? the 2401 independently, is that correct?>Does RFin / RFout accomplish the same thing
RFin is blocking. If that doesn't matter to you, then yes, that will work.
>It seems like the NKM2401 serves the role of the "two PIC" work around.
Yes.
>Is there a way of successfully using a dumb 433mHz ASK transmitter/super regen receiver in this role? (One receiver, several transmitters, each transmitting individually ).
Yes, with the NKM2401--provided you can tolerate collisions--without it if you can tolerate blocking (and collisions). Or you can put tx/rx with the NKM2401 on both ends and code so as to provide a wireless kind of round-robin, with your receiver/master querying each transmitter/client and either receiving an answer or timing out before proceeding to the next client.