Comments (4)
Fixed by adding #include "Wire.h"
and Wire.begin();
.
from arduino_machinecontrol.
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.
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.
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)
- InterruptIn error: irq channel conflict when BLE.begin() is called. HOT 1
- Serial.print doesn´t work HOT 1
- PT1000 isn´t compatible HOT 3
- digital_programmables.init() crash HOT 3
- Mode for analog in channels should be set individually HOT 1
- RS-485 full duplex example disables the receiver when sending data HOT 4
- More USB host examples HOT 2
- Initializing the IO Expander breaks the serial (Micro-USB) interface HOT 1
- IOExpander: digital_inputs.readAll() Out of sequence? HOT 1
- "Device attach failed" USB Host in the portenta machine control HOT 5
- PMC freeze when using ArduinoBLE with Arduino_MachineControl included. HOT 7
- Add GitHub Actions workflow to synchronise with shared repository labels
- Allow full bank reads from IO expander HOT 4
- Which is the latest official release of this library? HOT 2
- RTD reading too slow HOT 3
- Dual Core Example/Functionality HOT 7
- Reading state of digital_output pins HOT 1
- Analog output malfunction on AO2 HOT 2
- How to use Hardware interrupts on Portenta H7 machine control HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduino_machinecontrol.