# Help with basic HC12 communication using 2x HC12 + 2x Arduino Nano

#### djsfantasi

Joined Apr 11, 2010
8,081
hi dj,
The SET line has an internal pull up, so when the pin is o/c it is in the TX/RX mode, you have to pull and hold the SET pin Low to program the HC".
E
Yep! I see that in the datasheet now.

#### djsfantasi

Joined Apr 11, 2010
8,081
Incidentally, note that software serial 'RX' should connect to HC12 'TX', and vice versa.
And in regards to the pin connections is it mandatory for HC12 'RX' & 'TX' pins to be connected to the dedicated ones on the arduino for sending commands, ...

Is the software serial TX pin connected to the HC12 RX pin?

#### ericgibbs

Joined Jan 29, 2010
14,718
hi,
Ref this image.
On the Arduino, the TXDout goes to the RX pin.
E

#### KorrinF

Joined May 29, 2018
11
Hello, thanks for all the feedback I have taken it on board and rearranged a few things like the spring location. I also found a different bit of code to test the modules where I added a button on my controller and when pressed, it would light up an LED on my target. I did get that to work finally but it was inconsistent.

So I took everything into the robotics lab at the uni and spoke to one of the lecturers, they have an oscilloscope that helped in diagnosing the problem and it appears it was a power issue, in that the recommended diode and capacitor listed in the document specification, actually inhibited the HC12 unit from working because the capacitor drew to much power away from the arduino. So in removing both those elements I now have consistent result sending and receiving between the controller and targets. And it appears the power drain whilst sending is very very minuscule which was also really good news, as the targets are battery powered.

So thats all really good, one thing I have still been unsuccessful with is sending AT commands. I put the set pin to ground according to the specifications, and I thought this was the most straight forward method. But I havnt returned any results yet. I have tried swapping the RX and TX pins from the virtual ones on the arduino to the dedicated ones with the same issue. Not sure whats going on there, still some investigation to do. Luckily the standard settings on the HC12 will do for my project, although I would like to reduce the power a bit as you have recommended because I am only working in a close proximity but I will have to save that for another day and just work with what I have now. Thanks for the help.

#### ericgibbs

Joined Jan 29, 2010
14,718
hi K,
If you post your Arduino code as an attachment, I can test your code and maybe add the AT commands.

I have a UNO +TFT+HC12 running on test on my PC at this time.
E

#### KorrinF

Joined May 29, 2018
11
hi K,
If you post your Arduino code as an attachment, I can test your code and maybe add the AT commands.

I have a UNO +TFT+HC12 running on test on my PC at this time.
E
That would be great thank you, I tried to upload the arduino IDE documents as an attachment but it wouldn't allow it so ive had to copy in the code for ya...

AT_Commander: So the first code is the one everyone is using and apparently works with one arduino but it looks more like it sends the AT command to the another device to me. For this one the SET pin is connected to ground.

Code:
//HC-12 AT Commander
//Autor Tom Heylen tomtomheylen.com
//The HC-12 commander mode runs at baud rate 9600

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // TX,RX

void setup() {
Serial.begin(9600);
Serial.println("Enter AT commands:");
mySerial.begin(9600);

}

void loop(){
if (mySerial.available()){
}
if (Serial.available()){
}
}
AT_Commander_2: For this one I tried sending AT commands in the code to be displayed on the serial monitor and pulling the SET pin low as well.

Code:
#include <SoftwareSerial.h>
const byte RX = 11;
const byte TX = 10;
const byte SET = 8;
SoftwareSerial HC12 (TX,RX); //create software serial port
void setup() {
// put your setup code here, to run once:
// pinMode(RX,INPUT);
// pinMode(TX,OUTPUT);
pinMode(SET, OUTPUT);                  // Output High for Transparent / Low for Command
Serial.begin(9600); //open serial port to computer
HC12.begin(9600);// open serial port to HC-12
Serial.println("Hello World - Software Serial");
}
void loop() {
digitalWrite(SET, LOW);           // Set HC-12 into AT Command mode
delay(100);                          // Wait for the HC-12 to enter AT Command mode
HC12.print("AT+RX");               // Send AT Command to HC-12
delay(200);
while (HC12.available()) {           // If HC-12 has data (the AT Command response)
Serial.write(HC12.read());         // Send the data to Serial monitor
}

}

#### ericgibbs

Joined Jan 29, 2010
14,718
hi K,
Downloaded those two files, will post back later on how they go.
E

#### KorrinF

Joined May 29, 2018
11
hi K,
Downloaded those two files, will post back later on how they go.
E
Awesome thanks!

#### ericgibbs

Joined Jan 29, 2010
14,718
hi K,
That delay at line#19 on the second code listing is active while the HC12 is sending back the Status Data, delete the delay or move it after line #22.
E
BTW: Why are you creating a software serial port rather than using the hardware TX/RX.?
Also if you change the file extension from *.ino to *.txt you can upload the files as an attachment

#### Attachments

• 8.3 KB Views: 4

#### djsfantasi

Joined Apr 11, 2010
8,081
BTW: Why are you creating a software serial port rather than using the hardware TX/RX.?
Because he is using two serial ports and may only have one hardware TX/RX? The hardware serial port is already used for debugging and reading/writing from/to the HC12. And the hardware serial port is already tied to the console.

#### ericgibbs

Joined Jan 29, 2010
14,718
hi dj,
I am aware that the H/W & S/W serial I/O's are used for debugging etc, but I am asking the TS why he has chosen to do it this way.
E