Any tutorials on creating libraries ?

I've been playing with a DS1307 realtime clock and I have a bunch of functions I can use to read and set the rtc. I also have written some function to receive commands via serial and process them.

I'd like to just cleave these function out to a separate file and include them. I think I'm talking about creating DS1307.h or similar.

I have no idea hos to convert working code to an include file, are there any tutorials ?

Thanks

Not really, unfortunately, though we should have some. There's a bit of information and a sample library here: http://www.arduino.cc/en/Main/Libraries. If you have any questions, please ask, and then we can figure out what to put in the tutorial.

hi, i see you have got the ds1307 working, i am trying to do the same but no luck. can you give me a few examples of how to read the time from the chip? am pretty sure i have it wired up correctly. SCL to analgue 5 and SDA to analogue 4. do i need to do anything with SQW?

hi, i see you have got the ds1307 working, i am trying to do the same but no luck. can you give me a few examples of how to read the time from the chip? am pretty sure i have it wired up correctly. SCL to analgue 5 and SDA to analogue 4. do i need to do anything with SQW?

Start a new thread gazzy and I will happily post my code and offer any support I can. I'm using this item http://www.futurlec.com/Mini_DS1307.shtml, SQW is used for INT, for alarms, I'm not using or connecting it.

Not really, unfortunately, though we should have some. There’s a bit of information and a sample library here: http://www.arduino.cc/en/Main/Libraries. If you have any questions, please ask, and then we can figure out what to put in the tutorial.

Thanks mellis, that’s actually pretty useful.
I thought perhaps all libraries needed to be ported to cpp to be included, the example shows how I can put Wiring code in a lib.

/me rubs hands and adds to project stack

Hi,

I tidied up some functions and created a DS1307.h and DS1307.cpp, and put them in the correct folder as indicated by the tutorial.

My lib depends on the Wire lib.
When I try to compile mine I get undefined reference to Wire.
I’m not really sure how to include Wire.h in my lib or specify it’s requirement.

In my DS1307.h I have…

/*
  DS1307.h - library for DS1307 rtc
*/

// ensure this library description is only included once
#ifndef DS1307_h
#define DS1307_h

// include types & constants of Wiring core API
#include <WConstants.h>

// include types & constants of Wire ic2 lib
#include "../Wire/Wire.h"


#define DS1307_SEC 0
#define DS1307_MIN 1
#define DS1307_HR 2
#define DS1307_DOW 3
#define DS1307_DATE 4
#define DS1307_MTH 5
#define DS1307_YR 6

#define DS1307_BASE_YR 2000

#define DS1307_CTRL_ID B1101000  //DS1307

 // Define register bit masks  
#define DS1307_CLOCKHALT B10000000
 
#define DS1307_LO_BCD  B00001111
#define DS1307_HI_BCD  B11110000

#define DS1307_HI_SEC  B01110000
#define DS1307_HI_MIN  B01110000
#define DS1307_HI_HR   B00110000
#define DS1307_LO_DOW  B00000111
#define DS1307_HI_DATE B00110000
#define DS1307_HI_MTH  B00110000
#define DS1307_HI_YR   B11110000

// library interface description
class DS1307
{
  // user-accessible "public" interface
  public:
    void getRTC(int *, int);
    int getRTC(int, int);
      void setRTC(int, int);

  // library-accessible "private" interface
  private:
    byte rtc_bcd[7]; // used prior to read/set ds1307 registers;
      void readRTC(void);
      void saveRTC(void);
};

#endif

what do I need to include wire in my cpp ?
I just have

#include "../Wire/Wire.h"

Thanks

Right now, you need to also include the Wire library in your main sketch, since that's how the environment decides which libraries to link against.