Ga-Retired
New Member
Thanks Neil,I'll give it a try and see what the results are.
Jeff
Jeff
This is my code :-AT+SLEEP
After receiving this command, the module will enter sleep mode upon exiting from command mode, with a working current of about 22uA. This mode doesn’t allow serial port data transmission. Upon entering command mode again the module will exit from sleep mode automatically.
Sleep_HC12:
low HC12_set ;take set pin low
Pause FortymS ;wait 40mS
Serout TX_Pin,HC12BaudRate,("AT+SLEEP") ;night,night ;-)
high HC12_set ;take set pin high, which actions the command
Pause EightymS ;wait 80mS for any changes to take effect
return
#picaxe 08M2
#Terminal 38400
#No_data
;
; HC-12 458MHz FSK RF module connections
;
Symbol TX_pin = C.2 ;output to HC-12
Symbol RX_pin = C.1 ;input from HC-12
Symbol HC12_SET = C.4 ;"SET" pin, when low, places module into command mode - no data flow possible
;
; Assorted parameters
;
symbol FortymS = 40 * 8
symbol EightymS = 80 * 8
symbol OneSecond = 1000 * 8
symbol FiveSeconds = 5000 * 8
;
Symbol HC12BaudRate = T9600_32 ;HC-12 Baud rate
;
; START PROGRAM.
;
setfreq M32 ;for 9600 baud
;
; Set o/p ports.
;
dirsc = %00010101 ;C.0,C.2 + C.4 are outputs.
'
' Set transmit line idle state correctly, rather than waiting for an initial Serout to do it.
'
High TX_Pin ;set the line high.
Pause 16000 ;wait for serial terminal
sertxd(cr,lf,"START")
gosub Wake_HC12
Pause FiveSeconds ;5 secs...
low HC12_set ;take set pin low
Pause FortymS ;wait 40mS
sertxd(cr,lf,"AT+V") ;debug HC-12_V2.3
Serout TX_Pin,HC12BaudRate,("AT+V")
pause OneSecond
sertxd(cr,lf,"AT+DEFAULT") ;debug
Serout TX_Pin,HC12BaudRate,("AT+DEFAULT")
pause OneSecond
sertxd(cr,lf,"AT+SLEEP") ;debug
Serout TX_Pin,HC12BaudRate,("AT+SLEEP") ;night,night ;-)
high HC12_set ;take set pin high, which actions the command
Pause EightymS ;wait 80mS for any changes to take effect, before entering pass-thru
end
Wake_HC12:
low HC12_set ;take set pin low
Pause FortymS ;wait 40mS
high HC12_set ;take set pin high
Pause EightymS ;wait 80mS for for any changes to take effect, before entering pass-thru
return
The initial current was 15.3 mA, dropping to 1.6 mA when the AT+SLEEP was executed.HC-12_V2.3
OK+DEFAULT
OK+SLEEP
input TX_Pin ;set pins connected to HC-12
input RX_Pin ;back to being inputs.
input HC12_set ;** this causes the current drain to slightly INCREASE! **
Serout TX_Pin,HC12BaudRate,("AT+SLEEP") ;night,night ;-)
pause FortymS ;THIS IS ESSENTIAL
high HC12_set ;take set pin high, which actions the command
Pause EightymS ;wait 80mS for any changes to take effect.
Hserout 'of some description, detail unimportant'
Serin [2000,Timeout], RX_Pin, HC12Baudrate, ("REPLY "),#Sensor1,#Sensor2,#Sensor3,#Sensor4,#Sensor5,#Sensor6 ; Get responses
low HC12_set ;take set pin low
Pause FortymS ;wait 40mS
HSerout 0,("AT+SLEEP") ;night,night ;-)
Pause FortymS ;ABSOLUTELY ESSENTIAL PAUSE - else sleep mode is 1.6mA, instead of 20uA
high HC12_set ;take set pin high, which actions the command
Pause EightymS ;wait 80mS for any changes to take effect.
It turns out the microcontroller on the HC-12 is slower than the Picaxe @ 32MHz, so this code to put the HC-12 to sleep, checks the result of the "AT+SLEEP" and retries 'till it works :-In an ideal world, I'd simply check for either an "ERROR" or "OK+SLEEP" response, but it's probably not going to be particularly easy to do on a Picaxe.
_Disable_HC12:
;
; Clear out storage used to received response.
;
bptr = ByteArray ;address of our storage
for b0 = 0 to 7
@bptrinc = 0 ;clear 8 bytes
next b0
;
; Put HC-12 into command mode
;
low HC12_set ;take set pin low
Pause FortymS ;wait 40mS
bptr= ByteArray
;
; Send the Sleep command...
;
Serout tx_pin,hc12baudrate,("AT+SLEEP")
;
; and gather up the response. Should only be "OK+SLEEP" or "ERROR"
;
Serin [2000,noAnswer],RX_Pin,HC12Baudrate,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc ; 8 bytes.
noAnswer:
;
; debug - print the response
;
bptr = ByteArray
sertxd(cr,lf,"R:",@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc)
;
; Ensure response is "OK+SLEEP".
;
bptr = ByteArray
For b0 = 0 To 7
lookup b0,("OK+SLEEP"),b1 ;string to compare with
b2 = @bptrinc ;get Input byte
If b2 <> b1 Then Goto _Disable_HC12 ;mismatch
Next b0
;
; Response from HC-12 looks good,
; so take "SET" high to initiate power saving
;
Pause FortymS ;ABSOLUTELY ESSENTIAL PAUSE - else sleep mode is 1.6mA, instead of 20uA
high HC12_set ;take set pin high, which actions the command
Pause EightymS ;wait 80mS for any changes to take effect.
return
My HC-12s arrived yesterday, a bit over three weeks from the date I ordered (6th June). That's pretty average for deliveries from China, but they can be very variable. My first order of HC-12s from Satisfy Electronics arrived after just 8 days, so much faster than we usually get stuff from there. I have an order outstanding from another Chinese seller since 1st June, and waiting 5 or 6 weeks is not that unusual.Jeremy & Phil - re your ordering issues. China & NZ have a very beneficial free trade agreement that greatly speeds delivery. However even my deliveries from Rev.Ed are usually EXTREMELY rapid. I recall making a large online order once late on a Sunday (= Saturday UK) which arrived here Friday (NZ) morning.
Stan.
I think you're right - I've just received a parcel that was ordered from a Chinese eBayer ... but came by air from Singapore. It had Hong Kong Postal Service stickers on it, so I think it might have been on a ship as well, since it took 2 weeks in total.I'm sure that most of the delay is in the postal service, the puzzling thing is the wide variability, why some small packets should arrive in just over a week yet others take well over a month is a mystery.
;set up 433MHz transceiver port and data format
symbol Rx_data = B.3 ;received data (Tx pin on HC-12 module)
symbol Tx_data = B.2 ;data to be transmitted (Rx pin on HC-12 module)
symbol baud = T9600_4 ;set baud rate for Tx and Rx
serout Tx_data, baud, ("data")
serin Rx_data, baud, byte1, byte2, byte3, byte4
.........
low HC12_set ;take set pin low
Pause FortymS ;wait 40mS
sertxd(cr,lf,"AT+V") ;debug HC-12_V2.3
Serout TX_Pin,HC12BaudRate,([b]"AT+V"[/b])
pause OneSecond
,,,,,,,,,
In Post #54, I postulated that 100mW on Channel 64 (458.6MHz) was legal in the UK. Given the absence of any significant evidence to the contrary, that's what I've gone with.Don't forget the 100mW (20dBm) default TX power of HC-12 modules exceeds the 10-25 mW legal limit...
In Canada it may not even be 10mW?.
An update to my post from a while ago.1 - Running off 3 Duracell AA's, started off at 4.74v
2 - Running off a 2600maH 18650 LiPo, started off at 4.14v
3 - Running off a 1430maH new & unused iPhone 4s LiPo, started off at 4.14v
1 & 2 have been running for 12 days now.
1 is down to 4.12v from 4.74v.
2 is down to 3.89v from 4.14v.
3 has only been running for a day (following timing changes with code, reduced the post TX delay to 100ms from 250ms on 1 & 2).
No 1 is in the garage, approx 30m away through 2 brick walls.
No 2 is close to 100m away in a neighbours garden.
No 3 is in the house, probably only about 10m away.
I believe the main appeal of the ERF to us was that it could be used for over the air PICAXE programming in conjunction with a URF or SRF, and that also provided a means for easy inter-PICAXE and PICAXE to PC comms.It's some months now since Jeremy started this "alternative to the ERF" HC-11/12 topic. In light of largely positive postings (& Hippy's recent involvement), perhaps Rev.Ed may care to comment on the HC-12's PICAXE potential.
#Picaxe 08M2
;Remote control code for chicken coop door open and close unit, using HC-12 transceiver modules,
;The code uses 13 byte random alphanumeric codes for the "ready for command" signal, acknowledgements and commands
;Tested and works at range of up to ~100m, through walls etc
;NOTE: 4 second serin timeouts are mandatory because of the low data rate
;HC-12 transceivers are programmed to run on channel 1 (433.6MHz), 1200 baud, +8dBm, FU4 mode, 8 bit, no parity, 1 stop bit
;Switch is a DPCO, centre off, rocker switch, with one pole used for power switching and the other used for the control line
;Operating method is for the remote control transmitter to send a unique identification code, 13 bytes long, to the receiver as
;a "get ready to receive a command" signal
;The receiver responds by sending an acknowledgement transmission of 13 bytes to the remote control
;The remote control then transmits a 13byte command to open or close the door
;The receiver control unit acknowledges reception of this command, activates the appropriate relay for 10 seconds to allow the
;door motor time to open or close the door and sends a 13 bit acknowledgement back to the remote control that the relay has been activated
;On receipt of the "relay activated" acknowledgment signal the remote control turns on a red LED as confirmation to the user
symbol RFTxdata = c.4
symbol RFRxdata = c.3
symbol LED = c.0
initialise:
pullup %00000110 ;Set pullup on ports C.1 and C.2
main:
;Door close command
if pinc.1 = 0 then
;transmit encoded signal ("DpRntcWq7L9S1") from remote control to receiver unit to get ready to receive a command
serout RFTxdata, T1200_4, ("DpRntcWq7L9S1")
;receive encoded acknowledgment from receiver that it is ready to accept a command
serin [4000, main], RFRxdata, T1200_4, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12
;expected encoded signal from receiver is "5Vo3sXiQ8j4aU"
if b0 = "5" and b1 = "V" and b2 = "o" and b3 = "3" and b4 = "s" and b5 = "X" and b6 = "i" and b7 = "Q" and b8 = "8" and b9 = "j" and b10 = "4" and b11 = "a" and b12 = "U" then
pause 600 ;this 600ms pause seems to be needed to get unit to work reliably - something to do with the HC-12 timing?
;encoded transmission from remote control to close the door is "0CfIem2qPDz4j"
serout RFTxdata, T1200_4, ("0CfIem2qPDz4j")
;expected encoded return from receiver is "3GwMufp07Cza2" acknowledging that command has been correctly received
serin [4000, main], RFRxdata, T1200_4, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12
if b0 = "3" and b1 = "G" and b2 = "w" and b3 = "M" and b4 = "u" and b5 = "f" and b6 = "p" and b7 = "0" and b8 = "7" and b9 = "C" and b10 = "z" and b11 = "a" and b12 = "2" then
high LED ;LED signals to user that the command has been acted upon and is confirmation that the door is closing
;LED stays on until switch is released powering off the unit but receiver relay will remain activated for 10 seconds
endif
endif
endif
;Door open command
if pinc.2 = 0 then
serout RFTxdata, T1200_4, ("DpRntcWq7L9S1")
serin [4000, main], RFRxdata, T1200_4, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12
if b0 = "5" and b1 = "V" and b2 = "o" and b3 = "3" and b4 = "s" and b5 = "X" and b6 = "i" and b7 = "Q" and b8 = "8" and b9 = "j" and b10 = "4" and b11 = "a" and b12 = "U" then
pause 600
;encoded transmission from remote control to open the door is "8FDX5kW8mOax5"
serout RFTxdata, T1200_4, ("8FDX5kW8mOax5")
serin [4000, main], RFRxdata, T1200_4, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12
if b0 = "3" and b1 = "G" and b2 = "w" and b3 = "M" and b4 = "u" and b5 = "f" and b6 = "p" and b7 = "0" and b8 = "7" and b9 = "C" and b10 = "z" and b11 = "a" and b12 = "2" then
high LED
endif
endif
endif
END
#Picaxe 08M2
;RF receiver for chicken coop door remote control, using HC-12 transceiver modules,
;The code uses 13 byte semi-random alphanumeric codes for the "ready for command" signal, acknowledgements and commands
;just to give a modicum of security and resistance to false operation, but these are transmitted as plain text so can be intercepted
;and read, if anyone wished to, so this is not good security for use with something like a lock. In this application the
;main reason for using 13 bytes of gobbledegook text is to reduce the risk of false operation
;Tested and works at ranges of up to ~100m with "rubber duck" antennas at both ends
;NOTE: 4 second serin timeouts are needed because of the low data rate
;whole sequence takes around 4 seconds before confirmation signal is received by remote
;HC-12 transceivers are programmed to run on channel 1 (433.6MHz), 1200 baud, +8dBm, FU4 mode, 8 bit, no parity, 1 stop bit
;Operating method is for the remote control transmitter to send a unique identification code, 13 bytes long, to the receiver as
;a "get ready to receive a command" signal
;The receiver responds by sending an acknowledgement transmission of 13 bytes to the remote control
;The remote control then transmits a 13byte command to open or close the door
;The receiver control unit acknowledges reception of this command, activates the appropriate relay for 10 seconds to allow the
;door motor time to open or close the door and sends a 13 bit acknowledgement back to the remote control that the relay has been activated
;On receipt of the "relay activated" acknowledgment signal the remote control turns on a red LED as confirmation to the user
;Receiver uses a double 5V relay module, with built in relay driver opto isolator drivers. The relay drive signals are active LOW
symbol open_door = c.4
symbol close_door = c.2
symbol RFTxdata = c.1
symbol RFRxdata = c.3
initialise:
;set both relay outputs high at power on, to avoid accidentally oepning or closing the door
HIGH open_door
HIGH close_door
main:
;receive 13 bytes from remote control, time out after 4 seconds and loop back
serin [4000, main], RFRxdata, T1200_4, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12
;expected encoded signal from remote unit to signal that fixed unit should await a command is "DpRntcWq7L9S1"
if b0 = "D" and b1 = "p" and b2 = "R" and b3 = "n" and b4 = "t" and b5 = "c" and b6 = "W" and b7 = "q" and b8 = "7" and b9 = "L" and b10 = "9" and b11 = "S" and b12 = "1" then
;transmitted encoded "ready for command" signal to remote unit is "5Vo3sXiQ8j4aU"
serout RFTxdata, T1200_4, ("5Vo3sXiQ8j4aU")
;await encoded command signal from remote unit
serin [4000, main], RFRxdata, T1200_4, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12
;expected encoded signal from remote unit for door close command is "0CfIem2qPDz4j"
if b0 = "0" and b1 = "C" and b2 = "f" and b3 = "I" and b4 = "e" and b5 = "m" and b6 = "2" and b7 = "q" and b8 = "P" and b9 = "D" and b10 = "z" and b11 = "4" and b12 = "j" then
LOW close_door
serout RFTxdata, T1200_4, ("3GwMufp07Cza2") ;command being actioned acknowledgement to remote unit, "3GwMufp07Cza2"
pause 10000
HIGH close_door
endif
;expected encoded signal from remote unit for door open command is "8FDX5kW8mOax5"
if b0 = "8" and b1 = "F" and b2 = "D" and b3 = "X" and b4 = "5" and b5 = "k" and b6 = "W" and b7 = "8" and b8 = "m" and b9 = "O" and b10 = "a" and b11 = "x" and b12 = "5" then
LOW open_door
serout RFTxdata, T1200_4, ("3GwMufp07Cza2") ;command being actioned acknowledgement to remote unit, "3GwMufp07Cza2"
pause 10000
HIGH open_door
endif
endif
goto main
END
I'm still not clear, from reading this thread, whether you can use Robert Rozee's software to configure an HC-12 pair (one of which is connected via USB) to allow wireless programming of a Picaxe chip. Hence, it would be an alternative to the discontinued ERF/URF pair.It would be pretty easy to supply HC-12s pre-set to operate at 8dBm, in much the same way as Rev Ed supplied ERFs are preset to support the break command. Having said that, it's so easy to programme them using the very neat utility that Robert Rozee has written and kindly made available to all, that there's really need to supply them pre-programmed at all.