MCP3008 with Rasp Pi - Raspberry Pi Forums
hi,
quick background: working on project school , have raspberry pi 2 model b(ubuntu mate 1.10) , mcp3008, , of course analog output sensor. new both pi , python, , novice linux. partner better linux.
trying communicate mcp output sensor , save text file. know how save txt file, main problem having communicating mcp. have wired , used same code guy in link below(my code further down):
http://www.raspberrypi-spy.co.uk/2013/1 ... n-mcp3008/
difference have 1 sensor , trying view raw data @ least see now.
using python module , when run program error:
spi.open(0,0)
ioerror: [errno 2] no such file or directory
figured simple fix in enable isn't enabled(cause time library works fine). google searches have proven might simple can not figure out do. helpful sites seem on raspian , can't translate there ubuntu.
note: never wifi working raspian went ubuntu instead.
thank time,
sincerely,
raieth
code:
quick background: working on project school , have raspberry pi 2 model b(ubuntu mate 1.10) , mcp3008, , of course analog output sensor. new both pi , python, , novice linux. partner better linux.
trying communicate mcp output sensor , save text file. know how save txt file, main problem having communicating mcp. have wired , used same code guy in link below(my code further down):
http://www.raspberrypi-spy.co.uk/2013/1 ... n-mcp3008/
difference have 1 sensor , trying view raw data @ least see now.
using python module , when run program error:
spi.open(0,0)
ioerror: [errno 2] no such file or directory
figured simple fix in enable isn't enabled(cause time library works fine). google searches have proven might simple can not figure out do. helpful sites seem on raspian , can't translate there ubuntu.
note: never wifi working raspian went ubuntu instead.
thank time,
sincerely,
raieth
code:
code: select all
import time import spidev spi = spidev.spidev() spi.open(0,0) def readchannel(channel): adc = spi.xfer2([1,(8+channel)<<4,0]) data = ((adc[1]&3) << 8) + adc[2] return data #convert data voltage level def convertvolts(data,places): volts = (data*3.3)/float(1023) volts = round(volts,places) return volts #sensor channels cosensor = 0 delay = 3 while true: # read sensor data co_level = readchannel(cosensor) co_volts = convertvolts(co_level,2) print(co_level) print(co_volts) print("-----------------------") t.sleep(delay)
i suspect did not enable spi in raspi-config
raspberrypi
Comments
Post a Comment