User Tools

Site Tools


Navigation Menu

Flight-Control

<
Previous mounth
05/01/2024
>
Next mounth
SMTWFTS
18
28
28
29
29
30
30
01
01
020304
1905060708091011
2012131415161718
2119202122232425
2226272829303101









Hot Projects

SEEDStack

SEEDStack - Open 3D printable seed/sprouting systemDIY Food Hacking

UCSSPM

UCSSPM - Unified Clear-Sky Solar Prediction ModelOpen Solar Power

picoReflow

picoReflow - DIY PID Reflow Oven Controller based on RaspberryPiDIY Reflow Soldering

PiGI

PiGI - DIY Geiger Counter based on RaspberryPiRasPi Geiger Counter

DIY ARA-2000

Active Wideband Receiver Antenna for SDR - ARA-2000Wideband Antenna

DSpace

DSPace - Map everythingMap everything!

Mission-Tags

This is an old revision of the document!


Spark-Core Hacking: Read MQ2 sensor data

The aquarius needs a galley in order to prepare and cook food but due to unforeseen personal circumstances I had to invest into this infrastructure way before than it was necessary since the base trailer for the LM isn't available yet. So I've started to build a prototype kitchen with all that is needed for functional and fun food hacking. One of the primary energy carriers selected for cooking is gas. That can be either LPG (Propane/Butane) or Methane (delivered by utility gas lines).

Since gases can be a tricky and risky energy carriers and their combustion also creates potentially harmful by products like Carbon-Monoxide (CO), it seemed prudent to have an autonomous environmental monitoring and gas leakage detection system, in order to minimize the risk of an undetected leak, which could lead to potentially harmful explosions or a high concentration of CO, which could also lead to unconsciousness and death.

To cover everything, a whole team of sensors will monitor specific environmental targets and their data will then be fused and used as a basis for air quality and threat management to either proactively start to vent air or send out warnings via mail/audio/visual.

Sensor Target Description Mount
MQ7 CO Carbon-monoxide (Combustion product) Top/Ceiling
MQ4 CH4 Methane (Natural Gas) Top/Ceiling
MQ2 C3H8 Propane (Camping Gas Mix) Bottom/Floor
MQ2 C4H10 Butane (Camping Gas Mix) Bottom/Floor
DS18S20 Temperature Room/Air Temperature Monitoring Top

The ideal platform for this project seemed to be a spark-core, since it's a low power device which has to be always on, to justify its existence. The Spark-Core docs claim 50mA typical current consumption but it clocked in here with 140mA (using Tinker Firmware logged and averaged for 24h). After setting up a local spark cloud and claiming the first core it was time to tinker with it. The default firmware (called tinker) already get's you started quickly with no fuss: You can read and control all digital and analog out and inputs so with just a quick GNUPlot/watch hack I could monitor what a MQ2 sensor detects over the period of one evening, without even having to hack on the firmware itself (fast bootstrapping to get something done, as a prototype/concept/learning).

I'll try to release the local spark cloud howto soon, to get an easy start with spark-cores without having to use the official spark-cloud and thereby rendering control of the IoT to basically any government “agency” or other potentially evil institutions, groups or people in the world. In the meantime, you can follow these procedures with the official cloud server too, you only need to install Spark-CLI and add your global cloud account settings to its configuration.

Hardware

  • Spark-Core + SC Breadboard
  • Sainsmart MQ2 el cheapo sensor board
  • Two Resistors (Voltage Divider R1/R2: 10k/33k

Software

MQ2 Sensor data via spark-core over a period of one evening

#!/bin/bash

while :
do
    VAL=$(spark call 1234567890abcdef analogread "A0")
    TS=$(date +%s)
    echo "${TS} ${VAL}"
    echo "${TS} ${VAL}" >> mq2-test.txt
    sleep 1
done;

$ vi mq2-gnuplot.parm
set terminal pngcairo background "#383734" size 900,500 enhanced font 'Arimo,12'
set output "mq2-chart.png"

set title "Mapping MQ2 Sensor Data over one evening" textcolor ls 2 font 'Arial,16'
set grid
set lmargin 9 

set style line 1 lc rgb '#75890c' lt 1 lw 0.5 pt 7 ps 0.75 
set style line 2 lt 2 lc rgb "#d8d3c5" pt 6

set ylabel "ADC Read Value" tc ls 2 offset 1,0

set xtics textcolor linestyle 2 rotate
set ytics textcolor linestyle 1
set tics nomirror

set xdata time
set timefmt "%s"
set format x "%H:%M"

set border linewidth 1 linestyle 2  

unset key

plot "mq2-test.txt" using 1:2 with linespoints ls 1

quit
$ watch --interval=1 gnuplot mq2-gnuplot.parm

You can use Ristretto or any other image viewer to look at the resulting png. Ristretto automatcally redraws the image, as soon as gnuplot put's out another one.