极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 18119|回复: 0

在pcDuino上安装可燃气传感器

[复制链接]
发表于 2013-12-20 10:09:07 | 显示全部楼层 |阅读模式
LinkSprite有一款可燃气传感器Shield。我们只需要把它安装到pcDuino上就Okay了。
                                                                               
               
       
                       
                                                                                                                             
我们需要利用github来获得pcDuino上面的Arduino编程风格的API。
如果你使用的pcDuino没有安装过git, 我们需要安装git:
$sudo apt-get install git



然后,我们用刚刚安装的git来获取pcDuino上面的Arduino编程风格的API:
ubuntu@ubuntu:~$ git clone http://www.github.com/pcduino/c_enviroment

C代码:
/* 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=%d\n", sensorValue);
}
}

以上代码,也可以在这里(MQ2)下载。


修改\test\Makefile:
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是新加程序。
再打开命令终端编译库文件:
ubuntu@ubuntu:~$ cd c_enviroment
ubuntu@ubuntu:~/c_enviroment $ make


                                                                                在 test 目录下面运行:
$sudo ./MQ2
当我们在传感器旁边点燃打火机,我们可以观察到读数立刻上升。

               
       
                       







回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-19 21:43 , Processed in 0.040860 second(s), 17 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表