# Upload program/sketch to wireless through HC-12 for Arduino

#### kannannatesh

Joined Feb 11, 2019
5
Dear Friends,

now i am working with HC-12 for long distance data transmission. here i am facing some OTA problem for Upload the new program/sketch for my MC/arduino.

My project Concept:
i have a multi nodes for collecting temperature at different location. one master is collecting temperature data from all nodes and upload the data to server this main only connected with internet others are connected with only HC12. I set all nodes channels are different for avoid the data collision.

The above concept is working fine, but if i upload the new sketch like OTA is possible to master only other nodes can't because nodes don't have a internet connection. so i decide to upload the sketch via HC12 but HC-12 don't have a DTR pin for reset the node for set Boot loader for upload a sketch/ program.

thank you

with regards
kannannatesh

#### kannannatesh

Joined Feb 11, 2019
5
@Mark Hughes

Last edited by a moderator:

#### Mark Hughes

Joined Jun 14, 2016
409
Dear AAC,
i am trying to get multi receiver data with single receiver. so i set different channels for slave. the master automatically change the channel when client sent “complete” acknowledgment .
Here i face some issue, my concept is the master send request to slave for data transmission after that request received the client transmit the data to master. but issue is the request doesn’t shown to slave buffer but if i send two or more requests that is shown in slave buffer. what is the problem here.

thank you
Hey ya' @kannannatesh ! Welcome to the AAC Forums. It's much easier to have a back and forth conversation here -- and it has the added bonus of being viewed by dozens (and sometimes hundreds) of other users.

So -- let's define the problem: You've got everything running, but the secondary transceiver only responds to the second data transmission, correct? (I'll post your code from pastebin below.)

Here's what I'd like to do first if you have an oscilloscope. I'd like to verify where the data link is broken. So you'll tap the UART_TX line on the primary HC12 transceiver and the UART_RX line on the secondary HC12 transceiver.

If the data goes out of the transmitter, and never arrives at the receiver -- it might be stuck in a buffer (not a problem I've ever encountered, but something I've heard other users report). If the data goes out of the transmitter and into the receiver -- the problem is your code.

@ericgibbs, @Raymond Genovese -- any thoughts on this problem?

Code:
#include <SoftwareSerial.h>
#define setPin 9
SoftwareSerial HC12(10, 11); // HC-12 TX Pin, HC-12 RX Pin
byte incomingByte;
String StrAT;
char data[1024];
int chl=0;
bool req=true;
void setup()
{
Serial.begin(9600);
HC12.begin(9600);
pinMode(setPin, OUTPUT);
digitalWrite(setPin, HIGH);
Serial.println("HC-12 TEST");
}
void loop()
{
while (HC12.available())
{
}
delay(100);
while (Serial.available())
{
}
if(req)
{
for(int i=0; i<=1;i++)
{
}
req=false;
}
check();
}
void check()
{
{
chl+=5;
Serial.print("chl:");
Serial.println(chl);
if(chl>=15)
{
//Serial.println("First");
digitalWrite(setPin, LOW);
delay(100);
HC12.print("AT+C001");
delay(200);
while (HC12.available())
{
}
digitalWrite(setPin, HIGH);
chl=0;
req=true;
}
else
{
if(chl<10)
{
StrAT = "AT+C00";
}
else
{
StrAT = "AT+C0";
}
//Serial.println("Second");
digitalWrite(setPin, LOW);
delay(100);
String StrDos = StrAT + chl;
HC12.print(StrDos);
delay(200);
while (HC12.available())
{
}
digitalWrite(setPin, HIGH);
req=true;
}
}
{
Serial.println(data);
}
}

#### kannannatesh

Joined Feb 11, 2019
5
@Mark Hughes,
I will Re Check my code and check my module transmission lines with my oscilloscope, and i have a another problem that is described in above, If you have any idea about upload arduino sketch through HC-12, please let me know.

the HC-12 have a Si4463 Transceiver IC that is have a NIRQ pin opposite working from DTR.
DTR is get LOW when data is arrived but NIRQ pin get HIGH at data is arrived.
So i am going to switch the pin using 547 NPN transistor that is attached in attachment column.

#### Attachments

• 6 KB Views: 10

#### Mark Hughes

Joined Jun 14, 2016
409
@kannannatesh,
Oh -- I'm sorry kannannatesh -- I must have confused your problem statement with something else from the front-page of the site. So you want to use the HC12 to program the Arduino? Hmm. Let's see.
The first problem is one of voltage -- what is the programming voltage requirement of your IC? The HC12 cannot generate voltages higher than Vcc without additional circuitry. Arduino is based on the ATMega328 -- and I don't play around with the ATMega328 much -- but I believe it requires 12V on the reset line and some minor timing requirements on the Reset and Vcc line, as well as other pins set to zero. If that's the case -- you're going to have to add an additional microcontroller to the mix to control the programming conditions.
Can you tell me the IC that you are using and I'll look into it a bit for you?

@Robin Mitchell Have you ever done an OTA update of an ATMega or similar?

#### kannannatesh

Joined Feb 11, 2019
5
@Mark Hughes,
i was done upload the sketch through CP2102, that is have DTR(5V) PIN so i used that pin for reset the arduino. that is worked in wire so i desired to use this method for upload the sketch through wireless.
NOW i am trying to upload the sketch via HC12 to arduino UNO(Atmega 328)
some times(when i reset the arduino manually) the sketch was Successfully upload through HC-12. some time i missed the reset time so that is shown upload failed.
the HC-12 have Si4463/4 Transceiver IC that have NIRQ pin for indicates the bytes are received(NIRQ=HIGH) or not(NIRQ=LOW), so i desired to act the pin like a DTR pin. BUT it is opposite to DTR pin working so i add one inverting circuit with NPN transistor invert the NIRQ pin output.
that is working but the sketch is not upload to the arduino UNO.
The Arduino Compiler tries 10 attempt to upload the sketch and also 10 times my arduino is get reset but never enter the sketch upload mode.
Arduino UNO baudrate is 115200 for Upload the sketch so i set my HC12 baudrate is 115200.
i get this idea from this link he is use HC-05 for upload the sketch to Arduino modules

i am not a fluent in English i made some grammatical mistakes here, but i hope you understand my problems, If you have any idea about this concept please let me know,
thank you

with regards
kannannatesh

#### Mark Hughes

Joined Jun 14, 2016
409
@ericgibbs @Raymond Genovese
Can you chime in here? I get the impression that kannannatesh is on the right track -- and it's a very interesting problem. But I'm not seeing the solution. Is it a timing issue? Is it one that could be solved by putting a RC circuit between the NIRQ and inverting transistor? Or is there an open source arduino programmer that @kannannatesh can get a hold of and create custom timings.

@kannannatesh can you use an oscilloscope to intercept the signals and see what the actual times are so we know if we are in spec, too slow, too fast, etc...? If the NIRQ-Transistor is switching too slowly, it'll be a bit harder to fix than if the NIRQ-Transistor is switching too quickly.

Here's where I'd start -- go to the known working condition and use a scope to record the timings. Maybe show us a picture of the scope screen. Then go to the HC12 implementation and record the timings -- I suspect that is where the problem lies. Once we know whether or not it is in specification, we can further proceed.

Thanks for being patient with me!
Mark

#### kannannatesh

Joined Feb 11, 2019
5
@Dear Mark,
i shows some CRO output here
Test 1:
this image shows reset pin condition at when i upload the sketch through Arduino Cable.

Test2:
this image shows reset pin status at upload the sketch through TTL(CP2102) device.
and i add one 10uf/50V capacitor in DTR pin(Capacitor positive) to reset pin(Capacitor negative) to serious Connection.
that works fine. i was search the topic in google (upload the sketch through serial) the lot of peoples said add .1uf capacitor in DTR pin but my bad luck that is not worked so i add 10uf after that works fine.
My CRO CH1(Red line) probe connected to Reser pin and GND
CH2 probe(Yellow line) connected to DTR pin and GND

Test 3:
This image shows my HC12 ic Si4463 NIRQ pin status at upload the sketch through HC12.
Connection:
Transmitter Side:
TTL HC12
5V 5V
GND GND
TX RX
RX TX

HC12 Arduino UNO
5V 5V
GND GND
TX RX
RX TX
NIRQ- Connect to CRO

I hope this shows my exact status, if you have any idea or suggestion to solve this problem please let me know

thank you

with regards
kannannatesh

#### Attachments

• 167.6 KB Views: 8
• 148.3 KB Views: 7
• 156 KB Views: 7

#### Mark Hughes

Joined Jun 14, 2016
409
@kannannatesh ,
Based on the graphics you sent me, I believe you had your scope set to AC coupling. I wonder if you might not be able to reset the experiment, but set your scope to DC coupling instead. My current thought is that there might be some signal integrity issues.