@MarkHughes
Hello, I am new to arduinos and HC12 and just programming in general. Iv got a project that I am working on and the HC12 module was recommended to me by my local robotics club at the university who advised me on wiring as well. To start with I just wanted to test them using Mark Hughes, first sample script on his HC12 article and unfortunately they are not behaving accordingly.
FUTURE PROJECT SUMMARY: (bit of back story for the future of the project, not entirely relevant for this thread)
These wireless modules are actually a late edition to the project, something that was always intended to be incorporated into the programming but only after the initial programming was finished and the other electronics were working correctly. Ill give you a brief description of the project but it is not super relevant to this thread as all I want for this thread is the get that basic script to work. So my project is a game involving 'Targets', in total there is 10 physical targets all the same that include various electronics on a PCB, controlled by an arduino nano each (china version) and each with a HC12 module. The programming for these Targets, stage one is complete ie, all the electronics behave correctly and are a functional game I am now looking to expand the functionality by using the HC12 modules. This was always the intention so the PCB's were designed and made with space to add the HC12 modules later. These Targets will not be communicating with themselves instead I want them to communicate to a 'Controller' the controller is currently on a breadboard equipped with an Arduino Nano, HC12 module and a few buttons (to be ignored for now). The idea is a target gets 'hit' and wirelessly sends a signal to the controller (maybe it sends an 'a'). The controller receives the 'a' and sends that to a laptop to which it is connected to via USB. Thats the aim for the future but for now like I said I am simply trying to get the sample code to work from the article.
MAIN POINTS:
'Target' : 10 available, I am using one for this experiment. Its a PCB with an arduino Nano and HC12 already soldered to it.
'Controller': 1 available, relevant components on a breadboard include arduino nano and HC12 connected with jumper cables.
Both arduinos have been tested with my other program and all the electronics are working apart from the HC12 using the code below.
The HC12’s are wired to the following arduino pins:
VCC= 5v arduino pin (in series with the specified capacitor and diode)
GND = GND
RX = d11
TX = d10
SET = d8
Here is the code that has been uploaded to both arduino's, the pins have been changed to match my selection. Whats supposed to happen is when I type and send something in one serial monitor it should be received and displayed in the other serial monitor:
To test this code I set the 'target' and 'controller' up on 2 separate computers with the arduino IDE installed and serial monitor open. The computers were also a few meters apart to rule out disturbances.
POWER: This may turn out to be the issue, hopefully not as the robotics club recommended usb power as sufficient. In my main project, the 'Targets' are powered via the usb port on the arduinos and a power bank supplying 5v, but there are also other components draining power including 20 programmable LEDs (always on) and a piezo buzzer. The 'Controller' will also be powered by the usb port and then connected to a laptop, there are no other components that drain power. But whilst testing the above code obviously both the target and controller are plugged into a laptop for communication and power.
PHOTOS:
'Target' heres the back of the PCB showing the relevant connections and the last photo showing the front soldered arduino pins.
'Controller' sorry about the angle, the buttons are not relevant for this test.
Hopefully we can figure something out I am at a loss and completely new to wireless communications but am keen to learn. If we can get these working with the above code then its not to far off of achieving my end project goal so thats exciting. Thanks.
Hello, I am new to arduinos and HC12 and just programming in general. Iv got a project that I am working on and the HC12 module was recommended to me by my local robotics club at the university who advised me on wiring as well. To start with I just wanted to test them using Mark Hughes, first sample script on his HC12 article and unfortunately they are not behaving accordingly.
FUTURE PROJECT SUMMARY: (bit of back story for the future of the project, not entirely relevant for this thread)
These wireless modules are actually a late edition to the project, something that was always intended to be incorporated into the programming but only after the initial programming was finished and the other electronics were working correctly. Ill give you a brief description of the project but it is not super relevant to this thread as all I want for this thread is the get that basic script to work. So my project is a game involving 'Targets', in total there is 10 physical targets all the same that include various electronics on a PCB, controlled by an arduino nano each (china version) and each with a HC12 module. The programming for these Targets, stage one is complete ie, all the electronics behave correctly and are a functional game I am now looking to expand the functionality by using the HC12 modules. This was always the intention so the PCB's were designed and made with space to add the HC12 modules later. These Targets will not be communicating with themselves instead I want them to communicate to a 'Controller' the controller is currently on a breadboard equipped with an Arduino Nano, HC12 module and a few buttons (to be ignored for now). The idea is a target gets 'hit' and wirelessly sends a signal to the controller (maybe it sends an 'a'). The controller receives the 'a' and sends that to a laptop to which it is connected to via USB. Thats the aim for the future but for now like I said I am simply trying to get the sample code to work from the article.
MAIN POINTS:
'Target' : 10 available, I am using one for this experiment. Its a PCB with an arduino Nano and HC12 already soldered to it.
'Controller': 1 available, relevant components on a breadboard include arduino nano and HC12 connected with jumper cables.
Both arduinos have been tested with my other program and all the electronics are working apart from the HC12 using the code below.
The HC12’s are wired to the following arduino pins:
VCC= 5v arduino pin (in series with the specified capacitor and diode)
GND = GND
RX = d11
TX = d10
SET = d8
Here is the code that has been uploaded to both arduino's, the pins have been changed to match my selection. Whats supposed to happen is when I type and send something in one serial monitor it should be received and displayed in the other serial monitor:
Code:
/* HC12 Send/Receive Example Program 1
By Mark J. Hughes
for AllAboutCircuits.com
Connect HC12 "RXD" pin to Arduino Digital Pin 4 <<mine is 11
Connect HC12 "TXD" pin to Arduino Digital Pin 5 << mine is 10
Connect HC12 "Set" pin to Arduino Digital Pin 6 << mine is 8
Do not power over USB. Per datasheet,
power HC12 with a supply of at least 100 mA with
a 22 uF - 1000 uF reservoir capacitor.
Upload code to two Arduinos connected to two computers.
Transceivers must be at least several meters apart to work.
*/
#include <SoftwareSerial.h>
const byte RX = 11; // Recieve Pin on HC12
const byte TX = 10; // Transmit Pin on HC12
SoftwareSerial HC12(TX,RX); // Create Software Serial Port
void setup() {
Serial.begin(9600); // Open serial port to computer
HC12.begin(9600); // Open serial port to HC12
}
void loop() {
if(HC12.available()){ // If Arduino's HC12 rx buffer has data
Serial.write(HC12.read()); // Send the data to the computer
}
if(Serial.available()){ // If Arduino's computer rx buffer has data
HC12.write(Serial.read()); // Send that data to serial
}
}
To test this code I set the 'target' and 'controller' up on 2 separate computers with the arduino IDE installed and serial monitor open. The computers were also a few meters apart to rule out disturbances.
POWER: This may turn out to be the issue, hopefully not as the robotics club recommended usb power as sufficient. In my main project, the 'Targets' are powered via the usb port on the arduinos and a power bank supplying 5v, but there are also other components draining power including 20 programmable LEDs (always on) and a piezo buzzer. The 'Controller' will also be powered by the usb port and then connected to a laptop, there are no other components that drain power. But whilst testing the above code obviously both the target and controller are plugged into a laptop for communication and power.
PHOTOS:
'Target' heres the back of the PCB showing the relevant connections and the last photo showing the front soldered arduino pins.
'Controller' sorry about the angle, the buttons are not relevant for this test.
Hopefully we can figure something out I am at a loss and completely new to wireless communications but am keen to learn. If we can get these working with the above code then its not to far off of achieving my end project goal so thats exciting. Thanks.