Using Megunolink Check Box with ShieldBuddy

Support forum for MegunoLink
Post Reply
shields
Posts: 10
Joined: Sat Jan 06, 2018 7:10 pm

Sat Jan 05, 2019 7:05 am

Hi Phil,

I'm trying to use Megunolink with a multicore processor called the Hitex ShieldBuddy. This Arduino board uses the three core Infineon processor running at 200 Mhz. I made a simple sketch and *.mlx file to study how to transfer commands and data between the cores. I use core0 to handle the slow serial port operations while the time critical number crunching is on core 1. The files are pasted below. For some reason I couldn't attach the *.mlx file but I did attach a screen shot of the interface.

Previously you mentioned that I could add a function argument to tell the Megunolink code to use SerialASC instead of the Serial which is more common for typical Arduino boards such as the Due, Uno etc. The fix was to use declaration statements such as,

TimePlot WaterLevelPlot("Water Levels",SerialASC);

where the serial port to use is explicitly stated. This worked great but I have now moved on to trying to use a check box to control events in core 1. I place shared variables in the LMU of the processor which I'm told gives fast access to any of the three cores. I am able to change the variable "y" (see attached *.ino for definition of "y") in core1 and send it across the serial port to the host using core 0. What I'm having trouble with is using a check box to change how "y" is evaluated in core 1. The function Cmd_TestCheckBoxEvent(CommandParameter &Parameters) is not being called when I toggle the check box. I was hoping you could give me some pointers on how to get this to work. I think I set up the SerialCommandHandler properly but it might not be using the SerialASC port. Thanks in advance for any help you can provide.

-Joel

P.S. *.ino file below:

/*** Don't worry, the normal Arduino setup() and loop() are below this block! ***/
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <Metro.h>
#include "MegunoLink.h"
#include "CommandHandler.h"

#define PI 3.14159265358979
#define Serial SerialASC

/* LMU uninitialised data */
StartOfUninitialised_LMURam_Variables
/* Put your LMU RAM fast access variables that have no initial values here e.g. uint32 LMU_var; */
EndOfUninitialised_LMURam_Variables

/* LMU uninitialised data */
StartOfInitialised_LMURam_Variables
/* Put your LMU RAM fast access variables that have an initial value here e.g. uint32 LMU_var_init = 1; */
float y = 0.0;
boolean TEST_CONTROL_STATE = false;
EndOfInitialised_LMURam_Variables

/* If you do not care where variables end up, declare them here! */




/*** Core 0 ***/
CommandHandler<> SerialCommandHandler;

Metro ISRMetroCore0 = Metro(1000); // 1 sec, 1000 ms

const int CORE0HB = 2;
int CORE0HB_flag = 0;

void setup() {
// put your setup code for core 0 here, to run once:
Serial.begin(115200);

SerialCommandHandler.SetDefaultHandler(Cmd_Unknown);
SerialCommandHandler.AddCommand(F("TestCheckBoxEvent"), Cmd_TestCheckBoxEvent);

pinMode(CORE0HB, OUTPUT);
digitalWrite(CORE0HB,HIGH); // start out high
}


void loop() {

SerialCommandHandler.Process();

// put your main code for core 0 here, to run repeatedly:
if (ISRMetroCore0.check() == 1)
{

Serial.println("y =");
Serial.println(y,DEC);

CORE0HB_flag = !CORE0HB_flag;
digitalWrite(CORE0HB,CORE0HB_flag);
}

}

void Cmd_Unknown()
{
Serial.println(F("I don't understand"));
}

void Cmd_TestCheckBoxEvent(CommandParameter &Parameters)
{
TEST_CONTROL_STATE = Parameters.NextParameterAsInteger();
Serial.println("Hello from inside Cmd_TestCheckBoxEvent");
Serial.println("TEST_CONTROL_STATE =");
Serial.println(TEST_CONTROL_STATE,DEC);
}

/*** Core 1 ***/

Metro ISRMetroCore1 = Metro(100); // 100 ms

/* CPU1 Uninitialised Data */
StartOfUninitialised_CPU1_Variables
/* Put your CPU1 fast access variables that have no initial values here e.g. uint32 CPU1_var; */
EndOfUninitialised_CPU1_Variables

/* CPU1 Initialised Data */
StartOfInitialised_CPU1_Variables
/* Put your CPU1 fast access variables that have an initial value here e.g. uint32 CPU1_var_init = 1; */
const int CORE1HB = 22;
int CORE1HB_flag = 0;
float t = 0.0;
EndOfInitialised_CPU1_Variables

void setup1() {
// put your setup code for core 1 here, to run once:
pinMode(CORE1HB, OUTPUT);
digitalWrite(CORE1HB,HIGH); // start out high
}


void loop1() {
// put your main code for core 1 here, to run repeatedly:
if (ISRMetroCore1.check() == 1)
{

if (TEST_CONTROL_STATE)
{
y = sin(0.1*((2.0*PI)/1.0)*t);
}
else
{
y = 0.001*t;
}
t = t + 0.1;

CORE1HB_flag = !CORE1HB_flag;
digitalWrite(CORE1HB,CORE1HB_flag);
}

}



/*** Core 2 ***/

/* CPU2 Uninitialised Data */
StartOfUninitialised_CPU2_Variables
/* Put your CPU2 fast access variables that have no initial values here e.g. uint32 CPU2_var; */
EndOfUninitialised_CPU2_Variables

/* CPU2 Initialised Data */
StartOfInitialised_CPU2_Variables
/* Put your CPU2 fast access variables that have an initial value here e.g. uint32 CPU2_var_init = 1; */
EndOfInitialised_CPU2_Variables


void setup2() {
// put your setup code for core 2 here, to run once:


}


void loop2() {
// put your main code for core 2 here, to run repeatedly:


}
Attachments
Screenshot (1).png
Screen shot showing check box setup
Screenshot (1).png (382.29 KiB) Viewed 969 times
philr
Posts: 279
Joined: Mon May 26, 2014 10:58 am

Wed Jan 09, 2019 8:13 am

Hi Joel, looks like a pretty impressive device. I've never used one before. Did you have any luck getting it going?

Cheers
Phil
shields
Posts: 10
Joined: Sat Jan 06, 2018 7:10 pm

Wed Jan 30, 2019 7:29 am

Hi Phil,

Yeah it is a pretty awesome processor. It has all sorts of peripherals designed for automotive applications that I haven't even explored.

I took a look at the SetParameters example to see if I could get that to work. Turns our that I can use:

CommandHandler<> SerialCommandHandler(SerialASC);

to get this example to work. Not sure why this works, I'm not much of a C++ programmer ... at all. Maybe you could give me some insite into what's going on?

Also I noticed my Megunalink installation has two install directories

C:\Users\shields\Documents\Arduino\libraries\MegunoLink

and

C:\Program Files (x86)\Number Eight Innovation\MegunoLink\Libraries\Arduino

Do I need both of these?

-Joel
philr
Posts: 279
Joined: Mon May 26, 2014 10:58 am

Sat Feb 02, 2019 1:44 am

Yeah its in two places because we have to install it first to be able to copy it to a useful location for the user. If its not causing any harm its safe to leave both.

Yep the reason that works is because you can add arguments to customize it a little. Pretty lucky you discovered it ;)

You can read more about it here
https://www.megunolink.com/documentatio ... d-handler/

Look in the "Example Serial Command Handler declarations" section. It allows you to change the serial port, the start and stop characters etc.

Cheers
Phil
Post Reply