Building DateTime with Code::Blocks

Now that I have moved house from the Arduino IDE into Code::Blocks, I'm going to document the start of the development process in Code::Blocks. I expect to be tripped up by a number of problems and I'll write down how I muddle through.

I have my ConsoleDateTime project for Code::Blocks set up. I deliberately did not pull my DateTime.h and DateTime.cpp files over from Arduino. I'm going to run the two IDEs side-by-side and pull across chunks of code one at a time and deal with any errors that come up as I go.

Get code here: https://github.com/prawnhead/ConsoleDateTime


Developing Without an Arduino

Working on my DateTime library has slowed to a crawl. I guess because I'm out of the habit (of doing things differently) I've been developing the DateTime class in the Arduino IDE. I remember now why that's a bad idea.

The Arduino process (you probably know so well) goes:

  1. change the code
  2. upload to Arduino
  3. run
  4. find errors
  5. repeat (ad nauseam)

This is good and normal and healthy development for the "usual" Arduino applications that are hardware dependent and relatively simple. But for a library like DateTime a few factors completely change the equation.

Get code here: https://github.com/prawnhead/ConsoleDateTime


Using Program Memory (PROGMEM)

As I was building my DateTime class (Arduino library) I realised I had hard-coded strings for the names of the days of the week and the months of the year. I know that this is a huge drain on the Arduino's minimal amount of SRAM. It was finally time to tackle program memory and get an understanding of it. This is the process I went through ...

Get code here: https://github.com/prawnhead/ArduinoDateTime


Building DateTime for Arduino

Testing. Yup, testing. With this class it can’t be avoided. Actually, even better, instead of seeing testing as a chore, let’s use it to our advantage. We’ll build a suite of tests for the unfinished DateTime class and test it until it works.
The goal here is to write all the tests first and run them. Some percentage of them will fail. Then we modify the DateTime class until all tests pass. As we find issues along the way, we add more tests.
Get code here: https://github.com/prawnhead/ArduinoDateTime


The Need for a Date and Time Class for Arduino

I want a fully-functional date and time library for my Arduino applications. The goal behind my GPS clock is to have a clock with no buttons. Yes, if you’re wondering, I have been reading about Steve Jobs. No buttons!
Why no buttons? Because fundamentally any clock with buttons on it requires a human operator to set the time. Since every house has many clocks and every clock has buttons and every clock keeps slightly different time and it’s physically impossible to synchronise all your clocks you inevitably have different time displayed in each room of the house. Sorry for the run-on sentence. I’m sure there are some people for whom this is not a problem. But if you are a little OCD (and I say that admiringly, not mockingly) you’re regularly annoyed by the need to fix your clocks.


DS1307 Real-time Clock Library

As committed in my last post, I’ve put up my next coding effort on GitHub.
Get code here: https://github.com/prawnhead/DS1307
The DS1307 is a highly accurate clock module that connects to the Arduino via the I2C protocol (SDA/SCL lines). As implemented on the Sparkfun BOB-00099 break-out board it comes complete with a crystal (to keep time) and a watch battery so that it maintains current time even when not being powered externally.
This library was developed to be a full-featured implementation of the DS1307 chip. This includes the cool but probably not very often used feature of having 56 bytes of NVRAM that is persistent and can be read/written very simply.
I’m torn between a simple-as-pie implementation and the one I know I really need. At this stage I’ve only covered the simple option; you need to read/write the date/time as a set of bytes. I’d rather have the class read and write a DateTime data type, but I think that’s too much for people who want the basics. (Correct me!) I have a DateTime class that I’ve created, tested and used but that I haven’t posted on GitHub yet. That’s next.
I honestly don’t know how collaboration is achieved on GitHub yet. I understand at this stage that anyone can clone my repo and go to town on my code. That’s what I want, that’s great. But I also want people to suggest improvements and commit them!I’m unsure of how this happens. Is it anything goes? Is it “commits only by repo members?” Is there an approvals process? I need to go an answer these questions. For now, here’s the simple version of this class. I guess the appropriate thing to do is to fork it and build on the ‘advanced’ version of the same. Again, questions. If the same repo now makes two versions available, how are they surfaced? I guess I’ll go ahead and see.
That is all.


Gitting Hubbed

Ah the Uni holidays. A great time to play with the kids and get some coding done. I’ve been using Unfuddle for my version control system for code and it’s served me well. I was mainly after a free, SVN version control system and it’s been just perfect, really.

I have Tortoise SVN installed, which gives me shell integration in Windows and allows me to manage my code files directly from Windows Explorer. I’ve also been using AnhkSVN for Visual Studio to look after my .NET Micro Framework code. It’s a complete, simple solution.


I’m dreaming of going into business for myself. Whatever this business dream is it will likely involve code and microcontrollers. While I work out what’s a viable business to pursue, I’m continuing my Arduino/.NETMF development. I want to ‘open source’ my software. Not just make my code downloadable (barely) from my blog, as I have done, but go mainstream.

Developing code and providing downloadable ZIP files is a kind of closed/open model of development. If I go truly open, my incomplete code, as well as my completed code is in the public space. I’d like to be able to put up a blog post and say “I’m writing an Arduino library for the DS1307 real-time clock chip. The repo’s here. Contributions appreciated”. With this in mind I looked at Unfuddle to fulfil this new need. It can’t. It won’t. It’s not aimed at that use. GitHub is.

I’ve tried a number of times to wrap my head around GitHub. My main objection, as I suppose is the main objection of most, is that it’s “for Linux hippies”. Seriously. I mean, I’ve used Linux quite a bit, but not lived my life on the command line as it appears you need to do in GitHub’s world. Look at the documentation. 2.1 Git Basics – Getting a Git Repository takes you straight to the command line, with a bash prompt no less. Sorry, but the majority of the world’s computer users know Windows as a first UI language. But (as far as I’ve seen) not a single line in the documentation suggests “hey, if you’re here without any UNIX/Linux experience, you will find this a little strange”. I’m still looking for the documentation to confirm for me the command line syntax is the same on all platforms – nada!

I’m getting over my objections. That, and I’ve tried the GitHub Windows application this time. I expect it has limited functionality and at some point I’ll be forced to the command line. I guess I’ll have to configure VI or EMACS as my text editor then, won’t I? For the non-Linux hippies, these are text editors in UNIX/Linux. Again, if the service or the documentation even acknowledged the existence of Windows users there’d be some mention of Notepad++ or some such. But hey, when I get the command line under control I should be able to seamlessly move between my Windows, OSX and Linux machines as I do development. That would be sweet.

My GitHub account is in order, my application works, I can create repositories, commit files, all the good stuff. But there is much to learn here. The first major learning is there seems to be a “one project, one repository” mindset. I had anticipated creating a repository for Arduino, one for my .NETMF stuff and maybe a separate one for other bits and pieces. But no, I’m apparently going to manage a stack of repos. We’ll see how long this takes to become unwieldy.

So the model I imagining is this. I’ll want to create a project, like my GPS clock. I’ll assemble the hardware components and build (not download) code libraries for these. Each library will be a separate GitHub repo. When a library (class) is complete and tested for each software and hardware component, then the main project can begin as another repo. However, the main project will only #include the libraries and the repo will not contain them directly. For each #include required for the GPS_Clock project, the appropriate header and implementation files will be downloaded from their respective GitHub repositories to the Arduino \libraries folder.

I can see my overengineering this. The GPS clock repo will require the inclusion of the repo’s for:

  • EM-406A GPS
  • DS1307 RTC
  • BOB-00099 SparkFun 4x7-Segment LED Display
  • DateTime library (full-featured dates and times)
  • Location library (GPS coordinates)
  • … etcetera!

But that’s the plan for now. I’m going to have a hack at this and see what I learn. The library for the DS1307 is already mostly complete although it’s on Unfuddle at the moment. For the next post I’ll get that up on GitHub.

That is all.