×

Our Technical Support team will be out of the office on Wednesday, April 23 starting at 12pm. Tech Support will reopen with normal hours on Thursday, April 24 at 9am. Thank you

avatar

Toemat

Member Since: August 19, 2008

Country: United States

  • Product SEN-09418 | about 2 years ago

    Here’s a perl script I made for use on the Raspberry Pi using the Adafruit Occidentalis OS.

    Run this script as root or sudo to output the current temperature in Celsius and Fahrenheit:

    #!/usr/bin/perl
    
    #Grab the data from the device (Addr0 pin tied to ground gets 0x48 address)
    $rawhex = `i2cget -y 0 0x48 0x00 w`;
    
    #Switch the position of the two bytes and convert to integer
    $decimal = oct("0x" . substr($rawhex,4,2) . substr($rawhex,2,2));
    
    #Shift right four bits (12 bit mode)
    $decimal = $decimal >> 4;
    
    $celsius = $decimal * 0.0625;
    $f = (9.0/5.0) * $celsius + 32;
    
    #Profit!
    print "C: $celsius, F: $f\n";
    
Name Pieces Total
WISHY LISTY
1 69.95