RPC communication doesn't work

I'm trying to send the output of a BNO055 sensor through RPC, from the M7 core to the M4 core, but sometimes the code doesn't run, or there's no output in the Serial Monitor, since the M4 can't use the Serial Monitor, we print the output in the M7.

Here's the M4 code:

#include "Arduino.h"
#include "RPC.h"

void setup() {
  RPC.begin();
  Serial.begin(115200);

}

void loop() 
{
  int msg = RPC.call("getAngle_").as<int>();
  RPC.println(msg);
}

And the M7 code:


#include "Arduino.h"
#include "RPC.h"
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>

Adafruit_BNO055 bno = Adafruit_BNO055(55, 0x28);
int getAngle_()
{
  sensors_event_t event;
  bno.getEvent(&event);

  // Leitura bruta do eixo Z
  float angle= event.orientation.x;

  if (angle> 180) angulogiro -= 360;

  return angle;
}
void setup()
{
  RPC.begin();
  Serial.begin(115200);

  RPC.bind("getAngle_", getAngle_);
}

void loop()
{
  String buffer = "";
  while (RPC.available()) {
    buffer += (char)RPC.read();  // Fill the buffer with characters
  }
  if (buffer.length() > 0)
  {
   // Serial.println("a");
    Serial.print(buffer);
  }
}

You will have to write with much more details what you are doing.

Never seen such a task like sending data from a M7-core to a M4-core?

Is this a dual microcontroller-board that has two microprocessor-cores?

Are these two microcontroller-baords?

What is the exact type of this one dual microcontroller or two microcontroller-boards?

I’m using an Arduino Giga R1, it’s one board that has two microprocessors.

I did a quick research and found that the RPC-function needs to be bind.

If you look up here
https://docs.arduino.cc/tutorials/giga-r1-wifi/giga-dual-core/

I would take the demo-code there as the starting point
and then modify the working demo-code in small steps.

I did bind the function in the setup, and I wrote this code based on the example from the actual arduino docs.

The Guide to GIGA R1 Dual Cores

writes
The

Serial.print()

command only works on the M7-core.
In order to print values on the M4, we need to: Use

RPC.println()

on the M4. This will print the values to the RPC1 stream. Use

RPC.available()

and

RPC.read()

Now your M4-code does

I would do much smaller modifications to the code.
first step zero modification.
Does this code-example work on your board
M4-Sketch

#include <RPC.h>

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

void loop() {
  RPC.println("Printed from M4 core");
  delay(1000);
}

M7-sketch

#include <RPC.h>

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

void loop() {
  String buffer = "";
  while (RPC.available()) {
    buffer += (char)RPC.read();  // Fill the buffer with characters
  }
  if (buffer.length() > 0) {
    Serial.print(buffer);
  }
}

If this demo-code that is 100,000% the demo-code.
And if this demo-code does not work you know:
there is a different and very basic problem which must be solved first.

If it does work I would do a tiny small modification which would be counting up a variable
in the M4-core
M4-Sketch

#include <RPC.h>
int myInt = 0;

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

void loop() {
  myInt++;
  RPC.print("Printed from M4 core myInt=");  // intentionally FIXED text to make sure that SOME bytes are printed for SURE
  RPC.println(myInt);
  delay(1000);
}

Your M4-code does only

Which could be one problem that variable "msg" could - for whatever reason -
be "empty" or holding a not printable character
possible that using Serial.begin(115200); in your M4-Code is causing the problem.

The Demo-code does NOT have a Serial.begin(115200); in the M4-code

what do you mean by RPC?

the Arduino Giga guide explains it

Remote Procedure Call (RPC)

RPC is a method that allows programs to make requests to programs located elsewhere. It is based on the client-server model (also referred to as caller/callee), where the client makes a request to the server.

An RPC is a synchronous operation, and while a request is being made from the caller to another system, the operation is suspended. On return of the results, the operation is resumed.

The server side then performs the subroutine on request, and suspends any other operation as well. After it sends the result to the client, it resumes its operation, while waiting for another request.

sounds more like a communications mechanism the way it's described by, and used by the OP

the code below suggests it's a replacement for Serial. I don't see any code to associate the RPC on the processor with some other processor or task on another processor

and not unusually, the receive buffer is processed regardless if anything is received.

It looks similar because RPCClass inherits from the Stream class:
RPC.h:

class RPCClass : public Stream, public rpc::detail::dispatcher {

I think that happens in the begin() function, but I haven't dug through the library code deeply enough to understand exactly how.

1 Like