Notes About Working with Various Arduino & Netduino Microcontroller Boards

Tuesday, July 3, 2012

Chronodot v2.1 and Netduino

I finally got the Chronodot working with my Netduino using the DS1307 library. The required connection setup is:
  • SDA to A4 (with 2.2k Ω pull-up resistor to 5v)
  • SCL to A5  (with 2.2k Ω pull-up resistor to 5v)
  • VCC to 5v 
  • GND to GND
The pull-up resistors were the key (as I should have figured out before now). To spell things out clearly:  2.2k Ω resistors have three red bands. One end of the resistor goes between the pin on the Chronodot and the connection to the Netduino analog pin. The other end of the resistor is connected to the 5v power rail on the breadboard. On an Arduino, the built-in pull-ups do the job.

The DS1307 class is part of the Netduino Helpers library.

I have also tried using the I2C bus class. The following  code is intended to show a simple example of how to get the time and date using the I2C bus class.

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;
using Utilities.Helpers;

namespace RTC2
    public class Program
        public static void Main()
            I2CBus bus = I2CBus.GetInstance();
            I2CDevice.Configuration config = new I2CDevice.Configuration(0x68, 100);
            byte[] timeCmd = { 0 };
            bus.Write(config, timeCmd, 1000);
            byte[] timeData = { 0, 0, 0 };
            bus.Read(config, timeData, 1000);
            byte[] dateCmd = { 3 };
            bus.Write(config, dateCmd, 1000);
            byte[] dateData = { 0, 0, 0, 0 };
            bus.Read(config, dateData, 1000);
            Debug.Print((bcdToDec(timeData[2]) & 0x3F).ToString());
            Debug.Print((bcdToDec(timeData[0]) & 0x7F).ToString());

        public static byte bcdToDec(byte val)
            return (byte)((val / 16 * 10) + (val % 16));

No comments:

Post a Comment