极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 36935|回复: 37

Microduino小应用之一

[复制链接]
发表于 2012-11-19 22:03:17 | 显示全部楼层 |阅读模式
本帖最后由 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地址


代码
  1. #include
  2. #include
  3. #include
  4. #include

  5. #define OUT
  6. #define IN
  7. #define REQUEST_RATE 8000 // milliseconds
  8. #define DHT_PIN A4
  9. #define DHTTYPE DHT22   // DHT 22  (AM2302)
  10. #define N 2
  11. byte i=0;
  12. LiquidCrystal lcd(6, 5, 4, 3, 2, A5);
  13. DHT dht(DHT_PIN, DHTTYPE);

  14. // ethernet interface mac address
  15. static byte mymac[] = {
  16.   0x74,0x69,0x69,0x2D,0x30,0x31 };
  17. // ethernet interface ip address
  18. static byte myip[] = {
  19.   192,168,1,193 };
  20. // gateway ip address
  21. static byte gwip[] = {
  22.   192,168,1,254 };
  23. // dns ip address
  24. static byte dnsip[] = {
  25.   192,168,1,254 };
  26. // remote website name
  27. char website[] PROGMEM = "api.yeelink.net";
  28. char urlBuf[N][50] PROGMEM = {
  29.   "/v1.0/device/1249/sensor/1555/datapoints","/v1.0/device/1249/sensor/1576/datapoints"};
  30. char apiKey[] PROGMEM = "U-ApiKey: XXXXXXXXXXXXXXXXXXXXX";

  31. byte Ethernet::buffer[700];
  32. static long timer;

  33. const char* reply;
  34. boolean timeNeedSet = true;
  35. uint16_t timeSetTimer = 0;
  36. #define TIME_SET_TIMER 4000 //about TIME_SET_TIMER*5s
  37. // called when the client request is complete
  38. static void my_result_cb (byte status, word off, word len) {
  39.   Serial.print("<<< reply ");
  40.   Serial.print(millis() - timer);
  41.   Serial.println(" ms");
  42.   reply = (const char*)Ethernet::buffer+off;
  43.   Serial.println(reply);
  44.   if (timeNeedSet) setupTime();   
  45. }

  46. void setup () {
  47.   Serial.begin(57600);
  48.   lcd.begin(16, 2);
  49.   dht.begin();
  50.   Serial.println("[getStaticIp]");
  51.   lcd.setCursor(0,1);
  52.   lcd.print(" microduino.cn");
  53.   randomSeed(analogRead(0));
  54.   if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
  55.     Serial.println( "Failed to access Ethernet controller");

  56.   if (!ether.staticSetup(myip, gwip, dnsip))
  57.     Serial.println("Get static ip failed");

  58.   ether.printIp("My IP: ", ether.myip);
  59.   // ether.printIp("Netmask: ", ether.mymask);
  60.   ether.printIp("GW IP: ", ether.gwip);
  61.   ether.printIp("DNS IP: ", ether.dnsip);

  62.   if (!ether.dnsLookup(website))
  63.     Serial.println("DNS failed");
  64.   ether.printIp("Server: ", ether.hisip);

  65.   timer = - REQUEST_RATE; // start timing out right away
  66. }

  67. void loop () {
  68.   ether.packetLoop(ether.packetReceive());
  69.   if (millis() > timer + REQUEST_RATE) {
  70.     timer = millis();
  71.     Serial.println(">>> REQ");
  72.     Serial.println(i);
  73.     static char buf[20];
  74.     get_send_string(buf);
  75.     if (!ether.dnsLookup(website))
  76.       Serial.println("DNS failed");
  77.     ether.printIp("Server: ", ether.hisip);
  78.     ether.httpPost (urlBuf[i], website, apiKey, buf, my_result_cb);
  79.     i++;
  80.     if (i==N) i=0;
  81.     displayClock();
  82.   }
  83. }


  84. void get_send_string(OUT char *p){
  85.   uint16_t tempData;
  86.   uint8_t whole, fract;
  87.   switch(i){
  88.   case 0:
  89.     {
  90.       tempData = dht.readTemperature()*10;
  91.       whole = tempData/10 ;  // separate off the whole and fractional portions
  92.       fract = tempData%10;
  93.       lcd.setCursor(0,0);
  94.       printDigits(whole);
  95.       lcd.print(".");
  96.       lcd.print(fract);
  97.       lcd.print("C");
  98.       break;  
  99.     }
  100.   case 1:
  101.     {
  102.       tempData = dht.readHumidity()*10;
  103.       whole = tempData/10 ;  // separate off the whole and fractional portions
  104.       fract = tempData%10;
  105.       lcd.setCursor(6,0);
  106.       printDigits(whole);
  107.       lcd.print(".");
  108.       lcd.print(fract);
  109.       lcd.print("%");
  110.       break;  
  111.     }

  112.   }
  113.   Serial.println(tempData);
  114.   sprintf(p,"{"value":%d.%d}",whole,fract);  
  115. }
复制代码

  1. void setupTime(){
  2.   lcd.setCursor(0,1);
  3.   lcd.print("                ");
  4.   lcd.setCursor(0,1);
  5.   lcd.print("Update time...");
  6.   char bufx[21];
  7.     if(reply !=0){
  8.     for(uint8_t I=0;I<21;I++){
  9.       bufx[I]=reply[50+I];      
  10.     }
  11.     tmElements_t time1;
  12.     timeconvert(bufx,&time1);
  13.     time_t second = makeTime(time1);        
  14.     setTime(second);
  15.     adjustTime(8*60*60);
  16.     lcd.print("OK");
  17.     timeNeedSet=false;
  18.     }
  19. }
  20. void displayClock(){
  21.   // digital clock display of the time
  22.   timeSetTimer++;
  23.   if (timeSetTimer>TIME_SET_TIMER) {
  24.     timeSetTimer=0;
  25.     timeNeedSet=true;
  26.   }
  27.   lcd.setCursor(0,1);
  28.   lcd.print(year());
  29.   lcd.print("-");
  30.   printDigits(month());
  31.   lcd.print("-");
  32.   printDigits(day());
  33.   lcd.print(" ");
  34.   printDigits(hour());
  35.   lcd.print(":");
  36.   printDigits(minute());
  37. }
  38. void printDigits(int digits){
  39.   // utility function for digital clock display: prints preceding colon and leading 0
  40.   if(digits < 10)
  41.     lcd.print("0");
  42.   lcd.print(digits);
  43. }
复制代码


  1. int monthcmp( IN char *p)
  2. {
  3.   char *month[]={
  4.     "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"            };

  5.   int i;
  6.   for(i=0;i<12;i++){
  7.     if(strcmp(p,month[i])==0)
  8.       break;
  9.   }
  10.   if(i==12)
  11.   {
  12.     return i;
  13.   }
  14.   return i;
  15. }
  16. //将字串格式的时间转换为结构体,返回距离1970年1月1日0:0:0的秒数,当字符串格式错误或超值时返回0
  17. //BUF 为类似Tue May 15 14:46:02 2007格式的,p为时间结构体
  18. void timeconvert(IN char *buf,OUT tmElements_t *p)
  19. {
  20.   char cmonth[4];
  21.   int16_t td,th,tm,ts,ty;
  22.   sscanf(buf,"%d %s %d %d:%d:%d",&td,cmonth,&ty,&th,&tm,&ts);
  23.   //sscanf("2012 Aug " ,"%4d %s",&ty,cmonth);
  24.   p->Year = ty - 1970;
  25.   p->Month = monthcmp(cmonth) + 1;
  26.   p->Day = td;
  27.   p->Hour = th;
  28.   p->Minute = tm;
  29.   p->Second = ts;
  30. }
复制代码



库文件打包下载

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

评分

参与人数 1 +3 收起 理由
幻生幻灭 + 3 很给力!

查看全部评分

回复

使用道具 举报

发表于 2012-11-19 22:11:37 | 显示全部楼层
沙发。问一下,这个到底是干什么用的
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-11-19 22:18:23 | 显示全部楼层
本帖最后由 zcbzjx 于 2012-11-19 22:30 编辑
普通人 发表于 2012-11-19 22:11
沙发。问一下,这个到底是干什么用的


想了半天才知道问的Microduino....这个就是一个Arduino,只不过更加小型化和模块化了,而且添加了一些应用模块,便于大家集成到自己的作品中。
回复 支持 反对

使用道具 举报

发表于 2012-11-19 23:15:07 | 显示全部楼层
太小巧了,很萌呀
回复 支持 反对

使用道具 举报

发表于 2012-11-20 03:30:48 | 显示全部楼层
非常漂亮的Arduino系统哦。
回复 支持 反对

使用道具 举报

发表于 2012-11-20 08:53:53 | 显示全部楼层
功能上可以媲美Kickstarter上面的TinyDuino了,不错,可以考虑增加几个shield,如LED array或者电机平台等等,做云台,或者其他好玩的东西
回复 支持 反对

使用道具 举报

发表于 2012-11-20 10:00:02 | 显示全部楼层
Micro 就是微小意思,哈哈!做的不错!
回复 支持 反对

使用道具 举报

发表于 2012-11-20 10:22:39 | 显示全部楼层
把Arduino带回家。。。好羡慕 我都不敢把Arduino带回单位
回复 支持 反对

使用道具 举报

发表于 2012-11-20 10:38:34 | 显示全部楼层


不知道是否考虑过增加这种总线扩展底板(也可能是单纯的IO并联)
Micro是很好,但是一直叠高楼的话,应用反倒会被限制。可以通过底板将高度分量到水平方向上或许更容易做应用。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

发表于 2012-11-20 10:48:44 | 显示全部楼层
幻生幻灭 发表于 2012-11-20 10:38
不知道是否考虑过增加这种总线扩展底板(也可能是单纯的IO并联)
Micro是很好,但是一直叠高楼的话,应 ...

我想说的被你说了,同感啊,LZ这样的设计只能做成长条形的,不能铺开做扁平的
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-11-20 11:04:17 | 显示全部楼层
洞洞板很好扩展啊。比如可以吧spi总线引到边上,这些要自己考虑了,洞洞板很好操作,Microduino目前不准备开发主板的,因为每个人应用不一样!不可能批量。主板比较大,成本都在打板上了。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-11-20 11:04:59 | 显示全部楼层
不过我们会考虑一些主板方案供大家考虑
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-11-20 11:06:53 | 显示全部楼层
另外如果批量用什么方式比较好嘞,大家给点意见,我不想上点名时间,点名时间10%的手续费,利润都到不了10%啊。。
回复 支持 反对

使用道具 举报

发表于 2012-11-20 11:10:15 | 显示全部楼层
上点名时间估计会失败,不要上了,试试不要钱的众募如“追梦网”之类的,也可以放在淘宝上慢慢卖,学arduino qq群的教授
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-11-26 20:04:18 | 显示全部楼层
本帖最后由 zcbzjx 于 2012-11-26 20:16 编辑

up一下,报告下进展,目前pcb已经加工完毕,在路上,首批加工了500片arduino-core,100片enc和ft232,准备加工100片成品core,30-40片enc和ft232,成品什么时候出来还得靠郝老板了,
为了环保,core采用了沉金工艺,enc和ft232采用的镀金工艺(量太小了),“钱”都被俺吸了,样品全是有“钱”喷锡啊。。。

另外nRF24L01及microSD已经打样,core+准备采用atmega1284目前也已经打样,到时候会有应用教程和成品照片。有兴趣的同学可以关注微博[email protected]或者www.microduino.cn。当然也会在这里发布消息。


现在办公室只能翻墙上极客工坊。。。速度极慢。。。不知道为什么,有人和我一样么?



另外,core可以为168pa@16M5V及168pa@8M3V3,及328p@16M5V及328p@8M3V3,价格相差芯片的差价,有需要的同学可以回这个帖子,我大概了解下。。。看做不做不同的配置,目前是准备只做328P@16M。需要套件的也可以留言,如果多的话我会配点套件。


另外Yeelink作证Microduino-core及-enc28j60和ft232已经稳定工作一周,大家可以查看Yeelink探索——搜索“microduino”。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-5-15 15:41 , Processed in 0.099658 second(s), 26 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表