Go Down

Topic: Domino Clock (Read 12594 times) previous topic - next topic

CrossRoads

Don't know, never used the DS1307, can you send a linkt to a datasheet?  The drawing looks very nice.
I believe you have the right arduino pins (or at worst they are swapped).

For push buttons, why not use the internal pullups and switch to ground instead? Save on a few parts.
Which pins are PC0 & PC5? Aren't those the analog pins?
You already have A5 committed to SCL above, so that wouldn't be a good choice for an input pin.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

stregoi

Great Then ! yes the PC0 and the PC5 are analog pins, so i guess i will just use PC0 and PC3 wich is analog too.

i just did a little research about using internal pull-ups, but i cant see the logic in saving parts, because as far as i understood i will still using 2 push buttons and to resistors.

and the datascheet for the RTC is : http://www.datasheetdir.com/DS1307+download

CrossRoads

With the internal pullups, you only need the switch.
With the switch open, the pin is pulled high internally and reads as 1.
To get 0 you close the switch to ground.  No external resistors needed.

You can use digital pins for switch closures like this as well, doesn't have to go into an analog pin.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

stregoi

Sounds Very good, i guess i will stick with the 2 push up buttons to set the hours and the minutes, it is much easier for me to understand, the newbee as i am :)
I guess my hardware part is done .. thanks for a big help, i learned a lot.

now i have to move to the coding part, and i guess i will read the earlier post you answered earlier, i should learned something from there, since i guess it will fit with what i am doing.

i will surely ask for more help :) ... and i will publish my steps so others can learn something too :)

stregoi

#19
Feb 23, 2011, 11:46 pm Last Edit: Feb 23, 2011, 11:49 pm by stregoi Reason: 1
i Guess you should take a look at the the FP2880A is kind of smart and can be used to control the flip-dots, here is the dokumentation :

http://www.datasheetcatalog.org/datasheets/320/500899_DS.pdf

but there is no much information / projects with it in google.

Now for the code :) .... i've been studying the code from the original thread, from the biginning i can't understand this part of code :

Code: [Select]
//Data Lines to the hour stone
int hlatchPin = 3;
int hclockPin = 4;
int hdataPin = 5;

//Data Lines to the decimal minute stone
int dlatchPin = 6;
int dclockPin = 7;
int ddataPin = 8;

//Data Lines to the single minute stone
int mlatchPin = 9;
int mclockPin = 10;
int mdataPin = 11;


as far as i understood we are hooking ALL the 75HC595's to only 3 output pins ( latch / clock / data ) witch are ( 8 / 11 / 12 ),
In the code why are we defining 6 output pins from the adruino ? is it because every to 74HC595 are going to be hooked to three pin's in the adruino ( 2 shift registers at  3 / 4 / 5 ) ( 2 shift registers at  6 / 7 / 8 )( 2 shift registers at  9 / 10 / 11 )?


CrossRoads

Either method works.
The original allows the 3 "digits" to be updated individually.
Your schematics will have all data go out at once. Either way can work.

The FP2800 looks like a nice chip, able to both output high current and sink high current (unlike the ULN2803, which only sinks current).
Wonder where they are available?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

stregoi

Yeah .. it seems like something nice, unfortunetly it's quite hard to find and almost no DIY projects with it. I guess you can request it from this website : http://www.hobid.com/bin/buysell.php

i was thinking to experiment with it, but i guess i'll stick to the easy stuff for now .. this project, is kind of "learning by doing" so .

About the code .. that made sans !

i was editing the code spencerH wrote, taking in onsideration your answers too, i have a "finished" version ... is it okay you think ? ( it makes sans to me anyways :) )

Code: [Select]
#include <Time.h>


//Data Lines to the hour stone
int hlatchPin = 3;
int hclockPin = 4;
int hdataPin = 5;

//Data Lines to the decimal minute stone
int dlatchPin = 6;
int dclockPin = 7;
int ddataPin = 8;

//Data Lines to the single minute stone
int mlatchPin = 9;
int mclockPin = 10;
int mdataPin = 11;

int h = 0;
int m = 0;
int mins = 0;
int d = 0;
int previousHours = 0;
int previousMins = 0;


byte number_to_display;


//hour and minute adjust buttons
const int hourPin = 12;
const int minPin = 13;

void loop() {

hourState = digitalRead(hourPin);
minState = digitalRead(minPin);

//Hour adjustment
if (hourState == HIGH) {
  time_t t = now();
  t = t + 3600;
  setTime(t);
}
//Minute adjustment
if (minState == HIGH) {
  time_t t = now();
  t = t + 60;
  setTime(t);
}


void setup() {

  pinMode(hlatchPin, OUTPUT);
  pinMode(hclockPin, OUTPUT);
  pinMode(hdataPin, OUTPUT);

  pinMode(dlatchPin, OUTPUT);
  pinMode(dclockPin, OUTPUT);
  pinMode(ddataPin, OUTPUT);

  pinMode(mlatchPin, OUTPUT);
  pinMode(mclockPin, OUTPUT);
  pinMode(mdataPin, OUTPUT);



int hours_display[13];

number_to_display[0] = B0000000000000000;
number_to_display[1] = 0000000001000000;
number_to_display[2] = 0100000001000000;
number_to_display[3] = 0100000000100100;
number_to_display[4] = 0010010000100100;
number_to_display[5] = 0010010001100100;
number_to_display[6] = 0110010001100100;
number_to_display[7] = 0110010000101101;
number_to_display[8] = 0010110100101101;
number_to_display[9] = 0010110101101101;
number_to_display[10] = 0110110101101101;
number_to_display[11] = 0110110100111111;
number_to_display[12] = 0011111100111111;
}

void loop() {

    h = hourFormat12();
    m = minute();

    if(previousHours != h) {
digitalWrite(hlatchPin, LOW);
shiftOut(hdataPin, hclockPin, MSBFIRST, (number_to_display[h] >>8));
shiftOut(hdataPin, hclockPin, MSBFIRST, hours_display[h]);

digitalWrite(hlatchPin, HIGH);
previousHours = h;
    }
    if(previousMins != m) {
mins = m;
if(mins >= 10) {
  d = 0;
  while(mins >= 10) {
    mins = mins - 10;
    d = d + 1;
  }
  digitalWrite(dlatchPin, LOW);
  shiftOut(ddataPin, dclockPin, MSBFIRST, (number_to_display[d] >> 8));
          shiftOut(ddataPin, dclockPin, MSBFIRST, number_to_display[d]);

  digitalWrite(dlatchPin, HIGH);
  digitalWrite(mlatchPin, LOW);
          shiftOut(mdataPin, mclockPin, MSBFIRST, (number_to_display[mins] >> 8));
          shiftOut(mdataPin, mclockPin, MSBFIRST, number_to_display[mins]);

  digitalWrite(mlatchPin, HIGH);
}
else {
  digitalWrite(dlatchPin, LOW);
  shiftOut(ddataPin, dclockPin, MSBFIRST, 0);
  shiftOut(ddataPin, dclockPin, MSBFIRST, 0);
  shiftOut(ddataPin, dclockPin, MSBFIRST, 0);
  digitalWrite(dlatchPin, HIGH);
  digitalWrite(mlatchPin, LOW);
          shiftOut(mdataPin, mclockPin, MSBFIRST, (number_to_display[mins] >> 8));
          shiftOut(mdataPin, mclockPin, MSBFIRST, number_to_display[mins]);
  digitalWrite(mlatchPin, HIGH);
}
previousMins = m;
    }

}



CrossRoads

Okay, here's my initial comments.

Need to declare your time set buttons as pinMode inputs. (just good coding practice - may work as is with the default after a reset being to put the pins into input state I believe).

You declare a bunch of stuff in setup that belongs prior to setup.  May work as is, again just good coding practice
everything from
int hours_display[13];
down to
number_to_display[12] = 0011111100111111;

Okay, this part will be a gotcha:
You have void loop, void setup, and then void loop again.
I would probably take the button reading stuff in the first void loop and insert it before } that ends the 2nd void loop.
I'm not sure how fast the 2nd void loop goes thru, probably pretty darn fast since the 2 if conditions are only met once/hour and once/minute.

You likely need some debounce code with the button press to avoid multiple changes with each press.
You have access to seconds with time.h? Maybe  ensure that digits only change once a second or something.

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

stregoi

#23
Feb 24, 2011, 12:28 pm Last Edit: Feb 24, 2011, 01:10 pm by stregoi Reason: 1
Okay i made the changes in the code ( in red ) - including the debounce code, i hope it is coded right.

Thought I cannot figure out how to use the clock, i ensure that digits only change once a second.

I am using a real-time clock DS1307 i found this code, for defining the library, but honestly i can figure out how to do it :
Code: [Select]
/*
* DS1307RTC.h - library for DS1307 RTC
* This library is intended to be uses with Arduino Time.h library functions
*/

#ifndef DS1307RTC_h
#define DS1307RTC_h

#include <Time.h>

// library interface description
class DS1307RTC
{
  // user-accessible "public" interface
  public:
    DS1307RTC();
    static time_t get();
        static void set(time_t t);
        static void read(tmElements_t &tm);
        static void write(tmElements_t &tm);

  private:
        static uint8_t dec2bcd(uint8_t num);
    static uint8_t bcd2dec(uint8_t num);
};

extern DS1307RTC RTC;

#endif

stregoi

#24
Feb 24, 2011, 01:11 pm Last Edit: Feb 24, 2011, 11:11 pm by stregoi Reason: 1
Code: [Select]
#include <Time.h>


//Data Lines to the hour stone
int hlatchPin = 3;
int hclockPin = 4;
int hdataPin = 5;

//Data Lines to the decimal minute stone
int dlatchPin = 6;
int dclockPin = 7;
int ddataPin = 8;

//Data Lines to the single minute stone
int mlatchPin = 9;
int mclockPin = 10;
int mdataPin = 11;

int h = 0;
int m = 0;
int mins = 0;
int d = 0;
int previousHours = 0;
int previousMins = 0;

byte number_to_display;

//hour and minute adjust buttons
const int hourPin = 12;
const int minPin = 13;

[color=red]int hours_display[13];
number_to_display[0] = B0000000000000000;
number_to_display[1] = 0000000001000000;
number_to_display[2] = 0100000001000000;
number_to_display[3] = 0100000000100100;
number_to_display[4] = 0010010000100100;
number_to_display[5] = 0010010001100100;
number_to_display[6] = 0110010001100100;
number_to_display[7] = 0110010000101101;
number_to_display[8] = 0010110100101101;
number_to_display[9] = 0010110101101101;
number_to_display[10] = 0110110101101101;
number_to_display[11] = 0110110100111111;
number_to_display[12] = 0011111100111111;[/color]

void setup() {

  pinMode(hlatchPin, OUTPUT);
  pinMode(hclockPin, OUTPUT);
  pinMode(hdataPin, OUTPUT);

  pinMode(dlatchPin, OUTPUT);
  pinMode(dclockPin, OUTPUT);
  pinMode(ddataPin, OUTPUT);

  pinMode(mlatchPin, OUTPUT);
  pinMode(mclockPin, OUTPUT);
  pinMode(mdataPin, OUTPUT);

[color=red]  pinMode(hourPin, INPUT);
  pinMode(minPin, INPUT);[/color]

[color=red]
int hourState = digitalRead(hourPin);
int minState = digitalRead(minPin);

int buttonState;             // the current hourstate from the input pin
int lastButtonState = LOW;   // the previous hourstate from the input pin
int buttonState2;             // the current hourstate from the input pin
int lastButtonState2 = LOW;   // the previous hourstate from the input pin

long lastDebounceTime = 0;  // the last time the output pin was toggled
long debounceDelay = 50;    // the debounce time; increase if the output flickers

//Hour adjustment
// if the button is pressed
// 1) reset the debouncing timer
// 2) take the debounce delay as the current state
// 3) Set time
// 4) save the hourstat

if (hourState == HIGH) {

  lastDebounceTime = millis();

  if ((millis() - lastDebounceTime) > debounceDelay) {
    buttonState = hourstate;
  }

  time_t t = now();
  t = t + 3600;
  setTime(t);

  lastButtonState = hourstate;

}

//Minute adjustment
if (minState == HIGH) {

  lastDebounceTime = millis();

  if ((millis() - lastDebounceTime) > debounceDelay) {
    buttonState2 = minstate;
  }

  time_t t = now();
  t = t + 60;
  setTime(t);
  lastButtonState2 = minstate;
}[/color]
}

void loop() {

    h = hourFormat12();
    m = minute();

    if(previousHours != h) {
digitalWrite(hlatchPin, LOW);
shiftOut(hdataPin, hclockPin, MSBFIRST, (number_to_display[h] >> 8 ));
shiftOut(hdataPin, hclockPin, MSBFIRST, hours_display[h]);

digitalWrite(hlatchPin, HIGH);
previousHours = h;
    }
    if(previousMins != m) {
mins = m;
if(mins >= 10) {
  d = 0;
  while(mins >= 10) {
    mins = mins - 10;
    d = d + 1;
  }
  digitalWrite(dlatchPin, LOW);
  shiftOut(ddataPin, dclockPin, MSBFIRST, (number_to_display[d] >> 8 ));
          shiftOut(ddataPin, dclockPin, MSBFIRST, number_to_display[d]);

  digitalWrite(dlatchPin, HIGH);
  digitalWrite(mlatchPin, LOW);
          shiftOut(mdataPin, mclockPin, MSBFIRST, (number_to_display[mins] >> 8 ));
          shiftOut(mdataPin, mclockPin, MSBFIRST, number_to_display[mins]);

  digitalWrite(mlatchPin, HIGH);
}
else {
  digitalWrite(dlatchPin, LOW);
  shiftOut(ddataPin, dclockPin, MSBFIRST, 0);
  shiftOut(ddataPin, dclockPin, MSBFIRST, 0);
  shiftOut(ddataPin, dclockPin, MSBFIRST, 0);
  digitalWrite(dlatchPin, HIGH);
  digitalWrite(mlatchPin, LOW);
          shiftOut(mdataPin, mclockPin, MSBFIRST, (number_to_display[mins] >> 8 ));
          shiftOut(mdataPin, mclockPin, MSBFIRST, number_to_display[mins]);
  digitalWrite(mlatchPin, HIGH);
}
previousMins = m;
    }

}

CrossRoads

All this stuff here
Code: [Select]

//Hour adjustment
// if the button is pressed
// 1) reset the debouncing timer
// 2) take the debounce delay as the current state
// 3) Set time
// 4) save the hourstat

if (hourState == HIGH) {

  lastDebounceTime = millis();

  if ((millis() - lastDebounceTime) > debounceDelay) {
    buttonState = hourstate;
  }

  time_t t = now();
  t = t + 3600;
  setTime(t);

  lastButtonState = hourstate;

}

//Minute adjustment
if (minState == HIGH) {

  lastDebounceTime = millis();

  if ((millis() - lastDebounceTime) > debounceDelay) {
    buttonState2 = minstate;
  }

  time_t t = now();
  t = t + 60;
  setTime(t);
  lastButtonState2 = minstate;
}

needs to be part of void loop, or a function that void loop calls.
If it is in void setup, you get that brief shot as your sketch starts to press the buttons, and then no more.

please start putting [ code ] and [ /code ] (without the spaces) around the code you post. The # sign pull them up for you also.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

stregoi

okay thank you .. but was it the right way to do a debounce, because it was i understood from the sources i read ?

what about the RTC, do you have any suggestions how to set the digits to only change every second ... should i use delay(60000) efter the minutes is shifted ?

CrossRoads

This section of code
Code: [Select]

void loop() {

    h = hourFormat12();
    m = minute();

    if(previousHours != h) {
digitalWrite(hlatchPin, LOW);
shiftOut(hdataPin, hclockPin, MSBFIRST, (number_to_display[h] >>8));
shiftOut(hdataPin, hclockPin, MSBFIRST, hours_display[h]);

digitalWrite(hlatchPin, HIGH);
previousHours = h;
    }
    if(previousMins != m) {

constantly reads the RTC and see if the hour has changed, or if the minute has changed.
Why do you think you need to do anything else?
As far as debounce, give it a try, see if it works.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

stregoi

i just tried to make the setup .. i can flip the dot one way, but nit the other way ! .. i guess that i have to use a H-brigde anyways. i've looking around at the internet and i guess i will use "L293D"

http://www.datasheetcatalog.org/datasheet/texasinstruments/l293d.pdf

it can only run 2 stepmotors / electromagnets at a time ... my question is what is the smartest to do, one H-bridge for every single electromagnet ? and please how can i connect these to my shift registers ?

CrossRoads

So the magnet pulling back to the screwhead is not working? That's too bad. Let me do datasheet reading & thinking.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up