Uncategorized

mcp3008 adc flame sensor

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

Ask QuestionAsked todayActive todayViewed 23 times1

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)
    


sensorspianalog-to-digitalmcp3008ShareEditFollowClose 2Flagedited 3 hours agotlfong013,51633 gold badges77 silver badges2222 bronze badgesasked 9 hours agoGeorgetheCat1122 bronze badges

  • (1) Question “How do I setup the read from the ADC within the 8-10hz range?” – Answer, you just do conversions at a rate you want, up 200k samples per second. So eg if you want to have 10 conversions per second, you just read ADC conversion results 10 times per second, or repeat every 100mS. In other words, you just do one “single shot” conversion any time you want, within the limit of 200k conversion per second. – tlfong01 8 hours ago   
  • (2) Your samples per second is independent of SPI frequency. For example, you can do 50 conversions per second, but your SPI frequency can be 100kHz, or 400kHz. – tlfong01 8 hours ago   
  • (3) The conversion timing is a bit complicated. You can read the following for more details:Rpi Reading MCP3008 10 bit ADC Result Problem Asked 1 year, 9 months ago Active 1 year, 2 months ago Viewed 621 times raspberrypi.stackexchange.com/questions/98867/…. – tlfong01 8 hours ago   
  • (4) But if you are using python, then you don’t need to worry about the timing, if you are within limit of 200k conversions per second, and using appropriate SPI frequency. – tlfong01 8 hours ago   
  • (5) Using python, you can store the results, say a 500 conversions time frame in an python array/list and then use NumPy or other tools to do simple statistics like min, max, avg, or digital signal processing such as FFT etc. – tlfong01 8 hours ago    
  • 1So whats is the SPI frequency setting doing exactly? Is that just the speed the RPI can read from the ADC or should I limit the frequency to 10hz for the flicker of the frame? – GeorgetheCat 8 hours ago
  • 1For FFT, I can store each conversion from the loop in a list, but how can I plot FFT per frequency range from 8-10hz? – GeorgetheCat 8 hours ago
  • (6) You can set SPI freq to default 100kHz. There is no point setting it higher, because you sample rate is low. (7) You can eg do 3k conversion in 20 sec, and pass the results to a DSP package to do FFT. (8) Actually you can do higher sample rates than just 10 samples per second. (9) I would suggest to try 1k sps to see if you can get meaningful results. (10) For flame flickering, I don’t think you need to use FFT, for two reasons: (a) Flame flicker is aperiodic, no fundamental or higher harmonics are there for you to study, (b) you can just use MatPlotLib to plot and do simple analysis. – tlfong01 8 hours ago    
  • 1Ok I updated the code to 100kHz and updated to sample every .001s to dump into a list. The basic statistics give print every 2 seconds, and so far the avg hovers around 50value and when i flicker a flame, the min drops to around 40 while the simultaneously the max jumps to around 60 or more. Is it odd for the sensor to drop and also increase in values at the same time? – GeorgetheCat 7 hours ago 
  • Ah, I know too little about flame sensor to understand your advanced questions. I do have an R, G, B colour sensor, but I think it is different from flame sensor. Anyway, perhaps I can read the datasheet and see what else I can help. – tlfong01 7 hours ago   
  • Please confirm the following: (11) You are using Vcc = 5V for both flame sensor and MCP3008. (12) Do you have a scope to display the waveform of flame sensor Channel 1? (13) Do you have a list of newbie friendly references for your project? – tlfong01 6 hours ago   
  • 1I am using the 3.3v not 5v. I though 5v would kill RPI using MCP3008. I do not have a scope. I do not have any other documentation other than what I shared. And company shared some FFT algorithm but its very vague. Do I need any resistor values? I also have a .1uf capacitor to decouple. Do I need an external amplifier even though it has an internal one? – GeorgetheCat 6 hours ago 
  • (14) Are you talking about this appliaction note? AN0125 Application Note: Sample Flame Detection Ratio Based Algorithm – Pyreos pyreos.com/wp-content/uploads/2019/07/…. You need to understanding the underlying maths of FFT before you understanding the procedure to detect flames. At least you should first try to use MCP3008 to get the raw results and plot them as shown in the app notes. (15) Using Vcc = 3V3 to power MCP3008 is OK but not optimal. A better way is to convert Rpi 3V3 SPI signals to 5V0 (Using HCT125 or TSX0104 etc). – tlfong01 4 hours ago   
  • (16) You might also like to read the Pyreos evaluation kits user manual to get a rough idea of what they are doing: Pyreos Evaluation Kits: pyreos.com/evaluation-kits – tlfong01 4 hours ago   
  • (17) FFT is a difficult to understand. But luckily we actually don’t nee to understand what is going on inside the FFT process (of transforming from the “time domain” to “frequency domain”, blah, blah, blah, … ) We only need to know how to use FFT. I am a huge fan of Oliver Heaviside, who says the following: “Am I to refuse to eat because I do not fully understand the mechanism of digestion? – Oliver Heaviside” en.wikiquote.org/wiki/Oliver_Heaviside. So let us blindly follow the vendor’s application note and do some trials and errors! 🙂 – tlfong01 19 mins ago    

Add a comment

1 Answer

ActiveOldestVotes0

Question

How to use Rpi python MCP3008 ADC to help analyse flame flicker signals?


pyreos schematic

Notes

  1. A py0573 bandpass filter is used for CO2 spectrum
  2. To determine if a “flame” exists on the FOV of the sensor, the vendor recommends a plot/detect FFT bins from the 5-15hz frequency.

Electrical Characteristics

  1. Max. Voltage (+V) = 8.0 V
  2. Min. Voltage (+V) = 2.7 V
  3. Output voltage normalised around mid-rail
  4. Time Constant = ~12 ms
  5. Op-Amp with 10 GΩ feedback resistor

Answer

Part 1 – Using MCP3008 to read raw data

First thing first is to prepare 1,024 flame sensor readings for FFT. (See Reference 6 and Appendix B below for more details.)

FFT Raw Data

/ to continue , …


References

(1) Thin Film Pyroelectric Flame Sensor – PY-ITV-FLAME–TO39(2+1) R5.2 – Pyreos

(2) MCP3008 SPI 2.7V 8-Channel 10-Bit A/D Converters – MicroChip

(3) Rpi Reading MCP3008 10 bit ADC Result Problem – Rpi SE 2019may22

(4) Flame Detector – Wikipedia

(5) Tips To Select The Right Flame Detector – Edward Naranjo, Emerson Automation Solutions 2019mar06

(6) AN0125 Application Note: Sample Flame Detection Ratio Based Algorithm – Pyreos

(7) Pyreos Evaulation Kit


Appendices

Appendix A – Pyroelectric Flame Sensor PY-ITV Datasheet Summary

Introduction

The Pyreos thin film pyroelectric infrared flame detectors offer exceptionally high responsivity, a wide field of view of typically 100° (*subject to filter band pass specification) and class leading rapid recovery from thermal and electrical shocks (<1 second downtime). This current mode sensor has excellent signal to noise at the signature 8-10 Hz flicker range of a flame, and can provide accurate discrimination of flame sources in triple IR flame detection systems.

The sensor element is built into a low noise circuit that has an internal CMOS op amp with a 10GΩ feedback resistor outputting a voltage signal centred around half the supply rail.


Sensor Characteristics

Filter aperture = 5.2 mm x 4.2 mm

Element size = 1000 µm x 1000 µm

Package = TO39

Responsivity = 1 150,000 V/W

D* = 3.5 x 108 cm√Hz/ W

Noise = Mean 70 µV√Hz

Field of View = Typical 100°


Electrical Characteristics

Max. Voltage (+V) = 8.0 V

Min. Voltage (+V) = 2.7 V

Output voltage normalised around mid-rail

Time Constant = ~12 ms

Operating Temperature = -40 to +85 °C

Storage Temperature = -40 to +110 °C

Op-Amp with 10 GΩ feedback resistor

Filter As per Filters Available table


Appendix B – Package Info and Internal Schematic

package info and schematic

Appendix C – Example Raw Data for FFT

example raw data

/ to continue, …


ShareEditDeleteFlagedited 27 mins agoanswered 7 hours agotlfong013,51633 gold badges77 silver badges2222 bronze badgesAdd a comment

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.