Thicket data repository for the EEG
at main 2.8 kB view raw
1{ 2 "id": "https://www.tunbury.org/2020/12/26/temper-usb-temperature-sensor", 3 "title": "TEMPer USB Temperature Sensor", 4 "link": "https://www.tunbury.org/2020/12/26/temper-usb-temperature-sensor/", 5 "updated": "2020-12-26T12:41:29", 6 "published": "2020-12-26T12:41:29", 7 "summary": "These USB sensors are available pretty cheaply from PiHut and Amazon and are great for monitoring the temperature remotely (where you have a Pi).", 8 "content": "<p>These USB sensors are available pretty cheaply from PiHut and Amazon and\nare great for monitoring the temperature remotely (where you have a Pi).</p>\n\n<p>Install the necessary prerequisites:</p>\n\n<div><div><pre><code>sudo apt install libhidapi-dev/stable cmake bc\n</code></pre></div></div>\n\n<p>There is a <a href=\"https://github.com/edorfaus/TEMPered\">GitHub repository by Frode Austvik</a>:</p>\n\n<blockquote>\n <p>This project is a C implementation of a library and program to read all the\nvarious types of TEMPer thermometer and hygrometer USB devices, as produced by\nRDing Technology and sold under the name PCsensor.</p>\n</blockquote>\n\n<p>Download the software</p>\n\n<div><div><pre><code>git clone https://github.com/edorfaus/TEMPered\n</code></pre></div></div>\n\n<p>And build it and install:</p>\n\n<div><div><pre><code>cd TEMPered\ncmake .\nmake\nsudo cp utils/hid-query /usr/bin\n</code></pre></div></div>\n\n<p>Create a simple script to query the device and display the temperature.</p>\n\n<div><div><pre><code>!/bin/bash\nOUTLINE=/usr/bin/hid-query /dev/hidraw1 0x01 0x80 0x33 0x01 0x00 0x00 0x00 0x00 | grep -A1 ^Response|tail -1\nOUTNUM=echo $OUTLINE|sed -e 's/^[^0-9a-f]*[0-9a-f][0-9a-f] [0-9a-f][0-9a-f] \\([0-9a-f][0-9a-f]\\) \\([0-9a-f][0-9a-f]\\) .*$/0x\\1\\2/'\nHEX4=${OUTNUM:2:4}\nDVAL=$(( 16#$HEX4 ))\nCTEMP=$(bc &lt;&lt;&lt; \"scale=2; $DVAL/100\")\necho date $CTEMP\n</code></pre></div></div>\n\n<p>This works perfectly but it must be executed with <code>sudo</code>, or by first\nrunning <code>chmod 666 /dev/hidraw</code>. This can be automated by creating\n<code>/etc/udev/rules.d/99-hidraw.rules</code> with the content below which creates\nthe <code>/dev</code> node with the appropriate permissions.</p>\n\n<div><div><pre><code>KERNEL==\"hidraw*\", SUBSYSTEM==\"hidraw\", MODE=\"0666\", GROUP=\"root\"\n</code></pre></div></div>\n\n<p>I’ve added a cron job (<code>crontab -e</code>) to record the temperature every 5\nminutes:</p>\n\n<div><div><pre><code>0,5,10,15,20,25,30,35,40,45,50,55 * * * * /home/pi/temp.sh &gt;&gt; /home/pi/temperature.txt\n</code></pre></div></div>", 9 "content_type": "html", 10 "author": { 11 "name": "Mark Elvers", 12 "email": "mark.elvers@tunbury.org", 13 "uri": null 14 }, 15 "categories": [ 16 "raspberrypi" 17 ], 18 "source": "https://www.tunbury.org/atom.xml" 19}