Page 1 of 1

MQ-2 sensor and main library issue

Posted: Sun Mar 20, 2016 10:23 am
by Obel
Hi Guys

I am working on MQ2-sesnsor
So i fallow this article when it comes to connection

Then I have install that special spi dev-library from here

Code: Select all

pi@WeatherPi ~/py-spidev $ sudo python setup.py install
running install
running build
running build_ext
running install_lib
running install_egg_info
Removing /usr/local/lib/python2.7/dist-packages/spidev-3.2.egg-info
Writing /usr/local/lib/python2.7/dist-packages/spidev-3.2.egg-info
Ian trying to run this script

Code: Select all

# mq_x_smoke_sensor.py - print smoke level
# (c) BotBook.com - Karvinen, Karvinen, Valtokari
import time
import botbook_mcp3002 as mcp   # <1>

smokeLevel = 0

def readSmokeLevel():
        global smokeLevel
        smokeLevel = mcp.readAnalog()   # <2>

def main():
  while True:   # <3>
    readSmokeLevel()    # <4>
    print("Current smoke level is %i " % smokeLevel)    # <5>
    if smokeLevel > 120:
      print("Smoke detected")
    time.sleep(0.5) # s

if __name__ == "__main__":
  main()
I receive fallowing errors:

Code: Select all

pi@WeatherPi ~/smokesens $ sudo python ./mq_x_smoke_sensor.py
Traceback (most recent call last):
  File "./mq_x_smoke_sensor.py", line 21, in <module>
    main()
  File "./mq_x_smoke_sensor.py", line 14, in main
    readSmokeLevel()    # <4>
  File "./mq_x_smoke_sensor.py", line 10, in readSmokeLevel
    smokeLevel = mcp.readAnalog()       # <2>
  File "/home/pi/smokesens/botbook_mcp3002.py", line 19, in readAnalog
    spi.open(0, device)
IOError: [Errno 2] No such file or directory
I putt all required file in to same catalogue

Code: Select all

pi@WeatherPi ~/smokesens $ ls
botbook_mcp3002.py  botbook_mcp3002.pyc  mq_x_smoke_sensor.py
Any idea why this is not working I believe the script can't detect thespi library what iam installing on the beginning

Re: MQ-2 sensor and main library issue

Posted: Sun Mar 20, 2016 11:41 am
by joan
Do the SPI devices exist?

What does ls -l /dev/spi* report?

Re: MQ-2 sensor and main library issue

Posted: Sun Mar 20, 2016 12:10 pm
by Obel
Solved

I didn't turn on SPI devices via raspi-config