1

Topic: two or more HM-10 BLE over SoftwareSerial

Hi!

I need some help, please.

I have done some projects with Arduino Micro, HM-10 over SoftwareSerial and all work fine.

Now I want to have two (or maybe three) HM-10 Bluetooth-modules connected to an Arduino Micro, so that I can make two (or even three) connections to the Arduino from different phones at the same time.
I like to build a small game with 2 game controllers.

But I have no idea how to run multiple instances from RemoteXY on the same Arduino at the same time with different serial settings.

Can someone please help me?

Thanks a lot!

ungesimmt

2

Re: two or more HM-10 BLE over SoftwareSerial

Welcome,

Take a look at this, it might be helpful... smile

http://forum.remotexy.com/viewtopic.php?id=15

3

Re: two or more HM-10 BLE over SoftwareSerial

Hi,

and thanks for your reply.
I've found that code before smile
My code compiles without errors. But I'm not able to use 2 HM-10 in parallel. Is it possible with your library to use 2 or more SoftwareSerial in parallel? If I just use one of the modules (with no use of the code from e.g. rxy2), it works. With both of them the devices don't reply.

Do you have any ideas?

Please help me!
Thanks...

Here is my code...

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

#include <RemoteXY.h>

// RemoteXY connection settings 
#define REMOTEXY_SERIAL_RX1 8
#define REMOTEXY_SERIAL_TX1 10
#define REMOTEXY_SERIAL_RX2 9
#define REMOTEXY_SERIAL_TX2 11
//#define REMOTEXY_SERIAL_RX3 20
//#define REMOTEXY_SERIAL_TX3 23
#define REMOTEXY_SERIAL_SPEED 4800

// Data for RemoteXY's instance 1
CRemoteXY *rxy1;

const uint8_t PROGMEM rxy1_config[] =
  { 255,2,0,5,0,47,0,6,5,2,
  5,9,26,8,45,45,4,40,42,42,
  2,65,15,7,9,9,9,7,9,9,
  9,2,66,33,89,2,9,50,53,5,
  9,83,2,66,161,1,54,89,8,1,
  90,60,8,2 };

struct {
    // input variable
  int8_t joy_x; // =-100..100 x-coordinate joystick position 
  int8_t joy_y; // =-100..100 y-coordinate joystick position 
    // output variable
  uint8_t led_r; // =0..255 LED Red brightness 
  uint8_t led_g; // =0..255 LED Green brightness 
  uint8_t led_b; // =0..255 LED Blue brightness 
  int8_t ver; // =-100..100 level position 
  int8_t hor; // =-100..100 level position 
    // other variable
  uint8_t connect_flag;  // =1 if wire connected, else =0 
}  rxy1_struct;


// Data for RemoteXY's instance 2
CRemoteXY *rxy2;

const uint8_t PROGMEM rxy2_config[] =
  { 255,2,0,5,0,47,0,6,5,2,
  5,9,26,8,45,45,4,40,42,42,
  2,65,15,7,9,9,9,7,9,9,
  9,2,66,33,89,2,9,50,53,5,
  9,83,2,66,161,1,54,89,8,1,
  90,60,8,2 };; 

struct {
    // input variable
  int8_t joy_x; // =-100..100 x-coordinate joystick position 
  int8_t joy_y; // =-100..100 y-coordinate joystick position 
    // output variable
  uint8_t led_r; // =0..255 LED Red brightness 
  uint8_t led_g; // =0..255 LED Green brightness 
  uint8_t led_b; // =0..255 LED Blue brightness 
  int8_t ver; // =-100..100 level position 
  int8_t hor; // =-100..100 level position 
    // other variable
  uint8_t connect_flag;  // =1 if wire connected, else =0 
}  rxy2_struct;



//eigene Defines

#define LED_gruen 14//MISO
#define LED_rot   15//SCK




//globale Variablen
  

void setup() 
{ 
  pinMode(LED_BUILTIN, OUTPUT); //integrierte LED
  pinMode(LED_gruen, OUTPUT);
  pinMode(LED_rot, OUTPUT);

  Serial.begin(9600);  //Verbindung USB direkt zu PC (debug Console)
  //delay(800);
  Serial.println("RemoteXY for Light-Control by SG7");
  Serial.println("Startup...");
  //delay(1000);
 
  //RemoteXY_Init ();
  rxy1 = new CRemoteXY (rxy1_config, &rxy1, REMOTEXY_ACCESS_PASSWORD, REMOTEXY_SERIAL_RX1, REMOTEXY_SERIAL_TX1, REMOTEXY_SERIAL_SPEED);
  delay(1000);
  rxy2 = new CRemoteXY (rxy2_config, &rxy2, REMOTEXY_ACCESS_PASSWORD, REMOTEXY_SERIAL_RX2, REMOTEXY_SERIAL_TX2, REMOTEXY_SERIAL_SPEED);
  
  Serial.println("Startup done!");
} //Ende void setup() 



void loop() 
{ unsigned long currentMillis = millis();

  rxy1->handler();
  //delay(5);
  rxy2->handler();

  rxy1_struct.ver=rxy1_struct.joy_x;
  rxy1_struct.hor=rxy1_struct.joy_y;  
  rxy2_struct.ver=rxy2_struct.joy_x;
  rxy2_struct.hor=rxy2_struct.joy_y;
  
  rxy1_struct.led_r=250;
  rxy1_struct.led_g=250;
  rxy2_struct.led_g=255;
} //Ende void loop() 

4

Re: two or more HM-10 BLE over SoftwareSerial

Sorry, some mistake in my code... Here is my correct Testcode:
Like this, it is working fine. But as soon as i call

rxy2 = new CRemoteXY (rxy2_config, &rxy2_struct, REMOTEXY_ACCESS_PASSWORD, REMOTEXY_SERIAL_RX2, REMOTEXY_SERIAL_TX2, REMOTEXY_SERIAL_SPEED);


in setup() or

rxy2->handler();

in loop() both HM-10 do not reply anymore. Is this an pin-change-interrupt-problem??

Greetings, Simon

#define REMOTEXY_MODE__SOFTSERIAL
#include <SoftwareSerial.h>

#include <RemoteXY.h>

// RemoteXY connection settings 
#define REMOTEXY_SERIAL_RX1 8
#define REMOTEXY_SERIAL_TX1 10
#define REMOTEXY_SERIAL_RX2 9
#define REMOTEXY_SERIAL_TX2 11
//#define REMOTEXY_SERIAL_RX3 20
//#define REMOTEXY_SERIAL_TX3 23
#define REMOTEXY_SERIAL_SPEED 4800

// Data for RemoteXY's instance 1
CRemoteXY *rxy1;

const uint8_t PROGMEM rxy1_config[] =
  { 255,2,0,5,0,47,0,6,5,2,
  5,9,26,8,45,45,4,40,42,42,
  2,65,15,7,9,9,9,7,9,9,
  9,2,66,33,89,2,9,50,53,5,
  9,83,2,66,161,1,54,89,8,1,
  90,60,8,2 };

struct {
    // input variable
  int8_t joy_1_x; // =-100..100 x-coordinate joystick position 
  int8_t joy_1_y; // =-100..100 y-coordinate joystick position 

    // output variable
  uint8_t led_1_r; // =0..255 LED Red brightness 
  uint8_t led_1_g; // =0..255 LED Green brightness 
  uint8_t led_1_b; // =0..255 LED Blue brightness 
  int8_t ver_1; // =-100..100 level position 
  int8_t hor_1; // =-100..100 level position 

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


// Data for RemoteXY's instance 2
CRemoteXY *rxy2;

const uint8_t PROGMEM rxy2_config[] =
  { 255,2,0,5,0,47,0,6,5,2,
  5,9,26,8,45,45,4,40,42,42,
  2,65,15,7,9,9,9,7,9,9,
  9,2,66,33,89,2,9,50,53,5,
  9,83,2,66,161,1,54,89,8,1,
  90,60,8,2 }; 

struct {
    // input variable
  int8_t joy_2_x; // =-100..100 x-coordinate joystick position 
  int8_t joy_2_y; // =-100..100 y-coordinate joystick position 

    // output variable
  uint8_t led_2_r; // =0..255 LED Red brightness 
  uint8_t led_2_g; // =0..255 LED Green brightness 
  uint8_t led_2_b; // =0..255 LED Blue brightness 
  int8_t ver_2; // =-100..100 level position 
  int8_t hor_2; // =-100..100 level position 

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



//eigene Defines

#define LED_gruen 14//MISO
#define LED_rot   15//SCK




//globale Variablen
  

void setup() 
{ 
  pinMode(LED_BUILTIN, OUTPUT); //integrierte LED
  pinMode(LED_gruen, OUTPUT);
  pinMode(LED_rot, OUTPUT);

  Serial.begin(9600);  //Verbindung USB direkt zu PC (debug Console)
  //delay(800);
  Serial.println("RemoteXY for Light-Control by SG7");
  Serial.println("Startup...");
  //delay(1000);
 
  //RemoteXY_Init ();
  rxy1 = new CRemoteXY (rxy1_config, &rxy1_struct, REMOTEXY_ACCESS_PASSWORD, REMOTEXY_SERIAL_RX1, REMOTEXY_SERIAL_TX1, REMOTEXY_SERIAL_SPEED);
  delay(1000);
  //rxy2 = new CRemoteXY (rxy2_config, &rxy2_struct, REMOTEXY_ACCESS_PASSWORD, REMOTEXY_SERIAL_RX2, REMOTEXY_SERIAL_TX2, REMOTEXY_SERIAL_SPEED);
  
  Serial.println("Startup done!");
} //Ende void setup() 







void loop() 
{ 
   if ( rxy1_struct.connect_flag == 1 )
      { digitalWrite(LED_gruen, HIGH);
      }
  else
      { digitalWrite(LED_gruen, LOW);
      };
  //Serial.print("joy x");
  //Serial.println(rxy1_struct.joy_1_x);
  //Serial.print("ver_1");
  //Serial.println(rxy1_struct.ver_1);
  
  //RemoteXY_Handler ();
  rxy1->handler();
  //delay(5);
  //rxy2->handler();


  rxy1_struct.ver_1=rxy1_struct.joy_1_x;
  rxy1_struct.hor_1=rxy1_struct.joy_1_y;  
  //rxy2_struct.ver_2=rxy2_struct.joy_2_x;
  //rxy2_struct.hor_2=rxy2_struct.joy_2_y;
  
  rxy1_struct.led_1_r=100;
  rxy1_struct.led_1_b=100;
  
  //rxy2_struct.led_2_g=250;

} //Ende void loop() 

5 (edited by Guillaume 2017-07-17 19:16:52)

Re: two or more HM-10 BLE over SoftwareSerial

I have never used SoftwareSerial but maybe you need to modify (or better, create your own) RemoteXY module so that it makes use of listen().

But then you might have other problems and it might not work as you expect, because:

Only one software serial port can listen at a time; data that arrives for other ports will be discarded. Any data already received is discarded during the call to listen() (unless the given instance is already listening).

But can you use both HM-10 without RemoteXY ? And 4800 is very slow, maybe try with 115200.

I think you should use a board with multiple HardwareSerial ports (arduino mega 2560, for example) smile

6 (edited by Guillaume 2017-07-18 10:08:35)

Re: two or more HM-10 BLE over SoftwareSerial

By the way, if you use a esp8266 instead of your arduino micro, not only you can do your thing with Wifi, but you could also use two HM-10 because it has two HardwareSerial ports. Port 0 is normally used for sketch upload, so you will have to upload by OTA.

It also has a third TX pin that you can use for your debugging, but this will require another usb/serial adapter, but you could just communicate with PC with another way!

https://bennthomsen.files.wordpress.com/2015/12/nodemcu_pinout_700-2.png

7

Re: two or more HM-10 BLE over SoftwareSerial

Thanks Guillaume,

I've managed it like you suggested, with an Arduino Mega.
It works fine now, so thank you!

ungesimmt