Commit 294c3bfc authored by Nocturnal42's avatar Nocturnal42

Added support for the MCP3208 ADC

parent 4bc45786
......@@ -8,7 +8,7 @@ import subprocess, os, sys
import RPi.GPIO as GPIO
from interfaces.DHT22 import DHT22
from interfaces.BMP085 import BMP085
from interfaces.MCP3008 import MCP3008, AQSensor, LightSensor
from interfaces.MCP3008 import MCP3008, MCP3208, AQSensor, LightSensor
from interfaces.PiPlate import Adafruit_CharLCDPlate
import curses
......
......@@ -15,7 +15,8 @@ class AQSensor:
if result == 0:
resistance = 0
else:
resistance = (1550/result - 1)*self.pullup
vin = ((2**self.adc.ADCBITS) / 3.3) * 5
resistance = (vin/result - 1)*self.pullup
return resistance
def get_NO2(self):
......
......@@ -7,6 +7,7 @@ class MCP3008:
SPIMISO = 0
SPICLK = 0
SPICS = 0
ADCBITS=10
def __init__(self, mosipin, misopin, clkpin, cspin):
GPIO.setmode(GPIO.BCM)
......@@ -42,7 +43,7 @@ class MCP3008:
adcout = 0
# read in one empty bit, one null bit and 10 ADC bits
for i in range(12):
for i in range(self.ADCBITS+1):
GPIO.output(self.SPICLK, True)
GPIO.output(self.SPICLK, False)
adcout <<= 1
......@@ -50,6 +51,4 @@ class MCP3008:
adcout |= 0x1
GPIO.output(self.SPICS, True)
adcout /= 2 # first bit is 'null' so drop it
return adcout
#!/usr/bin/python
from MCP3008 import MCP3008
class MCP3208(MCP3008):
ADCBITS=12
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment