{"id":1804,"date":"2018-10-27T07:57:38","date_gmt":"2018-10-27T12:57:38","guid":{"rendered":"http:\/\/nootropicdesign.com\/projectlab\/?p=1804"},"modified":"2018-11-02T08:10:24","modified_gmt":"2018-11-02T13:10:24","slug":"samd21-lora-gps","status":"publish","type":"post","link":"https:\/\/nootropicdesign.com\/projectlab\/2018\/10\/27\/samd21-lora-gps\/","title":{"rendered":"SAMD21 LoRa Development Board with GPS"},"content":{"rendered":"<p>Project source code at GitHub: <a href=\"https:\/\/github.com\/nootropicdesign\/samd21-lora-gps\" target=\"_blank\">samd21-lora-gps<\/a><\/p>\n<p>I&#8217;ve been doing some LoRa projects lately in order to learn as much as I can about this exciting new radio technology (see this <a href=\"https:\/\/nootropicdesign.com\/projectlab\/2018\/10\/20\/lora-mesh-networking\/\" rel=\"noopener\" target=\"_blank\">LoRa mesh networking project<\/a> and this <a href=\"https:\/\/nootropicdesign.com\/projectlab\/2017\/09\/03\/solar-powered-lora-weather-station\/\" rel=\"noopener\" target=\"_blank\">LoRa weather station<\/a>). <a href=\"https:\/\/lowpowerlab.com\/guide\/moteino\/lora-support\/\" rel=\"noopener\" target=\"_blank\">ATmega328-based Moteino modules<\/a> work great for a lot of projects, but I wanted a LoRa node with more processing power, more memory, and an onboard GPS receiver. The ATmega328 is just too constrained with memory &#8212; I&#8217;ve outgrown it. I really wanted a LoRa board with an ARM Cortex microcontroller like the SAMD21. This is the microcontroller used on the Arduino Zero. So, my ideal board is a SAMD21 with LoRa radio module and GPS receiver, all programmable with the Arduino IDE.<\/p>\n<p>But, where is such a board? I could not find one so I decided to design and make one myself.<\/p>\n<p><a href=\"https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2018\/10\/LoRaWAN_node_top.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2018\/10\/LoRaWAN_node_top_sm.jpg\" alt=\"\" width=\"640\" height=\"480\" class=\"alignleft size-full wp-image-1832\" \/><\/a><br \/>\n<br clear=\"all\"\/><\/p>\n<h3>Hardware Design<\/h3>\n<p>Microchip\/Atmel makes a SAMD21 chip and there are several variants. Most designs use the &#8216;G&#8217; variant, but I wanted to use the <a href=\"https:\/\/www.mouser.com\/ProductDetail\/556-ATSAMD21E18A-AU\" rel=\"noopener\" target=\"_blank\">simpler &#8216;E&#8217; variant<\/a> because it comes in a TQFP-32 package that I can very easily solder in my reflow oven without any trouble, or even by hand if I have to.<\/p>\n<p>The GPS module is a cheap Quectel L80 with a MTK3339 chipset. It is easy to use but the backup power circuit requires a charging circuit, so I don&#8217;t have battery backup for quick startup. I mainly chose this module because it has big soldering pads with 2.54mm spacing for easier prototyping.<\/p>\n<p>The LoRa radio module is a HopeRF module soldered to the bottom of the board. <\/p>\n<p><a href=\"https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2018\/10\/LoRaWAN_node_bottom.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2018\/10\/LoRaWAN_node_bottom_sm.jpg\" alt=\"\" width=\"640\" height=\"480\" class=\"alignleft size-full wp-image-1836\" srcset=\"https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2018\/10\/LoRaWAN_node_bottom_sm.jpg 640w, https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2018\/10\/LoRaWAN_node_bottom_sm-300x225.jpg 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><br \/>\n<br clear=\"all\"\/><\/p>\n<p>Here is the schematic and image of the board design. The Eagle files are in the <span class=\"code\" style=\"font-size:1.1em;\">hardware<\/span> directory of the <a href=\"https:\/\/github.com\/nootropicdesign\/samd21-lora-gps\" rel=\"noopener\" target=\"_blank\">samd21-lora-gps GitHub repo<\/a>.<\/p>\n<p><a href=\"https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2018\/10\/LoRa-GPS-schematic.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2018\/10\/LoRa-GPS-schematic.png\" alt=\"\" width=\"640\" height=\"477\" class=\"alignleft size-full wp-image-1822\" srcset=\"https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2018\/10\/LoRa-GPS-schematic.png 2952w, https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2018\/10\/LoRa-GPS-schematic-300x224.png 300w, https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2018\/10\/LoRa-GPS-schematic-768x573.png 768w, https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2018\/10\/LoRa-GPS-schematic-1024x764.png 1024w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><br \/>\n<br clear=\"all\"\/><br \/>\n<a href=\"https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2018\/10\/LoRa-GPS-board.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2018\/10\/LoRa-GPS-board.png\" alt=\"\" width=\"640\" height=\"234\" class=\"alignleft size-medium wp-image-1830\" srcset=\"https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2018\/10\/LoRa-GPS-board.png 1224w, https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2018\/10\/LoRa-GPS-board-300x110.png 300w, https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2018\/10\/LoRa-GPS-board-768x280.png 768w, https:\/\/nootropicdesign.com\/projectlab\/wp-content\/uploads\/2018\/10\/LoRa-GPS-board-1024x374.png 1024w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><br \/>\n<br clear=\"all\"\/><\/p>\n<h3>Burning a Bootloader<\/h3>\n<p>To make this board work with Arduino, I had to burn the Arduino bootloader onto the chip using an <a href=\"https:\/\/www.microchip.com\/developmenttools\/ProductDetails\/atatmel-ice\" rel=\"noopener\" target=\"_blank\">Atmel-ICE<\/a> programmer. My board has 5 test points on the bottom for this purpose. The Atmel-ICE needs connections for VTG (3.3V), SWDIO, SWCLK, RESET, and GND. The board has to be powered over USB during the programming procedure. In the Arduino IDE, I selected Tools->Board = Arduino\/Genuino Zero (Programming Port), Tools->Programmer = Atmel-ICE, and then just clicked Tools->Burn Bootloader. In a few seconds, my board had a bootloader and is now programmable as an Arduino Zero!<\/p>\n<h3>Programming the Board<\/h3>\n<p>I was careful in my design to allow this board to be used as an ordinary Arduino Zero even though it uses a different variant of the SAMD21 chip. The downside of this is that the default SPI pins defined for the Arduino Zero board use pins that are not present in the &#8216;E&#8217; variant of the SAMD21. Luckily the design of the Arduino system is flexible enough that we can define a different SPI interface on different pins. There is a <a href=\"https:\/\/learn.adafruit.com\/using-atsamd21-sercom-to-add-more-spi-i2c-serial-ports\/creating-a-new-spi\" rel=\"noopener\" target=\"_blank\">great article by Adafruit on this topic<\/a> but it may be pretty hard to understand. The bottom line is that by using these lines in your Arduino sketch:<\/p>\n<pre class=\"codeblock\">\r\nSPIClass SPI1(&sercom1, 12, 13, 11, SPI_PAD_0_SCK_1, SERCOM_RX_PAD_3);\r\npinPeripheral(11, PIO_SERCOM);\r\npinPeripheral(12, PIO_SERCOM);\r\npinPeripheral(13, PIO_SERCOM);\r\n<\/pre>\n<p>You can now use interface SPI1 to communicate with the LoRa module. I wrote a simple test sketch that reads the GPS module and broadcasts the GPS coordinates on the radio every 15 seconds. See the <a href=\"https:\/\/github.com\/nootropicdesign\/samd21-lora-gps\" rel=\"noopener\" target=\"_blank\">samd21-lora-gps GitHub repo<\/a>.<\/p>\n<p>This test code uses the <a href=\"http:\/\/www.airspayce.com\/mikem\/arduino\/RadioHead\/\" target=\"_blank\">RadioHead library<\/a> to control the LoRa radio. The RadioHead library is flexible so I was able to use the SPI1 interface by defining a couple of new files, <span class=\"code\" style=\"font-size:1.1em;\">RHHardwareSPI1.[cpp,h]<\/span>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Project source code at GitHub: samd21-lora-gps I&#8217;ve been doing some LoRa projects lately in order to learn as much as I can about this exciting new radio technology (see this LoRa mesh networking project and this LoRa weather station). ATmega328-based Moteino modules work great for a lot of projects, but I wanted a LoRa node [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[30,32],"tags":[],"class_list":["post-1804","post","type-post","status-publish","format-standard","hentry","category-iot","category-lora"],"_links":{"self":[{"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/posts\/1804","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/comments?post=1804"}],"version-history":[{"count":17,"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/posts\/1804\/revisions"}],"predecessor-version":[{"id":1910,"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/posts\/1804\/revisions\/1910"}],"wp:attachment":[{"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/media?parent=1804"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/categories?post=1804"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nootropicdesign.com\/projectlab\/wp-json\/wp\/v2\/tags?post=1804"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}