Hello all,
I am measuring the current to my HC-12 module and it is steady at 14-15 mA whether in sleep mode or not. I do get an "OK+SLEEP" response from the module so I believe it is receiving the command ok. I am sure it is something really simple but I can't quite spot it. Any help would be greatly appreciated. I can see a drop in current for a split second when I send the sleep command so I think it may be waking up immediately for some reason. Here is stripped-down version of my code:
#include <SoftwareSerial.h>
#define HC12_SET 5
#define HC12_TX 10
#define HC12_RX 11
SoftwareSerial HC12(HC12_TX, HC12_RX);
void HC12_Sleep()
{
digitalWrite(HC12_SET, LOW); // Enter command mode
delay(100); // Allow chip time to enter command mode
HC12.print("AT+SLEEP"); // Send command
delay(200); // Wait for a response
digitalWrite(HC12_SET, HIGH); // Exit command / enter transparent mode
}
void HC12_Wake()
{
digitalWrite(HC12_SET, LOW); // Enter command mode
delay(100); // Allow chip time to enter command mode
digitalWrite(HC12_SET, HIGH); // Exit command mode
delay(100); // Delay before proceeding
}
void setup()
{
pinMode(HC12_SET,OUTPUT);
HC12.begin(9600);
HC12_Sleep();
HC12.end();
}
void loop()
{
HC12.begin(9600);
HC12_Sleep();
HC12.end();
delay(5000);
return;
}
Hey guys,
Thanks for your replies. I tried both very sketches and neither work. When I call sleep, the current drops to 0.05 mA for a split second, then goes right back to 15 mA. Very frustrating. Same result with three different modules. And when I check the return from AT+SLEEP I get the proper response so I know things are communicating.
I have a new HC-12 on order. Maybe I got a bad batch...but you know you are desperate when you are swapping hardware.
By "add a line feed" - I am guessing you meant to the SLEEP string as in "AT+SLEEP\n". That had no effect.
Removing the loop() return had no effect but that makes sense as the return in a void function in C is optional\implied.
I am really stumped. I will see if I can send AT commands directly from the serial monitor and see what that does.