I am starting a program to manage HC-12s. Read the current configuration, or reconfigure as necessary.
It compiles, it tells me it is talking to the HC-12, and nothing comes back. It could be my code, my setup, or my HC-12s. If anyone has a spare HC-12 and a spare minute could you tell me if this works?
//based on code from: Tom Heylen
#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 3
#define stPin 7
SoftwareSerial HC12(rxPin, txPin);
long baud = 9600;
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
pinMode(stPin, OUTPUT);
Serial.begin(baud);
Serial.println(); Serial.println();
while (!Serial) // wait for serial port to connect. Needed for native USB port only
{
;
}
digitalWrite(stPin, HIGH);
Serial.println("HC-12 Test & configure");
HC12.begin(9600);
Serial.println("HC-12 started");
if (HC12.isListening())
{
Serial.println("HC-12 is Listening ");
}
else
{
Serial.println("NOK");
}
{
if (!HC12.available())
Serial.println("HC-12 is not responding");
//while(1);
}
//test HC-12
digitalWrite(stPin, LOW);
delay(100);
Serial.println("Sending AT+RX");
HC12.print("AT+RX"); // Send different commands to see which method works
Serial.println("command sent");
Serial.println("setup end"); Serial.println();
delay(500);
digitalWrite(stPin, HIGH);
}
void loop()
{
if (HC12.available())
{
Serial.print("HC12.available()");
}
while (HC12.available()) // If HC-12 has data
{
Serial.write(HC12.read()); // Send the data to Serial monitor
}
digitalWrite(stPin, LOW);
while (Serial.available()) // If Serial monitor has data
{
HC12.write(Serial.read()); // Send that data to HC-12
}
digitalWrite(stPin, LOW);
}