I have an IR pyroelectic flame sensor which detects flames within the 8-10hz of flame flicker. I am new to the ADC world so any help is very appreciated.
I have the py0573 which has a bandpass filter for CO2 spectrum. According to the company's algorithm recommendation, I basically need to plot/detect FFT (Fast Fourier transform) bins from the 5-15hz frequency to determine a "flame" exists on the FOV of the sensor.
In order for me to read the signal from the half-rail, I installed a MCP3008 to my RPi model 4 and set the signal to CH0 of the ADC. I also included a .1uf decoupling capacitor.
Using the below code, I am able to get some readings from the sensor, but I am unsure if this sampling rate is setup correctly or not.
- How do I setup the read from the ADC within the 8-10hz range?
- Is there a way to plot this with FFT? Do I need FFT or can I determine the total sum values from ADC to indicate a "flame"?
- Is the frequency setup basically the loop speed of Python or the spi.max_speed_hz option?
- Am I converting the raw ADC values correctly using numpy interp?
- If the sensor has a max 10hz frequency then I need to double that for my sample rate?
- Should I be using Adafruit's adafruit-circuitpython-mcp3xxx package instead?
With the below code, I am able to see the values change when I light a flicker match but its a bit inconsistent and only changes when the flame is flickering and not when its still.
import spidev from numpy import interp import time import datetime from datetime import timedelta # Start SPI connection spi = spidev.SpiDev() # Created an object spi.open(0,0) # Read MCP3008 data def analogInput(channel, hz): spi.max_speed_hz = hz adc = spi.xfer2([1,(8+channel)<<4,0]) data = ((adc&3) << 8) + adc return data data_list=list() init_time = datetime.datetime.now() while True: output1 = analogInput(0, 1000000) output1 = interp(output1, [0, 1023], [0, 100]) data_list.append(output1) if init_time < datetime.datetime.now() - timedelta(seconds=2): print("min" + str(min(data_list))) print("max" + str(max(data_list))) print("avg" + str(sum(data_list)/len(data_list))) data_list=list() init_time = datetime.datetime.now() time.sleep(.001)