Arduino MEGA copy / atmega 2560 serial receive pins

Hello I bought a Arduino MEGA from AliExpress.

It is a bit more complex than the UNO I'm used to.
Anyway I got it working and can run scripts on it.

I start playing around with the HC-12 wireless module.

What I can't understand is why it's only some of pins that can receive serial data from the HC-12.

Pins I can get working:
10, 11, 12, 13, 50, 51, 52, 53.

Pins I can't get working:
0, to 9 and 14 to 21

The rest I haven't tested.

I can send serial data from almost all pins it seems.

Is it correct observed or is it faulty?

Show us your code.

//HC-12 messenger send/receive
//autor Tom Heylen tomtomheylen.com

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); //RX, TX

void setup() {
  Serial.begin(9600);
  mySerial.begin(9600);
}

void loop() {
  
  
  if(Serial.available() > 0){//Read from serial monitor and send over HC-12
    String input = Serial.readString();
    mySerial.println(input);    
  }
 
  if(mySerial.available() > 1){//Read from HC-12 and send to serial monitor
    String input = mySerial.readString();
    Serial.println(input);    
  }
  delay(20);
}

It works fine on my arduino Nano

Hi, @henrik9979

The Mega has 4 hardware serial ports, why are you using softwareserial?

Tom... :grinning: :+1: :coffee: :australia:

Because I haven't used a MEGA or a HC-12 transmitter before and is starting to learn how to use them.

Following YouTube videos like this. https://youtu.be/DGRPqeacJns?si=3UjhWoV-vYq2o_Av

The SoftwareSerial library webpage has the following note:

Okay it almost fit the description for my board.
Pin 14 and 15 won't receive data however.

But however it seems like I can get it to work with Pin0 if I connect it directly to the pin1 on the Arduino Nano, without using the HC-12

The board in your photos isn't an Arduino MEGA (2560), but a hybrid board based around the MEGA2560 with the addition of an ESP8266 module.

You need to read the documentation as I believe that one of the hardware serial ports on the MEGA2560 is used to communicate with the ESP8266.

https://a.aliexpress.com/_mKuvW1E

It says:
USB converter CH340G connect to RX0/TX0 of ATmega2560
ESP8266 connect to RX3/TX3 of ATmega25

Please reread post #5, you shouldn't use SoftwareSerial on Mega, use HardwareSerial instead

So you can use TX1 RX1 or TX2 RX2 for HC-12

Then what should I change in the code to use hardware serial, also what are the differences?

Use Serial1 or Serial2 ( it depends on pins you connect to HC-12) instead of mySerial. Get rid anything related to SoftwareSerial from the code.

Like this?

Serial1; //RX, TX

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop() {
  
  
  if(Serial.available() > 0){//Read from serial monitor and send over HC-12
    String input = Serial.readString();
    Serial1.println(input);    
  }
 
  if(Serial1.available() > 1){//Read from HC-12 and send to serial monitor
    String input = Serial1.readString();
    Serial.println(input);    
  }
  delay(20);
}

The very first line

is not needed, like the Serial, Serial1 already defined in Arduino IDE

Just for curiosity, why do you use different condition for two serial ports?

I basically just followed the YouTube video I send post#6