Categories
Statistics
Flag Counter
Since 08.08.2014
Counts only, if "DNT = disabled".

Your IP is 18.188.69.167
ec2-18-188-69-167.us-east-2.
Info
Valid HTML 4.01 Transitional Creative Commons Lizenzvertrag
rss
เราจะทำแบบวิศวกรผู้ยิ่งใหญ่
We love the King
30. December 2024
YOU RATED THIS ...
avg = 0.0 ,  n = 0


Clock To School Project :-)
Arduino-ClockToSchool.php    15086 Bytes    04-06-2024 19:34:43


Clock To School Project :-)


Let's see if our teachers get nervous ...



Sometimes also referred to as "Clockduino" or "Countdown Timer". The only genuine Swiss Arduino Clock in the World. With Alarm and Countdown functionality ...



Clock To School Project :-)

Clock To School Project :-) Clock To School Project :-)




✈ Hardware Description




The CTSP shield uses a CMOS clock and calendar circuit, optimised for low power consumption. Addresses and data are transferred serially via the two-line bidirectional I2C-bus. It is buffered with a 1 F capacitor to allow continuous operation. A PCF8593T from NXP is used here, but there are a lot of pin-compatible types out there. Four push buttons allow to set the time and the alarm. Special functions mayst evaluate the pressing of more than one button. The display uses 4 seven segment displays to show 4 digits (CC). The Arduino (UNO) multiplexes them. A small beeper mayst be used as an alarm (or countdown timer beep :-)

The device is supplied with an external battery in the range of 7 ... 12 V. Use curly wires under any circumstances. Multiple colours and some redundancy wires enhance the impression. We use 5 times an 1,5 V Baby C/ LR14/ AM2/ 4014/Alkaline Batterie resulting in a supply voltage of 7.5 V. The "battery case" is made of platic tubes, wrapped in paper.


SA39-11SRWA AN10652




✈ Calibrating that thing




The PCF8593 has an 1 Hz (1 pps) output. This is K6 (in the schematics) or "CAL" on the pcb. Connect a high resolution counter and adjust the Capacitor C2 to get 1.00000000 Hz. If the required accuracy is within 1 second per day you need at least an 8 digit frequency counter with an accuracy of 1 ppm. Here 1 ppm equals 32.768 mHz.




✈ Arduino Sketch - The Code (for a simple clock)



The buttons are used to set the clock.

/*
 *    ARDUINO CLOCK WITH PCF8593 I2C RTC
 *    https://www.changpuak.ch/electronics/Arduino-ClockToSchool.php
 *    Software Version 2.2
 *    14.01.2016, Alexander C. Frank
 */

#include "Wire.h"

#define PCF8593ADR 0x51

#include "TimerOne.h"     // Timer Interrupt Handling
// 50 Hz Scanrate >> 20 ms per 4 digits >> Interrupt every 5 ms
int alle_x_millisekunden = 5 ;
 
// 7-Segment
int ActualDigit ;
int ActualDigitValue ;
int A = 2;
int B = 3;
int C = 4;
int D = 5;
int E = 6;
int F = 7;
int G = 8;
int DP = 9;
int BEEP = A3;
int Digit1 = 13;
int Digit2 = 12;
int Digit3 = 11;
int Digit4 = 10;
int DETONATOR = A2;
int Key = A0;
int KeyValue = 0;

byte second, minute, hour ;

byte bcdToDec(byte value)
{
  return ((value / 16) * 10 + value % 16);
}

byte decToBcd(byte value){
  return (value / 10 * 16 + value % 10);
}

void SetPCF8593()
{
  Wire.beginTransmission(PCF8593ADR);
  Wire.write(0x00);
  Wire.write(decToBcd(0));    // CONTROL     
  Wire.write(decToBcd(0));    // HUNDRETHS
  Wire.write(decToBcd(second));       
  Wire.write(decToBcd(minute));      
  Wire.write(decToBcd(hour));        
  Wire.endTransmission();
}

void ReadPCF8593()
{
  Wire.beginTransmission(PCF8593ADR);
  Wire.write(0x03);
  Wire.endTransmission();
  Wire.requestFrom(PCF8593ADR, 2);
  minute = bcdToDec(Wire.read() & B01111111);  
  hour   = bcdToDec(Wire.read() & B00111111);  
}

void setup()
{
  Wire.begin();
  Serial.begin(9600);
  second = 0;
  minute = 0;
  hour = 0;
  // SetPCF8593();
  Timer1.initialize(alle_x_millisekunden*1000) ;
  Timer1.attachInterrupt(NextDigit) ;

  pinMode(A, OUTPUT); 
  pinMode(B, OUTPUT); 
  pinMode(C, OUTPUT); 
  pinMode(D, OUTPUT); 
  pinMode(E, OUTPUT); 
  pinMode(F, OUTPUT); 
  pinMode(G, OUTPUT); 
  pinMode(DP, OUTPUT); 
  pinMode(BEEP, OUTPUT); 
  pinMode(Digit1, OUTPUT); 
  pinMode(Digit2, OUTPUT); 
  pinMode(Digit3, OUTPUT);  
  pinMode(Digit4, OUTPUT);  
  pinMode(DETONATOR, OUTPUT); 
}

void DisplayDigit(int value)
{
  while (value >= 10) value = value - 10;
  switch (value)
  {
  case 0 : 
  digitalWrite(A, LOW); digitalWrite(B, LOW); digitalWrite(C, LOW);
  digitalWrite(D, LOW); digitalWrite(E, LOW); digitalWrite(F, LOW);
  digitalWrite(G, HIGH);
  break;
  case 1 :
  digitalWrite(A, HIGH); digitalWrite(B, LOW); digitalWrite(C, LOW);
  digitalWrite(D, HIGH); digitalWrite(E, HIGH); digitalWrite(F, HIGH);
  digitalWrite(G, HIGH);
  break;
  case 2 :
  digitalWrite(A, LOW); digitalWrite(B, LOW); digitalWrite(C, HIGH);
  digitalWrite(D, LOW); digitalWrite(E, LOW); digitalWrite(F, HIGH);
  digitalWrite(G, LOW);
  break;
  case 3 :
  digitalWrite(A, LOW); digitalWrite(B, LOW); digitalWrite(C, LOW);
  digitalWrite(D, LOW); digitalWrite(E, HIGH); digitalWrite(F, HIGH);
  digitalWrite(G, LOW);
  break;
  case 4 :
  digitalWrite(A, HIGH); digitalWrite(B, LOW); digitalWrite(C, LOW);
  digitalWrite(D, HIGH); digitalWrite(E, HIGH); digitalWrite(F, LOW);
  digitalWrite(G, LOW);
  break;
  case 5 :
  digitalWrite(A, LOW); digitalWrite(B, HIGH); digitalWrite(C, LOW);
  digitalWrite(D, LOW); digitalWrite(E, HIGH); digitalWrite(F, LOW);
  digitalWrite(G, LOW);
  break;
  case 6 :
  digitalWrite(A, LOW); digitalWrite(B, HIGH); digitalWrite(C, LOW);
  digitalWrite(D, LOW); digitalWrite(E, LOW); digitalWrite(F, LOW);
  digitalWrite(G, LOW);
  break;
  case 7 :
  digitalWrite(A, LOW); digitalWrite(B, LOW); digitalWrite(C, LOW);
  digitalWrite(D, HIGH); digitalWrite(E, HIGH); digitalWrite(F, HIGH);
  digitalWrite(G, HIGH);
  break;
  case 8 :
  digitalWrite(A, LOW); digitalWrite(B, LOW); digitalWrite(C, LOW);
  digitalWrite(D, LOW); digitalWrite(E, LOW); digitalWrite(F, LOW);
  digitalWrite(G, LOW);
  break;
  case 9 :
  digitalWrite(A, LOW); digitalWrite(B, LOW); digitalWrite(C, LOW);
  digitalWrite(D, LOW); digitalWrite(E, HIGH); digitalWrite(F, LOW);
  digitalWrite(G, LOW);
  break;    
  }
}

void NextDigit() 
{
ActualDigit = ActualDigit + 1;
if (ActualDigit > 4) ActualDigit = 1;
int HH = hour / 10;
int H = hour - ( HH * 10 ) ;
int MM = minute / 10 ;
int M = minute - ( MM * 10 ) ;
switch (ActualDigit)
  {
   case 1 : ActualDigitValue = HH ; break ;
   case 2 : ActualDigitValue = H ; break ;
   case 3 : ActualDigitValue = MM ; break ;
   case 4 : ActualDigitValue = M ; break ;
  }

DisplayDigit(ActualDigitValue);
switch (ActualDigit)
  {
   case 1 : digitalWrite(Digit1, LOW) ; digitalWrite(Digit2, HIGH) ; 
   			digitalWrite(Digit3, HIGH) ; digitalWrite(Digit4, HIGH) ; break ;
   case 2 : digitalWrite(Digit1, HIGH) ; digitalWrite(Digit2, LOW) ; 
   			digitalWrite(Digit3, HIGH) ; digitalWrite(Digit4, HIGH) ; break ;
   case 3 : digitalWrite(Digit1, HIGH) ; digitalWrite(Digit2, HIGH) ; 
   			digitalWrite(Digit3, LOW) ; digitalWrite(Digit4, HIGH) ; break ;
   case 4 : digitalWrite(Digit1, HIGH) ; digitalWrite(Digit2, HIGH) ; 
   			digitalWrite(Digit3, HIGH) ; digitalWrite(Digit4, LOW) ; break ;
  }
}

void loop()
{
  ReadPCF8593();
  KeyValue = analogRead(Key);
  // NO KEY = 930, KEY1 = 754, KEY2 = 579, KEY3 = 396, KEY4 = 193
  if ((KeyValue < 842) && (KeyValue > 666)) 
  { 
    // KEY1 WAS PRESSED
    hour = hour + 10;
    if (hour > 23) hour = hour - 30;
    SetPCF8593();
  }
  if ((KeyValue < 665) && (KeyValue > 489))  
  { 
    // KEY2 WAS PRESSED
    hour = hour + 1;
    if (hour > 23) hour = 0;
    SetPCF8593();
  }
  if ((KeyValue < 488) && (KeyValue > 296)) 
  { 
    // KEY3 WAS PRESSED
    minute = minute + 10;
    if (minute > 59) minute = minute - 60;
    SetPCF8593();
  }
  if ( KeyValue < 295 )  
  { 
    // KEY4 WAS PRESSED
    minute = minute + 1;
    if (minute > 59) minute = 0;
    SetPCF8593();
  }

  delay(1000);
}





✈ Showing that thing to my teachers (et al :-)




Clock to School Project
@ my school : passed
Clock to School Project
@ airport : pending ...




✈ Advanced Tips




• Do not forget your new clock in a train, tram or taxi.
• We shall not be held responsible, if the "show your teacher" part fails.




✈ Share your thoughts



The webmaster does not read these comments regularely. Urgent questions should be send via email. Ads or links to completely uncorrelated things will be removed.


Your Browser says that you allow tracking. Mayst we suggest that you check that DNT thing ?

 
t1 = 6745 d

t2 = 401 ms

★ ★ ★  Copyright © 2006 - 2024 by changpuak.ch  ★ ★ ★

Impressum