Go Down

Topic: Servo with HC-12 Module is twitching (Read 753 times) previous topic - next topic

FBW921

The arduino NANO (my transmitter in this case) has two ports, pins 0 (RX) and 1 (TX)

My receiving device- the arduino mega has 8 -

Mega

0(RX), 1(TX)

19(RX), 18(TX)

17(RX), 16(TX)

15(RX), 14(TX)


Since both devices will be disconnected from any CPU (unless new code is being uploaded), I think I should be good on the number of hardware serial ports. The question is how to go about the coding?

PaulS

Quote
The arduino NANO (my transmitter in this case) has two ports, pins 0 (RX) and 1 (TX)
A serial port consists of an input pin and an output pin, so you have ONE port on the Nano and FOUR on the Mega.

Quote
The question is how to go about the coding?
To do what?

Quote
Since both devices will be disconnected from any CPU
Then, just use Serial on each to talk to the HC-12.
The art of getting good answers lies in asking good questions.

FBW921

How do I use Serial (hardware serial) to communicate between the two hc-12s? I know how to use software serial to do it but not hardware serial. Here's some more direct questions since you like specific questions: Which functions can I directly swap out between software serial and hardware serial? Here's my controller code:

#include <SoftwareSerial.h>

int ROT ;
SoftwareSerial HC12(10, 11);
void setup() {
  Serial.begin(9600);             
  HC12.begin(9600);               
 
}
void loop() {

int ROT = analogRead(A3);
//Serial.println(ROT);
//ROT = map(ROT , 515 , 1023 , 1100  , 1800) ;
ROT = map(ROT , 0 , 876 , 760  , 1800) ;
Serial.println(ROT);
HC12.println(ROT);
delay(50);








What do I #include for harware serial?
Does "SoftwareSerial HC12(10, 11);" stay?
Do I use Serial.read() anywhere?

PaulS

Quote
Which functions can I directly swap out between software serial and hardware serial?
The public methods of the HardwareSerial class and the SoftwareSerial class are the same. So, any method of the SoftwareSerial class that you use can be used with the HardwareSerial instance (Serial) instead.

Quote
What do I #include for harware serial?
Nothing.

Quote
Does "SoftwareSerial HC12(10, 11);" stay?
No.

Quote
Do I use Serial.read() anywhere?
If you want to read from the HC-xx, after you connect it to the hardware serial pins, yes. And, if you want to talk to the HC-xx, you use Serial.print() and/or Serial.println() and/or Serial.write().
The art of getting good answers lies in asking good questions.

FBW921

I will try to use hardware serial given this new information, thank you for your answers.

Go Up