Page 1 of 1

Using LeoStick temperature sensor

Posted: Sun Sep 02, 2012 9:32 am
by garyaj
nonentity asked for an example of using the temp. sensor in the LeoStick Atmega32u4 chip. After uploading the sketch below, click on the magnifying glass icon on the top right hand side of the Arduino IDE to open the Serial Monitor window.

Code: Select all

/*
  ReportTemp
  Use internal temperature sensor to report temperature to Serial Monitor window
  Temp. sensor will be about 3 degrees higher than room temp.
  To see sensor in action touch, (very carefully with your finger tip), the top of the Atmega chip. (There aren't any dangerous
  voltages but you don't want to touch any pins or wires on the board.) This will provide a heatsink for the chip and the
  temperature reported will lower. Stop touching the chip and the temp. will return to previous values.

  This example code is in the public domain.
 */

void setup() {                
  Serial.begin(9600);
  Serial.println("LeoStick as Thermometer");
  ADMUX = 1<<REFS1 | 1<<REFS0 | 0x47; //2.56V reference, set temp. sensor to input to ADC
  ADCSRA = 1<<ADEN | 1<<ADSC | 0x07;  //enable ADC, start conversion, 2MHz clock
}

//adjust OFFSET by trial and error with a real thermometer
#define OFFSET 400

void loop() {
  Serial.print(ADC - OFFSET);
  Serial.println("C");
  bitSet(ADCSRA, ADSC); // start next conversion
  delay(3000); //wait 3 sec
}

Re: Using LeoStick temperature sensor

Posted: Tue Nov 13, 2012 10:29 am
by Flymo
Thanks! Works well on our Leostick, although it does report:

Code: Select all

Binary sketch size: 4452 bytes (of a 28672 byte maximum)
ioctl("TIOCMSET"): Value too large for defined data type
Wish I knew enough to be able to parse that.... :?

Re: Using LeoStick temperature sensor

Posted: Thu Nov 15, 2012 1:07 pm
by csconsulting
What happens when you add this to the sketch:
long TIOCMSET;

Re: Using LeoStick temperature sensor

Posted: Thu Nov 15, 2012 10:58 pm
by Flymo
Thank you!
No more error message. :D

The offset needed with our Leostick seems to be around 637
It's a bit jittery, but what would one expect! Great little sketch. Ben