MCP3008 Analog/SPI chip, for example MQ smoke/gas/carbon sensor or voltage reading.

Moderator: leecollings

Post Reply
User avatar
ILoveIOT
Posts: 59
Joined: Sunday 25 March 2018 17:47
Target OS: Linux
Domoticz version: 2020.2
Location: NL
Contact:

MCP3008 Analog/SPI chip, for example MQ smoke/gas/carbon sensor or voltage reading.

Post by ILoveIOT »

#!/bin/bash
#
# /root/scripts/mcp3008/mcp3008.sh
#
# Tested on : Orange PI PC, with MQ-2 and MQ-7 Sensor with MCP3008 analog chip, logic converters for the 5v to 3.3v conversion
# Date : 07-04-2021
# Version : 00,00.00,0a0.2
#
# Created by ILoveIOT 2021
# Updated by ILoveIOT 2022
#
# I Updated the kernel and I could not get this working again, back to old kernel
"Linux 5.8.16-sunxi #20.08.14 SMP Tue Oct 20 22:15:32 CEST 2020 armv7l GNU/Linux"
# Kernel module where loaded, /boot/ArmbianEnv.txt was fine, but no spi device with "ls /dev/sp*" should be like "/dev/spidev0.0"
check before you try.
#
############################################################################################################################

INFO="MCP3008 Analog/SPI chip, for example MQ smoke/gas/carbon sensor or voltage reading.

This script will execute the /root/scripts/mqsensor/readmcp3008 and put the output to a file,
get the value's from the output file, show them on console if needed, and send them to Domoticz, this is super simple, easy to change.

There is no analog port on the PI, so you can use this sensor with a trigger port (digital) or like this where you get the actual value of the sensor, trough the analog MCP3008 chip and logic converter (3.3v PI VS 5V sensor) mcp3008 chip sends a value of 0-1024/0v-3.3v.

You can make a simpel alarm with blocky Domoticz, and send a email when for example the value hits 200 or more.

For console use : /root/scripts/mcp3008/mcp3008.sh
For background use : /root/scripts/mcp3008/mcp3008.sh >> /dev/null 2>&1 &
For all the info from the mcp3008 : /root/scripts/mcp3008/readmcp3008 all (maybe you need to recompile the *.c file)
For all the generated info : cat /root/scripts/mcp3008/mcp3008.output.txt

1. Change the Domoticz IP & Port (see below)
2. Add/Change the acording Domoticz IDX's and channels (see below)
3. Optional : Change the working directory, where you wanna place the files
4. /boot/ArmbianEnv.txt
-. overlays=analog-codec i2c0 i2c1 i2c2 spdif-out spi-spidev w1-gpio
-. param_spidev_spi_bus=0
-. param_spidev_max_freq=100000000"

mcp3008.zip
(15.16 KiB) Downloaded 78 times
mcp3008.png
mcp3008.png (97.01 KiB) Viewed 1501 times
mcp3008.domoticz.png
mcp3008.domoticz.png (25.43 KiB) Viewed 1501 times
1x OPI PC 5.8.16 Debian 10, MiniDNLA,SMD230,EpEver,MPD,800GB,Wiegand,7 temps,DHT,32/64 I/O,2022.1
2x OPI PC 4.19.25 Debian 9, MPD,7 temps,16/32 I/O,BMP,4.10717
1x IntelNUC 5.10 Debian 10, 2TB,DalyBMS,2023.1
3x ESPEasy NodeMCU V3, 16/16 I/O
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests