last day (25 days later) » 

6:51 PM
1
Q: Using Rpi python and MCP3008 ADC to read flame (RGB) sensor data for FFT analysis

GeorgetheCatI 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 bandpa...

 
(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.
(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.
(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/….
(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.
(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.
 
So 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?
For FFT, I can store each conversion from the loop in a list, but how can I plot FFT per frequency range from 8-10hz?
 
(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.
 
Ok 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?
 
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.
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?
 
6:51 PM
I 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?
 
(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).
(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
(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! :)
(18) I am basically trying to answer the first of your six questions. Just now I skimmed you code and found that you use the numpy.interp numpy.org/doc/stable/reference/generated/numpy.interp.html. You seem to use this interp to get the flame sensor data, but it seems that you are not talking to MCP3008 at all. So I would say a qualified yes to your sixth question, on whether to use AdaFruit MCP3008 library or not. I actually never use AdaFruit libraries, because I DIY my own code for flexibility. But I do suggest use to use MCP3008 libraries, whether from AdaFruit or not.
(19) You might like to try this PyPi package, but I have not used it before.: pypi.org/project/mcp3008
 
I found what I believe to be exactly what the vendor does using numpy. First you get the raw data, then hanning window, then FFT. numpy.org/doc/stable/reference/generated/numpy.hamming.html Now why is the raw data count 1024, is there a reason for that? Should I use the Adafruit package, loop through 1024 to put into a list, then perform the numpy operations?
 
Quick replies. (1) Yes, AN0125 explains everything, including what is described by your first sentence. (2) Summary section of the app note answers your question about FFT window size. (3) I prefer the PyPi package over AdaFruit circuit python based on M0, which is not very compatible with Rpi. (Or you might like to consider the US$4 Rpi M0 Pico Thonny v3.3.3 MicroPython v1.14, which I am now playing) (4) One other reason I prefer MCP3201 over MCP3008 is that MCP3008 resolution is only 10-bit, too low even for my Micky Mouse toy projects.
 
For the raw data before hanning window, I am curious why they have negative values? Would you have an idea as to why the 1024 points of raw data include negative values? I imagine it is because of the half-rail having voltage increases and decreases but I did not observe that with Adafruits raw data outputs. Just values from 20,000 to 40,000
 
 
2 hours later…
9:06 PM
Do I need to convert the raw ADC values somehow? It seems int he Pyreos algorithm documentation they have raw values that range from -10k - 10k. It seems Adafruits package does not have negative outputs. I am getting values from 20k-40k with flickering flame. Do I need to convert based on bits?
 

  last day (25 days later) »