So after playing around with Arduino for a while and I decided to teach myself AVR programming without the “help” of the Arduino framework. Without going into the pros and cons of each, my main reasons were size, cost, and curiosity. However, after spending a while learning how to program the AVR (a bit more on that lately) I was hooked and haven’t looked back.
I spent quite a bit of time going through the “Make: AVR Programming” book and learning how to use the different parts of the uC. After that, I thought I’d try and see how I could use the AVR to help me with another hobby: swimming.
So I decided to design and build sports watch that I could use help me keep track of the number lengths I’ve been swimming in the pool.
I find it almost impossible to remember lengths past about 5 and although I do have a Garmin 910xt, I find that it ALWAYS adds lengths randomly making it impossible to know how far I’ve got left to go (although I can change the lengths after the swim, it’s of no use during the swim).
There are a few different devices you can buy out there for counting lengths, but none of them really meet my needs, which are:
- Count the number of lengths I’ve been swimming
- Tell me the length of time I’ve been swimming
- Tell me the time of the previous length
- Store all these details for later analysis
- Be easy to record each length
- Store a good number of swims in memory
- Allow me to store sets as well as lengths
- Allow me to pre-set training sessions (which I can easily do for running and cycling, but not swimming!)
Now despite looking – and someone might know of a device that I’ve missed – I’ve yet to find any device that will give me all of the above.
As already mentioned, for this project I’m using the Atmega328P (the same on that comes with the Arduino, but doesn’t have a bootloader installed). This is the one taught in the above mentioned book, and since I already had a few lying around, it made sense to use it. However, at this stage, 32k of flash is too much, but that might changer as more features are added.
The processor is connected to an external 16MHz crystal, and with no divide by 8, I’m currently getting the full 16MHz speed. I might change this as the project progresses, as 16MHz is probably a bit overkill, and from what I’ve read elsewhere, it’s probably going to be using more power. But for now it works well.
One of the goals at this point is that I can wear the device on my finger to make adding laps straight forward (similar to products like this, though I’m not too bothered if it’s a bit bigger). Therefore I’ve been looking for small displays not much bigger than my finger. After looking at a few different display’s (most of which were far too big or too expensive), I came across the 0.96″ OLED display here. Although I actually bought mine off Ebay for a few £ more, this one seems to be the same for a bit less.
The display is so much smaller than I expected, with the display section slightly smaller than my index finger as can be seen in the above photo.
The display is I2C controlled which is what I was looking for to potentially reduce the number of pins used on the processor (and potentially use a smaller processor in the future). I didn’t find many I2C controllers anywhere near this size, so it was a good choice at this stage.
To control the display I used u8glib, which contains a library for a wide variety of different displays for both Arduino and AVR. At the time of writing, the current version – 1.15 – can’t control the display, but a pre-release version is available here which worked nicely for me. So far I’m very impressed with the display and the u8glib library, both of which are working very nicely in the project so far.
To store the swim values I’m using a 24LC64 chip. Although at this stage, I could probably have gotten away with the internal EEPROM on the processor, the memory is just too small for what I hope to do in the near future. I chose this device because it’s I2C (so no extra pins needed on the processor), it’s got enough space for me to play around with (8KB), and it comes in DIP8 casing (though there are SMD versions available should I decide to use it in a future PCB version).
I was even able to find a library for the device here, which I’ve also incorporated into the project.
All together now
At this point, the swim watch only exists on a breadboard as I’m still developing and I’m interested in looking at different displays to see what works best for me.
However, for anyone how’s interested, the below is the circuit diagram and a photo of the current breadboard layout (which is VERY messy!).
Circuit diagram of SportsWatch 1.0 as it is built on the breadboard
My VERY messy breadboard circuit for the SwimWatch version 1.0
All the software was developed and compiled using a Raspberry Pi and avrdude. To program the AVR, I use the SPI drive from the Raspberry Pi (sadly I forget the link I used for setting it up, but I found it via Google). This allowed me to program and upload the code from the RasPi without the need for any extra programmers.
For my own use, I’ve setup a Google project page, and anyone is free to use the code and develop it as they see it. The link is here I’m looking at improving the code and adding more features as I go along, so I’m happy to take advice from anyone who’s interested in the project.
For anyone who’s interested, I’ve created a small video showing the device up and running here.
I’m happy to hear any comments and suggestions that people might have on the work. For the next version, I hope to work on the following:
- Tidy up the code and make use of enums, and structs;
- Improve the display. Having something similar to my Garmin watch where I can set different views for when recording a swim.
- Implement some power saving. I’ve got zero power saving methods implemented in this code. It would be interesting to see how long the current code would last on small rechargeable batteries.