zcbzjx 发表于 2012-11-19 22:03:17

Microduino小应用之一

本帖最后由 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查看
拍了一段小视屏。
http://player.youku.com/player.php/sid/XNDc3MTg5MDE2/v.swf

由于办公室是固定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 PROGMEM = {
"/v1.0/device/1249/sensor/1555/datapoints","/v1.0/device/1249/sensor/1576/datapoints"};
char apiKey[] PROGMEM = "U-ApiKey: XXXXXXXXXXXXXXXXXXXXX";

byte Ethernet::buffer;
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("");
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;
    get_send_string(buf);
    if (!ether.dnsLookup(website))
      Serial.println("DNS failed");
    ether.printIp("Server: ", ether.hisip);
    ether.httpPost (urlBuf, 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;
    if(reply !=0){
    for(uint8_t I=0;I<21;I++){
      bufx=reply;      
    }
    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)==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;
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;
}


库文件打包下载

普通人 发表于 2012-11-19 22:11:37

沙发。问一下,这个到底是干什么用的:)

zcbzjx 发表于 2012-11-19 22:18:23

本帖最后由 zcbzjx 于 2012-11-19 22:30 编辑

普通人 发表于 2012-11-19 22:11 static/image/common/back.gif
沙发。问一下,这个到底是干什么用的

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

韋編弎絕 发表于 2012-11-19 23:15:07

太小巧了,很萌呀

ninjiafan 发表于 2012-11-20 03:30:48

非常漂亮的Arduino系统哦。

erjiang 发表于 2012-11-20 08:53:53

功能上可以媲美Kickstarter上面的TinyDuino了,不错,可以考虑增加几个shield,如LED array或者电机平台等等,做云台,或者其他好玩的东西

Randy 发表于 2012-11-20 10:00:02

Micro 就是微小意思,哈哈!做的不错!

幻生幻灭 发表于 2012-11-20 10:22:39

把Arduino带回家。。。好羡慕:Q 我都不敢把Arduino带回单位

幻生幻灭 发表于 2012-11-20 10:38:34



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

ttyp 发表于 2012-11-20 10:48:44

幻生幻灭 发表于 2012-11-20 10:38 static/image/common/back.gif
不知道是否考虑过增加这种总线扩展底板(也可能是单纯的IO并联)
Micro是很好,但是一直叠高楼的话,应 ...

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

zcbzjx 发表于 2012-11-20 11:04:17

洞洞板很好扩展啊。比如可以吧spi总线引到边上,这些要自己考虑了,洞洞板很好操作,Microduino目前不准备开发主板的,因为每个人应用不一样!不可能批量。主板比较大,成本都在打板上了。

zcbzjx 发表于 2012-11-20 11:04:59

不过我们会考虑一些主板方案供大家考虑

zcbzjx 发表于 2012-11-20 11:06:53

另外如果批量用什么方式比较好嘞,大家给点意见,我不想上点名时间,点名时间10%的手续费,利润都到不了10%啊。。

erjiang 发表于 2012-11-20 11:10:15

上点名时间估计会失败,不要上了,试试不要钱的众募如“追梦网”之类的,也可以放在淘宝上慢慢卖,学arduino qq群的教授

zcbzjx 发表于 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”。
页: [1] 2 3
查看完整版本: Microduino小应用之一