Skip to main content
3 of 4
edited title
tlfong01
  • 4.8k
  • 3
  • 11
  • 24

Using Rpi circuit python and MCP3008 ADC to read Flame Sensor data

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.

Documentation: https://pyreos.com/wp-content/uploads/2020/11/Pyreos-Analog-TO-Flame-Sensor-One-Channel.pdf

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.

Questions:

  1. How do I setup the read from the ADC within the 8-10hz range?
  2. 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"?
  3. Is the frequency setup basically the loop speed of Python or the spi.max_speed_hz option?
  4. Am I converting the raw ADC values correctly using numpy interp?
  5. If the sensor has a max 10hz frequency then I need to double that for my sample rate?
  6. 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[1]&3) << 8) + adc[2]
  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)