Coder Social home page Coder Social logo

Comments (4)

JustusRijke avatar JustusRijke commented on June 27, 2024

Fixed by adding #include "Wire.h" and Wire.begin();.

from arduino_machinecontrol.

JustusRijke avatar JustusRijke commented on June 27, 2024

However... when trying to run this on both cores (CM4 and CM7), with the code shown below, there seems to be interference. When activating input 1, output 1 flickers. I suppose this is because of the communication with the I/O expander happening from both cores simultaneously.

What is the proper way to access the I/O expander from both cores?

CM4:

#include <Arduino_MachineControl.h>
#include "Wire.h"

using namespace machinecontrol;

void setup()
{
  Wire.begin();
  digital_inputs.init();
}

void loop()
{
   digital_outputs.set(1, digital_inputs.read(DIN_READ_CH_PIN_01));
}

CM7:

#include <Arduino_MachineControl.h>
#include "Wire.h"

using namespace machinecontrol;

void setup()
{
  Wire.begin();
  digital_inputs.init();
  LL_RCC_ForceCM4Boot();
}

void loop()
{
   digital_outputs.set(0, digital_inputs.read(DIN_READ_CH_PIN_00));
}

from arduino_machinecontrol.

facchinm avatar facchinm commented on June 27, 2024

Hi @JustusRijke ,
if you need to perform operations on the same bus (in this case i2c) from both cores you need to manually implement a mutex-like RPC function (or a shared variable) to signal that the peripheral is being used. A possible snippet would be similar to

CM7

bool status = false;
bool getBusstatus() { return status; }
void setBusStatus(bool _status) { status = _status; }
RPC.bind("getStatus", getBusstatus);
RPC.bind("setStatus", setBusStatus);

...
// on i2c operation
if (status == false) {
  status = true;
  // do the operation
  status = false;
}

CM4

// on i2c operation
if (RPC.call("getStatus").as<bool>()) {
  RPC.call("setStatus", true);
  // do the real operation
  RPC.call("setStatus", false);
}

from arduino_machinecontrol.

JustusRijke avatar JustusRijke commented on June 27, 2024

Hi Martino,
First of all: thanks for your support.

RPC seems quite slow. The test code below should toggle an output every 1 ms, but in reality this is 5 ms.
So we used shared memory to communicate between cores, this works fine.

Original problem solved, closing the issue.

CM4:

#include <Arduino_MachineControl.h>
#include "Wire.h"
#include "RPC.h"

using namespace std::chrono_literals;
using namespace events;
using namespace machinecontrol;

EventQueue event_queue;

void task()
{
  digital_outputs.set(7, RPC.call("get_toggle").as<bool>()); // this takes approx. 5 ms
}

void setup()
{
  Wire.begin();
  RPC.begin();
  event_queue.call_every(1ms, &task);
  event_queue.dispatch_forever();
}

void loop()
{
}

CM7:

#include <Arduino_MachineControl.h>
#include "RPC.h"

bool toggle;

bool get_toggle()
{
  toggle = !toggle;
  return toggle;
}

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

void loop()
{
}

from arduino_machinecontrol.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.