Hello,
I've assembled my timesquare, and love it, well ok I don't like the fit of the band (my wrist is just too big) and am working on finding a better enclosure to turn it into a pocket watch. With that in mind I'm thinking about other improvements that might be added, namely a temp sensor and perhaps a pressure sensor.
How hard would it be to add a low-power sensor or two? I'm thinking I can add to the i2c bus and implement them as another display mode. I'm also thinking of getting the parts separately and breadboarding them out so I can get a better idea of how things go together.
Timesquare DIY Watch - Adding to I2C?
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Timesquare DIY Watch - Adding to I2C?
That should be possible.
-
- Posts: 17
- Joined: Sat Jul 11, 2009 3:46 am
Re: Timesquare DIY Watch - Adding to I2C?
I've fiddled around with the Timesquare watch, attempting to add a 'temperature' mode using the ATMega's internal temperature sensor.
However, as the hardware is configured with the AREF pin tied to AVcc + Vcc, this prevents using the internal 1.1V reference - instead AREF is tied to the battery voltage. So you lose a lot of resolution - you only get 1.0 deg C / bit with the 1.1V reference, this degrades to ~3degC/bit with the battery as AREF.
(Aside: the 328 data sheet says "The internal 1.1V voltage reference must also be selected for the ADC voltage reference source in the temperature sensor measurement.", but it seems they really meant "should" rather than "must". i.e. using a larger AREF seems to work, but with poor resolution as above.)
Ben
However, as the hardware is configured with the AREF pin tied to AVcc + Vcc, this prevents using the internal 1.1V reference - instead AREF is tied to the battery voltage. So you lose a lot of resolution - you only get 1.0 deg C / bit with the 1.1V reference, this degrades to ~3degC/bit with the battery as AREF.
(Aside: the 328 data sheet says "The internal 1.1V voltage reference must also be selected for the ADC voltage reference source in the temperature sensor measurement.", but it seems they really meant "should" rather than "must". i.e. using a larger AREF seems to work, but with poor resolution as above.)
Ben
Code: Select all
// sensor voltage sensitivity is ~1 mV/°C
// with the 1.1V reference and 10 bit range, this is ~1.1°C / bit
// 25°C ~= 314mV ~= 292
// with the AVcc=3V reference, ~3°C / bit
// 25°C ~= 314mV ~= 107
// - though AVcc varies with varying battery voltage
#define TEMPSAMPLESEXP 4 // number of samples = 2^n
#define TEMPOFFSET 324
#define TEMPSCALE 1.0
static int readTemperature() {
uint16_t adc;
uint16_t n;
float t;
power_adc_enable();
// normally you'd use the internal 1.1V reference, but on the TIMESQUARE watch the
// hardware has AREF tied to AVcc+Vcc, so you're stuck using that.
ADMUX = _BV(REFS0) | // AVcc reference
_BV(MUX3); // ADC8 (temp sensor) input
ADCSRA = _BV(ADEN) | // Enable ADC
_BV(ADPS2) | _BV(ADPS1); // 1/64 prescaler (8 MHz -> 125 KHz)
for(adc=0, n=0; n<(1<<TEMPSAMPLESEXP); n++) {
ADCSRA |= _BV(ADSC); // start the conversion
while (ADCSRA & _BV(ADSC)); // wait for it to finish
adc += ADCW; // read ADCH and ADCL in the correct sequence
}
ADCSRA = 0; // ADC off
power_adc_disable();
adc >>= TEMPSAMPLESEXP; // average (2^TEMPSAMPLESEXP samples)
// Vtemp = ADC * VREF / 1024
// temp = Vtemp * 1000
// - watch.getmV() is battery voltage * 1000
t = ((float)adc * watch.getmV()) / 1024;
return (int)((t - TEMPOFFSET) / TEMPSCALE + 0.5);
}
void mode_temp(uint8_t action) {
if(action != ACTION_NONE) {
if(action >= ACTION_HOLD_LEFT) {
uint8_t depth = 6, plex = LED_PLEX_4;
// Reduce depth/plex if battery voltage is low
if(watch.getmV() < BATT_LOW_MV) {
depth = 2;
plex = LED_PLEX_1;
}
// Reconfigure display if needed
if((watch.getDepth() != depth) || (watch.getPlex() != plex))
fps = watch.setDisplayMode(depth, plex, true);
}
int t = readTemperature();
if (t > 0) {
digit[0] = (uint8_t)t / 10;
digit[1] = (uint8_t)t - digit[0] * 10;
}
// Reset sleep timeout on ANY button action.
watch.setTimeout(fps * 3);
}
watch.fillScreen(BACKGROUND);
/* blit: re-use the 'Set' mode's odoDigits */
blit(odoDigits, 21, 128, 0, digit[0] * 8 + 1, 0, 2, 3, 5, 255);
blit(odoDigits, 21, 128, 0, digit[1] * 8 + 1, 4, 2, 3, 5, 255);
// add 'degree' symbol (dot)
watch.drawPixel(7,1,200);
}
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Timesquare DIY Watch - Adding to I2C?
Nice try, anyway!
- jarchie
- Posts: 615
- Joined: Sun Jun 24, 2012 2:16 pm
Re: Timesquare DIY Watch - Adding to I2C?
The situation may be a bit worse, as the internal temperature sensor is only designed to detect gross temperature changes. According to the datasheet, "the accuracy of the temperature measurement is +/- 10°C." Using the internal 1.1v bandgap as a reference would probably not help much in regard to accuracy.af3556 wrote:So you lose a lot of resolution - you only get 1.0 deg C / bit with the 1.1V reference, this degrades to ~3degC/bit with the battery as AREF.
It is possible to eke out a bit more accuracy by calibrating the sensor to the particular chip, but the measurement is still pretty coarse. (See ATmel application note AVR122.)
-
- Posts: 17
- Joined: Sat Jul 11, 2009 3:46 am
Re: Timesquare DIY Watch - Adding to I2C?
Yeah; seems like the sensor is relatively precise, but not very accurate from the factory. As AVR122 shows, calibration can bring the accuracy down to about 1 °C (they state +/-2°C in the introduction, though their results show about +/-1°C over room temperatures). The app note assumes the sensor has approx. 1 LSB/°C, whereas with the battery reference (~3V) applying the same technique I'd expect would result in +/-3°C at best, and probably worse given the battery voltage measurement is also subject to noise. Signal processing might help a bit (pun intended? :-).
The starting point of ~10°C is not very useful on the watch whereas ~1°C could be slightly useful, but 3-5°C is probably no better than what many people can estimate themselves.
Still, it was a good learning exercise.
The starting point of ~10°C is not very useful on the watch whereas ~1°C could be slightly useful, but 3-5°C is probably no better than what many people can estimate themselves.
Still, it was a good learning exercise.
- jarchie
- Posts: 615
- Joined: Sun Jun 24, 2012 2:16 pm
Re: Timesquare DIY Watch - Adding to I2C?
For you and me both. ;-) The only reason I know a little about the temperature sensor is that I really wanted to add software-only temperature compensated timekeeping to the Ice Tube Clock. Calibration might have given me the necessary accuracy, but I wanted other people to be able to use the mod without the hassle of calibration. In the end, I went with an external temperature sensor next to the crystal, which worked well.af3556 wrote:Still, it was a good learning exercise.
I still think the Time Square temperature mod is pretty cool--even if it doesn't deliver perfect accuracy. After all, building a Time Square watch is more about coolness than practicality... at least in my opinion.
Yeah... My impression is that the internal temperature sensor was intended to detect overheating. It seems like you'd need a lot more accuracy for most other applications. Oh well.af3556 wrote:The starting point of ~10°C is not very useful on the watch whereas ~1°C could be slightly useful, but 3-5°C is probably no better than what many people can estimate themselves.
Please be positive and constructive with your questions and comments.