Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Full-featured driver / test code for the Maxim DS1307 real-time clock


  • Please log in to reply
16 replies to this topic

#1 Fabien Royer

Fabien Royer

    Advanced Member

  • Members
  • PipPipPip
  • 406 posts
  • LocationRedmond, WA

Posted 03 January 2011 - 06:29 PM

Hi,

Being unable to find a C# driver implementing the complete DS1307 spec, I wrote one and figured I'd share it with the community :)
http://fabienroyer.w...eal-time-clock/

Cheers,
-Fabien.

#2 JonnyBoats

JonnyBoats

    Advanced Member

  • Members
  • PipPipPip
  • 155 posts
  • LocationPhillips, ME

Posted 04 January 2011 - 11:22 PM

Thank you for sharing this code.

#3 Charles

Charles

    Advanced Member

  • Members
  • PipPipPip
  • 192 posts

Posted 05 January 2011 - 12:06 AM

That's awesome!!!! I have been kicking around the idea of adding this functionality for some time, but never got around to it. Thanks!!!

#4 Jan Olof

Jan Olof

    Advanced Member

  • Members
  • PipPipPip
  • 41 posts
  • LocationSweden

Posted 10 January 2011 - 06:55 PM

Fabien, I have downloaded the zip file (and some of your other zip files), both winrar, 7h and the builtin in win 7 says that the files are damaged (downloaded both with IE8 and Chrome) :( . Can you please check your website. /Jan Olof

#5 Fabien Royer

Fabien Royer

    Advanced Member

  • Members
  • PipPipPip
  • 406 posts
  • LocationRedmond, WA

Posted 11 January 2011 - 03:21 AM

Hi Jan,

I'm not sure what the deal is: I always test the archives after uploading them and I never had corruption issues so far.

In any event, I just started a CodePlex project called 'netduino.helpers' which contains everything that's on the site :)

Let me know if you're bumping into any more problems.

Cheers,
-Fabien.

#6 Joschua

Joschua

    New Member

  • Members
  • Pip
  • 7 posts

Posted 15 February 2011 - 05:04 PM

Hi Fabien Did you test the DS1307 code with the netduino plus ? Unfortunately, my device is not able to communicate with the DS1307. I'm sure, the issue is not the code, because I can't see any activity on the 4+5 pin of the netduino-plus with a logic analyzer. So I'm not sure, the I2C works with the netduino-plus well. I'm using the folloing firmeware: HalSystemInfo.halVersion: 4.1.2821.0 HalSystemInfo.halVendorInfo: Netduino Plus (v4.1.1.0 a6) by Secret Labs LLC Regards Joschua

#7 Fabien Royer

Fabien Royer

    Advanced Member

  • Members
  • PipPipPip
  • 406 posts
  • LocationRedmond, WA

Posted 15 February 2011 - 06:16 PM

Hi Joschua, I have never tested the code on a N+. I'm wondering: can you share a link to the datasheet of the DS1307 clock module you're using? You may need pull-up resistors if the module doesn't have any on board. Cheers, -Fabien.

#8 Joschua

Joschua

    New Member

  • Members
  • Pip
  • 7 posts

Posted 17 February 2011 - 07:09 PM

Hi Fabien Thanks for your answer. I guess the battery of the RTC Module was empty. After a change, is works. Regards. Joschua

#9 AMD_Fusion

AMD_Fusion

    New Member

  • Members
  • Pip
  • 7 posts

Posted 15 July 2011 - 10:38 PM

Hi, I’m new here. I’m having a hard time trying to display time and date on a LCD. I have wired up a Netduino, DS1307 RTC module and a 20x4 HD44780-controlled LCD on a breadboard. I can get “Hello World” to appear on the LCD, but not time and date. Any help is welcome. Thanks in advance.

#10 Stuart Crawshaw

Stuart Crawshaw

    Advanced Member

  • Members
  • PipPipPip
  • 60 posts
  • LocationLeeds, United Kingdom

Posted 18 July 2011 - 03:49 PM

Hi, I’m new here. I’m having a hard time trying to display time and date on a LCD.

I have wired up a Netduino, DS1307 RTC module and a 20x4 HD44780-controlled LCD on a breadboard. I can get “Hello World” to appear on the LCD, but not time and date.

Any help is welcome. Thanks in advance.


Hi,

Could you describe the problems you are having? I.E. does it just display garbage, Not at all etc...

And code examples would be a great help also.

Thanks,
Intelligent People Aren't Afraid To Ask For Help.

#11 AMD_Fusion

AMD_Fusion

    New Member

  • Members
  • Pip
  • 7 posts

Posted 19 July 2011 - 09:09 AM

Hi Stuart, Here is the unfinished Program.cs code. The LCD screen is blank. Error messages: The name ‘_ds1307’ does not exist in the current context. The type or namespace name ‘DS1307’ could not be found. Since my RTC module is a Sparkfun unit, I placed two 1.5K resistors between SDA/5V and SCL/5V. Thanks for any suggestion. using System; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.Netduino; using MicroLiquidCrystal; using Devices; namespace NetduinoClock { public class Program { public static void Main() { var lcdProvider = new GpioLcdTransferProvider( Pins.GPIO_PIN_D12, // RS Pins.GPIO_NONE, // RW Pins.GPIO_PIN_D11, // enable Pins.GPIO_PIN_D9, // d0 Pins.GPIO_PIN_D8, // d1 Pins.GPIO_PIN_D7, // d2 Pins.GPIO_PIN_D6, // d3 Pins.GPIO_PIN_D5, // d4 Pins.GPIO_PIN_D4, // d5 Pins.GPIO_PIN_D3, // d6 Pins.GPIO_PIN_D2); // d7 var lcd = new Lcd(lcdProvider); lcd.Begin(20, 4); _ds1307 = new DS1307(); _ds1307.Halt(false); Debug.Print("Clock: " + _ds1307.Get().ToString("HH:mm dd/MM/yyyy")); Utility.SetLocalTime(_ds1307.Get()); Debug.Print("Dev: " + DateTime.Now.ToString("HH:mm dd/MM/yyyy")); } } } The Explorer (right side) window contains these files: DS1307.cs GpioLcdTransferProvider.cs ILcdTransferProvider.cs Lcd.cs Program.cs http://10rem.net/blo...th-the-netduino

#12 Fabien Royer

Fabien Royer

    Advanced Member

  • Members
  • PipPipPip
  • 406 posts
  • LocationRedmond, WA

Posted 19 July 2011 - 03:46 PM

AMD_Fusion,

Take a look at this sample: http://netduinohelpe...s/DS1307/RTC.cs for interacting with the DS1307.

I see nowhere in the code where the LCD screen is actually being written to.
Debug.Print() only writes to the Output window of the Netduino.
You need to use a call to lcd.Write() instead with the properly formatted date string.


Cheers,
-Fabien.

#13 AMD_Fusion

AMD_Fusion

    New Member

  • Members
  • Pip
  • 7 posts

Posted 21 July 2011 - 02:57 AM

Hi Fabien, Thanks for your advice. I can get the date and time to appear on the LCD screen, but the time does not update itself. LCD Output: 07/20/2011 22:10:00 How do you make the time output increment? Is it possible to display the month in char (eg Jul) and the day (eg Friday)? Here’s the updated Program.cs code. using System; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.Netduino; using MicroLiquidCrystal; using netduino.helpers.Hardware; namespace NetduinoClock { public class Program { public static void Main() { var lcdProvider = new GpioLcdTransferProvider( Pins.GPIO_PIN_D12, // RS Pins.GPIO_NONE, // RW Pins.GPIO_PIN_D11, // enable Pins.GPIO_PIN_D9, // d0 Pins.GPIO_PIN_D8, // d1 Pins.GPIO_PIN_D7, // d2 Pins.GPIO_PIN_D6, // d3 Pins.GPIO_PIN_D5, // d4 Pins.GPIO_PIN_D4, // d5 Pins.GPIO_PIN_D3, // d6 Pins.GPIO_PIN_D2); // d7 var lcd = new Lcd(lcdProvider); lcd.Begin(20, 4); var clock = new DS1307(); // Set the clock to some arbitrary date / time clock.Set(new DateTime(2011, 7, 20, 22, 10, 00)); // Make sure the clock is running clock.Halt(false); // Test reading RTC clock registers lcd.Write(clock.Get().ToString()); } } }

#14 Fabien Royer

Fabien Royer

    Advanced Member

  • Members
  • PipPipPip
  • 406 posts
  • LocationRedmond, WA

Posted 21 July 2011 - 07:31 PM

How do you make the time output increment?




Try something like this:


while(true) {
lcd.Write(clock.Get().ToString());
Thread.Sleep(1000);
}


I've found this resource helpful when I first learned C#: http://www.blackwasp...ndamentals.aspx and I hope it helps you as well.

Cheers,
-Fabien.



#15 AMD_Fusion

AMD_Fusion

    New Member

  • Members
  • Pip
  • 7 posts

Posted 22 July 2011 - 03:39 AM

Hi Fabien, Thanks for the info. The clock is now counting. Is it possible to display the time in 12-hour format showing AM/PM? Here’s the updated Program.cs code. using System; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.Netduino; using MicroLiquidCrystal; using netduino.helpers.Hardware; namespace NetduinoClock { public class Program { public static void Main() { var lcdProvider = new GpioLcdTransferProvider( Pins.GPIO_PIN_D12, // RS Pins.GPIO_NONE, // RW Pins.GPIO_PIN_D11, // enable Pins.GPIO_PIN_D9, // d0 Pins.GPIO_PIN_D8, // d1 Pins.GPIO_PIN_D7, // d2 Pins.GPIO_PIN_D6, // d3 Pins.GPIO_PIN_D5, // d4 Pins.GPIO_PIN_D4, // d5 Pins.GPIO_PIN_D3, // d6 Pins.GPIO_PIN_D2); // d7 var lcd = new Lcd(lcdProvider); lcd.Begin(20, 4); var clock = new DS1307(); // Set the clock to some arbitrary date / time (do once) clock.Set(new DateTime(2011, 7, 22, 00, 00, 00)); clock.Halt(false); while (true) { lcd.SetCursorPosition(0, 0); lcd.Write(clock.Get().ToString()); Thread.Sleep(1000); } } } }

#16 AMD_Fusion

AMD_Fusion

    New Member

  • Members
  • Pip
  • 7 posts

Posted 23 July 2011 - 02:58 AM

To anyone who wants to build this project: You have to download the code twice for the clock to work properly. First time: download the above code as shown with today's date and your local time Second time: turn the clock.Set( ) line into a comment and download DS1307 Datasheet: http://www.maxim-ic....dex.mvp/id/2688

#17 zelphia

zelphia

    New Member

  • Members
  • Pip
  • 6 posts

Posted 30 December 2011 - 08:27 PM

I've been able to run this demo on a NetduinoPlus. Changed 'using ...Netduino' to 'using...NetduinoPlus'. Used 1k pullup resistors to 3.3v for the I2C lines, 5v power for the DS1307. Put an led (internal resistor) to 3.3v on the sq wave output to watch it pulse. DS1307 came from Spark Fun. Thanks for the code.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.