JeeLabs Precision RTC Module #271
Replies: 36 comments
-
Posted at 2014-04-29 by @gfwilliams I'd take a look at http://www.espruino.com/Writing+Modules - but IMO it's worth just trying to communicate with it (using http://www.espruino.com/I2C I guess) first before you start trying to write a module. Having said all that, Espruino has an RTC built-in - it just counts in seconds, but @mgg1010 has written a Date module which should get put online this week sometime. Normally it runs of the in-built oscillator which isn't too accurate, but it's dead easy to solder a watch crystal on: http://www.espruino.com/Clocks |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-29 by mgg1010 I've also found an online web page which has the current date on it here - http://currentmillis.com/api/millis-since-unix-epoch.php - I'm using this with the Wiznet Ethernet adaptor to set the time. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-29 by StuntMonkeh I had seen the post about clocks. As I had the module it I thought I may as well use it as I don't have a crystal to solder onto the Espruino. I setup the I2C
Then tried
The interpreter returns
What am I doing wrong? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-29 by @gfwilliams Have you got 2x pullup resistors on each I2C line? Also, it's possible that you have the address in 8 bit format (in which case you'll have to shift 0x68 right by one bit). |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-30 by graf Nice thing about these modules is that they have a tiny battery, you can't really go without it if you need a time and date (instead of a counter). |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-30 by StuntMonkeh Yes have pullup resistors on the I2C lines. I think its my understanding thats lacking here. Let me see if what I am assuming is correct. So the wiki for the RTC module indicates that the DS3231 default I2C address is 0x68. There is no reason this should be different and I have no other devices on the bus. The DS3231 registers run from BIT0 to BIT7. So if I want to read 'seconds' for instance am I right in understanding that I need to calculate the exact location by adding the I2C address (0x68) + the register address (00h) and then read 4 Bits?
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-30 by @gfwilliams The register address is usually something different to the I2C address. I could be wrong here, but I think you need:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-30 by StuntMonkeh Thanks Gordon, I'm one step close. I'm now getting data back.
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-30 by mgg1010 @graf - you can if you have ethernet, because you can get the time from the internet on device startup. The combination of extra clock crystal and my date module seems to work for me :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-30 by graf @mgg1010 that's assuming you always have a working internet connection at startup and you want to expose your device to the internet. Both assumptions are not an option if you ask me, but I guess that depends on the project. Thanks for the module BTW :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-30 by StuntMonkeh @mgg1010 - for some applications there is no internet however if there is then I agree that the other method with the crystal would be better. Okay back to this little module: The data I get back if I ask for 2 bytes starting at address 0 seems to come back okay to give me the seconds and minutes into an array, however for some reason it appears that minutes are counted in 90 seconds intervals rather than 60. i.e. the seconds count up to 89 then the minute is incremented by one and the seconds restart from 0. Why is this? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-30 by mgg1010 @graf - OK ! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-30 by @gfwilliams Are the seconds stored in BCD (Binary coded decimal)?
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-30 by StuntMonkeh Well I think I may have it working! The following code appears to be reading the time okay.
I just need to leave it running a while to see if its keeping the right time. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-30 by StuntMonkeh Nope, that's not working very accurately. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-05-06 by StuntMonkeh I'm not sure I have got the grasp of these modules. How does something like this look?
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-05-06 by @gfwilliams Looks good - there are a few bits you need though:
Then to use it, you just do To test it, I'd just put |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-05-06 by mgg1010 Thanks for beating me to it :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-05-07 by StuntMonkeh Thanks Gordon, I think I have made the appropriate changes correctly. There are no errors at least when I drop the code into the Espruino. When I type What is the syntax to call one of the public functions now? i.e. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-05-07 by @gfwilliams I'd hope it's just |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-05-07 by StuntMonkeh Yes that works, got some errors to work though now but its at least calling it okay. It appears some of my old function code doesn't work. I have tried reflashing the board but still errors.
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-05-07 by StuntMonkeh Fixed! For some reason it didn't like the return statement on the end. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-05-07 by @gfwilliams Ahh. Thanks for letting me know - I've just put a fix in for that, it'll be in 1v63. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-05-07 by @gfwilliams Out of interest, did you turn on minification, or was that on by default? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-05-07 by StuntMonkeh Minification was set to 'Whitespace Only' in the IDE. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-05-10 by StuntMonkeh How does this look?
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-05-12 by @gfwilliams Looks great! Do you want to send a git pull request with a documentation page for it ( info ) or should I knock something up? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-05-12 by StuntMonkeh No problem Gordon I will follow the tutorial and put something together. There is one thing I didn't quite understand. Can you explain when you might use a public constant rather than a private constant? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-05-12 by @gfwilliams Thanks! It's if you want someone using the module to be able to use that constant. For example:
If you don't need them to be able to use it then you can make it private, and when the code is minified the minifier can then take that constant, remove it, and put the numeric value right into the |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-05-13 by StuntMonkeh Thanks for all your help Gordon! If anyone has been following this the code has been merged into the main branch and is now available as a module. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-29 by StuntMonkeh
I have a precision RTC module from JeeLabs knocking about that I want to use for some date time stuff.
http://jeelabs.net/projects/hardware/wiki/Precision_RTC_Plug
I'm guessing a module has to be written, so can someone point me in the right direction.
Beta Was this translation helpful? Give feedback.
All reactions