在pcDuino上安装可燃气传感器
LinkSprite有一款可燃气传感器Shield。我们只需要把它安装到pcDuino上就Okay了。http://cnlearn.linksprite.com/wp-content/uploads/2013/10/800px-MQ2_1.jpg
我们需要利用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) < -o $@
MQ2: MQ2.c
$(CC) $(LIBS) $(INCS) < -o $@
adc_test: adc_test.c
$(CC) $(LIBS) $(INCS) < -o $@
pwm_test: pwm_test.c
$(CC) $(LIBS) $(INCS) < -o $@
spi_test: spi_test.c
$(CC) $(LIBS) $(INCS) < -o $@
adxl345_test: adxl345_test.c
$(CC) < -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
当我们在传感器旁边点燃打火机,我们可以观察到读数立刻上升。
http://cnlearn.linksprite.com/wp-content/uploads/2013/10/800px-MQ2_2.jpg
页:
[1]