Pages: 1 [2]   Go Down
Author Topic: [Advice needed] Building a small BCD clock.  (Read 3412 times)
0 Members and 1 Guest are viewing this topic.
Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4092
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You will need to (re)set the time sometime.

Yes.

Quote
Daylightsaving f.ex.

I humbly submit my fix for that, for your consideration:
http://arduino.cc/forum/index.php/topic,96891.0.html
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 33
Posts: 1225
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Best way to explain is the code smiley

The setuploop is called in the loop() code, when we are setting the clock (initiated by a long press of the button, as a short press was used to do something else), ie. it is called repeatedy and often (until the SetClock is false)

Instead of LEDs I have a meter, you just do some visual feedback on your LEDs instead at the SetNeedle()
Code:
void setuploop() {
/* This is a small state machine, ensuring we can enter current HH:MI with one button.
  The needle is waved a bit, then wait for number button pushes that sets a single digit. */

  static byte Entry = 0 ; // State machine
  static byte N ; static byte H = 0 ; static byte T = 0 ; static byte M = 0 ;

  switch (Entry) {
    case 0: case 2: case 4: case 6: wiggle() ; Entry++ ; break ;
    case 1: if (ButtonUpd(&N)) Entry++ ; if (N>2) N=0 ; break ;
    case 3: if (ButtonUpd(&H)) Entry++ ; if (H>9 || (N==2&&H>3)) H=0 ; break ;
    case 5: if (ButtonUpd(&T)) Entry++ ; if (T>5) T=0 ; break ;
    case 7: if (ButtonUpd(&M)) Entry++ ; if (M>9) M=0 ; break ;
    case 8: SetClock = false ;
            //Store a new value in the RTC chip. Date is ignored (random)
            RTC.stopClock();
            RTC.fillByHMS(N*10+H,T*10+M,0);
            RTC.setTime();
            RTC.startClock();
            break ;
  }
}

boolean ButtonUpd(byte *Pdig) {
/* return true when no button change for several seconds. Increment argument for every button push
  put needle at value for feedback. (Wrap is handled by calling function) */

  static byte PrvBtn = HIGH ;
  byte Button ;

  SetNeedle( *Pdig, 10 ) ;
  if ( millis() - Timer > 5 && (Button=digitalRead(BUTN1)) != PrvBtn) {
    // button change, increment digit if push
    if (Button==LOW) (*Pdig)++ ;
    Timer = millis() ; PrvBtn = Button ;
  }
  return millis() - Timer >5000L ;
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Best way to explain is the code smiley

The setuploop is called in the loop() code, when we are setting the clock (initiated by a long press of the button, as a short press was used to do something else), ie. it is called repeatedy and often (until the SetClock is false)

Instead of LEDs I have a meter, you just do some visual feedback on your LEDs instead at the SetNeedle()
Code:
void setuploop() {
/* This is a small state machine, ensuring we can enter current HH:MI with one button.
  The needle is waved a bit, then wait for number button pushes that sets a single digit. */

  static byte Entry = 0 ; // State machine
  static byte N ; static byte H = 0 ; static byte T = 0 ; static byte M = 0 ;

  switch (Entry) {
    case 0: case 2: case 4: case 6: wiggle() ; Entry++ ; break ;
    case 1: if (ButtonUpd(&N)) Entry++ ; if (N>2) N=0 ; break ;
    case 3: if (ButtonUpd(&H)) Entry++ ; if (H>9 || (N==2&&H>3)) H=0 ; break ;
    case 5: if (ButtonUpd(&T)) Entry++ ; if (T>5) T=0 ; break ;
    case 7: if (ButtonUpd(&M)) Entry++ ; if (M>9) M=0 ; break ;
    case 8: SetClock = false ;
            //Store a new value in the RTC chip. Date is ignored (random)
            RTC.stopClock();
            RTC.fillByHMS(N*10+H,T*10+M,0);
            RTC.setTime();
            RTC.startClock();
            break ;
  }
}

boolean ButtonUpd(byte *Pdig) {
/* return true when no button change for several seconds. Increment argument for every button push
  put needle at value for feedback. (Wrap is handled by calling function) */

  static byte PrvBtn = HIGH ;
  byte Button ;

  SetNeedle( *Pdig, 10 ) ;
  if ( millis() - Timer > 5 && (Button=digitalRead(BUTN1)) != PrvBtn) {
    // button change, increment digit if push
    if (Button==LOW) (*Pdig)++ ;
    Timer = millis() ; PrvBtn = Button ;
  }
  return millis() - Timer >5000L ;
}

Nice, may I use it?

Alright guys, I'm back to school and now I have it all set up:
Arduino uno as ISP, trying to program ATtiny2313. All connections are triple checked, the heartbeat led is beating, the cap is between reset and ground. I uploaded the patched ArduinoISP sketch to the arduino, connected the cap and all four wires from the tiny, plus 5 volts and ground. Also connected a resistor and a led to attiny pin 2. Then I tried uploading the sketch to the tiny. No errors, but nothing happens. Tried pins 2 and 6, when it was pin 2 I set it to pin 1 in the sketch. Also tried 2. This is my second processor, since the last one gave the same error every time, so I don't think this one would be broken.

I don't need a bootloader for the tiny when I'm using the arduino as a programmer, right?
Logged

Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 33
Posts: 1225
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nice, may I use it?
Of course, as long as you do not use it for nuclear powerstations, monitoring medical lifesupport, yada da da...
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks.

Alright, I got it working and now I'm experimenting button usage with the ATTiny. Pin 12 is where the button goes and pin 11 is where an LED should light up when the input is high.
Code:
int setm;

void setup() {               
  // initialize the digital pin as an output.
  pinMode(9, INPUT);
  pinMode(8, OUTPUT); 
}

// the loop routine runs over and over again forever:
void loop() {
setm = digitalRead(9);    // Read state
    if(setm == HIGH){
      digitalWrite(8, HIGH);
      delay(250);
}
else
{
  digitalWrite(8,LOW);
  delay(250);
    }
}

However, now the LED is low when the button is pressed and when it's not, the LED just blinks. Any advice here?
Logged

Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 33
Posts: 1225
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Apart from the obvious that your program uses 8 and 9 and your description says 11 and 12 ... no. Sorry.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The pin numbers in the sketch do not match the actual pin numbers in the processor. For example, the 12th pin on the processor is referred to as 9 in the sketch.

Anyway, I had a lot of problems with the ATTiny, especially with the programming setup, so I decided that I'd switch to ATMega328. At least I shouldn't face any compatibility problems and it isn't that much bigger anyway. I guess the ATTiny could've worked with an external clock, but I'd rather not waste resources and time just to come up with another problem. Using the same processor that the Uno has seems like the best choice for now.

Just in case anyone else is having trouble programming a chip with the arduino, try making your wires shorter than 3 cm (1.18").
I don't know if that's a no-brainer for you guys, but it wasn't for me.

Other than that, I've made some nice progress. I've got the code working, the parts should be available and I've done the schematic and the board with Eagle.
Though I'm gonna have to do the board again since I made the wires a little too small.

Logged

Pages: 1 [2]   Go Up
Jump to: