Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Mod Moved Comments To Chat
edited title
Link
tlfong01
  • 4.8k
  • 3
  • 11
  • 24

Using Rpi circuit python and MCP3008 ADC to read Flame Sensorflame (RGB) sensor data for FFT analysis

edited title
Link
tlfong01
  • 4.8k
  • 3
  • 11
  • 24

Flame Sensor Analog Using Rpi circuit python and MCP3008 ADC signal processing at 5-10hzto read Flame Sensor data

added 468 characters in body
Source Link
 
import spidev 
from numpy import interp
fromimport time
import datetime
from datetime import sleeptimedelta

# 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, 201000000)
    output1 = interp(output1, [0, 1023], [0, 100])
    print
    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(.5001)
    

import spidev 
from numpy import interp
from time import sleep

# 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

while True:
    output1 = analogInput(0, 20)
    output1 = interp(output1, [0, 1023], [0, 100])
    print(output1)
    sleep(.5)

 
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)
    

Source Link
Loading