Help with HC-12 communications and Leonardo

I am hoping you can help me find a solution to a problem using the HC12 modules on Arduino Leonardo.

I am a bit new to Arduino but want to develop a project that requires 3 modules to transfer, relatively simple, commands over 30 - 70 metres. In brief the project is an SMS controlled bush fire response system. A central control module with a GSM shield and two slave controllers operating the pump and water valves. I have the central control module working , starting a Genset, monitoring power source etc. The plan was to communicate with the two slave control modules via a 433 MHz transmission. I was not able to get enough range with a simple transmitter so I thought about trying HC-12 modules.

I choose Leonardo as the base modules for a not very compelling reason.

I am having trouble getting the HC12 transceiver to talk to the Leonardo. The Leonardo uses a hardware serial on pins 0 and 1. Other parts of my project uses Pins 2, 4, 5, 6 and 7. I choose pins 8, 9 and 11 for Tx, Rx and Set, changing the sketch accordingly. I tried the sketch on a Uno and it all worked fine. But not on the two Leonardos. I could not see any response to a simple AT command or any communication between two Leonardos.

I suspect this is a configuration problem to do with the Leonardo and its hardware serial comms. Any help in me understanding this is appreciated.

I am using the code, that I downloaded from a Lyad tutorial, below as an initial try to communicate

#include <SoftwareSerial.h>
SoftwareSerial hc12(9, 8);
void setup() {
while (!Serial);
pinMode(11,OUTPUT);
digitalWrite(11,LOW); // enter AT command mode.  WP Pin 7 is used by Relay Shield move Set to Pin 11
Serial.begin(9600);
hc12.begin(9600);
hc12.print(F("AT+C001\r\n")); // set to channel 1
delay(100);
//digitalWrite(11,HIGH);// enter transparent mode
Serial.print("done setup move to Loop");
}
void loop() {
if(Serial.available()) hc12.write(Serial.read());
if(hc12.available()) Serial.write(hc12.read());
}

I am now perplexed.
Is my problem:
Too easy?
Too difficult?
Poorly described?
Is my only solution to scrap the project on Leonardo and switch to Uno?
Am I being impatient?

Thanks

Am I being impatient?

Yes.

My first question would be why are you using SoftwareSerial to read from the bluetooth device on a board with 2 hardware serial ports. Unlike the Uno, pins 0 and 1 are NOT connected to Serial on the Leonardo. They are connected to Serial1.

I'd connect the bluetooth thing to pins 0 and 1, use Serial1 to read from/write to it, and use Serial to debug the code/show what you read from/wrote to the Serial1 instance.

I accept your point about my impatience, apologies.

As I said I am a bit new to Arduino and 433 MHz communication.
In answer to your question about why I am not using the hardware serial port on pins 0 and 1. That is used to communicate with the 3G GSM shield. I thought, perhaps mistakenly, that trying to communicate with both the GSM shield and the HC-12 on the same port would not be possible.

Leaving that aside for the moment and to test on a basic configuration (no GSM shield), I made the following changes to the code. Changing Serial.begin to Serial1.begin

Is this the only change that I need to make?

#include <SoftwareSerial.h>
SoftwareSerial hc12(2, 1);
void setup() {
  while (!Serial);
  pinMode(11, OUTPUT);
  digitalWrite(11, LOW); // enter AT command mode.  WP Pin 7 is used by Relay Shield move Set to Pin 11
  Serial1.begin(9600);  // using hardware serial port
  hc12.begin(9600);
  hc12.print(F("AT+C001\r\n")); // set to channel 1
  delay(100);
  //digitalWrite(11,HIGH);// enter transparent mode
  Serial.print("done setup move to Loop");
}
void loop() {
  if (Serial.available()) hc12.write(Serial.read());
  if (hc12.available()) Serial.write(hc12.read());
}

You are still using 3 serial communication instances, to talk to two devices. Which instance goes with which device? Serial talks to the PC. Serial1 talks to? hc12 talks to?

FYI I did find a solution to this problem. It turned out to be hardware related. The Leonardo Board works fine with an HC-12 communication module run under a SoftwareSerial library. I have not received much help from the forum on diagnosing my problem but I thank you all, particularly PaulS. I think that I now understand more about the way serial communications work with Arduino boards. I still have some hurdles to jump on my project so I expect I will need more help in the future. This thread can be marked Solved.