Penguins Unbound
User:goeko > Temp Sensor

Temp Sensor

Page last modified 01:47, 12 Dec 2011 by goeko

     

    Get the hardware

    I found a usb temp sensor on Amazon (about $10). I was also able to find software that worked with this on linux.

    http://www.amazon.com/Powered-Thermo.../ref=pd_cp_e_1

     

    Get software

    There are several software options.

    I decided to use the pcsensor software

    Install Software

    First you will need to install the development usb library

    sudo apt-get install libusb-dev 
    

    Then you will need to download the software and compile it.

    wget http://momtchil.momtchev.com/files/pcsensor-1.0.0-multi.tgz 
    tar -zxvf pcsensor-1.0.0-multi.tgz
    cd pcsensor-1.0.0
    make
    

    The you should have the program that should be able to read the sensor! Make sure your sensor is pluged in, you can use lsusb to check that.

    user@Mish:~$ lsusb
    Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 002 Device 019: ID 0c45:7401 Microdia
    Bus 002 Device 018: ID 0c45:7401 Microdia
    Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    

    In that example you can see I have two of them, the "0c45:7401 Microdia" device listed there.

    Now you should be ready to get temp info!

    user@Mish:~/pcsensor-1.0.0$ ./pcsensor 
    Could not set configuration 1 on device 0
    user@Mish:~/pcsensor-1.0.0$ sudo ./pcsensor 
    [sudo] password for goeko: 
    2011/12/08 14:09:16 Temperature 65.19F 18.44C
    2011/12/08 14:09:16 Temperature 61.59F 16.44C
    user@Mish:~/pcsensor-1.0.0$ 
    

    In that example I tried to run the program (pcsensor) as a user, but it didn't work. I had to run the script as root. When I ran it as root you can see that I got data from both the USB temp sensors!

    Setup continuous temp monitoring

    Next I setup a cron job to run the pcsensor program every minute and record the data to a file in my directory.

    goeko@Mish:~/pcsensor-1.0.0$ crontab -l
    # Edit this file to introduce tasks to be run by cron.
    # 
    # ... (A whole bunch of crontab comments deleted)
    # 
    # m h  dom mon dow   command
    * * * * * /usr/local/sbin/pcsensor >> $HOME/.temp_info
    

    Create Graph

    use Gnuplot

    Create the graph "script"

    Here is my Basic Script to graph the root temp (this was my frist use of gnuplot, so it is pretty much just parts of other scripts I found on the itnernet. See referances).  It will only make a graph for a single 24 hours period.

    #!/usr/bin/gnuplot
    set terminal png size 1200,800
    set xdata time
    #set timefmt "%b-%d-%H:%M:%S"
    #set timefmt "%Y-%m-%d %H:%M:%S"
    set timefmt "%H:%M:%S"
    set output "/home/goeko/Desktop/room_temp.png"
    # time range must be in same format as data file
    #set xrange ["Mar-25-00:00:00":"Mar-26-00:00:00"]
    #set yrange [0:50]
    set grid
    set xlabel "Time"
    set ylabel "Temp"
    set title "Room Temp"
    set key left box
    plot ".temp_info" using 2:4 index 0 title "Office Temp" with lines
    

     

    And this is what I get

    room_temp.png

     

    Setup continuous running of graph script

     

    After I was happy with the graph my script made, I once again used cron to auto run the script every 5 minutes to update the graph.  I then put graph file on my desktop, where I was able to view it all the time!

    */5 * * * * /home/goeko/plot_temp_data.gp
    

     

     

    Create Desktop Temp Image

    Create a jpg with a simple soild background color

    Then used the Linux convert command (part of ImageMagik).

     

    Then once again, set it up to auto run via cron.

    * * * * * /home/goeko/Projects/Temp_Sensor/temp_pict.sh
    
    Powered by MindTouch Core