Wasn't going to jump in since @KurtE pretty much covered everything but over the last couple of days I have been running into an issue where all of sudden out of no where the Q will reboot and I have to close applab and reconnect, and once in a while I will get the following:
At this point I just close applab and restart applab and it works for a while and then it will crash again. ps have to power cycle the Q as well.
Here is the sketch that seems to generate the most reboots
/****************************************************
* Links
* https://toptechboy.com/9-axis-imu-lesson-10-making-a-tilt-compensated-compass-with-arduino/
* https://forums.adafruit.com/viewtopic.php?t=136640
*
******/
#include <Wire.h>
#include <LibPrintf.h>
/**************************************
* BNO055 *
*************************************/
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
/* Set the delay between fresh samples */
uint16_t BNO055_SAMPLERATE_DELAY_MS = 100;
// Check I2C device address and correct line below (by default address is 0x29 or 0x28)
// id, address
Adafruit_BNO055 bno = Adafruit_BNO055(55, 0x28, &Wire1);
#define MSGQ_MAX_MSGS 100
#define MSG_SIZE sizeof(struct sensor_msg)
struct sensor_msg {
uint32_t timestamp;
float roll;
float pitch;
float yaw;
float heading;
};
/*
* K_MSGQ_DEFINE:
* Parameters
* q_name Name of the message queue.
* q_msg_size Message size (in bytes).
* q_max_msgs Maximum number of messages that can be queued.
* q_align Alignment of the message queue's ring buffer (power of 2).
*/
K_MSGQ_DEFINE(bno055_msgq, MSG_SIZE, MSGQ_MAX_MSGS, 4);
K_THREAD_STACK_DEFINE(bno055_thread_stack_area, 1024);
static struct k_thread bno055_thread_data;
K_THREAD_STACK_DEFINE(odometry_thread_stack_area, 1024);
static struct k_thread odometry_thread_data;
void bno055_thread(void *dummy1, void *dummy2, void *dummy3)
{
/* Initialize sensor */
Serial.println("Orientation Sensor Test"); Serial.println("");
/* Initialise the sensor */
if (!bno.begin())
{
/* There was a problem detecting the BNO055 ... check your connections */
Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
while (1);
}
bno.setExtCrystalUse(true);
delay(1000);
while (1) {
struct sensor_msg msg;
//sensors_event_t event;
//bno.getEvent(&event);
imu::Vector<3> euler = bno.getVector(Adafruit_BNO055::VECTOR_EULER);
// Calculate heading
float heading = 0;
msg.timestamp = k_uptime_get_32();
msg.yaw = euler.x();
msg.roll = euler.y();
msg.pitch = euler.z();
msg.heading = 0;
int ret = k_msgq_put(&bno055_msgq, &msg, K_NO_WAIT);
if (ret != 0) {
Serial.println("Message queue full, dropping message");
}
delay(BNO055_SAMPLERATE_DELAY_MS);
}
}
void odometry_thread(void *dummy1, void *dummy2, void *dummy3)
{
struct sensor_msg msg;
while (1) {
int ret = k_msgq_get(&bno055_msgq, &msg, K_FOREVER);
if (ret == 0) {
printf("Uploading: time=%u roll=%f, pitch=%f, yaw=%f, heading=%f\r", msg.timestamp, msg.roll, msg.pitch, msg.yaw, msg.heading);
}
}
}
void setup() {
Serial.begin(115200);
delay(5000);
k_thread_create(&bno055_thread_data, bno055_thread_stack_area,
K_THREAD_STACK_SIZEOF(bno055_thread_stack_area),
bno055_thread, NULL, NULL, NULL,
7, 0, K_FOREVER);
k_thread_name_set(&bno055_thread_data, "bno055_thread");
k_thread_create(&odometry_thread_data, odometry_thread_stack_area,
K_THREAD_STACK_SIZEOF(odometry_thread_stack_area),
odometry_thread, NULL, NULL, NULL,
5, 0, K_FOREVER);
k_thread_name_set(&odometry_thread_data, "odometry_thread");
k_thread_start(&odometry_thread_data);
k_thread_start(&bno055_thread_data);
Serial.println("Example Started");
}
void loop() {
delayMicroseconds(100);
}