2014年1月23日 星期四

IV-18 Arduino Shield 製作


於是,IV-18 時鐘的Arduino 版登場啦~~~
經過快半個月的時間這張板子終於到了我手上,沒辦法,我真的找不到有哪一家比OSHPark便宜的PCB製作廠了

好啦,言歸正傳,這次的版本沿用http://forum.43oh.com/topic/2487-siv-18-vfd-clock-booster-pack/大致上的Layout,但是增加了DS1307 RTC,然後5V可以直接從Arduino拉過來.
首先,先上MC34063,MAX6921,DS1307,By the way,我的DS1307還沒到所以右下角沒焊接

SOIC應該不會很難焊,圖片稍微放大一點就可以發現我的焊工根本___
再來上電阻,二極體,可變電阻
剩下電容,電感,電池座和針母上完後,主體大致上就完成了
然後不想等DS1307只好把手邊的RTC模組拆了(=゚ω゚)ノ
右下角就全補齊了

再來先插上Arduino測試MC34063升壓得如何
測量點是二極體的輸出端,電壓大概20~30V就可以了,太高太低就轉可變電阻
之後換重頭戲,IV-18的轉接版~
英文不錯的話就看http://learn.adafruit.com/ice-tube-clock-kit/board-assembly這裡其中的IV-18部分吧

先上90度的雙排針,這點需要非常注意,排針要從右手邊插,如圖,如果插了的話會"非常麻煩"喔
接下來就是上IV-18
上板子之前,最好先把他的腳給剪一剪,繞一圈長度越來越短,這樣的話會比較好上去
注意到了嗎?中間有三個PIN腳是沒有功能的,這三隻PIN要插到標示在PCB上三個"NC"的地方
,插進去後,先不要焊接,把Program upload到Arduino上面,再把這個板子插到Shield上測試
測試完成後再焊接.
Program is here:GITHUB

焊接完就大功告成啦~

後來順便改一下電路板把一些缺點修一修
把有點占空間的電池座換了一個,然後有多的空間讓DS3231放背面,還有蜂鳴器也可以直接放在板子上,電感挪到MC34063旁邊
不過電池彈片還真難買.....光華繞了大半圈都沒有,只好從RS叫貨了

另外就是我發現MAX6921只能叫貨.....非常不方便,尤其是我手邊的6921快沒了
所以只好另尋他法
希望這版能測試成功

==Update==
程式碼加入了調整時間的直接方式
先輸入大寫的S,就可以進到調整時間的程式

#include <Arduino.h>

#include <Wire.h>  
#include <Time.h>  
#define DS1307_ADDRESS 0x68
#define  dataPin  11
#define  clockPin 13
#define  loadPin  5

byte zero = 0x00;
const byte segFont[] ={B00111111, B00000110, B01011011, B01001111,B01100110, B01101101, B01111100, B00000111,B01111111, B01100111, B01000000};

int lastsecond = 0;

byte bChars[10] ;
int dChars[10] ;

byte seconds;
byte hours;
byte minutes;

void serialEvent();
void setTime();
byte readByteq();
void RefreshIV18();
byte bcdToDec(byte val);
void timetoIV18(byte h,byte m,byte s);
byte decToBcd(byte val);
void printDate();

void setup()
{
  pinMode(loadPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  
  Serial.begin(9600);
  Wire.begin();
  timetoIV18(12,75,34);
  printDate();
  RefreshIV18();

}

void loop(){

  printDate();
  timetoIV18(hours,minutes,seconds);

  if (lastsecond != seconds){
   lastsecond = seconds;
   dChars[1] = !dChars[1];
   dChars[4] = !dChars[4];
   dChars[7] = !dChars[7];
   timetoIV18(hours,minutes,seconds);
 }
 RefreshIV18();

}
void serialEvent(){
int answer = Serial.read();
if (answer=='S'){
  Serial.read();
  setTime();
}
}

void setTime() {
  Serial.read();
  Serial.println("Please enter the current year, 00-99. - ");

  byte yearsett = readByteq();
  Serial.println("Please enter the current month, 1-12. - ");
  byte monthset = readByteq();
  //Serial.println(months[monthset-1]);
  Serial.println("Please enter the current day of the month, 1-31. - ");
  byte monthdayset = readByteq();
  //Serial.println(monthday);
  Serial.println("Please enter the current day of the week, 1-7.");
  Serial.println("1 Sun | 2 Mon | 3 Tues | 4 Weds | 5 Thu | 6 Fri | 7 Sat - ");
  byte weekdayset = readByteq();
  //Serial.println(days[weekday-1]);
  Serial.println("Please enter the current hour in 24hr format, 0-23. - ");
  byte hourset = readByteq();
  //Serial.println(hour);
  Serial.println("Please enter the current minute, 0-59. - ");
  byte minuteset = readByteq();
  //Serial.println(minute);
  byte secondset = 0;
  Serial.println("The data has been entered.");

  // The following codes transmits the data to the RTC
  Wire.beginTransmission(0x68);
  Wire.write(byte(0));
  Wire.write(decToBcd(secondset));
  Wire.write(decToBcd(minuteset));
  Wire.write(decToBcd(hourset));
  Wire.write(decToBcd(weekdayset));
  Wire.write(decToBcd(monthdayset));
  Wire.write(decToBcd(monthset));
  Wire.write(decToBcd(yearsett));
  Wire.write(byte(0));
  Wire.endTransmission();
  // Ends transmission of data
}


byte readByteq() {
  while (!Serial.available()) delay(10);
  byte reading = 0;
  byte incomingByte = Serial.read();
  while (incomingByte != '\n') {
    if (incomingByte >= '0' && incomingByte <= '9')
      reading = reading * 10 + (incomingByte - '0');
    else;
    incomingByte = Serial.read();
  }
  Serial.flush();
  return reading;
}
void RefreshIV18() 
  for (int count = 1;count<=9;count++){

    long data=0;
    data = segFont[bChars[count]];
    bitSet(data,17-count);
    if (dChars[count] == 1){
      bitSet(data,7);
    }
    digitalWrite(loadPin, LOW); 
  //Shiftin 20 bits
  for(byte i=0; i<20; i++) 
  { 
    //clockPin LOW
    digitalWrite(clockPin, LOW);
    //datapin bit to 1 OR 0 
    digitalWrite(dataPin,bitRead(data, i));
    //Set clockPin HIGH
    digitalWrite(clockPin, HIGH); 
  }

  digitalWrite(loadPin, HIGH);

}
}

byte bcdToDec(byte val)  {
// Convert binary coded decimal to normal decimal numbers
return ( (val/16*10) + (val%16) );
}


void timetoIV18(byte h,byte m,byte s)
{
  memset(bChars,0,sizeof(bChars));

  bChars[7]=h % 10;
  bChars[8]=h / 10;
  
  bChars[6]=10;

  bChars[4]=m % 10;
  bChars[5]=m / 10;

  bChars[3]=10;

  bChars[1]=s % 10;
  bChars[2]=s / 10;

  

}


byte decToBcd(byte val){
// Convert normal decimal numbers to binary coded decimal
return ( (val/10*16) + (val%10) );
}
void printDate(){
  Wire.beginTransmission(DS1307_ADDRESS);
  Wire.write(zero);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_ADDRESS, 3);

  seconds = bcdToDec(Wire.read());
  minutes = bcdToDec(Wire.read());
  hours = bcdToDec(Wire.read() & 0b111111); //24 hour time
   /*
  int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
  int monthDay = bcdToDec(Wire.read());
  int months = bcdToDec(Wire.read());
  int years = bcdToDec(Wire.read());

  //print the date EG   3/1/11 23:59:59
  Serial.print(months);
  Serial.print("/");
  Serial.print(monthDay);
  Serial.print("/");
  Serial.print(years);
  Serial.print(" ");
  Serial.print(hours);
  Serial.print(":");
  Serial.print(minutes);
  Serial.print(":");
  Serial.println(seconds);
  */
}


有日期的版本:
#include <Arduino.h>

#include <Wire.h>  
#include <Time.h>  
#define DS1307_ADDRESS 0x68
#define  dataPin  11
#define  clockPin 13
#define  loadPin  5

byte zero = 0x00;
const byte segFont[] ={B00111111, B00000110, B01011011, B01001111,B01100110, B01101101, B01111100, B00000111,B01111111, B01100111, B01000000, B00000000};

int lastsecond = 0;

byte bChars[10] ;
int dChars[10] ;

byte seconds;
byte hours;
byte minutes;
int weekDay ; //0-6 -> sunday - Saturday
  int monthDay ;
  int months ;
  int years ;
void serialEvent();
void setTime();
byte readByteq();
void RefreshIV18();
byte bcdToDec(byte val);
void timetoIV18(byte h,byte m,byte s);
byte decToBcd(byte val);
void printDate();

void setup()
{
  pinMode(loadPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  
  Serial.begin(9600);
  Wire.begin();
  timetoIV18(12,75,34);
  printDate();
  RefreshIV18();

}

void loop(){

  printDate();
  datetoIV18(years,months,monthDay);

  for(int j=0;j<=1000;j++){
 RefreshIV18();
}
 timetoIV18(hours,minutes,seconds);
 for(int j=0;j<=1000;j++){
 RefreshIV18();
}

}
void serialEvent(){
int answer = Serial.read();
if (answer=='S'){
  Serial.read();
  setTime();
}
}

void setTime() {
  Serial.read();
  Serial.println("Please enter the current year, 00-99. - ");

  byte yearsett = readByteq();
  Serial.println("Please enter the current month, 1-12. - ");
  byte monthset = readByteq();
  //Serial.println(months[monthset-1]);
  Serial.println("Please enter the current day of the month, 1-31. - ");
  byte monthdayset = readByteq();
  //Serial.println(monthday);
  Serial.println("Please enter the current day of the week, 1-7.");
  Serial.println("1 Sun | 2 Mon | 3 Tues | 4 Weds | 5 Thu | 6 Fri | 7 Sat - ");
  byte weekdayset = readByteq();
  //Serial.println(days[weekday-1]);
  Serial.println("Please enter the current hour in 24hr format, 0-23. - ");
  byte hourset = readByteq();
  //Serial.println(hour);
  Serial.println("Please enter the current minute, 0-59. - ");
  byte minuteset = readByteq();
  //Serial.println(minute);
  byte secondset = 0;
  Serial.println("The data has been entered.");

  // The following codes transmits the data to the RTC
  Wire.beginTransmission(0x68);
  Wire.write(byte(0));
  Wire.write(decToBcd(secondset));
  Wire.write(decToBcd(minuteset));
  Wire.write(decToBcd(hourset));
  Wire.write(decToBcd(weekdayset));
  Wire.write(decToBcd(monthdayset));
  Wire.write(decToBcd(monthset));
  Wire.write(decToBcd(yearsett));
  Wire.write(byte(0));
  Wire.endTransmission();
  // Ends transmission of data
}


byte readByteq() {
  while (!Serial.available()) delay(10);
  byte reading = 0;
  byte incomingByte = Serial.read();
  while (incomingByte != '\n') {
    if (incomingByte >= '0' && incomingByte <= '9')
      reading = reading * 10 + (incomingByte - '0');
    else;
    incomingByte = Serial.read();
  }
  Serial.flush();
  return reading;
}
void RefreshIV18() 
  for (int count = 1;count<=9;count++){

    long data=0;
    data = segFont[bChars[count]];
    bitSet(data,17-count);
    if (dChars[count] == 1){
      bitSet(data,7);
    }
    digitalWrite(loadPin, LOW); 
  //Shiftin 20 bits
  for(byte i=0; i<20; i++) 
  { 
    //clockPin LOW
    digitalWrite(clockPin, LOW);
    //datapin bit to 1 OR 0 
    digitalWrite(dataPin,bitRead(data, i));
    //Set clockPin HIGH
    digitalWrite(clockPin, HIGH); 
  }

  digitalWrite(loadPin, HIGH);

}
}

byte bcdToDec(byte val)  {
// Convert binary coded decimal to normal decimal numbers
return ( (val/16*10) + (val%16) );
}


void timetoIV18(byte h,byte m,byte s)
{
  memset(bChars,0,sizeof(dChars));
  memset(dChars,0,sizeof(bChars));
  bChars[7]=h % 10; 
  bChars[8]=h / 10;
  bChars[6]=11;
  dChars[6]=1;

  bChars[4]=m % 10; 
  bChars[5]=m / 10;
 bChars[3]=11;
  dChars[3]=1;

  bChars[1]=s % 10; 
  bChars[2]=s / 10;

  

}
void datetoIV18(int yy,int mm,int dd)
{
  memset(dChars,0,sizeof(dChars));
  memset(bChars,0,sizeof(bChars));

  bChars[8]=yy/10;
  bChars[7]=yy%10; 
  
  bChars[6]=10;

  bChars[5]=mm/10; 
  bChars[4]=mm%10;

  bChars[3]=10;

  bChars[2]=dd / 10;
  bChars[1]=dd % 10; 

}


byte decToBcd(byte val){
// Convert normal decimal numbers to binary coded decimal
return ( (val/10*16) + (val%10) );
}

void printDate(){
  Wire.beginTransmission(DS1307_ADDRESS);
  Wire.write(zero);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_ADDRESS, 7);

  seconds = bcdToDec(Wire.read());
  minutes = bcdToDec(Wire.read());
  hours = bcdToDec(Wire.read() & 0b111111); //24 hour time
  
   weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
  monthDay = bcdToDec(Wire.read());
  months = bcdToDec(Wire.read());
   years = bcdToDec(Wire.read());
/*
  //print the date EG   3/1/11 23:59:59
  Serial.print(months);
  Serial.print("/");
  Serial.print(monthDay);
  Serial.print("/");
  Serial.print(years);
  Serial.print(" ");
  Serial.print(hours);
  Serial.print(":");
  Serial.print(minutes);
  Serial.print(":");
  Serial.println(seconds);
  */
}

2 則留言:

  1. 請問可以購買套件嗎?

    回覆刪除
    回覆
    1. PCB有的賣
      IC去申請Sample吧~
      管子上ebay買一兩支含運也兩三百左右

      刪除