Thanks for the feedback, I tested your idea, first by simply printing numbers between sections of code to narrow down where it is crashing. Interestingly enough, with this code, it will not crash… I’ve left it for 10 minutes and nothing. It gets weirder.
-
With the new Serial.println()'s, it does not crash DURING “particle serial monitor” (up to 10 minutes) A notable observation is that my lidar sampling is reduced by 50% when doing this.
-
With the new Serial.println()'s, if I ctr+c “particle serial monitor” it will crash within 30-60 seconds… So essentially I can’t watch it crash.
-
If I comment the Serial.println()'s out, it crashes within 30 seconds DURING “particle serial monitor” like it used to.
This has become some kind of schrodinger’s cat situation.
#include <RPLidar.h>
byte LED = D0;
byte RLY1 = D1;
byte RPLIDAR_MOTOR = A3;
RPLidar lidar;
int points = 0;
uint32_t lastTime = millis() + 1000;
bool startBit;
void setup() {
Serial.begin();
pinMode(LED, OUTPUT);
pinMode(RLY1, OUTPUT);
pinMode(RPLIDAR_MOTOR, OUTPUT);
//settle
delay(3000);
lidar.begin(Serial1);
digitalWrite(LED, HIGH);
digitalWrite(RLY1, HIGH);
}
void rplidar_loop()
{
Serial.print("2");
if (IS_OK(lidar.waitPoint())) {
Serial.print("3");
//float distance = lidar.getCurrentPoint().distance; //distance value in mm unit
//float angle = lidar.getCurrentPoint().angle; //anglue value in degree
startBit = lidar.getCurrentPoint().startBit; //whether this point is belong to a new scan
Serial.print("4");
//byte quality = lidar.getCurrentPoint().quality; //quality of the current measurement
points += 1;
Serial.print("5");
if (startBit) {
Serial.print("new frame\n");
}
Serial.print("6");
if (millis() - lastTime > 1000) {
Serial.printf(" p%d\n", points);
points = 0;
lastTime = millis();
}
Serial.print("7");
} else {
Serial.print("r");
// reconnect
analogWrite(RPLIDAR_MOTOR, 0); //stop the rplidar motor
// try to detect RPLIDAR...
rplidar_response_device_info_t info;
if (IS_OK(lidar.getDeviceInfo(info, 100))) {
// detected...
lidar.startScan();
// start motor rotating at max allowed speed
analogWrite(RPLIDAR_MOTOR, 255);
delay(1000);
}
}
}
void loop() {
Serial.print("1");
rplidar_loop();
}
.
So in an attempt to see when the error is happening, I removed all of the random printing and only print the angle every time a new point is read. This also prevented the argon from crashing…
.
/*
* Project test
* Description:
* Author:
* Date:
*/
#include <RPLidar.h>
byte LED = D0;
byte RLY1 = D1;
byte RPLIDAR_MOTOR = A3;
RPLidar lidar;
int points = 0;
uint32_t lastTime = millis() + 1000;
bool startBit;
void setup() {
Serial.begin();
pinMode(LED, OUTPUT);
pinMode(RLY1, OUTPUT);
pinMode(RPLIDAR_MOTOR, OUTPUT);
//settle
delay(3000);
lidar.begin(Serial1);
digitalWrite(LED, HIGH);
digitalWrite(RLY1, HIGH);
}
void rplidar_loop()
{
if (IS_OK(lidar.waitPoint())) {
//float distance = lidar.getCurrentPoint().distance; //distance value in mm unit
float angle = lidar.getCurrentPoint().angle; //anglue value in degree
startBit = lidar.getCurrentPoint().startBit; //whether this point is belong to a new scan
//byte quality = lidar.getCurrentPoint().quality; //quality of the current measurement
points += 1;
if (startBit) {
Serial.print("new frame\n");
}
if (millis() - lastTime > 1000) {
Serial.printf(" p%d\n", points);
points = 0;
lastTime = millis();
}
Serial.printf("%f\n", angle);
} else {
// reconnect
analogWrite(RPLIDAR_MOTOR, 0); //stop the rplidar motor
// try to detect RPLIDAR...
rplidar_response_device_info_t info;
if (IS_OK(lidar.getDeviceInfo(info, 100))) {
// detected...
lidar.startScan();
// start motor rotating at max allowed speed
analogWrite(RPLIDAR_MOTOR, 255);
delay(1000);
}
}
}
void loop() {
rplidar_loop();
}
.
Based on the discovery that printing something every “point” prevents a crash, I removed the angle print() code and added a simple delay(1) during every point and it’s perfectly stable, no crashes (after 30 minutes of testing). Essentially, I’m doing something too fast.
This makes me think about how disabling Particle.cloud with SYSTEM_MODE(MANUAL) fixed the issue. It honestly feels like Particle cloud doesn’t like how fast I’m doing (something?) and is crashing. Maybe it has something to do with slamming Serial1 with data? Correlation does not imply causation, but all arrows are pointing in the direction of the cloud system.
It may be notable that commands like “particle serial mac” and “particle serial identify” timeout/error when running this code even though the void loop() is running & printing properly.