Author Topic: Oak constantly restarting (at least, according to the Particle dashboard)  (Read 2968 times)

micahwedemeyer

  • Newbie
  • *
  • Posts: 6
I'm in a state where it seems like my Oak is constantly restarting (see attached image of the particle dashboard). I'm unable to push new code to the Oak via the Arduino IDE.

The basic gist of my sketch (also attached) is to watch a piezo vibration sensor and then send a PWM signal to a tone buzzer when a hit is detected.

This has happened a couple times, and each time I've restored back to safe mode (via the P1 to GND jumper method). Even that is dicey, as resetting the WiFi setup seem pretty flakey and only works about half the time. Overall, I'm just really frustrated.

AFAIK, I'm using Firmware 1.0.5

Any ideas here?

PeterF

  • Hero Member
  • *****
  • Posts: 881
My gut feeling as far as the safe mode problems is that the safe mode firmware is probably not 1.0.5, as that doesn't update when you update the Oak board package on the Arduino IDE. Best way to rectify that problem at the moment is via a serial update of the firmware, or by doing a restore (but that takes longer and can be problematic). Hopefully there will be a way to force an OTA update/check of the safe mode firmware, but we're not there yet! Also, when you're in safe mode, you shouldn't need to reconfigure your wireless setup... you should see on the particle dashboard a few seconds after powering it up than the Oak is online, and in config mode, waiting for a new program. You can connect to the Oak with SoftAP if you want to change which network it connects to, but you don't need to if you're not changing that.

With the constant restarts, what happens with nothing connected to the Oak? Will it let you program it then? (indicating there is something wrong with the wiring) ... that is a problem! I tried this on my Oak with nothing connected, and I get the same online cycles you've been getting... hm....

Code: [Select]
[13:26:05] Device change: Oak4
[13:26:13] Event: spark/status - online
[13:26:36] Event: spark/status - online
[13:26:46] Event: spark/status - offline
[13:26:47] Event: spark/status - online
[13:27:11] Event: spark/status - online
[13:27:34] Event: spark/status - online

To stop the crashes/restarts, it appears you need to not use analogRead!!! Which isn't a very good option :(

i.e. changing line 33 of the code you provided to not use anaalogRead stops the restarts... but defeats the purpose of the code as well! I also added a second delay (100) so I could see the led blinking.

Code: [Select]
/******************************************************************************
Piezo_Vibration_Sensor.ino
Example sketch for SparkFun's Piezo Vibration Sensor
  (https://www.sparkfun.com/products/9197)
Jim Lindblom @ SparkFun Electronics
April 29, 2016

- Connect a 1Mohm resistor across the Piezo sensor's pins.
- Connect one leg of the Piezo to GND
- Connect the other leg of the piezo to A0

Vibrations on the Piezo sensor create voltags, which are sensed by the Arduino's
A0 pin. Check the serial monitor to view the voltage generated.

Development environment specifics:
Arduino 1.6.7
******************************************************************************/
const int PIEZO_PIN = A0; // Piezo output
const int PIEZO_LOWER_BOUND = 10; // Piezo values below this are ignored
const int BUZZER_PIN = 5;
const int LED_PIN = 1;

void setup()
{
  //Serial.begin(9600);
  pinMode(LED_PIN, OUTPUT);
  pinMode(BUZZER_PIN, OUTPUT);
}

void loop()
{
  // Read Piezo ADC value in, and convert it to a voltage
  int piezoADC = 100;//analogRead(PIEZO_PIN);

  if(piezoADC > PIEZO_LOWER_BOUND) {
    // Map the value to between 0 and 255 for PWM to the buzzer
    //int toneVal = map(piezoADC, 0, 1023, 0, 255);
    int toneVal = 100;

    // Fire up the buzzer
    analogWrite(BUZZER_PIN, toneVal);
    digitalWrite(LED_PIN, HIGH);
    delay(100);
    analogWrite(BUZZER_PIN, 0);
    digitalWrite(LED_PIN, LOW);
    delay(100);
  }
}

I'm currently reading a thread about AnalogRead on the ESP8266 causing resets, so I think it's a known bug that may or may not have been fixed...

I'm trying to work out how to use the following code as a workaround.

Code: [Select]
extern "C" {
#include "user_interface.h"
}

uint LDR_Value = 0; //Value of LDR (ADC)

LDR_Value=system_adc_read();


PeterF

  • Hero Member
  • *****
  • Posts: 881
Ok, unsurprisingly using the system_adc_read() function instead does nothing to fix the problem, as that is the code that is used internally when you use the AnalogRead() function on ESP8266 boards (per core_esp8266_wiring_analog.c).

However... and very strangely, I added a delay(10) after the analogRead, and that is all it needed to stop it from crashing... very peculiar!!

So just add a delay to after the analogRead(), and see if that fixes it for you. :)

Code: [Select]
void loop()
{
  // Read Piezo ADC value in, and convert it to a voltage
  int piezoADC = analogRead(PIEZO_PIN);
  delay(10); //delay seems to be needed to prevent WDT reset

https://github.com/esp8266/Arduino/issues/669

micahwedemeyer

  • Newbie
  • *
  • Posts: 6
Thanks! I'll definitely give the delay a try, once I can push code to the Oak. I'll also double check that dropping into safe mode (jumping P1 to GND) does not reset the Wifi settings. I didn't realize that.


micahwedemeyer

  • Newbie
  • *
  • Posts: 6
Putting the 10ms delay in there really seems to help. Now my little buzzer thingy plays when the analog sensor is tripped, just like it should.

This is big! I'm very close to a working prototype for my project.

Thanks for your help!