1 (edited by ATaylorwatts 2025-02-20 14:16:37)

Topic: Values outputting to the wrong indicators

I made screen that was working fine and then I added an Edit Field (switch_time). I changed the code based on the source code provided. The Switch Time field shows up but it displays what should be in the Speed indicator (all of the indicators are mixed up).

The only change I made was adding the Switch Time edit field, nothing else. See attached images. Any help would be greatly appreciated.

https://i.ibb.co/6JPFL6tZ/IMG-20250220-080058.jpg
https://i.ibb.co/4RwZHQQT/IMG-20250220-080046.jpg
https://i.ibb.co/7NYCrMJD/IMG-20250220-080051.jpg
https://i.ibb.co/cKN1Trqb/1000011550.png

https://ibb.co/2YtdHXM6
https://ibb.co/nMqsFWWc
https://ibb.co/n8gmQdsy
https://ibb.co/nqDbkLp3

2

Re: Values outputting to the wrong indicators

Most likely you did not copy the RemoteXY structure from the code that the editor gave you into your code.
If you changed something in the interface, you need to copy two things: RemoteXY_CONF array and RemoteXY structure. Copy it as is.

3

Re: Values outputting to the wrong indicators

I copied the array and i have the variables that are from the structure. My code still works fine, but value indicators are switched up

RemoteXY Code:

/*
   -- v4 --
   
   This source code of graphical user interface 
   has been generated automatically by RemoteXY editor.
   To compile this code using RemoteXY library 3.1.13 or later version 
   download by link http://remotexy.com/en/library/
   To connect using RemoteXY mobile app by link http://remotexy.com/en/download/                   
     - for ANDROID 4.15.01 or later version;
     - for iOS 1.12.1 or later version;
    
   This source code is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.    
*/

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

// you can enable debug logging to Serial at 115200
//#define REMOTEXY__DEBUGLOG    

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

#include <SoftwareSerial.h>

// RemoteXY connection settings 
#define REMOTEXY_SERIAL_RX 10
#define REMOTEXY_SERIAL_TX 11
#define REMOTEXY_SERIAL_SPEED 9600


#include <RemoteXY.h>

// RemoteXY GUI configuration  
#pragma pack(push, 1)  
uint8_t RemoteXY_CONF[] =   // 206 bytes
  { 255,10,0,8,0,199,0,19,0,0,0,0,31,1,106,200,1,1,14,0,
  2,4,13,29,13,0,2,26,31,31,79,78,0,79,70,70,0,2,4,37,
  31,12,0,2,26,31,31,79,78,0,79,70,70,0,129,9,4,16,9,64,
  17,76,69,68,0,129,8,30,21,7,64,17,69,110,97,98,108,101,0,2,
  89,5,11,6,0,2,26,31,31,79,78,0,79,70,70,0,2,89,14,12,
  5,0,2,26,31,31,79,78,0,79,70,70,0,4,21,99,14,67,0,2,
  26,4,69,99,15,66,0,2,26,129,16,171,23,8,64,24,83,112,101,101,
  100,0,129,61,171,32,8,64,8,68,105,115,116,97,110,99,101,0,67,8,
  92,40,10,78,2,26,2,67,56,92,40,10,78,2,26,2,7,53,39,40,
  10,110,64,2,26,2,2,129,54,31,39,7,64,17,83,119,105,116,99,104,
  32,84,105,109,101,0 };
  
// this structure defines all the variables and events of your control interface 
struct {

    // input variables
  uint8_t LED; // =1 if switch ON and =0 if OFF
  uint8_t enable; // =1 if switch ON and =0 if OFF
  uint8_t dir; // =1 if switch ON and =0 if OFF
  uint8_t step; // =1 if switch ON and =0 if OFF
  int8_t Speed; // from 0 to 100
  int8_t Distance; // from 0 to 100
  float switchTime;

    // output variables
  float speed_indicator;
  float distance_indicator;

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

} RemoteXY;   
#pragma pack(pop)
 
/////////////////////////////////////////////
//           END RemoteXY include          //
/////////////////////////////////////////////

#define PIN_LED 13
#define PIN_ENABLE 4
#define PIN_DIR 2
#define PIN_STEP 3


void setup() 
{
  RemoteXY_Init (); 
  
  pinMode (PIN_LED, OUTPUT);
  pinMode (PIN_ENABLE, OUTPUT);
  pinMode (PIN_DIR, OUTPUT);
  pinMode (PIN_STEP, OUTPUT);
  
  // TODO you setup code
  
}

void loop() 
{ 
  RemoteXY_Handler ();
  
  digitalWrite(PIN_LED, (RemoteXY.LED==0)?LOW:HIGH);
  digitalWrite(PIN_ENABLE, (RemoteXY.enable==0)?LOW:HIGH);
  digitalWrite(PIN_DIR, (RemoteXY.dir==0)?LOW:HIGH);
  digitalWrite(PIN_STEP, (RemoteXY.step==0)?LOW:HIGH);
  
  // TODO you loop code
  // use the RemoteXY structure for data transfer
  // do not call delay(), use instead RemoteXY_delay() 


}

my code:

#define REMOTEXY_MODE__SOFTSERIAL
#include <SoftwareSerial.h>
#define REMOTEXY_SERIAL_RX 10
#define REMOTEXY_SERIAL_TX 11
#define REMOTEXY_SERIAL_SPEED 9600
#include <RemoteXY.h>

// RemoteXY configuration structure
#pragma pack(push, 1)  
#pragma pack(push, 1)  
uint8_t RemoteXY_CONF[] =   // 206 bytes
  { 255,10,0,8,0,199,0,19,0,0,0,0,31,1,106,200,1,1,14,0,
  2,4,13,29,13,0,2,26,31,31,79,78,0,79,70,70,0,2,4,37,
  31,12,0,2,26,31,31,79,78,0,79,70,70,0,129,9,4,16,9,64,
  17,76,69,68,0,129,8,30,21,7,64,17,69,110,97,98,108,101,0,2,
  89,5,11,6,0,2,26,31,31,79,78,0,79,70,70,0,2,89,14,12,
  5,0,2,26,31,31,79,78,0,79,70,70,0,4,21,99,14,67,0,2,
  26,4,69,99,15,66,0,2,26,129,16,171,23,8,64,24,83,112,101,101,
  100,0,129,61,171,32,8,64,8,68,105,115,116,97,110,99,101,0,67,8,
  92,40,10,78,2,26,2,67,56,92,40,10,78,2,26,2,7,53,39,40,
  10,110,64,2,26,2,2,129,54,31,39,7,64,17,83,119,105,116,99,104,
  32,84,105,109,101,0 };

struct {
  uint8_t LED;
  uint8_t enable;
  uint8_t dir;
  uint8_t step;
  int8_t Speed;
  int8_t Distance;
  float speed_indicator;
  float distance_indicator;
  uint8_t connect_flag;
  float switch_time;
} RemoteXY;
#pragma pack(pop)

#define PIN_LED 13
#define PIN_ENABLE 4
#define PIN_DIR 2
#define PIN_STEP 3

unsigned long previousStepTime = 0;
int stepCounter = 0;
int targetSteps = 0;
bool currentDirection = true; // true for one direction, false for the other

void setup() {
  RemoteXY_Init(); 
  pinMode(PIN_LED, OUTPUT);
  pinMode(PIN_ENABLE, OUTPUT);
  pinMode(PIN_DIR, OUTPUT);
  pinMode(PIN_STEP, OUTPUT);
  digitalWrite(PIN_ENABLE, LOW); // Enable the driver
}

void loop() {
  RemoteXY_Handler();
  
  // Update indicators and LED
  RemoteXY.speed_indicator = map(RemoteXY.Speed, 1, 100, 5000, 500);
  RemoteXY.distance_indicator = map(RemoteXY.Distance, 1, 100, 0, 16000);
  digitalWrite(PIN_LED, (RemoteXY.LED==0)?LOW:HIGH);
  
  // Control motor
  digitalWrite(PIN_ENABLE, (RemoteXY.enable==0)?HIGH:LOW); // Enable is active LOW
  
  if (RemoteXY.enable == 1) { // If motor is enabled
    unsigned long currentMicros = micros();
    if (currentMicros - previousStepTime >= RemoteXY.speed_indicator) {
      previousStepTime = currentMicros;
      
      if (stepCounter < RemoteXY.distance_indicator) {
        digitalWrite(PIN_DIR, currentDirection ? HIGH : LOW);
        digitalWrite(PIN_STEP, HIGH);
        delayMicroseconds(2); // Short delay for the step pulse
        digitalWrite(PIN_STEP, LOW);
        stepCounter++;
      } else {
        // Change direction and reset counter when target is reached
        currentDirection = !currentDirection;
        stepCounter = 0;
      }
    }
  } else {
    stepCounter = 0; // Reset counter when motor is disabled
  }
}

4

Re: Values outputting to the wrong indicators

I know I copied the code right. My program has other variables and I added the ones generated by remotexy to the structure. I tried to start over and now the input is somehow tied to the slider to the edit field.

5

Re: Values outputting to the wrong indicators

Just don't change anything in the RemoteXY structure. Copy it as is. Something you added or manually corrected caused the error. Just copy and paste.

6

Re: Values outputting to the wrong indicators

Wow, I see....thanks. Do you have a Patreon or other way to tip? RemoteXY is too good to be this cheap.

7

Re: Values outputting to the wrong indicators

Thank you. Just buy the full version of the app and tell your friends about us.

8

Re: Values outputting to the wrong indicators

remotexy wrote:

Just don't change anything in the RemoteXY structure. Copy it as is. Something you added or manually corrected caused the error. Just copy and paste.

I always copy everything between the first /////////////////// line, to the last //////////////// line.

I then have a separate tabbed page on my sketch that just has the RemoteXY definition in it. I use an #include
statement in my main code so that the GUI configuration gets pulled in.

Once I've copied the RemoteXY source code, it is then easy to go to the RemoteXY include page, do Ctrl-A (select All), then Ctrl-C (Paste) to replace all of the RemoteXY stuff.  Sounds more difficult to describe than it is to do ...

2B, or not 2B, that is the pencil ...