I need help to modify RemoteXY library

Hi guys,

My project uses the RemoteXY library (public domain), but that library does not currently support the board I am using (Teensy 3.2)

To get my project to compile, I choose the Arduino Micro in the RemoteXY configuration, which then quotes “Serial1” for the hardware serial port, and it all works as it should on Rx1 and Tx1

However, I now need to use the Serial1 port for debugging on the IDE, so RemoteXY needs to be modified to use Serial2 for communication with an ESP8266 module. The project will compile if I change the port spec to Serial2, but RemoteXY will not know anything about this, nor will it know which pins to use for Rx2 and Tx2, and presumably is still looking for comms on Rx1 and Tx1.

// RemoteXY select connection mode and include library 
#define REMOTEXY_MODE__ESP8266_HARDSERIAL_POINT

#include <RemoteXY.h>

// RemoteXY connection settings 
#define REMOTEXY_SERIAL Serial2
#define REMOTEXY_SERIAL_SPEED 115200
#define REMOTEXY_WIFI_SSID "BaitBoat"
#define REMOTEXY_WIFI_PASSWORD "12345678"
#define REMOTEXY_SERVER_PORT 6377

I have looked at the library code, and to be honest, a lot of it is way above my comprehension, but it looks to me like it should be possible to steer RemoteXY to Serial2 away from Serial1

I’m thinking that some modifications must be made in serial.h and possibly RemoteXY_Serial.h, but

I have attached the whole of the library, and hoping I’m not leading myself up a dark alley…

TIA

RemoteXY.zip (36.6 KB)

There is a long Forum Thread about RemoteXY and AFAIK the developer appears their fairly regularly.

As you have not mentioned RemoteXY in your Title he is unlikely to notice your Thread.

...R

Robin2:
There is a long Forum Thread about RemoteXY and AFAIK the developer appears their fairly regularly.

As you have not mentioned RemoteXY in your Title he is unlikely to notice your Thread.

…R

Yes I saw that thread, but shev hasn’t posted on it since 2016.

I can’t see in it anything about using the library with an unsupported board.

I’m looking at the “WiFiPoint_ESP8266_HardSerial” example sketch and it’s quite odd because all those #define directives don’t do anything at all. However, if you move them up in the sketch to above this line:

#include <RemoteXY.h>

they will be able to configure the library code (because it’s a header-only library). Give that a try to see if it will solve your problem with no need to mess with the library code.

pert:
I’m looking at the “WiFiPoint_ESP8266_HardSerial” example sketch and it’s quite odd because all those #define directives don’t do anything at all. However, if you move them up in the sketch to above this line:

#include <RemoteXY.h>

they will be able to configure the library code (because it’s a header-only library). Give that a try to see if it will solve your problem with no need to mess with the library code.

Thank-you for taking time on this, and I have tried your suggestion, but no luck…

// RemoteXY select connection mode and include library 
#define REMOTEXY_MODE__ESP8266_HARDSERIAL_POINT

//#include <RemoteXY.h>

// RemoteXY connection settings 
#define REMOTEXY_SERIAL Serial2
#define REMOTEXY_SERIAL_SPEED 115200
#define REMOTEXY_WIFI_SSID "BaitBoat"
#define REMOTEXY_WIFI_PASSWORD "12345678"
#define REMOTEXY_SERVER_PORT 6377

#include <RemoteXY.h>

Can you see anywhere in the library code that defines the pin numbers for HARDSERIAL ?

Because I have configured the RemoteXY board as a (now) Arduino Mega, I can choose Serial2 without having to change it in the RemoteXY “configurate”, but the pin numbers are wrong. I am compiling my sketch as a Teensy 3.2, with no errors, but I think RemoteXY_Init (); is not starting the correct port, because it thinks it’s a MEGA.

If I can get at the pin numbers I might be able to change them to match the Teensy

I just took a look into the library and I don't see any reason the code you have above wouldn't set it to use Serial2. The most important code is in esp8266.h, line 220:

#define RemoteXY_Init() remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY, REMOTEXY_ACCESS_PASSWORD, &REMOTEXY_SERIAL, REMOTEXY_SERIAL_SPEED, REMOTEXY_WIFI_SSID, REMOTEXY_WIFI_PASSWORD, REMOTEXY_SERVER_PORT)

This creates a macro function named RemoteXY_Init(), which will pass REMOTEXY_SERIAL to the CRemoteXY constructor. That constructor, at esp8266.h, line 24:

  CRemoteXY (const void * _conf, void * _var, const char * _accessPassword, HardwareSerial * _serial, long _serialSpeed, const char * _wifiSsid, const char * _wifiPassword, uint16_t _port) {
    initSerial (_serial, _serialSpeed);

passes the serial object to initSerial.

You haven't ever posted your full sketch. Do you call RemoteXY_Init() in your sketch?

pert:
You haven’t ever posted your full sketch. Do you call RemoteXY_Init() in your sketch?

Yes definitely – but I have temporarily abandoned my project sketch, and am using this to test the connection.

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

// RemoteXY select connection mode and include library 
#define REMOTEXY_MODE__ESP8266_HARDSERIAL_POINT

#include <RemoteXY.h>

// RemoteXY connection settings 
#define REMOTEXY_SERIAL Serial2
#define REMOTEXY_SERIAL_SPEED 115200
#define REMOTEXY_WIFI_SSID "TeensyTest"
#define REMOTEXY_WIFI_PASSWORD "12345678"
#define REMOTEXY_SERVER_PORT 6377


// RemoteXY configurate  
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
  { 255,1,0,1,0,19,0,8,13,0,
  1,0,17,19,12,12,2,31,88,0,
  65,4,48,20,9,9 };
  
// this structure defines all the variables of your control interface 
struct {

    // input variable
  uint8_t button_1; // =1 if button pressed, else =0 

    // output variable
  uint8_t led_1_r; // =0..255 LED Red brightness 

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

} RemoteXY;
#pragma pack(pop)

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



// **********************************************************************

void setup() {

  RemoteXY_Init (); 
 
} // end setup

// ***********************************************************************

// LOOP
// ***********************************************************************

void loop() {

  RemoteXY_Handler ();
 
  RemoteXY.led_1_r = RemoteXY.button_1 * 255;

  delay(25);
  
} // void(loop)

If I compile and upload for Serial1, it works…

If I compile and upload for Serial2 (no other changes), move my connections RX1 to RX2, and TX1 to TX2, I get an error on the RemoteXY app : “Error (61) Connection refused”

So it seems that it may be communicating…

What board are you compiling for?

gfvalvo:
What board are you compiling for?

Teensy 3.2

I needed 4 interrupts, and the small size.

Anyway, I have discovered, quite by chance, that Serial (USB) and Serial1 (HARDWARE_SERIAL) are in fact separate ports on the Teensy, so I can go back to Serial1, and I don't need to use Serial2.

I just need to add some debugging Serial.print statements so I can find out why things aren't working on my project, that I can do now on Serial, leaving Serial1 to talk to RemoteXY