0% found this document useful (0 votes)
3 views

ATtiny-Watch-Core

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

ATtiny-Watch-Core

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

technology workshop craft home food play outside costumes

ATtiny Watch Core


by ?? on December 13, 2015

Table of Contents

ATtiny Watch Core . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

Intro: ATtiny Watch Core . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Step 1: Preparation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

MCU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

ISP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Battery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Other Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Step 2: Assembly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

Step 3: Power Down, WDT and Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

Step 4: I2C Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

Step 5: Custom Font . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

Step 6: Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

Step 7: User Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

Step 8: Calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

Step 9: What's Next? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

http://www.instructables.com/id/ATtiny-Watch-Core/
Intro: ATtiny Watch Core
This instructable show how to use an ATtiny85 to create a tiny watch core that can run over 1 year before recharge or replace battery.

The instruction to make the watch case may be in next instructable.

I have made a few Arduino watch before, but I found the watch using ATmega boards or ATmega chips are a little bit too big to wear. So I would like to make it with a
smaller chips.

I have choose ATtiny85 just because I can easy to get one.

The challenges for using ATtiny85 are:

1. It only have 8K flash memory


2. It only have 5 IO pins (I would like to keep the 6th IO pin as reset for easy re-programming)
3. Since the above 2 limitations, it is hard to find a complete source code for an ATtiny watch on the web

I design to develop a tailor-make code to complete these challenge, it include:

1. Power control to make the watch can run over 1 year


2. Revise a time library to utilize WDT for power saving purpose
3. Trim down a display library to meet 8K binary limitation
4. Customizable font type
5. Basic UI for adjust time just like a normal digit watch

Step 1: Preparation
MCU

Today core subject, ATtiny85.

ISP

Any ISP that can program ATtiny85.

Battery

In general expectation, a watch should run over 1 year without charging or replace battery. For my simple measurement of power usage and the battery specification,
CR1220 can only run about half an year, CR2016, CR2025 and CR2032 can run over 1 to 2 years representatively.

Display

Since the number of IO pins of ATtiny85 is very limited, I design display and further modules should all run in I2C. Power consumption and source availability are also
important factors. I choose an OLED screen drive with SSD1306. It can find in 3 different sizes, 64x32 is the smallest one. (another sizes are 128x64 and 128x32)

Other Parts

A battery holder, a small bread board, some bread board wires, two buttons and a power switch (optional).

http://www.instructables.com/id/ATtiny-Watch-Core/
Step 2: Assembly
connect all the parts on the bread board:

ATtiny85

pin 1: not connected

pin 2: set button, other button pin connect to GND

pin 3: up button, other button pin connect to GND

pin 4: connect to GND

pin 5: connect to OLED board SDA pin

pin 6: not connected

pin 7: connect to OLED board SCL pin

pin 8: VCC

Also connect battery and OLED board to VCC and GND.

http://www.instructables.com/id/ATtiny-Watch-Core/
Step 3: Power Down, WDT and Time
When MCU and OLED turned on, it consume about 6 mA.

In order to make the watch can run over 1 year, I will use the most power saving sleep mode, SLEEP_MODE_PWR_DOWN, when user not in use. According to my
cheap power meter, it show 0.1 uA if disable all the function. But It still need to enable WDT for time keeping, after enable WDT, it show 4 uA. Assume MCU and OLED
auto sleep after 5 seconds and user view the watch 12 times, the watch will consume about 0.2 mAh. ((0.004 mA * 24 hours) + (6 mA * (5 / 60 / 60) hours * 12)) So a 150
mAh CR2025 battery can run 750 days.

The time source code mainly come from PaulStoffregen. However, the power down sleep mode will stop the normal timer, use mills() function for time keeping is not
valid. So I keep another variable to replace mills() function. For each WDT interrupt, it increase the variable value. The increment value depends on the WDT interval
settings and the chip's oscillator. When using 1 second WDT interrupt, my chip's calibrated increment value is 998 (around 1000 milliseconds).

And also I have added the readVcc() function for monitoring the battery status.

Ref.:

WDT and power related: http://www.re-innovation.co.uk/web12/index.php/en...

time function v1.4: https://github.com/PaulStoffregen/Time

readVcc: http://www.re-innovation.co.uk/web12/index.php/en...

http://www.instructables.com/id/ATtiny-Watch-Core/
File Downloads

WDT_Time.cpp (9 KB)
[NOTE: When saving, if you see .tmp as the file ext, rename it to 'WDT_Time.cpp']

WDT_Time.h (7 KB)
[NOTE: When saving, if you see .tmp as the file ext, rename it to 'WDT_Time.h']
Step 4: I2C Display
The code is reference from DigisparkOLED, but since its example code complied size is over 6K, the complete example cannot put on their ATtiny85 product, Digispark.
(it require to comment out the bitmap code) The complete example can only run on their another product, Digispark Pro.

Here are something I have revised or rewritten:

1. Trim out many unused data, including font and bitmap


2. Init SSD1306 setting according to the SSD1306 data sheet page 64
3. Try to support all known resolution (64x32, 128x32, 128x64)
4. Support custom font
5. Function for turning OLED on and off for power saving purpose

Ref.:

DigisparkOLED: https://github.com/digistump/DigistumpArduino/tre...

SSD1306 data sheet: https://www.adafruit.com/datasheets/SSD1306.pdf

Another instructables using ATtiny85 and SSD1306: http://www.instructables.com/id/ATTiny85-connects-...

File Downloads

ssd1306.cpp (5 KB)
[NOTE: When saving, if you see .tmp as the file ext, rename it to 'ssd1306.cpp']

ssd1306.h (1 KB)
[NOTE: When saving, if you see .tmp as the file ext, rename it to 'ssd1306.h']

http://www.instructables.com/id/ATtiny-Watch-Core/
Step 5: Custom Font
8K flash has no enough room to store all characters in large font size. (such as 24 pixels font height)

As watch only require 10 digital characters, we only need to tailor-make a selected font type binary to make it.

I will use imagicmagick command line tools to show how to do that:

http://www.imagemagick.org/script/index.php

I need 2 font sizes, one with font height 8 pixels to show date digits and one with font height 24 pixels to show time digits:
convert -depth 1 -font Lucida-Sans-Unicode -pointsize 11 label:00123456789 -crop 70x8+7+4 -flip -rotate 90 watch_digit.xbm
convert -depth 1 -font Cooper-Black -pointsize 25 label:00123456789 -crop 150x24+14+4 -flip -rotate 90 watch_3x_digit.xbm

Lucida-Sans-Unicode and Cooper-Black are the font type in Windows 7, you may use your selected font type in your OS.

The corp, flip and rotate option help to adjust the binary data in correct position and direction.

Then we can copy the binary to the watchdigit.h source file:


#include <avr/pgmspace.h>

#define FONTWIDTH 7
#define FONT3XWIDTH 15

static const uint8_t watch_digit[] PROGMEM = {


//watch_digit.xbm binary
};

static const uint8_t watch_3x_digit[] PROGMEM = {


//watch_3x_digit.xbm binary
};

File Downloads

watchdigit.h (3 KB)
[NOTE: When saving, if you see .tmp as the file ext, rename it to 'watchdigit.h']
Step 6: Program
I am using littlewire something like that:

https://digistump.com/wiki/digispark/tutorials/pro...

File Downloads

attiny85watch.ino (3 KB)
[NOTE: When saving, if you see .tmp as the file ext, rename it to 'attiny85watch.ino']

http://www.instructables.com/id/ATtiny-Watch-Core/
Step 7: User Input
Set button: select adjust field, the field will highlighted

Up button: increment value of selected field

Step 8: Calibration
Press Up button when not select any field will enter debug screen.
The first number is WDT interrupt count, this value can be used to calculate the value of millis per interrupt.
The second number is current battery voltage in millivolt. It also require calibrate with multimeter.

http://www.instructables.com/id/ATtiny-Watch-Core/
Step 9: What's Next?

Related Instructables

ATTiny85 Traffic DIY Motion


Sensing Ceiling Attiny85 watch + weather Arduino Use ATtiny85
Light by decision box ATTiny85
Fan/light ***5$ station by with I2C
nthdesign V2.0 by Voltage Monitor
Energy ????????1 EEPROM by
Saver!!!*** by Victor805 RGB LED by brewforce
FoamboardRC tytower

Advertisements

Comments
2 comments Add Comment

minibit says: Dec 26, 2015. 5:48 AM REPLY


Nice project! Could you give us the link to this super tiny OLED display? Thank you

plouc says: Dec 26, 2015. 5:26 AM REPLY


Your concept is really cool, I just wonder,, is the watch running on internal oscillator? How precise will it be?

http://www.instructables.com/id/ATtiny-Watch-Core/

You might also like