Wireless Question

Wombat_In_Space

New Member
I am hoping there is an easy answer to this question I am building a 14m&433Mhz remote hand pad which I want to switch a second 2 Picaxe 28x chips outputs high or low. I am use to using serout & in with the data logger to the LCD.

I have read through Hippies wireless page and search through the forum I am more looking for a confirmation of the exact code.

I can get the code Hippy wrote to work and output to a LCD on the 28X now I want to start controlling the pins.

Thanx in advance
 

moxhamj

New Member
Which bit do you need - the wireless code or the LCD code? If you already have the LCD working as you say then you are well on the way. The wireless part is quite easy - see http://picaxe.orcon.net.nz/433rpt.jpg for a repeater circuit but you can leave the middle repeater circuit out and just build a transmitter and receiver. The code is only a few lines.

Build it in stages on a protoboard - eg get the wireless working as one project, then the LCD then put it together.
 

Wombat_In_Space

New Member
I can get the wireless sending text for the LCD writing thats no prob Hippies code does that no probs. I am have trouble working out how to make it switch pins hi and low on the receiving chip.

Eg; press button on hand pad which is to switch output 0 high
 

steliosm

Senior Member
Well, you need to define a protocol for doing that.
What you have now, is passing the raw data received to the LCD module. You need to use a simple way to identify the 'message' type.
What I would do, would be to also send another byte in the beginning along with the text which will indicate what I want the receiver to do. On the receiver you can check the value of that specific byte and act accordingly.
 

Wombat_In_Space

New Member
Trying to find 11 bytes

Here is the code for the transmitting picaxe I have worked out the receiver side now I have a problem with the TX I need to find 11 bytes :-( so the code will fit on a 14M chip. here is the code. I am not very good at optimizing code I normally go to a bigger chip.

Thank you for any help in finding these 11 bytes.
 

Attachments

Last edited:

BCJKiwi

Senior Member
You could try this for starters;

Code:
'*******************************************************
'****      Wireless Hand Pad TX For Telescope       ****
'****  Control System Ver 1.0a       ****
'****  Written By Darren Quinert      ****
'****  © DP & TL Computers 2000-2008      ****
'****      Parts of this code was obtained     ****
'****    from         ****
'**** [URL]http://www.hippy.freeserve.co.uk/picaxewf.htm[/URL] ****
'****            ****
'*******************************************************
'*******************************************************
'****    Picaxe 14M and 433 Wireless        ****
'****    Module         ****
'*******************************************************
'
'*******************************************************
'*******************************************************
#PICAXE 14M
setfreq m8

SYMBOL  RECEIVER_CODE   = 1 ' 0 .. 15
SYMBOL  SENDER_CODE     = 1 ' 0 .. 15
SYMBOL  TX_PIN          = 0
SYMBOL  TX_BAUD         = 2400
SYMBOL  TX_LED  = 1

SYMBOL  POWER_ON_PIN    = 2
SYMBOL  POWER_UP_DELAY  = 20
SYMBOL  POWER_UP_LED = 3
SYMBOL  SIDERIAL_RUN = 4
SYMBOL  PREAMBLE_LENGTH = 5
SYMBOL  MAX_DATA_LENGTH = 4
SYMBOL  PREAMBLE_BYTE   = $AA
SYMBOL  SOM_BYTE        = $C5
SYMBOL  EOM_BYTE        = $5C
SYMBOL  POSTAMBLE_BYTE  = $3A
SYMBOL  dataLength      = b0
SYMBOL  byteNumber      = b1
SYMBOL  bytePtr         = b2
SYMBOL  byteo           = b3
SYMBOL  bit             = b4
SYMBOL  k               = b5
SYMBOL  crc             = b6
SYMBOL  POLYNOMIAL      = $8C
'********************************************
'********************************************
Powerup:
 let dirsc=%00000001
 PAUSE 5000
Main:
 let pins =%00000
 
 if pin1=1 then let b7="1" : goto createpacket :endif 'CreatePacket1
 if pin2=1 then let b7="2" : goto createpacket :endif 'CreatePacket2
 if pin3=1 then let b7="3" : goto createpacket :endif 'CreatePacket3
'***************************************
'****   Checks 3 Position Switch ****
'***************************************

Checksw:
        if portc pin1=1 then let b7="4" : goto createpacket :endif 'CreatePacket4
        if pin0=0 then Decroutine 
        if pin0=1 then Focus 
       if pin1=0 then let b7="0" : goto createpacket :endif 'CreatePacket0
     
     GOTO Main
 
'***************************************
'****   Checks 2 Position Switch ****
'***************************************
Decroutine:
   
   if pin4=1 then let b7="5" : goto createpacket :endif 'CreatePacket5
        if portc pin2=1 then let b7="6" : goto createpacket :endif 'CreatePacket6
        if pin4=0 then Main
        
Focus:
        
        if pin4=1 then let b7="7" : goto createpacket :endif 'CreatePacket7
        if portc pin2=1 then let b7="8" : goto createpacket :endif 'CreatePacket8
        if pin4=0 then Main
 
'**************************************
'***** Create Control State Packet ****
'**************************************
CreatePacket:
        dataLength = 1
        POKE $50,b7
        GOTO Send
#rem
CreatePacket0:
        dataLength = 1
        POKE $50,"0"
        GOTO Send
        
CreatePacket1:
        dataLength = 1
        POKE $50,"1"
        GOTO Send
CreatePacket2:
        dataLength = 1
        POKE $50,"2"
        GOTO Send
        
CreatePacket3:
        dataLength = 1
        POKE $50,"3"
        GOTO Send
        
CreatePacket4:
        dataLength = 1
        POKE $50,"4"
        GOTO Send
        
CreatePacket5:
        dataLength = 1
        POKE $50,"5"
        GOTO Send
        
CreatePacket6:
        dataLength = 1
        POKE $50,"6"
        GOTO Send
        
CreatePacket7:
        dataLength = 1
        POKE $50,"7"
        GOTO Send
        
CreatePacket8:
        dataLength = 1
        POKE $50,"8"
        GOTO Send
#endrem        
'***************************
'**** Send Data Packet *****
'***************************
    
Send:
        ' On entry, 'dataLength' contains the number of bytes
        ' of data to send. The bytes of data are stored in SFR
        ' RAM from location $50 upwards.
CalculateCrc:
        crc = 0
        byteo = SENDER_CODE * $10 | RECEIVER_CODE
        bytePtr = $50
        FOR byteNumber = 1 TO dataLength
          PEEK bytePtr,byteo
          bytePtr = bytePtr+1
          GOSUB CrcAdd
        NEXT
PowerUpTransmitter:
        HIGH POWER_ON_PIN
   HIGH POWER_UP_LED
      
        PAUSE POWER_UP_DELAY
SendPreamble:
   TOGGLE TX_LED
   
        FOR byteNumber = 1 TO PREAMBLE_LENGTH
          SEROUT TX_PIN,TX_BAUD,(PREAMBLE_BYTE)
        NEXT

SendStartOfMessage:
   SEROUT TX_PIN,TX_BAUD,(SOM_BYTE)
   
SendReceiverAndSenderCode:
   byteo = SENDER_CODE * $10 | RECEIVER_CODE
        SEROUT TX_PIN,TX_BAUD,(byteo,datalength)
   
'SendDataLength:
'   
'   SEROUT TX_PIN,TX_BAUD,(dataLength)
   
SendData:
   TOGGLE TX_LED
   bytePtr = $50
   FOR byteNumber = 1 TO dataLength
          PEEK bytePtr,byteo
          bytePtr = bytePtr+1
         
          SEROUT TX_PIN,TX_BAUD,(byteo)
        NEXT
        
SendChecksum:
   
        SEROUT TX_PIN,TX_BAUD,(crc,EOM_BYTE)
   
   
'SendEndOfMessage:
'   
 '       SEROUT TX_PIN,TX_BAUD,(EOM_BYTE)
   
   
SendPostamble:
   TOGGLE TX_LED
        FOR byteNumber = 1 TO MAX_DATA_LENGTH
          SEROUT TX_PIN,TX_BAUD,(POSTAMBLE_BYTE)
        NEXT
   GOTO Main
CrcAdd:
       
      FOR bit = 0 TO 7
       k = byteo ^ crc & 1
       IF k = 0 THEN CrcAdd1
       k = POLYNOMIAL
      CrcAdd1:
       crc = crc / 2 ^ k
       byteo = byteo / 2
      NEXT
 RETURN
Added the #PICAXE 14M and moved the setfreq to the top.
Added a next in one of your lower for .. next loops

Since only the $50 memory location was used for all 8 conditional tests, presumably only one is active per pass so replaced all the gosubs/subroutines with direct writes to $50.
At a quick glance this would appear to be logically the same.

Code now 248 bytes.
 
Last edited:

Wombat_In_Space

New Member
BCJKiwi thank you for the edited version I had to make some small changes to it to get the correct reaction from the switches. The changes you made showed me a different way of doing things.

Code:
'*********************************************************
'****      Wireless Hand Pad TX For Telescope        ****
'****      Control System Ver 1.0a                 ****
'****      Written By Darren Quinert              ****
'****      © DP & TL Computers 2000-2008             ****
'****      Parts of this code was obtained        ****
'****                from                    ****
'**** http://www.hippy.freeserve.co.uk/picaxewf.htm    ****
'****                                   ****
'*********************************************************
'*********************************************************
'****    Picaxe 14M and 433 Wireless            ****
'****            Module                        ****
'*********************************************************
'
#PICAXE 14M
setfreq m8
 
SYMBOL  RECEIVER_CODE   = 1 ' 0 .. 15
SYMBOL  SENDER_CODE     = 1 ' 0 .. 15
SYMBOL  TX_PIN          = 0
SYMBOL  TX_BAUD         = 2400
SYMBOL  TX_LED  = 1
 
SYMBOL  POWER_ON_PIN    = 2
SYMBOL  POWER_UP_DELAY  = 20
SYMBOL  POWER_UP_LED = 3
SYMBOL  SIDERIAL_RUN = 4
SYMBOL  PREAMBLE_LENGTH = 5
SYMBOL  MAX_DATA_LENGTH = 4
SYMBOL  PREAMBLE_BYTE   = $AA
SYMBOL  SOM_BYTE        = $C5
SYMBOL  EOM_BYTE        = $5C
SYMBOL  POSTAMBLE_BYTE  = $3A
SYMBOL  dataLength      = b0
SYMBOL  byteNumber      = b1
SYMBOL  bytePtr         = b2
SYMBOL  byteo           = b3
SYMBOL  bit             = b4
SYMBOL  k               = b5
SYMBOL  crc             = b6
SYMBOL  POLYNOMIAL      = $8C
'********************************************
'********************************************
Powerup:
 let dirsc=%00000001
 PAUSE 5000

Main:
 let pins =%00000
 
     if pins=%01000010 or pins=%01000011 then Emergency

     if pins=%01000000 then poke $50,"4" :endif     'CreatePacket4
     if portc pin1=0 then poke $50,"0" :endif     'CreatePacket0
     if pin1=1 then poke $50,"1" :endif         'CreatePacket1
     if pin2=1 then poke $50,"2" :endif         'CreatePacket2
     if pin3=1 then poke $50,"3" :endif         'CreatePacket3

'***************************************
'****   Checks 2 Position Switch ****
'***************************************
 
Checksw:
        
      if pin0=1 then Focus 
 
    if pins=%00000000 then Main
 

Decroutine:
 
       if pin4=1 then poke $50,"5" :endif             'CreatePacket5
    if portc pin2=1 then poke $50,"6" :endif         'CreatePacket6
    if portc pin2=1 or pin4=1 then datalenght_chk
Focus:
 
        if pin4=1 then poke $50,"7" :endif         'CreatePacket7
        if portc pin2=1 then poke $50,"8" :endif     'CreatePacket8
     
      if pins=%00000000 then Main
 
'**************************************
'***** Create Control State Packet ****
'**************************************
 datalenght_chk: 
       dataLength = 1
        GOTO Send


Emergency:
        dataLength = 1
        POKE $50,"0"
'        GOTO Send
  
'***************************
'**** Send Data Packet *****
'***************************
 
Send:
        ' On entry, 'dataLength' contains the number of bytes
        ' of data to send. The bytes of data are stored in SFR
        ' RAM from location $50 upwards.
CalculateCrc:
        crc = 0
        byteo = SENDER_CODE * $10 | RECEIVER_CODE
        bytePtr = $50
        FOR byteNumber = 1 TO dataLength
          PEEK bytePtr,byteo
          bytePtr = bytePtr+1
          GOSUB CrcAdd
        NEXT
PowerUpTransmitter:
        HIGH POWER_ON_PIN
   HIGH POWER_UP_LED
 
        PAUSE POWER_UP_DELAY
SendPreamble:
   TOGGLE TX_LED
 
        FOR byteNumber = 1 TO PREAMBLE_LENGTH
          SEROUT TX_PIN,TX_BAUD,(PREAMBLE_BYTE)
        NEXT
 
SendStartOfMessage:
   SEROUT TX_PIN,TX_BAUD,(SOM_BYTE)
 
SendReceiverAndSenderCode:
   byteo = SENDER_CODE * $10 | RECEIVER_CODE
        SEROUT TX_PIN,TX_BAUD,(byteo)
 
SendDataLength:
 
   SEROUT TX_PIN,TX_BAUD,(dataLength)
 
SendData:
   TOGGLE TX_LED
   bytePtr = $50
   FOR byteNumber = 1 TO dataLength
          PEEK bytePtr,byteo
          bytePtr = bytePtr+1
 
          SEROUT TX_PIN,TX_BAUD,(byteo)
        NEXT   '#############################
 
SendChecksum:
 
        SEROUT TX_PIN,TX_BAUD,(crc)
 
 
SendEndOfMessage:
 
        SEROUT TX_PIN,TX_BAUD,(EOM_BYTE)
 
 
SendPostamble:
   TOGGLE TX_LED
        FOR byteNumber = 1 TO MAX_DATA_LENGTH
          SEROUT TX_PIN,TX_BAUD,(POSTAMBLE_BYTE)
        NEXT
   GOTO Main
CrcAdd:
 
      FOR bit = 0 TO 7
       k = byteo ^ crc & 1
       IF k = 0 THEN CrcAdd1
       k = POLYNOMIAL
      CrcAdd1:
       crc = crc / 2 ^ k
       byteo = byteo / 2
      NEXT
 RETURN
This is now fully operational code yet to be hardware tested though.

The receiver checks the code in $50 depending on what it is it then switches on the outputs. (this part of the project is still being developed) once I finish it I will post it in the forum.
 
Last edited:

BCJKiwi

Senior Member
I had changed the logic initially without the 'goto createpacket' but considered this fundamentally changed the logic.
I don't know what the possible mix of conditions on the pins might be or if there is a hierarchy of importance, but the new code is fundamentally different from the original as all the tests will occur regardless and all store to the same location thus overwriting each other. Previously the code branched from the tests to the action immediately a pin test was satisfied.

Is there a particular reason for not sending two bytes in the serouts where possible?
 

Wombat_In_Space

New Member
No reason, this is the fist one I have written for a picaxe to send a data string to turn on an output on another, normally all I use serout for is LCD's.
 
Last edited:

BCJKiwi

Senior Member
It is just that bytes can be saved and performance improved if you send more bytes in one session. e.g. these two changes;
Code:
'SendStartOfMessage:
 '  SEROUT TX_PIN,TX_BAUD,(SOM_BYTE)
 
SendReceiverAndSenderCode:
   byteo = SENDER_CODE * $10 | RECEIVER_CODE
        SEROUT TX_PIN,TX_BAUD,([B][I]SOM_BYTE[/I][/B],byteo,[B][I]dataLength[/I][/B])
 
'SendDataLength:
 
'   SEROUT TX_PIN,TX_BAUD,(dataLength)
and

Code:
SendChecksum:
 
        SEROUT TX_PIN,TX_BAUD,(crc,[B][I]EOM_BYTE[/I][/B])
 
 
'SendEndOfMessage:
 
 '       SEROUT TX_PIN,TX_BAUD,(EOM_BYTE)
save 9 bytes and should reduce processing time.
 

Wombat_In_Space

New Member
Thank you again since the start of this tread you have taught me new ways to code and have found my 11 bytes I was over and gained me 14 so total of 25 bytes found. (Dancing smiley)
 
Top