tests: added test for MQ-3 alcohol sensor driver
This commit is contained in:
parent
5bd6155ca6
commit
d3f207c8be
28
tests/driver_mq3/Makefile
Normal file
28
tests/driver_mq3/Makefile
Normal file
@ -0,0 +1,28 @@
|
||||
APPLICATION = driver_mq3
|
||||
include ../Makefile.tests_common
|
||||
|
||||
FEATURES_REQUIRED = periph_adc
|
||||
|
||||
# Define default pin mappings for some boards:
|
||||
ifneq (,$(filter stm32f4discovery,$(BOARD)))
|
||||
export MQ3_ADC ?= ADC_1
|
||||
export MQ3_CHAN ?= 0
|
||||
endif
|
||||
|
||||
USEMODULE += mq3
|
||||
USEMODULE += vtimer
|
||||
|
||||
ifneq (,$(MQ3_ADC))
|
||||
CFLAGS += -DMQ3_ADC=$(MQ3_ADC)
|
||||
else
|
||||
# set random default
|
||||
CFLAGS += -DMQ3_ADC=ADC_0
|
||||
endif
|
||||
ifneq (,$(MQ3_CHAN))
|
||||
CFLAGS += -DMQ3_CHAN=$(MQ3_CHAN)
|
||||
else
|
||||
# set random default
|
||||
CFLAGS += -DMQ3_CHAN=0
|
||||
endif
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
64
tests/driver_mq3/main.c
Normal file
64
tests/driver_mq3/main.c
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Freie Universität Berlin
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser General
|
||||
* Public License v2.1. See the file LICENSE in the top level directory for more
|
||||
* details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup tests
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Test application for the MQ-3 alcohol sensor driver
|
||||
*
|
||||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "vtimer.h"
|
||||
#include "mq3.h"
|
||||
#include "periph_conf.h"
|
||||
#include "periph/adc.h"
|
||||
|
||||
#ifndef MQ3_ADC
|
||||
#error "MQ3_ADC is not specified"
|
||||
#endif
|
||||
#ifndef MQ3_CHAN
|
||||
#error "MQ3_CHAN is not specified"
|
||||
#endif
|
||||
|
||||
int main(void)
|
||||
{
|
||||
mq3_t dev;
|
||||
int res;
|
||||
|
||||
puts("MQ-3 alcohol sensor test application\n");
|
||||
printf("Initializing MQ-3 sensor at ADC_%i, channel %i... ", MQ3_ADC, MQ3_CHAN);
|
||||
res = mq3_init(&dev, MQ3_ADC, MQ3_CHAN);
|
||||
if (res == 0) {
|
||||
puts("[ok]\n");
|
||||
}
|
||||
else {
|
||||
puts("[failed]");
|
||||
return 1;
|
||||
}
|
||||
|
||||
puts("Will now read and print the sensor twice a second:");
|
||||
while (1) {
|
||||
int raw, ppm, alc_a, alc_b;
|
||||
raw = mq3_read_raw(&dev);
|
||||
ppm = mq3_read(&dev);
|
||||
alc_a = ppm / 1000;
|
||||
alc_b = ppm - (alc_a * 1000);
|
||||
|
||||
printf("RAW: %4i, per mille: %1i.%03i\n", raw, alc_a, alc_b);
|
||||
|
||||
vtimer_usleep(500 * 1000);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user