Serial Logging HM10 BLE module with Android App

I have a BLE module connected to pins 19,18 on MEGA. I’ve uploaded this simple code to read what Arduino sends:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(19,18); // RX, TX  
// Connect HM10      Arduino MEGA

void setup() {  
  Serial.begin(9600);
  // If the baudrate of the HM-10 module has been updated,
  // you may need to change 9600 by another value
  // Once you have found the correct baudrate,
  // you can update it using AT+BAUDx command 
  // e.g. AT+BAUD0 for 9600 bauds
  mySerial.begin(9600);
}

void loop() {  
  char c;
  if (Serial.available()) {
    c = Serial.read();
    mySerial.println(c);
  }
  if (mySerial.available()) {
    c = mySerial.read();
    Serial.println(c);    
  }
}

If I open the serial monitor and write something and click Send, i receive it on the Android device connected to the BLE module because I can see it log in Logcat (the console on Android Studio for debugging). So I know the communication between both is working.

Then I try to send data from the Android to the hm10 module and I click a button which sends data to the connected BLE device and logs in the logcat for debug purposes. I can see the log in the logcat once again, but I dont get anything in the serial monitor. SM baud is set to 9600 as it should according to the sketch.

But I connect the BLE to the PL2303 directly to my mac and the Android app sends the commands successfully to the ble module as seen from CoolTerm here:

Screenshot 2016-04-19 16.52.11.png

So its an issue with my code in the Arduino sketch that I am not receiving the data successfully in the SM.

Pins 18,19 are hardware serial ports Serial1, and clearly marked as such. Using them, or any other hardware serial port on any Arduino as software serial is a fatal mistake. Using software serial on a Mega, which has four, yes four, hardware serial ports, is a very bad idea. Indeed using software serial on any arduino is only a means of last resort.

Deleting all references to software serial, and changing all instances of mySerial to Serial1 might get a result.

Oh you're right! Forgot about that when I switched over form the UNO.

Thanks