弘毅 发表于 2012-9-21 20:47:02

奥氏体 发表于 2012-9-21 20:29 static/image/common/back.gif
也发一个我的程序,可以直接显示小数点后两位的的温度,另外如何把程序发上来的时候和楼主一样呢?
#inclu ...

高级编辑里,右上角有<>形状的图标,点击后,把代码写进去确认就可以。

奥氏体 发表于 2012-9-21 21:37:37

弘毅 发表于 2012-9-21 20:47 static/image/common/back.gif
高级编辑里,右上角有形状的图标,点击后,把代码写进去确认就可以。

多谢版主还编辑了我的程序

太行摄狼 发表于 2012-9-21 22:43:18

没用过这芯片,据说不错

hk386 发表于 2012-10-8 14:12:36

temperature = (val*0.0048828125*1000);         
1度是10MV,那么后面应该乘的是100啊

弘毅 发表于 2012-10-8 16:41:08

hk386 发表于 2012-10-8 14:12 static/image/common/back.gif
temperature = (val*0.0048828125*1000);         
1度是10MV,那么后面应该乘的是100啊

额。。。。可以看注释,是故意10倍的~~

peter13447 发表于 2013-2-18 10:21:46

疑问:
5/1024=0.0048828125
根据公式 val*0.0048828125
而 val 的有效值是 0到1023
那么当val取到最大值,即1023,而得到的温度就是 0.0048828125*1023=4.9951171875
不知道这里是否存在误差

弘毅 发表于 2013-2-18 14:59:49

peter13447 发表于 2013-2-18 10:21 static/image/common/back.gif
疑问:
5/1024=0.0048828125
根据公式 val*0.0048828125


肯定是存在的,不过对于民用级别,这个误差在0.01V之内,是不影响使用的。因为无法整除,浮点数的使用肯定会有误差,大小多少的问题。

peter13447 发表于 2013-2-18 16:56:29

弘毅 发表于 2013-2-18 14:59 static/image/common/back.gif
肯定是存在的,不过对于民用级别,这个误差在0.01V之内,是不影响使用的。因为无法整除,浮点数的使用肯定 ...

我的想法是
5/1023 而不是 5/1024
这样不是更加精确吗
老大 你看是否可以呢

弘毅 发表于 2013-2-18 22:31:12

peter13447 发表于 2013-2-18 16:56 static/image/common/back.gif
我的想法是
5/1023 而不是 5/1024
这样不是更加精确吗


0-1023是1024个数字。。。所以还是要除以1024的

peter13447 发表于 2013-2-18 23:02:00

弘毅 发表于 2013-2-18 22:31 static/image/common/back.gif
0-1023是1024个数字。。。所以还是要除以1024的

你的概念里面,点和段 没有认识清楚
2个点 组成1个段

0-1023 实际是1024个点,但是却是1023段
我们目前是把5V电压分成1023段

初始值与结束值一定是一一对应的
也就是说
0V电压 对应 0
5V电压 对应 1023

请再仔细研究下看

王木木 发表于 2013-4-15 21:25:19

请问这里的LiquidCrystal库可以用spi接法么?

玄冰之神 发表于 2013-4-16 14:53:14

:lol:lol:lol想知道那个模拟口和数字口都用4了不会冲突么。。不是A4么?

njj10 发表于 2013-4-16 21:42:16

幻影殇∮ 发表于 2012-2-4 18:22 static/image/common/back.gif
那张示意图使用什么软件画的,感觉很不错的样子啊。

用fritzing画的

philhoo 发表于 2013-5-26 20:55:15

本帖最后由 philhoo 于 2013-5-26 21:05 编辑

我也做了实验,并且改了程序,没有明白弘毅大师为什么要转换温度,一个位一个位的显示?用这个程序和弘老师的程序比较了一下温度也没有太大的差别。我还以为1602不能显示变量的值,非要转换后显示10位,显示个位,显示小数点这样的。
/*
LiquidCrystal Library - Hello World

Demonstrates the use a 16x2 LCD display.The LiquidCrystal
library works with all LCD displays that are compatible with the
Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface.

This sketch prints "Hello World!" to the LCD
and shows the time.

The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)

Library originally added 18 Apr 2008
by David A. Mellis
library modified 5 Jul 2009
by Limor Fried (http://www.ladyada.net)
example added 9 Jul 2009
by Tom Igoe
modified 22 Nov 2010
by Tom Igoe

This example code is in the public domain.

http://www.arduino.cc/en/Tutorial/LiquidCrystal
*/

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int potPin = 4;                     //设置模拟口4为LM35的信号输入端
float temperature = 0;                //设置temperature为浮点变量
long val=0;   
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
}
void loop() {
val = analogRead(potPin);             //val变量为从LM35信号口读取到的数
temperature = (val*0.0048828125*100);         //把读取到的val转换为温度数值的10倍
lcd.clear(); //清屏
lcd.print("Now Temp is"); //使屏幕显示文字
lcd.setCursor(0, 1) ; //设置光标位置为第二行第一个位置
lcd.print(temperature);   //显示温度
lcd.print((char)223); //显示o符号
lcd.print("C"); //显示字母C
delay(1000);
}


弘毅 发表于 2013-5-28 11:52:54

philhoo 发表于 2013-5-26 20:55 static/image/common/back.gif
我也做了实验,并且改了程序,没有明白弘毅大师为什么要转换温度,一个位一个位的显示?用这个程序和弘老师 ...

哈哈。。当年不会用,随便写的了。。其实原来写的东西BUG;连篇。。。
页: 1 [2] 3 4
查看完整版本: arduino学习笔记11 - 温度传感器实验