|
Forum Index : Microcontroller and PC projects : HC-12
| Page 1 of 2 |
|||||
| Author | Message | ||||
| macca Newbie Joined: 21/02/2017 Location: AustraliaPosts: 32 |
Hi to all I have 2 HC-12 one as a slave and one as a master. My question is if it is possible how can I get the master to send a request to the slave to send data and for the master to receive that data. regards John |
||||
| panky Guru Joined: 02/10/2012 Location: AustraliaPosts: 1116 |
John, The HC-12 is essentially a serial com port to 433MHz wireless converter. They are used in pairs and set up such that whatever one of the units transmits, the other receives and visa versa. There is no 'MASTER' or 'SLAVE' as such but of course, you could operate like that within your program on the MM if you chose to do so. All transmission protocols such as Master/Slave, checksum etc. etc. are the responsibility of the program driving the HC-12. Do a search on the Backshed for HC-12 and you will see several examples of how they are used. panky. ... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it! |
||||
| macca Newbie Joined: 21/02/2017 Location: AustraliaPosts: 32 |
Thank you Panky I will have a look tonight Regards John |
||||
| panky Guru Joined: 02/10/2012 Location: AustraliaPosts: 1116 |
John, You might want to read Captainboing's excellent response to your original post about the HC-12 - he has given you all the info you need to get two HC-12'talking to one another. panky ... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it! |
||||
Grogster![]() Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9751 |
On one module, send data into ground and RXD(serial to send), and on the other, receive data out of ground and TXD(serial received). Both need to be powered by 5v. Both need to be setup for the same channel. Assuming that, data sent out of the transmitting end, will be received by the receiving end as if it was a wired serial link - as Panky says. If you have the receiving HC12 connect to a MM COM port that has been opened, then the MM will buffer any data received and all you need to do, is read the buffer. Smoke makes things work. When the smoke gets out, it stops! |
||||
| Andrew_G Guru Joined: 18/10/2016 Location: AustraliaPosts: 872 |
Hi John (and Panky and Grogster), Panky and Grogster are spot on. I've had a lot of stuffing around that you can easily avoid - they will work as a pair straight out of the box if: - they are from the same batch/supplier, preferably genuine ones (see Grogster's thread here - they are configured to the same frequency, speed and FU type (the default out of the box is fine - no need to alter it unless you need to and you know how to - eg use Rob.Rozee's config. program) - 5V (I stuffed around with 3.8 to 4.2V which the data sheet says is OK - those at 5V all do much better) - the supplied coil antennae are better than I gave them credit for (I have some 17cm external ones for critical legs - they are better, but try the coils first - the antennae line of sight should not be obscured by any material that a radio signal won't go through (air, glass,wood, bricks, thin Fe are OK but onboard batteries, PCBs, and Faraday cages may not be) - the two andtennae should be orientated the same way but I have found that they can work when not so - on a MM170 you can use either COM1 or 2 - just get the Tx and Rx pair the right way around (I had no problem if I initially got it wrong - just swapped them around) Good luck, Andrew |
||||
| plover Guru Joined: 18/04/2013 Location: AustraliaPosts: 306 |
For my own record, as I am hoping to get stuck into something like that in the future: Here is CaptainBoing and others previous contributions. http://www.thebackshed.com/forum/forum_posts.asp?TID=10026 |
||||
Grogster![]() Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9751 |
Clickable link for plover's post above.... [Quote=Andrew_G]I've had a lot of stuffing around that you can easily avoid - they will work as a pair straight out of the box if: - they are from the same batch/supplier, preferably genuine ones[/Quote] Indeed. I now sell the genuine ones from my website. These are guaranteed to be genuine, as I now buy them direct from the original manufacturer. [Quote=Andrew_G]- 5V (I stuffed around with 3.8 to 4.2V which the data sheet says is OK - those at 5V all do much better)[/Quote] Agreed. You CAN run the HC12 as a RECEIVE ONLY node on 3v3, but if you try to transmit on 3v3, this often overwhelms the on-board 3v2 regulator as you only have 100mV(0.1V) headroom to play with, and transmitting takes current, so the voltage drops - and if it drops by more then 0.1V, the HC12 will reset and the transmission is lost. They work flawlessly at 5v as Andrew mentions. [Quote=Andrew_G]- the supplied coil antennae are better than I gave them credit for (I have some 17cm external ones for critical legs - they are better, but try the coils first[/Quote] They are indeed. I have got about 2km of range THROUGH WALLS with the HC12's using the little helical on the transmitting node, and a roof antenna and amplifier on the receiving end. Truly amazing range for the size of the thing and helical transmitting antenna. [Quote=Andrew_G]- on a MM170 you can use either COM1 or 2 - just get the Tx and Rx pair the right way around (I had no problem if I initially got it wrong - just swapped them around)[/Quote] Even now, after more then 25 years working with RS232 and serial, I am STILL getting the bloody COM port connections wrong. Serial out with respect to.....which end was it again? Smoke makes things work. When the smoke gets out, it stops! |
||||
| macca Newbie Joined: 21/02/2017 Location: AustraliaPosts: 32 |
Hi again I have scanned the forum on HC-12 last night thanks Panky and now have it all working next question what is this error [190] If CtrlVal(tempa) < CtrlVal(lowtemp) Then Error: Incompatible types in expression Is there such a thing as error codes that I can look up.? Regards again John |
||||
Grogster![]() Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9751 |
No error-code list you can look up. I DID start to write an error glossary, but simply did not have the time, as there are lots and lots of different possible error messages. That specific error message you are getting, is because either tempa or lowtemp are NOT numbers. One might be, but the other one is not, so the interpreter throws that error. When you get that error, at the command-prompt, type the following commands and press ENTER: ? CTRLVAL(tempa):? CTRLVAL(lowtemp) This will show you what those GUI controls CURRENTLY are. From that, you should be able to work out which one is causing the issue, and then dig deeper to find out why. Smoke makes things work. When the smoke gets out, it stops! |
||||
| macca Newbie Joined: 21/02/2017 Location: AustraliaPosts: 32 |
A big thank you Grogster will try in a few minutes regards John |
||||
| macca Newbie Joined: 21/02/2017 Location: AustraliaPosts: 32 |
Hi I ran again and same error so typed in ctrlval etc etc and this is the results [190] If CtrlVal(tempa) < CtrlVal(lowtemp) Then Error: Incompatible types in expression > ? CTRLVAL(tempa):? CTRLVAL(lowtemp) 22.6 0 Both are numbers the Lowtemp is from a numberbox maybe this is where the problem is?? I will keep playing around regards John |
||||
Grogster![]() Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9751 |
That's interesting. Taking the GUI controls out of the mix for now, the interpreter is trying to If 22.6 < 0 Then, which to me, is perfectly legal. IE: The result should be false, because 22.6 is NOT less then zero. Watching this thread with interest. Smoke makes things work. When the smoke gets out, it stops! |
||||
| erbp Senior Member Joined: 03/05/2016 Location: AustraliaPosts: 195 |
Unfortunately printing the contents of these items doesn't identify the item data type (unless the contents happen to contain alpha or special characters in which case it would have to be String). In the above case CTRLVAL(tempa) could be a String or a Float while CTRLVAL(lowtemp) could be String, Float or Integer. I **think** the error is because there is a mismatch of data types between the two items being compared. Phil. |
||||
| Andrew_G Guru Joined: 18/10/2016 Location: AustraliaPosts: 872 |
Hi Phil, we haven't seen the code for the derivation of "tempa" and "lowtemp" but let's assume it is OK. How about you run the program but <CTL><C> when it should have values for each "tempa" and "lowtemp" (you could confirm by printing each as you have above). Then from the console enter "? VAL(tempa)" then "? VAL(lowtemp)" Then "? STR$(tempa)" then "? STR$(lowtemp)" This should show if they are string when we think they are not and vice versa. Another possibility is that a bug means it is treating "0" not as "0" ?? Cheers, Andrew |
||||
| Andrew_G Guru Joined: 18/10/2016 Location: AustraliaPosts: 872 |
John, if you refer to Geoff's post about the latest Beta release he may have fixed a relevant bug?? Cheers, Andrew |
||||
| macca Newbie Joined: 21/02/2017 Location: AustraliaPosts: 32 |
Hi Andrew_G and all involved especially Geoff Loaded latest release and all is working fine Regards John |
||||
| Andrew_G Guru Joined: 18/10/2016 Location: AustraliaPosts: 872 |
Hi John, glad it is all sorted. In case you hadn't noticed, Geoff (and a few others) is a marvel! Andrew |
||||
Grogster![]() Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9751 |
Wow. Awesome. So what version WERE you using? I assume you are now on 5.04.09? Smoke makes things work. When the smoke gets out, it stops! |
||||
| macca Newbie Joined: 21/02/2017 Location: AustraliaPosts: 32 |
Hi and yes Grogster 5.04.09 and a very big tank's to Geoff and all involved. This is the best forum by far that I have had any thing to do with. You guy's are awesome Regards John |
||||
| Page 1 of 2 |
|||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |