Page 1 of 1

RequestAMatrix Example Modifications

Posted: Wed Jan 06, 2021 2:34 pm
by tabear
I am trying to modify the example sketch and interface panel "RequestAMatrix" to be able to read char text values in one of the five textboxes and int’s in the other four textboxes. I have changed p1 to:

CurConfig [CurRow - 1].p1 = Parameters.NextParameter(CurConfig [CurRow - 1].p1);

But I get an error message in the arduino IDE:

no matching function for call to 'CommandParameter::NextParameter(char&)'

I have tried making several changes to add a function call to 'CommandParameter::NextParameter(char&)', but I continue to get the same error message. First, is it possible to do what I want (mix char text and int textboxes in the same interface panel? And second, how would I modify the example code to achieve my goal? I’ve been working on this for 3 days and can’t seem to get what I want. I’ve been able to add checkboxes and numeric up down boxes and can retrieve the data I need, but I just can’t seem to get the textbox working with char text. Somebody please try to lead me in the right direction.



Re: RequestAMatrix Example Modifications

Posted: Fri Jan 08, 2021 9:05 pm
by philr
Hmm thats trickier. I think you would need to adjust the structure to have character arrays and then use pstring to print the remaining parameters into those buffers.

pstring library can be found here


Re: RequestAMatrix Example Modifications

Posted: Sun Jan 10, 2021 5:50 am
by philr
Something like this..

PString P1(CurConfig[CurRow - 1].p1, sizeof(CurConfig[CurRow - 1].p1));
const char* NewValue = Parameters.NextParameter();
if (NewValue != NULL)

Re: RequestAMatrix Example Modifications

Posted: Sat Jan 23, 2021 9:47 pm
by tabear
Hi philr

Thanks for your previous replys. I've spent the last 2 weeks reading up on Pstrings, structs, characters and Strings, but I still haven't been able to get the text from the matrix UI textbox to print out correctly. I'm able to request the text and it shows up in the monitor correctly, but I can't get the text to be available for the arduino or to print out. I can get numbers from numeric up/down and whether or not checkboxes and radio buttons are checked but I'm stuck on the text. I'm showing my sketch code below and have attached the UI file. Could someone look this over and tell me what I am doing wrong. I'm a hobbyist and a cut and paste code writer, so examples with explanation would be really helpful.



Code: Select all

/* ************************************************************************
This program demonstrates how MegunoLink's Interface Panel and our command
handler Arduino library can be used to query a matrix of text boxes to retrieve
a configuration that can be used by the program to execute instructions.

The example folder also contains a MegunoLink project, with an Interface
Panel to update the variables.
* to download MegunoLink.
This example requires:
* The PString library
* Our MegunoLink Arduino library
************************************************************************ */

#include <MegunoLink.h>
#include <CommandHandler.h>
#include <ArduinoTimer.h>
#include <PString.h>

#define Rows 2

InterfacePanel MyPanel;
CommandHandler<> SerialCommandHandler;
ArduinoTimer RequestRowTimer;

// Structure to store the values sent from MegunoLink
struct Config {
  char* p1;
  int p2;
  int p3;
  byte p4;
  byte p5;

String NewValue = "";

int CurrentRow = Rows + 1; //Start at 5 so it doesn't request anything at startup
Config CurConfig[Rows]; //Create array to store each config row

/*----------------Command Hanlder Functions--------------------------*/
//This function processes the row data sent from MegunoLink.
void Cmd_GetProcessTableRow(CommandParameter &Parameters)
  int CurRow = Parameters.NextParameterAsInteger();
  if (CurRow != -1 && CurRow <= Rows)
    CurConfig[CurRow - 1].p1 = Parameters.NextParameterAsInteger(CurConfig[CurRow - 1].p1);
    CurConfig[CurRow - 1].p2 = Parameters.NextParameterAsInteger(CurConfig[CurRow - 1].p2);
    CurConfig[CurRow - 1].p3 = Parameters.NextParameterAsInteger(CurConfig[CurRow - 1].p3);
    CurConfig[CurRow - 1].p4 = Parameters.NextParameterAsInteger(CurConfig[CurRow - 1].p4);
    CurConfig[CurRow - 1].p5 = Parameters.NextParameterAsInteger(CurConfig[CurRow - 1].p5);

void Cmd_SetText(CommandParameter &Parameters)
  int CurRowText = Parameters.NextParameter();
  if (CurRowText != -1 && CurRowText <= Rows)
    PString array(CurConfig[CurRowText - 1].p1, sizeof(CurConfig[CurRowText - 1].p1));
    String NewValue = Parameters.NextParameter();
    if (NewValue != NULL)
void Cmd_StartConfigTransfer(CommandParameter &Parameters)
  CurrentRow = 1; //By setting current row to 1 it will begin requesting row data from MegunoLink

void Cmd_ShowParameters(CommandParameter &Parameters)

/*----------------------Main Program---------------------------*/
void setup()

  Serial.println(F("  "));
  Serial.println(F("      MatrixTest"));
  SerialCommandHandler.AddCommand(F("Table"), Cmd_GetProcessTableRow);
  SerialCommandHandler.AddCommand(F("SetText"), Cmd_SetText);
  SerialCommandHandler.AddCommand(F("StartCfgXfer"), Cmd_StartConfigTransfer);
  SerialCommandHandler.AddCommand(F("ShowParameters"), Cmd_ShowParameters);

void loop()

  // This rate limits the row requests to MegunoLink. One every 100mS. 
  // This prevents the microcontroller from being overwhelmed.
  if (RequestRowTimer.TimePassed_Milliseconds(100))
    if (CurrentRow <= Rows)
      char buffer1[10];
      PString array(buffer1, sizeof(buffer1)); //Initialise PString object
      MyPanel.CallCommand(array); //This sends the request message
      char buffer[4];
      PString cmd(buffer, sizeof(buffer));
      MyPanel.CallCommand(cmd); //This sends the request message

void RequestParameters()
  Serial.println(F("Requesting parameters"));

// Print out all of the rows in the current config
void DumpCurConfig()
  for (int i = 0; i < Rows; i++)
    Serial.print(i + 1); Serial.print("\t");
    Serial.print(NewValue[i]); Serial.print("\t");
    Serial.print(CurConfig[i].p2); Serial.print("\t");
    Serial.print(CurConfig[i].p3); Serial.print("\t");
    Serial.print(CurConfig[i].p4); Serial.print("\t");

Re: RequestAMatrix Example Modifications

Posted: Sat Jan 23, 2021 10:42 pm
by philr
Hi, here is an example showing how this could work.
(14.65 KiB) Downloaded 558 times
In this I have replaced the last column with Name and included some sample names. Check it out and see if this helps you make progress.


Re: RequestAMatrix Example Modifications

Posted: Sun Jan 24, 2021 2:03 pm
by tabear
Thanks philr for the very timely response. It worked perfectly when I rearranged per your file. Now I need to compare my original with my modified to figure out what I was doing wrong. Thanks again !