Hello Gents, I'm trying to get transmission back and forth to two hc12's and they are not transmitting, according to my SDR system. I know they are both good and on the same channel, (I've even swapped them out with other known good ones), both have power, both are wired correctly, both are connected to the nano according to the code. According to the site that produced this code, they should communicate between each serial monitor. Admittedly I am no code guru, (thus I am posting here), so I'm asking for your help. What is the code missing, anything? I would like to think that it being posted to their site and not getting any comment responses that the code doesn't work, it should be ok- but I'm having a problem somewhere. I've checked and double checked but can't see any problem with wiring.
Thank You!
type or paste code here
/*Arduino Long Range Wireless Communication using HC-12
Example 01
by Dejan Nedelkovski, www.HowToMechatronics.com
*/
void setup() {
Serial.begin(9600); // Serial port to computer
HC12.begin(9600); // Serial port to HC12
}
void loop() {
while (HC12.available()) { // If HC-12 has data
Serial.write(HC12.read()); // Send the data to Serial monitor
}
while (Serial.available()) { // If Serial monitor has data
HC12.write(Serial.read()); // Send that data to HC-12
}
}
"The same code is used for both Arduinos. We can connect the two Arduinos on two separate computers but also we can use a single computer".
Also... I see you tried to paste your code in a < CODE > block, but missed by a little...
/*
Arduino Long Range Wireless Communication using HC - 12
Example 01
by Dejan Nedelkovski, www.HowToMechatronics.com
*/
#include <SoftwareSerial.h>
SoftwareSerial HC12(10, 11); // HC-12 TX Pin, HC-12 RX Pin
void setup() {
Serial.begin(9600); // Serial port to computer
HC12.begin(9600); // Serial port to HC12
}
void loop() {
while (HC12.available()) { // If HC-12 has data
Serial.write(HC12.read()); // Send the data to Serial monitor
}
while (Serial.available()) { // If Serial monitor has data
HC12.write(Serial.read()); // Send that data to HC-12
}
}
Hello! Yes the pins are connected properly, I looked them over a few times.
I might have missed as you say, first time I ever did this, but all the code is essentially there. Thanks for your help!
Yes they have antennas, the coils, for now. The units are extremely close but I can fix that easy enough, although I've had success with other hc12 circuits being that close with no interference or desense, but I'll try it.
They are being powered with two different computers through the usb ports.
Excellent Paul! This helped me get it working!
One thing though, (always something), the web site suggested opening another instance of the IDE which I did, but, when I tried to load the code onto the second IDE it defaulted to the one that was already open! When I tried to open the serial monitor in the second IDE it also defaulted to the open one.
I ended up using two computers to prove out the setup, which worked.
Any thoughts about this?
To answer 'bluejets'- SDR = software defined radio. If you still want to see my setup I can do that, but since it's working now, should I?
Now onto the rest of the project, which is, remote monitoring of a battery voltage and displayed on an lcd. I have already done this with just an lcd reading it locally, but now with the hc12's, I'm not sure of the code. Any thoughts about this too?
the web site suggested opening another instance of the IDE
With 1.8.19 it should be possible to have two instances of the ide running with monitor screens open. Did you open the second instance by clicking on the application icon, or just using File>New from an open instance?
I think it was a combination of things, starting with the code. I had better luck with the new code from the suggested site. I also think I had a failure prone nano as one died.
After reading your question about 'instances', I had to check what I did. I opened a new instance by going to 'file' and stating a new one. This is where I failed. Going to the desktop shortcut icon and starting a new instance that way was successful! Lesson learned!
Again, Thank you all!
Now to deal with the voltage part of the project. Cheers!