Problem using serial1 instead SoftwareSerial mySerial();

Hello,
I have some trouble using the serial1 to communicate with my bluetooth module.
I’m using a bluetooth terminal on my smartphone to send some character that the arduino have to print on the terminal.
When I’m using personal serial pin with SoftwareSerial mySerial(); , there is no problem, I receive the character. But when I’m using serial1 (or serial2 / serial3), the terminal just prints 0 all the time…

Here is my code with personal serial pin (which works):

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); 

#define USB  Serial
//#define BT   Serial1
#define BT mySerial

int bt_value = 0;


void setup() 
{
  // initialize both serial ports:
  USB.begin(9600);
  USB.println("USB started");
  BT.begin(9600);
  USB.println("BT started");
  USB.println("System Initialized");
}

void loop() 
{
   while (BT.available()) 
  {
    bt_value = BT.read();
    USB.println(bt_value);
  }
}

Here is my code with serial1 (which doesn’t works):

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11);

#define USB  Serial
#define BT   Serial1
//#define BT mySerial

int bt_value = 0;


void setup() 
{
  // initialize both serial ports:
  USB.begin(9600);
  USB.println("USB started");
  BT.begin(9600);
  USB.println("BT started");
  USB.println("System Initialized");
}

void loop() 
{
   while (BT.available()) 
  {
    bt_value = BT.read();
    USB.println(bt_value);
  }
}

In fact, I just replace #define BT mySerial by #define BT Serial1. And, of course, I’m moving the pin from 10-11 (personnal serial pin) to 19-18 (serial pin).
Someone has some idea…? Thanks

  • Hardware used :
    Bluetooth: JY MCU HC06
    Arduino MEGA 2560

remove softwareserial when using Serial1.

It changes nothing, the terminal still print '0'.

Now the code is :

#define USB  Serial
#define BT   Serial1

int bt_value = 0;

void setup() 
{
  // initialize both serial ports:
  USB.begin(9600);
  USB.println("USB started");
  BT.begin(9600);
  USB.println("BT started");
  USB.println("System Initialized");
  
}

void loop() 
{

   while (BT.available() > 0) 
  {
    bt_value = BT.read();
    USB.println(bt_value);
  }
}

What happens if you explicitly use "Serial1" instead of "BT" ?

...R

Nothing...

Code looks reasonable. RX/TX reversed?

Are you moving the Arduino RX wire from 10 to 19 (connected to Bluetooth TX pin) and the Arduino TX wire from 11 to 18 (connected to BT RX pin)? That is, 10/11 corresponds to 19/18.

Cheers, /dev

It is well wired, I just made a mistake during the explaination.

Maybe you need level shifting? The BT device is a 3.3V device, so you should probably divide the Arduino's 5V TX line down to 3.3v (use two resistors). It can damage the device to give it out-of-spec voltages.

In your case, you might need to scale the BT TX line up to solid 5V levels. Two resistors, can do it, although there are lots of ways. I prefer to use those cheap Level-Shift modules, which are required for high-speed devices, like an SD card. Just search "level shift 5 3.3" here to find some threads.

Cheers, /dev

It may be worth trying Serial2 (with the appropriate pins) just in case Serial1 is damaged.

...R

Thanks /dev, I will investigate this possibility. I already tried serial2 and serial3, it doesn't change anything... So for the moment I will continue with my personal serial pin. If I find the solution, I will post it here.

You could also hook Serial1 to Serial2 or Serial3. Then upload a sketch that writes a little to Serial1, reads from Serial2 (or 3), and echoes to Serial. Also try to write to Serial2 (or 3), read from Serial1, and echo to Serial. That will confirm the UARTs and pins are ok. Be sure to cross RX to TX and vice versa.

Cheers, /dev