I wish to monitor the RPM of a generator (usually 3600 RPM, 60 Hertz)
Gotta convert this script to:
work with EITHER a Pi OR an Esp12-e,
then post the RPM/frequency to a variable and
send the variable to Cayenne.
I do NOT need a LCD display!
No photosensor will be used!
The input will be a 10Kohm impedance pickup coil (or a dynamic microphone),
about 1V peak to peak.
Use the output (10 bit) from a MCP3008
Here’s code for a “different” type of freq counter. I need to modify this- heavily!
// Compute the frequency of an AC input using a MCP3008
#include <LiquidCrystal.h>
#define PMS_PIN 2 // Pin for signal from Photomicrosensor
#define LED_PIN 13 //Using Arduino's Internal LED; just as an indicator
boolean counted=false;
int t1=0,t2=0;
int hits=0;
int rps=0;
LiquidCrystal lcd(9, 8, 7, 6, 5, 4);
void setup(){
pinMode(PMS_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
lcd.begin(16, 2);
}
void loop(){
t2 = millis();
if(t2 >= (t1 + 1000)){
rps = hits;
hits = 0;
t1=t2;
lcd.clear();
lcd.print("RPM: ");
lcd.print(rps*60);
}
if(digitalRead(PMS_PIN) == HIGH){
if(!counted){
counted = true;
hits++;
}
} else {
counted = false;
}
digitalWrite(LED_PIN, digitalRead(PMS_PIN));
}
The existing code won’t quite work- it’s for a different kind of application.
I need to monitor the FREQUENCY of a generator output (60Hz or 3600 RPM). I have a few unused MCP3008 inputs- so…let’s use one of them!
Think of it as…a challenge.
The output of a MCP3008 is a10 bit “NUM” type, 0 to 1023, 512 is the zero crossover.
Input to the MCP3008 will be an inductive (coil) pickup, about 10Kohm impedance. About 1 volt peak to peak, 60 Hz (usually). A “null” input to the MCP3008 would be output as 512 (or close to it). I will bias the input at 1.65 volts (50% of 3.3 volt full scale), and isolate with a .1 microfarad DC blocking capacitor.
Sorry, I forgot to reply here. You’re not going to be able to do this with a Pi using Cayenne. You shouldn’t do this using python because of the possibility of Python waiting for the OS to give it time to run. You might be able to use C but I don’t have any experience there.
Your best bet is to use Arduino since there is no OS to wait on. It looks like the code you posed is actually for an Arduino, so if you want to go down that path I can try to help you there.
sure- @adam I’m game…
Arduino it is!
so, as far as a sensor(s)-
I was hoping to use an inductive A/C CURRENT clamp type sensor. basically, a 10k ohm coil, -fitted around an AC “current carrying” #12 wire,
a la AmpProbe
After it’s digitized in some way, the AC cycles can be counted.
If I can use the MCP300x on the ESP12 chip, that would be great.
I haven’t even tried using the SPI bus on the '12 yet.
I can, of course, measure voltage using the MCP300x, too-
I’m looking at the SMT version of the chip now-
tiny is GOOD!
SPI simple enough with the ESP-12. Have a search around for some sample code and get familiar with reading voltages (AA battery will be a good test). I won’t be able to test anything on mine until tomorrow.
I’m fer sure gonna put the voltage dividers on this PC board,
The monitored 120/240 VAC AC INPUT
-will be the secondary of a
12VAC (or whatever) wall wart transformer.
(I avoid bringing in high voltage on a monitoring device).
AND the Dc isolation ceramic capacitor,
-and I’m gonna include 8 biasing resistors
to bias the MCP voltage inputs to 50% (512), (1.65Vdc).
And, of course, 2 start/stop relays.
Definitely using the 78SR3.3 voltage regulator!
With luck, I can make everything fit
on a 1/3 PCB footprint (Pi Zero).
This would yield (9) PC boards-
I’m pretty sure I cannot make it fit on a 1/4 PC board.
-not enough real estate.
with the freq counter- logic
When NewSample < OldSample, clock= true
When NewSample > OldSample, clock = false
then sum update once per second?
The variable “NewSample” being
ONE of the (8) 10-bit outputs
from the MCP3008