Commit d3eebcd2 authored by Tom Hartley's avatar Tom Hartley

Merge pull request #1 from Nocturnal42/master

MCP3208 support
parents d6531056 a867d171
......@@ -3,11 +3,12 @@
from time import sleep
import datetime
import eeml
import eeml.datastream
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
......@@ -34,7 +35,7 @@ def mainUpload(stdscr):
LCDENABLED = 1
DEBUG = 1
LOGGER = 1
if LCDENABLED:
lcd = Adafruit_CharLCDPlate.Adafruit_CharLCDPlate(busnum=bus)
lcd.clear()
......@@ -51,6 +52,8 @@ def mainUpload(stdscr):
DHTPin = 4
if not DEBUG:
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(22,GPIO.OUT)
GPIO.setup(21,GPIO.OUT)
......@@ -67,17 +70,17 @@ def mainUpload(stdscr):
UVADC = 4
dht = DHT22.DHT22(DHTPin)
bmp = BMP085.BMP085()
bmp = BMP085.BMP085(bus=bus)
adc = MCP3008.MCP3008(SPIMOSI,SPIMISO,SPICLK,SPICS)
airSensor = AQSensor.AQSensor(adc,AQADC,22000)
airSensor = AQSensor.AQSensor(adc,AQADC,pullup=22000)
lightSensor = LightSensor.LightSensor(adc,LightADC)
uvSensor = LightSensor.LightSensor(adc,UVADC)
no2Sensor = AQSensor.AQSensor(adc,NO2ADC,90000,10000)
coSensor = AQSensor.AQSensor(adc,COADC,190000,100000)
API_KEY = 'AaBeQoyPHcnC8rwEN2YJJbEKrJOSAKxBa0hEN08rblZUZz0g'
FEED = 85080
API_KEY = 'YOURAPIKEY'
FEED = 00000
API_URL = '/v2/feeds/{feednum}.xml' .format(feednum=FEED)
failCount = 0
......@@ -117,7 +120,7 @@ def mainUpload(stdscr):
if LOGGER:
#Attempt to submit the data to cosm
try:
pac = eeml.Pachube(API_URL, API_KEY)
pac = eeml.datastream.Cosm(API_URL, API_KEY)
for dp in datas:
if dp.uploadID!=-1:
pac.update([eeml.Data(dp.uploadID, dp.roundedValue())])
......
......@@ -8,9 +8,9 @@ import smbus
class Adafruit_I2C :
def __init__(self, address, bus=smbus.SMBus(0), debug=False):
def __init__(self, address, bus=0, debug=False):
self.address = address
self.bus = bus
self.bus = smbus.SMBus(bus)
self.debug = debug
def reverseByteOrder(self, data):
......
......@@ -48,8 +48,8 @@ class BMP085 :
_cal_MD = 0
# Constructor
def __init__(self, address=0x77, mode=1, debug=False):
self.i2c = Adafruit_I2C(address)
def __init__(self, address=0x77, mode=1, bus=0, debug=False):
self.i2c = Adafruit_I2C(address, bus)
self.address = address
self.debug = debug
......
......@@ -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