Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By walders
#90168 Hi, I am using an interupt to catch motion events through a slotted infrared type sensor (spped / tacho sensor). The code works reliably and fine catching each event apart from this one error case. on startup, there is garbage on the serial monitor. On hitting the reset button and activating the slotted sensor at the same time, the sketch runs normally with events being displayed on the serial monitoring screen

Any advice on how to solve or sidestep this startup issue greatly appreciated, thank you.

Sensor connected to D3, Like the one here Image


void ICACHE_RAM_ATTR isr()
unsigned long now = micros();
float pulselength;
pulseNow = now;
int averagepulse;
int totalsample = 0;

if ((pulseNow - pulseThen) > resolution)
Serial.print("numPulses ");
Serial.print(" ");
pulselength = (float)(pulseNow - pulseThen) /1000000;
if( count < sample )
keeppulse[count] = pulselength;
count = 0;
Serial.print("Average in a sample of ");
Serial.print(" is ");
for( int x=0; (x<sample); x++ ) {
totalsample += (int)keeppulse[x];
averagepulse = totalsample/sample;

pulseThen = pulseNow;

void setup()
pinMode(3, OUTPUT); //probe output on pin 3
attachInterrupt(0, isr, RISING);
numPulses = 0; // prime the system to start a new reading
User avatar
By walders
#90178 Thanks :) I've set 74800 baud to see the output. It's problematic as on initil startup the sensor events are not recognised by the esp.

this is the output:

nothing on initial startup, sensor events not recognised.

pressing reset: ets Jan 8 2013,rst cause:2, boot mode:(1,7), , sensor events not recognised.

pressing reset with sensor activated: sensor events recognised with the following

load 0x4010f000, len 3584, room 16
tail 0
chksum 0xb0
csum 0xb0
Sensor Events

numPulses 1 4.70
User avatar
By QuickFix
#90180 GPIO3 is serial RX (high at boot) and when using both serial in code as defining other use for a GPIO1 or GPIO3 might give conflicts.
Have you tried using another GPIO (I'm not sure what board you're using)?