|
本帖最后由 zcbzjx 于 2012-12-11 01:21 编辑
从来也没有把Arduino实验这么轻易的带回家,那么多线,咋个拿。
图一 下班的时候用了点卫生纸一包,放包里就拿回来了
图二 打开看看完好无损
图三 组合起来看看
今天用了几个排母把Microduino-HR911105A模块加高,把-328P及-FT232R叠在了上面,也是没问题的。
好了,说说Microduino如何应用到大家的作品中吧。
Microduino不考虑设计主板,洞洞板是Microduino的天然主板,大的,小的,长的,短的,根据自己的应用随意选择,切割。有同学说这个太小了不好实验,其实大家用圆排母和洞洞板也很容易的做一个底座(顺便说以下,UNO实验常用的导线也可以很合适的插入圆排母,这样大家也可以在面包板上做实验)。
当然,我这次的说的不是实验,说的是出一个作品——也是我以前做过的,家庭环境监控,及通过Arduino采集DHT22的温度数据,通过ENC28J60发送到Yeelink,并在Lcd1602上显示温度和湿度,同时通过Yeelink服务器校准本地时钟,没有用时钟芯片,而是用的Arduino的Time库,在Lcd上显示日期和时间。
开始之前要做原理图,由于这个应用比较简单,以前我做过,比较熟悉,就没有画。
然后洞洞板布线,由于LCD1602比Microduino大得多,所以选择洞洞板大小就是LCD的大小,Fritzing没什么大用,不过对于洞洞板布线还是比较直观的。大家看图:
图四 洞洞板布线示意图
洞洞板通过铜柱固定在1602底板上,1602上的排针和洞洞板背面排母(16针)对插,正面方形排母就是Microduino的底座了,左边4针排母只是个示意,实际是把DHT22直接焊接在洞洞板上的,现在有点后悔,还是应该弄成插拔的。。20多块啊。。。万一拆坏了。接线不多说了吧,有问题的请留言。。。。
下面就是按图施工了。。。。。一个小时后。。。。。
图五 洞洞板背面(接LCD)
图六 洞洞板正面(接Microduino)
开始组装。。
图七 安上铜柱的LCD1602
图八 LCD1602加上了背板
大家可以看到,LCD和背板之间其实是很空的,Microduino完全可以分片放在中间,由于我只有这么高的4根铜柱了,所以就没有那么设计。
图九 组装好的另外一个侧面的图
图十 -HR911105A露头的样子
看看我以前做的,就知道我为什么要设计Microduino了。
实时数据请到Yeelink查看
拍了一段小视屏。
由于办公室是固定ip,家里只需要改ip就可以用了,所以我用的固定ip地址
代码 - #include
- #include
- #include
- #include
- #define OUT
- #define IN
- #define REQUEST_RATE 8000 // milliseconds
- #define DHT_PIN A4
- #define DHTTYPE DHT22 // DHT 22 (AM2302)
- #define N 2
- byte i=0;
- LiquidCrystal lcd(6, 5, 4, 3, 2, A5);
- DHT dht(DHT_PIN, DHTTYPE);
- // ethernet interface mac address
- static byte mymac[] = {
- 0x74,0x69,0x69,0x2D,0x30,0x31 };
- // ethernet interface ip address
- static byte myip[] = {
- 192,168,1,193 };
- // gateway ip address
- static byte gwip[] = {
- 192,168,1,254 };
- // dns ip address
- static byte dnsip[] = {
- 192,168,1,254 };
- // remote website name
- char website[] PROGMEM = "api.yeelink.net";
- char urlBuf[N][50] PROGMEM = {
- "/v1.0/device/1249/sensor/1555/datapoints","/v1.0/device/1249/sensor/1576/datapoints"};
- char apiKey[] PROGMEM = "U-ApiKey: XXXXXXXXXXXXXXXXXXXXX";
- byte Ethernet::buffer[700];
- static long timer;
- const char* reply;
- boolean timeNeedSet = true;
- uint16_t timeSetTimer = 0;
- #define TIME_SET_TIMER 4000 //about TIME_SET_TIMER*5s
- // called when the client request is complete
- static void my_result_cb (byte status, word off, word len) {
- Serial.print("<<< reply ");
- Serial.print(millis() - timer);
- Serial.println(" ms");
- reply = (const char*)Ethernet::buffer+off;
- Serial.println(reply);
- if (timeNeedSet) setupTime();
- }
- void setup () {
- Serial.begin(57600);
- lcd.begin(16, 2);
- dht.begin();
- Serial.println("[getStaticIp]");
- lcd.setCursor(0,1);
- lcd.print(" microduino.cn");
- randomSeed(analogRead(0));
- if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
- Serial.println( "Failed to access Ethernet controller");
- if (!ether.staticSetup(myip, gwip, dnsip))
- Serial.println("Get static ip failed");
- ether.printIp("My IP: ", ether.myip);
- // ether.printIp("Netmask: ", ether.mymask);
- ether.printIp("GW IP: ", ether.gwip);
- ether.printIp("DNS IP: ", ether.dnsip);
- if (!ether.dnsLookup(website))
- Serial.println("DNS failed");
- ether.printIp("Server: ", ether.hisip);
- timer = - REQUEST_RATE; // start timing out right away
- }
- void loop () {
- ether.packetLoop(ether.packetReceive());
- if (millis() > timer + REQUEST_RATE) {
- timer = millis();
- Serial.println(">>> REQ");
- Serial.println(i);
- static char buf[20];
- get_send_string(buf);
- if (!ether.dnsLookup(website))
- Serial.println("DNS failed");
- ether.printIp("Server: ", ether.hisip);
- ether.httpPost (urlBuf[i], website, apiKey, buf, my_result_cb);
- i++;
- if (i==N) i=0;
- displayClock();
- }
- }
- void get_send_string(OUT char *p){
- uint16_t tempData;
- uint8_t whole, fract;
- switch(i){
- case 0:
- {
- tempData = dht.readTemperature()*10;
- whole = tempData/10 ; // separate off the whole and fractional portions
- fract = tempData%10;
- lcd.setCursor(0,0);
- printDigits(whole);
- lcd.print(".");
- lcd.print(fract);
- lcd.print("C");
- break;
- }
- case 1:
- {
- tempData = dht.readHumidity()*10;
- whole = tempData/10 ; // separate off the whole and fractional portions
- fract = tempData%10;
- lcd.setCursor(6,0);
- printDigits(whole);
- lcd.print(".");
- lcd.print(fract);
- lcd.print("%");
- break;
- }
- }
- Serial.println(tempData);
- sprintf(p,"{"value":%d.%d}",whole,fract);
- }
复制代码
- void setupTime(){
- lcd.setCursor(0,1);
- lcd.print(" ");
- lcd.setCursor(0,1);
- lcd.print("Update time...");
- char bufx[21];
- if(reply !=0){
- for(uint8_t I=0;I<21;I++){
- bufx[I]=reply[50+I];
- }
- tmElements_t time1;
- timeconvert(bufx,&time1);
- time_t second = makeTime(time1);
- setTime(second);
- adjustTime(8*60*60);
- lcd.print("OK");
- timeNeedSet=false;
- }
- }
- void displayClock(){
- // digital clock display of the time
- timeSetTimer++;
- if (timeSetTimer>TIME_SET_TIMER) {
- timeSetTimer=0;
- timeNeedSet=true;
- }
- lcd.setCursor(0,1);
- lcd.print(year());
- lcd.print("-");
- printDigits(month());
- lcd.print("-");
- printDigits(day());
- lcd.print(" ");
- printDigits(hour());
- lcd.print(":");
- printDigits(minute());
- }
- void printDigits(int digits){
- // utility function for digital clock display: prints preceding colon and leading 0
- if(digits < 10)
- lcd.print("0");
- lcd.print(digits);
- }
复制代码
- int monthcmp( IN char *p)
- {
- char *month[]={
- "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec" };
-
- int i;
- for(i=0;i<12;i++){
- if(strcmp(p,month[i])==0)
- break;
- }
- if(i==12)
- {
- return i;
- }
- return i;
- }
- //将字串格式的时间转换为结构体,返回距离1970年1月1日0:0:0的秒数,当字符串格式错误或超值时返回0
- //BUF 为类似Tue May 15 14:46:02 2007格式的,p为时间结构体
- void timeconvert(IN char *buf,OUT tmElements_t *p)
- {
- char cmonth[4];
- int16_t td,th,tm,ts,ty;
- sscanf(buf,"%d %s %d %d:%d:%d",&td,cmonth,&ty,&th,&tm,&ts);
- //sscanf("2012 Aug " ,"%4d %s",&ty,cmonth);
- p->Year = ty - 1970;
- p->Month = monthcmp(cmonth) + 1;
- p->Day = td;
- p->Hour = th;
- p->Minute = tm;
- p->Second = ts;
- }
复制代码
库文件打包下载
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
评分
-
查看全部评分
|