Shop OBEX P1 Docs P2 Docs Learn Events
DS1302 add ons — Parallax Forums

DS1302 add ons

GrantmcFGrantmcF Posts: 30
edited 2011-12-04 09:34 in Propeller 1
I'm looking for routines to add a scheduler and control buttons to the DS1302_full object. I want to be able to use the buttons to set the time and date without a PC interface. I looked through the OBEX and did not find anything that looked like it would work. Anybody have any suggestions?

Comments

  • BRBR Posts: 92
    edited 2011-11-15 19:42
    You could try this object as a starting point. It is pretty easy to add functionality using it as a template...
  • JLockeJLocke Posts: 354
    edited 2011-11-15 22:44
    I've used that same object (beau1button) to set the time on a DS1307. Works great, and only 1 button!

    Here's how I use the button. This loop is in cog 0, as all the work is being done in other cogs...
      repeat                                              ' loop
        if ina[BUTTON]                                    ' ├─ if button pressed
          waitcnt((clkfreq / 16) + cnt)                   ' │  ├─ short delay to help debounce
                                                          ' │  │
          if ina[BUTTON]                                  ' │  └─ button still pressed?
            settingRTC := TRUE                            ' │     └─ set the indicator flag
                                                          ' │   
        waitcnt((clkfreq / 10) + cnt)                     ' └─ wait 0.1 seconds
    

    My various cog methods check the flag 'settingRTC' to see if they should alter their behavior. For instance, the 'clock' cog:
    PUB cog_Clock | t
      ''* initializes and reads the RTC
      ''* updates the global time variables every 1 sec
      ''
      ' == cog initialization ==
      rtc.RTCEngineStart(RTC_DATA, RTC_CLOCK, -1)         ' start the clock object
    
      waitcnt((clkfreq * 2) + cnt)                        ' wait 2 seconds
      t := cnt
    
      ' == cog loop ==
      repeat                                              ' loop
        ifnot settingRTC                                  ' └─ if normal operation
          rtc.readTime                                    '    ├─ get current time
                                                          '    │
          hour   := rtc.clockHour                         '    ├─ update the hub time values
          minute := rtc.clockMinute                       '    │
          second := rtc.clockSecond                       '    │
          day    := rtc.clockDate                         '    │
          month  := rtc.clockMonth                        '    │
          year   := rtc.clockYear                         '    │
          dow    := rtc.clockDay                          '    │
          waitcnt(t += clkfreq)                           '    ├─ update every second
                                                          '    │
        else                                              '    else we're setting the date/time
          setTimeButton                                   '    ├─ so call function to set the date/time
          Comms.str(LCD, String("?f"))                    '    ├─ clear the LCD screen
          waitcnt((clkfreq / 20) + cnt)                   '    ├─ short delay after screen clear
          settingRTC := FALSE                             '    ├─ reset the flag                                                      
          t := cnt                                        '    ├─ keep the count going
          waitcnt(t += clkfreq)                           '    └─ update 't' for one second delay
    
    

    other cogs test for the flag similarly. And these two functions tie it up. I think you'll find the object (beau1button) is well documented and easy to understand.
    PRI beau1button(buttonPin, strPtr, varSet, loLim, hiLim) | tmp
    ' 1-button user input routine as suggested by Beau:
    ' http://forums.parallax.com/showthread.php?p=921531
    '
    '* press and release to increment digit
    '* press and hold to increment field
    'buttonPin = input button pin number
    'strPtr    = pointer to message string output to line 1 of LCD
    'varSet    = variable to be set (determines initial setting
    'loLim     = lower limit of variable range
    'hi Lim    = high limit of variable range
    '* set up to work with a single pushbutton switch connected to the buttonPin with a pulldown
    '* outputs to LCD
    '
    '                        220Ω
    '    +3.3v ─[button]──┳──── buttonPin
    '                      │
    '                      10KΩ
    '                      
    '                     gnd
    '
      waitpeq(0, |< buttonPin, 0)                         'wait for button release
        
      repeat                                              'loop
        Comms.str(LCD, String("?f"))                      '&#9500;&#9472; clear screen
        Comms.str(LCD, strPtr)                            '&#9500;&#9472; display the prompt
        Comms.str(LCD, String("?y1"))                     '&#9500;&#9472; move to the first line
        Comms.str(LCD, String("?x00"))                    '&#9500;&#9472; move to first column
        Comms.str(LCD, SimplNum.decx(varSet, 2))          '&#9500;&#9472; display the variable
                                                          '&#9474;
        waitpeq(|< buttonPin, |< buttonPin, 0)            '&#9500;&#9472; wait for button press
        tmp := cnt                                        '&#9500;&#9472; copy the counter value
        waitcnt((clkfreq / 20) + cnt)                     '&#9500;&#9472; short delay to help debounce
        waitpne(|< buttonPin, |< buttonPin, 0)            '&#9500;&#9472; wait for button release
                                                          '&#9474;
        if (cnt - tmp) > INCR_MENU                        '&#9500;&#9472; button held down > 1 sec?
          return varSet                                   '&#9474;  &#9492;&#9472; yes, return value
        else                                              '&#9500;&#9472; otherwise
          varSet++                                        '&#9474;  &#9492;&#9472; no, increment value
                                                          '&#9474;
          if varSet > hiLim                               '&#9500;&#9472; if top of list
            varSet := loLim                               '&#9474;  &#9492;&#9472; start over at bottom of list
                                                          '&#9474;
        waitcnt((clkfreq / 5) + cnt)                      '&#9492;&#9472; short pause to help debounce
        
    {
    ===============================================================================
    }
    PRI setTimeButton
    'routine to set day/time using a single button
    'has to be called from cog_Clock (for access to rtc)
    
      repeat until not lockset(lockData)                  ' lock the access
      
      dow    := beau1Button(BUTTON, @dowStr, dow, 1, 7)
      day    := beau1Button(BUTTON, @dayStr, day, 1, 31)
      month  := beau1Button(BUTTON, @monthStr, month, 1, 12)
      year   := beau1Button(BUTTON, @yearStr, year, 11, 26)
      hour   := beau1Button(BUTTON, @hourStr, hour, 0, 23)
      minute := beau1Button(BUTTON, @minuteStr, minute, 0, 59)
      second := 0
      second := beau1Button(BUTTON, @secondStr, second, 0, 59)
      year   := year + 2000                               ' fill out the year
      rtc.writeTime(second, minute, hour, dow, day, month, year)
      waitcnt((clkfreq / 4) + cnt)                        
      lockclr(lockData)                                   ' unlock
    
    DAT
      FileHeader  byte "Date,Time,Upstairs (F),Humidity (%),Downstairs (F),Outside (F),Humidity (%)", 13, 0
    
      dowStr    byte "Set Day (Sun=1)", 0                 'prompt strings used in setting RTC
      dayStr    byte "Set Date", 0                         
      monthStr  byte "Set Month", 0
      yearStr   byte "Set Year", 0
      hourStr   byte "Set Hour", 0
      minuteStr byte "Set Minute", 0
      secondStr byte "Set Second", 0
     
    
  • GrantmcFGrantmcF Posts: 30
    edited 2011-11-17 08:41
    Thanks guys. I will try that when I get a chance. I'm fighting the DS1302_ full right now. I can't seem to get the debug display to come up. I have to get that object to work as advertised first before I start modifying.
  • Jorge PJorge P Posts: 385
    edited 2011-11-20 04:56
    I am doing something similar to this project but I am not using buttons, I will be using a 4x4 matrix keypad to change the date and time through a couple of PCA9555 IC's. I need to finish a few things before I continue with the project but it is still moving along in the background. I have a DS1302 connected to pins 3, 4, 5 of the propeller in that project. I am only using the 6 digit 16 segment display on the "Propeller Professional Development Board" to view the date and time so you may have to add some code to see the output on other systems.

    If you would like to see a bit more about my project using a PCA9555 bus extender, check out my post in the next few weeks as I will be posting a new update. http://forums.parallax.com/showthread.php?134537-PPDB-Using-the-full-PPDB-Code-Version-1.3 .
  • GrantmcFGrantmcF Posts: 30
    edited 2011-12-04 09:34
    I finally got the clock working with a serial lcd and 3 button configuration. I'm still need help with an on/off scheduler. Are there any objects available to kick start me?
Sign In or Register to comment.