DS1307 Real Time Clock - Page 2 - Project Showcase - Netduino Forums
   
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

DS1307 Real Time Clock


  • Please log in to reply
41 replies to this topic

#21 Giuliano

Giuliano

    Advanced Member

  • Members
  • PipPipPip
  • 361 posts
  • LocationSimi Valley, CA

Posted 17 February 2013 - 09:09 AM

Has someone got this to work on the N+2?

 

Fails in this line:

 

private I2CDevice clock = new I2CDevice(new I2CDevice.Configuration(I2CAddress, I2CClockRateKhz));

 

System.InvalidOperationException  



#22 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 17 February 2013 - 12:29 PM

I have several of the adafruit ones working with several ND+2. Need much more info. What address and speed are your setting. How is it wired?

#23 Giuliano

Giuliano

    Advanced Member

  • Members
  • PipPipPip
  • 361 posts
  • LocationSimi Valley, CA

Posted 17 February 2013 - 05:13 PM

Hi Dave,

 

Yes, the problem might be the address and speed as you pointed out. This is the code I am using which I got it from this thread posted by stacyh3 and got it to work only in the N+:

 

private const int I2CAddress = 0x68;

private const int I2CTimeout = 1000;

private const int I2CClockRateKhz = 100;

public const int UserDataAddress = 8;

public const int UserDataLength = 56;

 

Of course I connected to the SC and SD ports respectivelly in the N+2, not the A4 and A5 Analog ports, and here is the device capabilities:

 

HalSystemInfo.halVersion: 4.2.0.0

HalSystemInfo.halVendorInfo: Netduino Plus 2 (v4.2.2.2) by Secret Labs LLC

HalSystemInfo.oemCode: 34

HalSystemInfo.modelCode: 177

HalSystemInfo.skuCode: 4102

HalSystemInfo.moduleSerialNumber: 00000000000000000000000000000000

HalSystemInfo.systemSerialNumber: 0000000000000000

ClrInfo.clrVersion: 4.2.0.0

ClrInfo.clrVendorInfo: Netduino Plus 2 (v4.2.2.2) by Secret Labs LLC

ClrInfo.targetFrameworkVersion: 4.2.0.0

SolutionReleaseInfo.solutionVersion: 4.2.2.2

SolutionReleaseInfo.solutionVendorInfo: Netduino Plus 2 (v4.2.2.2) by Secret Labs LLC

SoftwareVersion.BuildDate: Jan 26 2013

SoftwareVersion.CompilerVersion: 410894



#24 Giuliano

Giuliano

    Advanced Member

  • Members
  • PipPipPip
  • 361 posts
  • LocationSimi Valley, CA

Posted 17 February 2013 - 06:33 PM

Hi Dave,

 

I got rid of that code and use the Toolbox.NETMF.Hardware.DS1307 class instead and worked like a charm by itself but seems to be conflicting with the drivers for the Hd44780 Lcd if I put the code all together.

 

I'll keep you posted of my findings on why the LCD drivers are conflicting.



#25 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 17 February 2013 - 10:28 PM

What drivers are you using for the LCD?  Is this an I2C based backpack of some type to drive it or are you using SPI?



#26 Giuliano

Giuliano

    Advanced Member

  • Members
  • PipPipPip
  • 361 posts
  • LocationSimi Valley, CA

Posted 17 February 2013 - 10:47 PM

Hi Dave,

 

Yes, I am using the backpack you recommended me a while ago and using SPI and the code is pretty much the same as posted below with the difference that the project I am running is for N+2:

 

http://forums.netdui...cd-for-n/page-2

 

If I instantiate the _bus variable lile this:

 

_bus = new I2CBus();

 

at the beginning of the program, then this line crashes:

 

dS1307 = new DS1307();

 

To be more specific this line if I step into:

 

_I2CDevice = new I2CDevice(this._Configuration);

 

Throwing this error:

 

"Exception was thrown: System.InvalidOperationException"

 

However if I comment out the instantiation of the _bus variable, then the instantiation of dS1307 runs just fine.

 

Any clues what could be causing this issues? Maybe I cannot use the LCD in SPI mode when using the SDA and SCL ports?

 

Thanks



#27 Giuliano

Giuliano

    Advanced Member

  • Members
  • PipPipPip
  • 361 posts
  • LocationSimi Valley, CA

Posted 18 February 2013 - 12:26 AM

Here is the project that re-creates the issue I am experiencing.

http://www.rcntech.c...uino/index.html
 
And here is my wiring, I am using SC, SD, 5V and GND for the DS1307, 5V, GND, D13-CLK, D11-DAT, D10-LAT, D9- GREEN (Even though the wire is RED), D6-BLUE, and D5-RED for all the LCD connections. All others wires are connected to a temperature sensor (D0, D1 and 3.3V) and D2 to a relay.
 
Posted Image

Attached Files



#28 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 18 February 2013 - 12:56 PM

I'll download the code later today try it on  the bench.  I have a ND+2 with RTC1307 and an I2C/SPI backpack test rig.

 

First thing I would recommend is upgrading the Firmware.  Looks like you are still on 4.2.1.0 and there were SPI Changes made in the versions following that.  Latest is 4.2.2.2.



#29 Giuliano

Giuliano

    Advanced Member

  • Members
  • PipPipPip
  • 361 posts
  • LocationSimi Valley, CA

Posted 18 February 2013 - 10:03 PM

Thanks Dave, I appreciate your help on this. By the way I open MFDeploy and this is what I got in Device Capabilities:

 

Posted Image

 

Question, would the .NET MF Toolbox (http://netmftoolbox.codeplex.com/) work with the i2c / SPI character LCD backpack I have?



#30 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 21 February 2013 - 06:43 PM

I am getting the same failure as you using your setup and code.  I'll try to debug through it and post my findings in a little while.



#31 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 21 February 2013 - 07:14 PM

So, it looks like the issue is that you don't need to create the instance of I2CBus when you are using the MultiI2C.  I am using a different Multiple I2C provider so my initializeLCD method was being passed that bus.  Since you are using SPI for the LCD and not I2C you should be fine.  You need to make the following changes.

 

Remove the Lines:

private static I2CBus _bus;

and

_bus = new I2CBus();

Then change the initializeLCD Method from:

private static void initializeLCD(I2CBus bus){}

To (so you are not passing the I2CBus)

private static void initializeLCD(){}

Then change the

initializeLCD(_bus);

To

initializeLCD();

Finally, you may want to add the second line of code below to sync the Netduino's time to the DS1307 each time the ND+2 is started

dS1307 = new DS1307();dS1307.Synchronize();

The MultiI2C should handle it all from here forward.  Just remember any I2C Device Drivers you get off the internet, Netduino forums or other developers may use various means of handing I2C and you may need to change the Class' constructor to handle MultiI2C for your needs.

 

After I made these changes I was able to use both the DS1307 and the LCD together.  I rebooted the Netduino Plus 2 several times to ensure that it would sync the time each time.

 

PS: Is you want to give it a good workout after the changes add this method to make it a clock pulling from the DS1307 each time.

while (true){      LCD.Print(Lcd.Position.ROW_4, Lcd.Position.COLUMN_1, Lcd.FillRow(dS1307.GetTime().ToString()));      Thread.Sleep(10);}


#32 Giuliano

Giuliano

    Advanced Member

  • Members
  • PipPipPip
  • 361 posts
  • LocationSimi Valley, CA

Posted 21 February 2013 - 08:19 PM

Thank you so much Dave for getting back to me an explaining what the issue was in such much detail. I really appreciate it.



#33 engrjaypee

engrjaypee

    New Member

  • Members
  • Pip
  • 1 posts

Posted 22 July 2013 - 09:40 AM

The attached zip files doesnt work. Any instructions how to open it properly? Thanks



#34 Giuliano

Giuliano

    Advanced Member

  • Members
  • PipPipPip
  • 361 posts
  • LocationSimi Valley, CA

Posted 13 December 2013 - 07:39 PM

Which code is not working, the one from stacyh3 or mine?

 

Did you install the .NET Micro Framework for Visual Studio 2010 or Visual Web Express 2010?

 

Thanks



#35 cloris

cloris

    New Member

  • Members
  • Pip
  • 8 posts

Posted 16 December 2013 - 07:42 PM

If it is of any help, I have a blog post on hooking up the DS1307 with some code.

 

http://christianlori...ttle-soldering/



#36 gismo

gismo

    Advanced Member

  • Members
  • PipPipPip
  • 110 posts

Posted 16 December 2013 - 08:10 PM

Another example here on youtube:

 

Netduino RealTimeClock Library Tutorial:

http://www.youtube.c...h?v=ePT2Q0C5aBY



#37 MattAtBCL

MattAtBCL

    New Member

  • Members
  • Pip
  • 1 posts

Posted 22 December 2013 - 02:12 PM

Hi. First post to this forum - hope you can help? I'm a bit new to all of this so apologies if this is a daft question:

 

Trying to get this code working on a Netduino Plus 2 on framework v4.2. I'm getting a runtime error when I get to the line coloured in red below. 

 public class DS1307RealTimeClock : IDisposable    {        private const int I2CAddress = 0x68;        private const int I2CTimeout = 1000;        private const int I2CClockRateKhz = 100;        public const int UserDataAddress = 8;        public const int UserDataLength = 56;        private I2CDevice clock = new I2CDevice(new I2CDevice.Configuration(I2CAddress, I2CClockRateKhz));        /// <summary>        /// Set the local .NET time from the RTC board. You can do this on startup then call        /// DateTime.Now during program execution.        /// </summary>        public void SetLocalTimeFromRTC()        {            var dt = Now();            Utility.SetLocalTime(dt);        }

The error states: 

 

[font="'courier new', courier, monospace;"]Locating source for 'C:DocumentsSecret LabsProjectsProductionSecretLabs.NETMF.Hardware.NetduinoNetduinoHardwareProvider.cs'. Checksum: MD5 {9a 41 9e 8d e1 47 28 af 1a ec 47 39 bb 46 2 8b}[/font]
[font="'courier new', courier, monospace;"]The file 'C:DocumentsSecret LabsProjectsProductionSecretLabs.NETMF.Hardware.NetduinoNetduinoHardwareProvider.cs' does not exist.[/font]
 
Sure enough, I don't have that file on my disk - so how do I go about resolving this please?
 
Regards, Matthew


#38 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 23 December 2013 - 11:56 PM

Hi Matthew, It sounds like you're trying to step into the firmware source code. You can grab it from the Downloads page--but "stepping over" rather than "stepping into" the code should also fix this issue for you. Chris

#39 Fahdil

Fahdil

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts
  • LocationJakarta, Indonesia

Posted 23 January 2014 - 02:32 PM

Still can't get the DateTime.Now... it's return 2002/01/01 00:00:00

 

I'm using RTC from Seed Studio. the configuration below:

 

SDA -- > R 4.7k  --> Vcc (5v)

SCL --> R 4.7 k --> Vcc

 

should I breakout the Pull Up resistor from Vcc to 3.3V battery? to make this code works?

 



#40 Fahdil

Fahdil

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts
  • LocationJakarta, Indonesia

Posted 23 January 2014 - 02:59 PM

what a silly... :unsure:

 

I just Run this code

// TODO: Do this only once to set your clock//clock.SetClock(10, 8, 26, 17, 45, 30, DayOfWeek.Wednesday);

then It's work..... :P

 

so I need to set the clock at the first time. umm

 

is there any way for me to get the Clock from my PC?






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.