1 (edited by zobayeralam1 2021-06-12 10:04:10)

Topic: Software Serial not working

I have tried connecting bluetooth via hardware serial. Everything works fine but when I try to do the connection using software serial, bluetooth fails to connect to the smartphone app.
Either it shows 'GUI configuration error' or 'Receiving Variables error'

I have updated RemoteXY Library to the latest version, tried changing to different baud rates and different software serial pins but nothing worked.

2 (edited by Gunner 2021-06-12 17:53:02)

Re: Software Serial not working

Start by supplying some needed details please.

- Actual version number of library
- BT/BLE module used
- Board type used
- What pins used for Soft Serial
- How is everything wired together (as in proper crossover? proper power?)
- Show your tested sketch

"And voila, which is French for.......'and then I found out.'" - Ready Player One

3 (edited by zobayeralam1 2021-06-13 09:03:57)

Re: Software Serial not working

Library version is 3.1.6 updated on 31.05.21
Bluetooth module is HC-05
On board - Arduino Nano

Following sketch is written for showing Heart Rate from pulse sensor via analog pin A0. Pin 2 and 3 is used as Software serial pins. Board is powered by laptop and the powering cable is fine because other program written using hardware serial works just fine.



<<<<<<
//////////////////////////////////////////////
//        RemoteXY include library          //
//////////////////////////////////////////////

// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__SOFTSERIAL
#include <SoftwareSerial.h>

#include <RemoteXY.h>

// RemoteXY connection settings
#define REMOTEXY_SERIAL_RX 2
#define REMOTEXY_SERIAL_TX 3
#define REMOTEXY_SERIAL_SPEED 19200
#define REMOTEXY_ACCESS_PASSWORD "0000"


// RemoteXY configurate 
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
  { 255,0,0,15,0,31,0,11,26,0,
  67,5,67,32,19,8,2,26,11,129,
  0,69,23,16,7,31,66,80,77,0,
  68,17,7,16,51,30,8,36 };
 
// this structure defines all the variables and events of your control interface
struct {

    // output variables
  char text_1[11];  // string UTF8 end zero
  float onlineGraph_1;

    // other variable
  uint8_t connect_flag;  // =1 if wire connected, else =0

} RemoteXY;
#pragma pack(pop)

/////////////////////////////////////////////
//           END RemoteXY include          //
/////////////////////////////////////////////



#define USE_ARDUINO_INTERRUPTS true    // Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h>     // Includes the PulseSensorPlayground Library.   

//  Variables
const int PulseWire = 0;
int Threshold = 510;

PulseSensorPlayground pulseSensor;


void setup() {
  RemoteXY_Init ();
  pulseSensor.begin();                 //This Function is to initialize the whole library function.
  pulseSensor.analogInput(PulseWire);
  pulseSensor.setThreshold(Threshold);
}

void loop() {
  RemoteXY_Handler ();
  RemoteXY.onlineGraph_1 = float (analogRead(A2));
  int myBPM = pulseSensor.getBeatsPerMinute();
  if (pulseSensor.sawStartOfBeat()) {
    dtostrf(myBPM, 0, 2, RemoteXY.text_1);
  }
}
>>>>>



bluetooth is powered by 5v pin from the arduino. I have changed it to 3.3v , but it didn't solve the problem.

When the sketch is written for hardware serial, RemoteXY (pro- purchased 5 days ago) app runs well but the variables are found to be scrambled due to pulse created by bluetooth.
When the sketch is written for software serial (for any pins), the mobile app fails to connect. Sometimes it shows GUI configuration problem, sometimes it shows variables error. Only a few times the app could run the program, but it crashed within a few seconds showing an message " Board did not reply. "

4 (edited by Gunner 2021-06-12 19:57:38)

Re: Software Serial not working

zobayeralam1 wrote:

#define REMOTEXY_SERIAL_RX 2
#define REMOTEXY_SERIAL_TX 3
#define REMOTEXY_SERIAL_SPEED 19200

Make sure your Nano RX goes to the TX of the HC-05 and vise versa. 
19200 may be too fast for Soft Serial to use reliably.  Adjust both your module and code for 9600

EDIT OK, you didn't parse out your code from your comments in your post, using the <>, so I didn't see your explanation until later.  Clearly the wiring is fine but the speed is unreliable, fix that and see what happens smile

"And voila, which is French for.......'and then I found out.'" - Ready Player One

5

Re: Software Serial not working

Following are some combinations I've used so far.

i) Baud rate at 9600
    a. Hardware serial - Everything works just fine
    b. Software serial at different pins - RemoteXY app on phone fails to launch

ii) Baud rate at 19200
    a. Hardware serial - Everything works just fine
    b. Software serial at different pins - RemoteXY app on phone fails to launch

The problem happens only when the sketch is done for software serial.

6

Re: Software Serial not working

I just found out, the problem happens when there is analog pins are related. whenever the sketch has anything that reads from analog pins, app crashes, shows "Board did not reply". But there is nothing problem when reading from digital pins.

So, the problem with software serial is with analog pins. excluding analog pins from the sketch solves the software serial problem.
But I really really need to use analog pin, at least one. What to do? please inform me.

7 (edited by Gunner 2021-06-13 17:14:54)

Re: Software Serial not working

Hello. when referring to <> I meant using the button that looks that way at the top of the editing window and placing your code between the two resultant hypertext like elements.

As for your issue... a bit of a red herring on the BT connectivity issue as it is working just fine until something else interferes with the internal process.

What you actually seem to be running into is a not so much an RemoteXY connectivity issue as it is native Arduino limitations of the internal timers on a Nano and common conflicts between generating a software serial process and other timing sensitive tasks.

I am not sure if/how you could try alternate Soft Serial libraries with RemoteXY, but I would simply recommend using the Hardware Serial.  It works fine and your sketch doesn't show any need to use the Serial/USB port when running, so all is clear there.

Or use a different device like a MEGA with many Hard Serial ports, or ESP with WiFi instead of BT... and much faster.

"And voila, which is French for.......'and then I found out.'" - Ready Player One

8

Re: Software Serial not working

My project is small in size, thats why I can't use bigger boards. And for Hardware serial, Pulse made by bluetooth interferes with read signal from analog pins. As a result the values are scrambled or not accurate at all

9 (edited by Gunner 2021-06-13 18:40:52)

Re: Software Serial not working

Look at the Wemos D1 Mini  The word mini in the name means something smile  Smaller than your Nano, HC-05 combo, built in WiFi.  You will have to account for the 1v input max on the analog port, but that is a simple resistor.  Although, it is not the best ACD out there, Google for more info. 

The NodeMCU is not much bigger.

And of course there are many small ESP32 boards out there... options.

I would seriously consider the ESP32... better ADC, processing power, even dual core options if you are feeling brave.


As for the rest... All I can say is that I have seen many heartbeat monitor projects trying to use an App for display.  And it has always seemed an issue getting the dual fast timing, high bandwidth functions to play nicely together. 

But at least you can Have Fun trying!

BTW, RemoteXY seems to use the SoftwareSerial.h library... you could always try modifying that part of library to use an alternate Soft Serial library.  No idea how much work that would involve, or if it would even make a diff, but again... options.

RemoteXYStream_SoftSerial.h

"And voila, which is French for.......'and then I found out.'" - Ready Player One

10 (edited by zobayeralam1 2021-06-14 15:52:55)

Re: Software Serial not working

Thank you very much for helping me. But my project contains many sensors, almost 15 different pins with combination of digital and analog pins. Wemos D1 mini has 10 pins, including only one analog pin. And for ESP32 board, it gets way over the budget for a simple project and NODEMCU is unavailable here big_smile . But anyhow, I appreciate your help, I could know many things from here as I am a beginner in this section.

11

Re: Software Serial not working

SoftwareSerial library use timer interrupt on chip. Because of this, other libraries that use the same timer interrupt vector are not compatible with the software serial.
For example, we know a Servo.h library that is incompatible with SoftwareSerial.h
This does not apply directly to the RemoteXY. This is a conflict between libraries that use the same chip resources.
Maybe the library PulseSensorPlayground.h  has the same problem.