我在contiki2.7 (我使用InstantContiki)使用Z1 motes和ZIGLET Z001 (温湿度)时有一个问题。我尝试了示例/z1目录中的代码“test-sht11.c”来获取温度和湿度,但结果是错误的:
Rime started with address 227.15
MAC e3:0f:00:00:00:00:00:00 Contiki 2.7 started. Node id is set to 4067.
CSMA ContikiMAC, channel check rate 8 Hz, radio channel 26
Starting 'SHT11 test'
Temperature: 615 degrees Celsius
Rel. humidity: 2650%
Temperature: 615 degrees Celsius
Rel. humidity: 2650%我看到I2c驱动程序必须被禁用(http://sourceforge.net/p/contiki/mailman/message/29682840/),但是它仍然不能工作,我有相同的结果。
代码:
#include "contiki.h"
#include "dev/sht11.h"
#include <stdio.h>
PROCESS(test_sht11_process, "SHT11 test");
AUTOSTART_PROCESSES(&test_sht11_process);
PROCESS_THREAD(test_sht11_process, ev, data)
{
static struct etimer et;
static unsigned rh;
PROCESS_BEGIN();
i2c_disable();
sht11_init();
for (etimer_set(&et, CLOCK_SECOND);; etimer_reset(&et)) {
PROCESS_YIELD();
printf("Temperature: %u degrees Celsius\n",
(unsigned) (-39.60 + 0.01 * sht11_temp()));
rh = sht11_humidity();
printf("Rel. humidity: %u%%\n",
(unsigned) (-4 + 0.0405*rh - 2.8e-6*(rh*rh)));
}
PROCESS_END();
}我很确定这不是硬件问题(我尝试使用不同的ZIG001和不同的Z1模块)。谢谢你的帮助,我绝望了,…吉布斯。
发布于 2015-09-23 16:33:15
存储库的负责人建议使用SHT25而不是SHT11。如果您被困在旧的contiki上,这些新文件可能不存在,因此您必须手动获取它们。如果您切换到一个较新的版本,您将得到它们。
如果您只是将文件(.c和.h)放在旧的sht11文件旁边(而没有更新contiki),不要忘记在Makefile中(在sht11.c之后)添加sht25.c。
若要使用新版本的感测(请参阅Z1的新示例):
PROCESS_THREAD(test_sht25_process, ev, data)
{
int16_t temperature, humidity;
PROCESS_BEGIN();
SENSORS_ACTIVATE(sht25);
while(1) {
etimer_set(&et, CLOCK_SECOND);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
temperature = sht25.value(SHT25_VAL_TEMP);
printf("Temperature %d.%d ºC\n", temperature / 100, temperature % 100);
humidity = sht25.value(SHT25_VAL_HUM);
printf("Humidity %d.%d %RH\n", humidity / 100, humidity % 100);
}
PROCESS_END();
}也不要使用sht11对Z1内置的温度传感器,像我,只对连接到它的拉链(不适用于OP,但可能帮助别人).
https://stackoverflow.com/questions/29338515
复制相似问题