Hello everyone,
I’m trying to put a simple cycle time sensor together which will be used in conjuction with a cnc machine (thats the plan).
The code worked for a while until I tried to incorporate a circular buffer for a running average. I then went back to the previously working version, but I get constant reboots with the following exception:
Exception (0):
epc1=0x40106889 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
ctx: cont
sp: 3ffefd90 end: 3ffeff80 offset: 01a0
stack>>>
3ffeff30: 00000000 3ffeef54 3ffeef4c 40203c04
3ffeff40: 402010d2 000003e8 000003e8 40203dd8
3ffeff50: 3fffdad0 00000000 3ffeef4c 402030c5
3ffeff60: 3fffdad0 00000000 3ffeef4c 402045a0
3ffeff70: feefeffe feefeffe 3ffeef60 40100718
<<<stack<<<
I’m pretty new to the coding practices of Blynk, so I might be doing something very stupid, but I think I need to periodically send the “sensor” data (every second or every few seconds). That is why I need the interrupt, I need to measure the time when a signal is detected (this signal will range from 0 to 4000 pulses per hour max which should be slow enough for the code to run in the interrupt routine).
ESP8266 (Wemos D1 mini)
Android version 2.17.2
Blynk server
v0.5.0
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This example runs directly on ESP8266 chip.
Note: This requires ESP8266 support package:
https://github.com/esp8266/Arduino
Please be sure to select the right ESP8266 module
in the Tools -> Board menu!
Change WiFi ssid, pass, and Blynk auth token to run :)
Feel free to apply it to any other example. It's simple!
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxx";
char ssid[] = "xxxx";
char pass[] = "xxxx";
#define cyclePin 15
volatile int elapsedTime = 0;
volatile int previousTime = 0;
unsigned long averageCycle = 0;
BlynkTimer timer;
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(LED_BUILTIN,OUTPUT);
digitalWrite(LED_BUILTIN,HIGH);
pinMode(cyclePin, INPUT);
attachInterrupt(digitalPinToInterrupt(15), cycle_ISR, RISING);
// Setup a function to be called every second
timer.setInterval(1000L, myTimerEvent);
delay(1000);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
}
void myTimerEvent()
{
Blynk.virtualWrite(V0, 3600000/elapsedTime);
digitalWrite(LED_BUILTIN,LOW);
delay(10);
digitalWrite(LED_BUILTIN,HIGH);
}
void cycle_ISR()
{
unsigned long currentTime = millis();
elapsedTime = currentTime - previousTime;
previousTime = currentTime;
}