New to Q and looking to understand more of the bridge and using it in a thread. My issue is the bridge.call or notify. when used in the task below the board hangs. I believe I have setup and called the correct functions. Any pointers would be great!
Notes:
- With bridge call commented out, all tasks run fine and code works.
- Notify or call have the same issue.
- Added a delay to see if the issue with calling bridge too fast was the cause. no luck.
- because the MCU hangs but the MPU stays active I do believe the issue is with the MCU part of the code.
- I am using the board directly to code and test. Monitor, Keyboard and mouse attached.
MCU code:
Main sketch - Starts 4 tasks and 2 queues
#include "queue.h"
/* size of stack area used by each thread */
#define STACKSIZE 512
/* scheduling priority used by each thread */
#define PRIORITY 7
void setup() {
blink3_setup();
MPU_setup();
LEDMatrix_setup();
enc_setup();
}
// Queues
K_MSGQ_DEFINE(qData,sizeof(int32_t[2]),4,1);
K_MSGQ_DEFINE(QmpuData,sizeof(int32_t[2]),4,1);
// Threads
K_THREAD_DEFINE(blink3_id, STACKSIZE, tBlink3, NULL, NULL, NULL, PRIORITY, 0, 0);
K_THREAD_DEFINE(MPUsend_id, STACKSIZE, tMPUSend, NULL, NULL, NULL, PRIORITY, 0, 0);
K_THREAD_DEFINE(LEDM_id, STACKSIZE, tLEDmatrix, NULL, NULL, NULL, PRIORITY, 0, 0);
K_THREAD_DEFINE(ENC_id, STACKSIZE, tEncoder, NULL, NULL, NULL, PRIORITY, 0, 0);
void loop() {
// Let Magic happen
}
Task that calls bridge.call or notify both yield the same result
#include "Arduino_RouterBridge.h"
void MPU_setup() {
Bridge.begin();
}
void tMPUSend() {
struct Package_data mcuData;
while(1){
//int ret = k_msgq_get(&QmpuData,&mcuData, K_MSEC(4000));
mcuData.pos = 66;
mcuData.speed = 55;
int ret = 0;
if (ret == 0){
Bridge.call("From_MCU", mcuData.pos, mcuData.speed);
}else{ //no message in queue
Bridge.call("From_MCU", 0, 0);
}
delay(500); //debug delay
}
}
MPU code:
Just a basic print something if it gets a call
from arduino.app_utils import *
import time
from arduino.app_utils import App, Bridge
def loop():
time.sleep(1)
def From_MCU(pos: int32, speed: int32)):
print("hello from mcu")
Bridge.provide("From_MCU", From_MCU)
App.run(user_loop=loop)
Pointing to any documents or examples that cover threading with the bridge might be helpful. I have review a fair bit of posts.