AT24C32 Real time clock

  • AT24C32 / DS1307 Real Time Clock

Here below is an example code:

an example of a project with the module.

/*
Author: Danny van den Brande, arduinosensors.nl. BlueCore Tech.
This code is written for the AT24C32/DS1307 RTC Module and 
4 digit Seven Segment displays. 
Be sure to check if you have a common anode or cathode display.(change @ line 26)
 */
#include "Wire.h"
#include "SevSeg.h" //https://github.com/sparkfun/SevSeg/tree/master/src
 
#define DS1307_ADDRESS 0x68
 
//Create an instance
SevSeg display7seg;
 
int valor = 0;
 
byte zero = 0x00; 
unsigned long timer;
void setup()
{
  Wire.begin();
  //Comment this line after you have set the date @ void TimeSelection() below
//   TimeSelection(); Uncomment this line when your setting the time. Set time @ (line 66)
  
  //Change to COMMON_ANODE if you have a Common anode display.
  int displayType = COMMON_CATHODE; 
     
  int digit1 = 10; 
  int digit2 = 11; 
  int digit3 = 12; 
  int digit4 = 13; 
 
  int segA = 2;  
  int segB = 3; 
  int segC = 4; 
  int segD = 5; 
  int segE = 6; 
  int segF = 7; 
  int segG = 8; 
  int segDP= 9; 
   
  int numberOfDigits = 4;
 
  //Initialize display
  display7seg.Begin(displayType, numberOfDigits, digit1, digit2, digit3, digit4, segA, segB, segC, segD, segE, segF, segG, segDP);
   
  //Set brightness
  display7seg.SetBrightness(50);
  timer = millis();
}
 
void loop()
{
  char tempString[10]; //Used for sprintf
  Wire.beginTransmission(DS1307_ADDRESS);
  Wire.write(zero);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_ADDRESS, 7);
  int seconds = ConvertToDecimal(Wire.read());
  int minutes = ConvertToDecimal(Wire.read());
  int hours = ConvertToDecimal(Wire.read() & 0b111111); 
  sprintf(tempString, "%02d%02d", hours, minutes);
  display7seg.DisplayString(tempString, 3);
}
 
void TimeSelection()   //Select date and time here below!!(line 69,70,71)
//after setting time also comment time TimeSelection() @ void setup
{
  byte seconds = 10; //Valores de 0 a 59
  byte minutes = 38; //Valores de 0 a 59
  byte hours = 3; //Valores de 0 a 23
  Wire.beginTransmission(DS1307_ADDRESS);
  Wire.write(zero); //Stop no CI para que o mesmo possa receber os dados
 
  //As linhas abaixo escrevem no CI os valores de 
  //data e hora que foram colocados nas variaveis acima
  Wire.write(ConvertToPCD(seconds));
  Wire.write(ConvertToPCD(minutes));
  Wire.write(ConvertToPCD(hours));
  Wire.write(zero);
  Wire.endTransmission(); 
}
 
byte ConvertToPCD(byte val)
{ 
  //Convert Decimal to binary
  return ( (val/10*16) + (val%10) );
}
 
byte ConvertToDecimal(byte val)  
{ 
  //Convert binary to decimal
  return ( (val/16*10) + (val%16) );
}

Write a review

Please login or register to review

AT24C32 / DS1307 Real Time Clock

  • Webwinkel Keurmerk en klantebeoordelingen

  • 14 dagen bedenktijd 
  • Verzendkosten voor eigen rekening
  • Product Code: AT24C32
  • Availability: 12
  • 3.50€

  • Ex Tax: 2.89€

Similar Products

GY-521 MPU6050 3-Axis Accelerometer Gyroscope 6DOF Module

GY-521 MPU6050 3-Axis Accelerometer Gyroscope 6DOF Module

The InvenSense MPU-6050 sensor contains a MEMS accelerometer and a MEMS gyro in a single chip. It is..

4.50€ Ex Tax: 3.72€

lm2596 DC-DC Step-down module 5V/12V/24V 3A

lm2596 DC-DC Step-down module 5V/12V/24V 3A

LM2596S power module for decreasing a supply voltage on the basis of a voltage regulator.The input v..

1.95€ Ex Tax: 1.61€

IIC I2C Logic Level Converter Bi-Directional Module 5V to 3.3V

IIC I2C Logic Level Converter Bi-Directional Module 5V to 3.3V

Logic Level Converter bi-directional is a small device that safely 5V signals to 3.3 Sales and 3.3V ..

1.95€ Ex Tax: 1.61€

Tags: arduino, AT24C32, ds1307, RTC