Intel Edison Arduino 温度检测并上传至网站

来源:互联网 发布:新还珠格格知乎 编辑:程序博客网 时间:2024/05/29 18:02

采用的Arduino的温度传感器,其说明见此链接。参数罗列如下:

  • Voltage: 3.3 ~ 5V
  • Zero power resistance: 100 KΩ
  • Resistance Tolerance: ±1%
  • Operating temperature range: -40 ~ +125 ℃
  • Nominal B-Constant: 4250 ~ 4299K

关键计算公式如下:

// Define the B-value of the thermistor.

// This value is a property of the thermistor used in the Grove - Temperature Sensor,and used to convert from the analog value it measures and a temperature value.

const int B = 3975;

// Get the (raw) value of the temperature sensor.

    int val = analogRead(pinTemp);

// Determine the current resistance of the thermistor based on the sensor value.

    float resistance = (float)(1023-val)*10000/val;

// Calculate the temperature based on the resistance value.

    float temperature = 1/(log(resistance/10000)/B+1/298.15)-273.15;


使用直接Linux操作系统下写到我的网站数据库方式上传数据(

/usr/local/pgsql/bin/psql -U postgres -h 180.xx.xxx.xxx -d lporxxx -c "insert into ut_ut_detect_value (recordsn, groupid, companyid, userid, username, pointnumberd, pointdetect_number, pointdetect_value, pointdetect_date, pointdetect_assit_infor ) values ((select max(recordsn)+1 from ut_ut_detect_value),20181,20154,20434, 'David', 101, 1, $sensorvalue, now(), 'Edison Raw Value Added成功')"

)后,注:以上代码中xxx非原文, 在上传到网站的前端看到的数据例子:




温度传感器隔着2层塑料袋泡开水里面的曲线如下,数值是传感器原始数值:




要验证原始检测值正确与否,重新研究Edison Arduino板子。相关的Intel网站如下:https://software.intel.com/en-us/get-started-edison-osx


在Arduino IDE界面下,Mac采用的端口是usbmodem(不在角上的那个Micro USB接口),和采用Terminal(角上的那个Micro USB接口)的端口不一样,见下图:




采用Terminal(角上的那个Micro USB接口)时使用的是usbserial:



另外,采用Arduino IDE和采用Terminal直接读数,得到的数值不一样,在温度时60摄氏度左右,分别是800左右和3200左右,如下图:


在温度26度左右,分别是520和2100左右,如下图:



在LCD板子上也可以显示,如下:



直接拍摄的LCD显示照片如下:



在调试过程中,Arduino可以打开“串口监视器”窗口,查看用输出的数据,如下图:


然后就有一个单独的窗口显示使用输出的数据,如下:



为什么Arduino采集和计算出的数据是正确的,而直接通过Linux系统采集的就不一样呢?这个是下一步要研究的问题。

Linux下的操作如下2图:



为什么Arduino采集和计算出的数据是正确的,而直接通过Linux系统采集的就不一样呢?走在路上还在继续想这个问题。突然灵光一闪,520和2100相差大约四倍。800和3200正好四倍。原来Arduino采集原始数据时右移2位减少了精度!不过原始精度变动大,除以四正好有滤波的作用!于是改了代码,把传感器测值向右移位2位(即除以4),得到了和Arduino采集的值一样的值了。参见下图:




0 0
原创粉丝点击