-->
Page 1 of 2

Speed sensor error condition on startup

PostPosted: Tue Jan 12, 2021 7:31 am
by walders
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

Code:

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(numPulses+1);
Serial.print(" ");
pulselength = (float)(pulseNow - pulseThen) /1000000;
Serial.print(pulselength);
Serial.print("\n");
if( count < sample )
{
keeppulse[count] = pulselength;
count++;
}
else
{
count = 0;
Serial.print("Average in a sample of ");
Serial.print(sample+1);
Serial.print(" is ");
for( int x=0; (x<sample); x++ ) {
totalsample += (int)keeppulse[x];
}
averagepulse = totalsample/sample;
Serial.print(averagepulse);
Serial.print("\n\n");
}

pulseThen = pulseNow;
++numPulses;
}
}

void setup()
{
Serial.begin(19200);
pinMode(3, OUTPUT); //probe output on pin 3
attachInterrupt(0, isr, RISING);
numPulses = 0; // prime the system to start a new reading
}

Re: Speed sensor error condition on startup

PostPosted: Tue Jan 12, 2021 9:19 pm
by davydnorris
This would be the ESP's own start up messages. The ESP puts out startup messages on the serial line at 76800 baud initially so this will look like garbage to a monitor connect at 19200

Re: Speed sensor error condition on startup

PostPosted: Wed Jan 13, 2021 3:35 am
by walders
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
v2843a5ac
~ld
Sensor Events

numPulses 1 4.70

Re: Speed sensor error condition on startup

PostPosted: Wed Jan 13, 2021 6:13 am
by QuickFix
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)?