• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
Previous Next

Install flammable gas sensor on pcDuino

Posted by: Alvin Jin , March 27, 2014

[vc_row][vc_column][vc_column_text]LinkSprite has a flammable gas sensor shield. In this tutorial, we will look at how to use it on pcDuino.[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column width=”1/1″][vc_tour][vc_tab title=”Wiring Diagram” tab_id=”1395884460-1-1″][vc_column_text]1[/vc_column_text][/vc_tab][vc_tab tab_id=”1395884460-2-64″ title=”pcDuino gets an Arduino style API”][vc_column_text]We can grab the Arduino style API on pcDuino from github.

If your pcDuino doesn’t have it installed,  we need to install git using:

$sudo apt-get install git

Then, we can download Arduino style API on pcDuino by git.

ubuntu@ubuntu:~$ git clone http://www.github.com/pcduino/c_enviroment

[/vc_column_text][/vc_tab][vc_tab title=”C code” tab_id=”1395896860204-2-3″][vc_column_text]

/* Sample code for MQ2 Smoke Sensor Shield for pcDuino
05/09/2013
**********************************************/
#include <core.h>

const int analogInPin =0;

int sensorValue = 0;        // value read from the pot
int count1;

void setup() {
pinMode(7, OUTPUT);
}

void loop() {

count1++;
// read the analog in value:
sensorValue = analogRead(analogInPin);

if(count1==3000)
{
count1=0;

printf("sensor=%dn", sensorValue);
}
}

The above code, also can be downloaded from ( MQ2)[/vc_column_text][/vc_tab][vc_tab title=”Compile” tab_id=”1395897312675-3-1″][vc_column_text]Modify testMakefile:

LIBS=-L../../sample/core -larduino -lspi
INCS=-I../../sample/core/include
TARGET=../../sample/test

OBJS = io_test adc_test pwm_test spi_test adxl345_test MQ2

all: $(OBJS)
@mkdir -p $(TARGET)
@mv $(OBJS) $(TARGET)

io_test: io_test.c
$(CC) $(LIBS) $(INCS) &lt; -o $@

MQ2: MQ2.c
$(CC) $(LIBS) $(INCS) &lt; -o $@

adc_test: adc_test.c
$(CC) $(LIBS) $(INCS) &lt; -o $@

pwm_test: pwm_test.c
$(CC) $(LIBS) $(INCS) &lt; -o $@

spi_test: spi_test.c
$(CC) $(LIBS) $(INCS) &lt; -o $@

adxl345_test: adxl345_test.c
$(CC) &lt; -o $@
clean:
@for i in $(OBJS); do rm -f $(TARGET)/$$i; done

MQ2: MQ2.c is a new program

To open a terminal compiled library file:

ubuntu@ubuntu:~$ cd c_enviroment

ubuntu@ubuntu:~/c_enviroment $ make

[/vc_column_text][/vc_tab][vc_tab title=”Run” tab_id=”1395897360656-4-8″][vc_column_text]Running in the test directory:

$sudo ./MQ2

When we ignite the lighter by the side of the sensor, we can observe the readings immediately rise.

800px-MQ2_2[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]

Tags: ADC

Share!
Tweet

Alvin Jin

About the author

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors