Using LeoStick temperature sensor

A shrunk down Leonardo-compatible board, thumb drive sized with native USB support. [Product info]
Post Reply
garyaj
Posts:4
Joined:Fri Aug 31, 2012 1:29 am
Using LeoStick temperature sensor

Post by garyaj » Sun Sep 02, 2012 9:32 am

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
}

Flymo
Posts:19
Joined:Sun Jan 22, 2012 10:06 am

Re: Using LeoStick temperature sensor

Post by Flymo » Tue Nov 13, 2012 10:29 am

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.... :?

csconsulting
Posts:71
Joined:Fri Sep 21, 2012 7:22 am

Re: Using LeoStick temperature sensor

Post by csconsulting » Thu Nov 15, 2012 1:07 pm

What happens when you add this to the sketch:
long TIOCMSET;

Flymo
Posts:19
Joined:Sun Jan 22, 2012 10:06 am

Re: Using LeoStick temperature sensor

Post by Flymo » Thu Nov 15, 2012 10:58 pm

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

Post Reply