de-bouncing an S0 energy sensor on a pi

I hooked up a submeter to my fuseboard some time ago, and not too long ago I started to read it with a Pi Zero. 
However every now and again I would get a crazy reading, and from logging I would see bouncing. I would see interrupts where wiringpi would report the input as 0, and then again as 0, with no change to 1 inbetween. 
I read up on debouncing and how the Pi is meant to do this, and also how some people have handled it in code by removing large deviations. 
 In my case, the solution has been to simply add logic in an encompassing if statement, to ignore interrupts where the pin is the same value as the last interrupt, and only count interrupts where the pin is a different like this 



if (digitalRead(PIN) == last_interrupt_pin) { 
	printf("Bounce ! Last Pin = %d This Pin = %d\n",
		digitalRead(PIN), 
		last_interrupt_pin); 
}

Comments

Popular posts from this blog

Baileys liquor Chocolate Chip and Cream desert

using t1n1wall, opnsense or pfsense on Google Compute Engine GCE

nginx decode base64 url for use with imgproxy