{"id":571,"date":"2018-09-14T11:23:10","date_gmt":"2018-09-14T11:23:10","guid":{"rendered":"http:\/\/lora.vsb.cz\/?page_id=571"},"modified":"2018-09-17T09:33:12","modified_gmt":"2018-09-17T09:33:12","slug":"build-sensor-with-adafruit-feather-32u4","status":"publish","type":"page","link":"https:\/\/lora.vsb.cz\/index.php\/build-sensor-with-adafruit-feather-32u4\/","title":{"rendered":"Build Sensor with Adafruit Feather 32u4"},"content":{"rendered":"<h2><strong><span style=\"color: #800000;\">General Configuration<\/span><\/strong><\/h2>\n<p>At the <strong>Feather 32u4<\/strong>&#8218;s heart is at ATmega32u4 clocked at 8 MHz and at 3.3V logic.\u00a0<strong>Feather 32u4 LoRa Radio<\/strong>\u00a0uses the extra space left over to add\u00a0an RFM9x LoRa 868\/915 MHz radio module. We use 868 MHz one. <a href=\"https:\/\/www.adafruit.com\/product\/3078\" target=\"_blank\" rel=\"noopener\">See complete specification here<\/a>.<\/p>\n<ol>\n<li>Run Arduino IDE.<\/li>\n<li>You will need to install the <a href=\"https:\/\/learn.adafruit.com\/adafruit-feather-32u4-radio-with-lora-radio-module\/setup\" target=\"_blank\" rel=\"noopener\">Adafruit Package<\/a> in your <a href=\"https:\/\/www.arduino.cc\/en\/Main\/Software\" target=\"_blank\" rel=\"noopener\">Arduino IDE<\/a>. Copy and paste the link below into the Additional Boards Manager URLs option in the Arduino IDE preferences. <code>https:\/\/adafruit.github.io\/arduino-board-index\/package_adafruit_index.json<\/code><\/li>\n<li>Install the Adafruit boards via Tools -&gt; Boards Manager<\/li>\n<li>You should see in menu <strong>Tools<\/strong> -&gt; <strong>Board<\/strong> the Adafruit Feather 32u4<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-573\" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2018\/09\/adafruit.jpg.png\" alt=\"\" width=\"211\" height=\"367\" srcset=\"https:\/\/lora.vsb.cz\/wp-content\/uploads\/2018\/09\/adafruit.jpg.png 211w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2018\/09\/adafruit.jpg-172x300.png 172w\" sizes=\"auto, (max-width: 211px) 100vw, 211px\" \/><\/li>\n<li>Connect\u00a0 the Adafruit Feather using directly micro USB cable (no FTDI adapter is needed here).<\/li>\n<li>Check the appropriate COM port which is used for communication with Adafruit.<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-574\" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2018\/09\/Clipboard01-1.png\" alt=\"\" width=\"496\" height=\"322\" srcset=\"https:\/\/lora.vsb.cz\/wp-content\/uploads\/2018\/09\/Clipboard01-1.png 496w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2018\/09\/Clipboard01-1-300x195.png 300w\" sizes=\"auto, (max-width: 496px) 100vw, 496px\" \/><\/li>\n<\/ol>\n<h2><span style=\"color: #800000;\"><strong>Temperature Sensor using Adafruit Feather 32u4 and DHT22<\/strong><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-575\" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2018\/09\/dht22.png\" alt=\"\" width=\"200\" height=\"142\" \/><br \/>\n<\/span><\/h2>\n<ol>\n<li>Connect the one wire temperature sensor DHT22 to Adafruit. For data, we can use any of available <strong>digital<\/strong> pins, <a href=\"https:\/\/learn.adafruit.com\/assets\/46253\" target=\"_blank\" rel=\"noopener\">see here<\/a><\/li>\n<li>Use an addition 4.7k resistor between +3.3V and the data line.<\/li>\n<li>You need to additionally wire up the board&#8217;s IO1 pin with the board&#8217;s pin 6. You can use a simple wire bridge for that. Check the picture below to make sure you are actually using the right pins.<\/li>\n<li>Everything assembled:<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-585\" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2018\/09\/adafruit-all-1.jpg\" alt=\"\" width=\"643\" height=\"200\" srcset=\"https:\/\/lora.vsb.cz\/wp-content\/uploads\/2018\/09\/adafruit-all-1.jpg 643w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2018\/09\/adafruit-all-1-300x93.jpg 300w\" sizes=\"auto, (max-width: 643px) 100vw, 643px\" \/><\/li>\n<li>For communication with DHT22 we need\u00a0<a href=\"https:\/\/github.com\/adafruit\/DHT-sensor-library\" target=\"_blank\" rel=\"noopener\">Arduino library for DHT11DHT22, etc Temp &amp; Humidity Sensors<\/a>, import it to Arduino IDE<\/li>\n<li>Check if your Adafruit Feather can simply read the temperature and humidity from a sensor using Arduino IDE simple sketch:\n<pre><span style=\"color: #808000;\">#include <\/span><span style=\"color: #008000;\">\"DHT.h\"<\/span>\r\n\r\n<span style=\"color: #808000;\">#define<\/span> DHTPIN 2 \/\/ define data pin on Adafruit, we used 2\r\n<span style=\"color: #808000;\">#define<\/span> DHTTYPE DHT22   \/\/ define type of sensor\r\n<span style=\"color: #ff6600;\">DHT<\/span> dht(DHTPIN, DHTTYPE); \/\/define properties of sensor\r\n\r\n<span style=\"color: #99cc00;\">float<\/span> hum;\r\n<span style=\"color: #99cc00;\">float<\/span> temp;  \r\n                                \r\n<span style=\"color: #99cc00;\">void<\/span> <span style=\"color: #808000;\">setup<\/span>()\r\n{\r\n  <span style=\"color: #ff6600;\">Serial.begin<\/span>(9600);   \r\n  dht.<span style=\"color: #ff6600;\">begin<\/span>(); \/\/initiate the communication with sensor                                \r\n}\r\n\r\n<span style=\"color: #99cc00;\">void<\/span> <span style=\"color: #808000;\">loop<\/span>()\r\n{\r\n  hum = dht.readHumidity();  \/\/save the value of humidity to hum variable\r\n  temp = dht.<span style=\"color: #ff6600;\">readTemperature<\/span>(); \/\/ save the value of temperature to temp variable             \r\n\r\n <span style=\"color: #ff6600;\"> Serial.print<\/span>(<span style=\"color: #008000;\">\"Humidity is: \"<\/span>);                \r\n<span style=\"color: #ff6600;\">  Serial.print<\/span>(hum);\r\n  <span style=\"color: #ff6600;\">Serial.print<\/span>(<span style=\"color: #008000;\">\"% | \"<\/span>);\r\n  <span style=\"color: #ff6600;\">Serial.print<\/span>(\"Temperature is: \");\r\n  <span style=\"color: #ff6600;\">Serial.print<\/span>(temp);\r\n <span style=\"color: #ff6600;\"> Serial.println<\/span>(<span style=\"color: #008000;\">\" degrees of Celsius\"<\/span>);\r\n\r\n  <span style=\"color: #ff6600;\">delay<\/span>(1000);                              \r\n}<\/pre>\n<\/li>\n<li>\u00a0Use serial monitor,&#8230; and it works!<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-579\" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2018\/09\/printscreeenDHT22.png\" alt=\"\" width=\"601\" height=\"333\" srcset=\"https:\/\/lora.vsb.cz\/wp-content\/uploads\/2018\/09\/printscreeenDHT22.png 601w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2018\/09\/printscreeenDHT22-300x166.png 300w\" sizes=\"auto, (max-width: 601px) 100vw, 601px\" \/><\/li>\n<li>Within TheThingsNetwork\u00a0<a class=\"bbc_link\" href=\"https:\/\/thethingsnetwork.org\/\" target=\"_blank\" rel=\"noopener\">https:\/\/thethingsnetwork.org\/<\/a>\u00a0 we use the LMIC-Library\u00a0\u00a0<a class=\"bbc_link\" href=\"https:\/\/github.com\/matthijskooijman\/arduino-lmic\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/matthijskooijman\/arduino-lmic<\/a>,\u00a0slightly modified to run in the Arduino environment, allowing using the SX1272, SX1276 tranceivers and compatible modules (such as some HopeRF RFM9x modules).<\/li>\n<li>Import following library into ArduinoIDE:\u00a0<a href=\"https:\/\/github.com\/matthijskooijman\/arduino-lmic\">https:\/\/github.com\/matthijskooijman\/arduino-lmic<\/a><\/li>\n<li>Before a device can communicate via <a href=\"https:\/\/thethingsnetwork.org\/\">The Things Network<\/a> you need to register it with an application. To use the default Over The Air Activation (OTAA) you will need to<a href=\"https:\/\/www.thethingsnetwork.org\/docs\/devices\/registration.html\" target=\"_blank\" rel=\"noopener\"> register your device with its Device EUI<\/a>.<\/li>\n<li>We used\u00a0<a href=\"https:\/\/github.com\/wklenk\/adafruit-feather-32u4-lora-ota\/blob\/master\/adafruit-feather-32u4-lora-ota.ino\" target=\"_blank\" rel=\"noopener\">adafruit-feather-32u4-lora-ota.ino<\/a>\u00a0sketch with slight modification.<\/li>\n<li>Change the\u00a0<strong>DEVEUI<\/strong>, <strong>APPEUI<\/strong> and <strong>APPKEY.<br \/>\n<\/strong><span style=\"color: #ff0000;\">Note:<\/span>\u00a0<strong>DEVEUI<\/strong>, <strong>APPEUI\u00a0<\/strong>are reverse order (LSB)<\/li>\n<li>Change pin mapping to:\n<pre>const lmic_pinmap lmic_pins = { \r\n   .nss = 8, \r\n   .rxtx = LMIC_UNUSED_PIN, \r\n   .rst = 4, \r\n   .dio = {7, 6, LMIC_UNUSED_PIN}, \r\n};<\/pre>\n<\/li>\n<li>To send current temperature via TTN comment following:\n<pre>\/\/static mydata[] = \"Hello, TTN over OTAA!\";<\/pre>\n<\/li>\n<li>Don&#8217;t forget to add:<br \/>\n<code>#include \"DHT.h\"<\/code><\/li>\n<li>Add to\u00a0<code>void do_send(osjob_t* j)<\/code>\u00a0the following:\n<pre>float teplota = dht.readTemperature();\r\ndtostrf(teplota,5,2,(char*)mydata);   \r\nLMIC_setTxData2(1, mydata, strlen((char*) mydata), 0); \r\nSerial.println(F(\"Packet queued\"));<\/pre>\n<\/li>\n<li>Let LMIC compensate for an inaccurate clock. Just add this to your setup somewhere:\n<pre>LMIC_setClockError(MAX_CLOCK_ERROR * 1 \/ 100);\u00a0\/\/ Let LMIC compensate for +\/- 1% clock error<\/pre>\n<p>This lets LMIC make the RX windows longer and start sooner so it will catch a downlink even when the clock runs up to 1% faster or slower.<\/li>\n<li>Check TTN console if payload as temperature is received:<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-584\" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2018\/09\/Clipboard05.png\" alt=\"\" width=\"500\" height=\"362\" srcset=\"https:\/\/lora.vsb.cz\/wp-content\/uploads\/2018\/09\/Clipboard05.png 500w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2018\/09\/Clipboard05-300x217.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>General Configuration At the Feather 32u4&#8218;s heart is at ATmega32u4 clocked at 8 MHz and at 3.3V logic.\u00a0Feather 32u4 LoRa Radio\u00a0uses the extra space left over to add\u00a0an RFM9x LoRa 868\/915 MHz radio module. We use 868 MHz one. See complete specification here. Run Arduino IDE. You will need to install the Adafruit Package in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-571","page","type-page","status-publish","hentry","post"],"_links":{"self":[{"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/pages\/571","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/comments?post=571"}],"version-history":[{"count":6,"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/pages\/571\/revisions"}],"predecessor-version":[{"id":586,"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/pages\/571\/revisions\/586"}],"wp:attachment":[{"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/media?parent=571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}