Issues with RPC Communication Between M7 and M4 on Arduino Giga R1

Hello everyone,

I am working on a project using the Arduino Giga R1, where I need to establish communication between the M7 and M4 processors. My goal is to have the M4 processor read values from four pressure sensors, process the data, and then send the values to the M7 processor. The M7 processor should then display these values—currently via the serial interface, but later through a graphical interface using LVGL.

The problem I am facing is that I am unable to transmit multiple integer values simultaneously using the RPC function. I have already tried different approaches, but none have worked as expected.

M4 Code:

#include <Arduino.h>
#include <RPC.h>

int counter = 0;
char pressure_string[30];

void setup() {
  RPC.bind("get_pressure", get_pressure);
}

void loop() {
}

char *get_pressure() {
  int values[4] = { 1000, 150, 1200, 300};

  int current_pressure_melting_coarse = int(values[0] + counter);
  int current_pressure_melting_fine = int(values[1] + counter);
  int current_pressure_tower_coarse = int(values[2] + counter);
  int current_pressure_tower_fine = int(values[3] + counter);

  counter++;

  snprintf(pressure_string, sizeof(pressure_string), "%d,%d,%d,%d",
            		current_pressure_melting_coarse, current_pressure_melting_fine, current_pressure_tower_coarse, current_pressure_tower_fine);
  
  return pressure_string;
}

M7 Code:

#include <Arduino.h>
#include <RPC.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <MsgPack.h>

int current_pressure_melting_coarse = 0;
int current_pressure_melting_fine = 0;
int current_pressure_tower_coarse = 0;
int current_pressure_tower_fine = 0;

void setup() {
  RPC.begin();
  Serial.begin(9600);
}

void loop() {
  getPressure();
  Serial.print("Melting Pressure coarse: ");
  Serial.println(current_pressure_melting_coarse);
  Serial.print("Melting Pressure fine: ");
  Serial.println(current_pressure_melting_fine);
  Serial.print("Tower Pressure coarse: ");
  Serial.println(current_pressure_tower_coarse);
  Serial.print("Tower Pressure fine: ");
  Serial.println(current_pressure_tower_fine);
  delay(1000);
}

void getPressure() {
  String data = String(RPC.call("get_pressure"));

  int lastIndex = 0;
  float values[4];
  int index = 0;
  for (int i = 0; i < data.length(); i++) {
    if (data[i] == ',') {
      String value = data.substring(lastIndex, i);
      values[index] = value.toFloat();
      index++;
      lastIndex = i + 1;
    }
  }
  // Letzten Wert auch hinzufügen
  values[index] = data.substring(lastIndex).toFloat();

  current_pressure_melting_coarse = values[0].as<int>();
  current_pressure_melting_fine = values[1].as<int>();
  current_pressure_tower_coarse = values[2].as<int>();
  current_pressure_tower_fine = values[3].as<int>();
}

I would appreciate any advice or suggestions on how to properly send and receive multiple integer values between the two cores using RPC.

Thanks in advance for your help!

What other methods have you tried?

This may require a couple of interim steps to prove that all is working as expected. For example, have you tried making sure you can at least receive a single integer value.

If this works, you then have the option of using a long data type to merge two integer values. Can this long value for retrieved etc.

I'm guessing that as the size of string is undefined it won't work. Have you tried a fixed size data array. Then make two requests (say to receive part A and part B etc).