Sunday, June 26, 2016

LoRaWAN FeatherWing for Adafruit Feather

In this post I will document a new custom FeatherWing I have designed to add the MicroChip RN2483/RN2903 LoRaWAN module to Adafruit Feather.

Help your Feather fly into the IoT clouds with this awesome
LoRaWAN module from MicroChip.


I have designed some FeatherWings in the past to add a LoRa transceiver module to Feather. I did the LoRa FeatherWing Development Breakout and the LoRa FeatherWing IOX that used the HopeRF RFM95/96(W) modules. The RFM modules are small and cheap, which is great for IoT projects. However, they have a limitation if you want to use them with LoRaWAN: the stack is not implemented in the module, leaving that burden to the microcontroller. The LoRaWAN stack takes a fair amount of code space, and it's difficult to implement in some 8-bit microcontrollers.

This new FeatherWing uses the RN2483 (868 MHz) or RN2903 (915 MHz) from MicroChip. It's an excellent module that fully implements the LoRaWAN stack itself. The microcontroller talks to it over USART with a simple command structure to configure it and send/receive messages. The module also has several GPIO pins available. This is the preferred module on The Things Network, and there are a lot of great example projects and code on the Internet to help you get started.

My FeatherWing is very simple. It connects the module serial pins and the module Reset pin to the Feather. It has an SMA connector for attaching an antenna, and a small white silk-screen box for writing in a node ID or other information. GPIO10 from the RN module is attached to an LED for status indication. Finally, I added an ICSP connector for the module that is compatible with the PicKit3. You'll probably never need this, but it can be used to update the firmware on the module if that is ever necessary.


Despite the simplicity of the FeatherWing, there was a unique challenge along the way. The RN module is a bit wide, and in fact nearly as wide as the header spacing on the Feather boards. My first revision of this board used a very narrow footprint for the module and normal through-hole headers. It was extremely difficult to solder. Though I made two functional boards with that PCB, I didn't think it was suitable to release as a shared project.

My solution was to make the FeatherWing a bit wider (1" wide instead of the normal 0.9") and use surface mount headers on the bottom. This is the first "wide-body" FeatherWing that I have seen.

 Surface mount headers on the bottom of the LoRaWAN FeatherWing.
Notice that the board is a bit wider than normal FeatherWings.


This board is compatible with Feather M0, Feather 32U4, and Feather WICED.

It is NOT compatible (as-is) with Feather HUZZAH (ESP8266). The single hardware USART on the HUZZAH is tied to the USB-Serial chip, and other things shouldn't be connected to those pins. If you really want to use the HUZZAH, you can:
  • Pick a software serial library for ESP8266
  • Download the Eagle design files
  • Modify the board so that the serial pins from the RN module go to the pins you want to use for software serial
  • Order your custom PCB on OSH Park or whatever service you like

Because this FeatherWing is wider than normal FeatherWings, it probably won't work on a Doubler. The board will overlap with the Feather and prevent it from being fully seated.

Shared as Open Source Hardware (OSHW)

Eagle Files: Shared on Github
Grab my Eagle parts library if you want to edit the footprints: Shared on Github

LoRaWAN FeatherWing: Order PCBs on OSH Park!

LoRaWAN FeatherWing Schematic

LoRaWAN FeatherWing Board Layout
Parts List:

LoRaWAN Module: MicroChip RN2483 (868 MHz) or RN2903 (915 MHz)
RF Connector: SMA or RP-SMA Edge-Launch for 1.6mm/0.062" board thickness
12-pin Header: 0.1" SMD, Female (Digikey) or make your own Male connector (see below)
16-pin Header: 0.1" SMD, Female (Digikey) or make your own Male connector (see below)
R1, R2: 680 ohm 0603 SMD (or adjust value to change brighness of LED)
PWR, G10 LEDs: 0805 SMD (color of your choice)
C1: 1uF 0603 SMD
C2: 470nF 0603 SMD

Notes: C1 and C2 are located on the bottom of the board. The ICSP header is rarely used and you don't need to solder headers to that. Be sure to pick the correct LoRaWAN module (frequency) for your country/region.

Make Your Own Male Surface Mount Headers

I typically avoid surface mount headers because they are more expensive and not something I have sitting around in the parts bin. Thankfully you can make your own surface mount male headers from right-angle breakway header strips.

Using a pair of pliers, pull every other pin on the header out of the plastic spacer, rotate it 180 degrees, then re-insert it. Next cut the pins a bit shorter so that they fit within the footprint on the PCB. Super easy and cheap. The below picture should make that more clear:

Make your own SMD male headers from right-angle breakway strips.

Software and Usage

These are the pin connections from the RN module to the Feather. On all three of these Feather variants, call "Serial1" to talk to the module instead of "Serial" in the Arduino IDE. The default baud rate is 57600. Drive Reset HIGH to enable the module.

Pin connections for Feather M0, 32U4 and WICED.

Here are some good software examples available on the Internet for using this module:
  • Great blog post on using the RN2483/2903 in Peer-to-Peer mode. This is useful for testing your boards and learning about the command interface to the modules.
  • Write-up on taking the next step into LoRaWAN and making a TTN node. The software is shared on Github.
  • This is the Command Reference for the RN modules. Definitely download a copy of this.
Finally, the status LED on the LoRaWAN FeatherWing is connected to a GPIO pin on the RN module, not the Feather. If you can make it blink with your program, that is great confirmation that the module is operational and talking to the Feather. The command is "sys set pindig GPIO10 1" to turn it on and "sys set pindig GPIO10 0" to turn it off.


This was a long post for a simple board! I hope you find this little FeatherWing useful. If you have any questions or feedback please post in the comments below. Finally, if you make your own LoRaWAN FeatherWing definitely tweet me a picture @sync_channel.

Thanks for reading!

- Dan W.

Tuesday, June 21, 2016

Eagle Custom Parts Library

I've created a new Eagle custom parts library for the projects I post on this blog. Though I upload the design files for individual Open-Source projects, you might like to re-use some of the parts in your own projects with a standalone, documented library. I have several parts to bring over, clean up, and comment, so it will be growing quite a bit over the next few weeks.

You can check it out on Github here:

Sync Channel Blog Design Files on Github

Ready-to-use Eagle footprints.

I will include Digikey part numbers where possible. I will only add parts to this library that I have personally tested using the OSH Park PCB service. I may also add other random things to this repo in the future. Note that I have released everything in it under the Creative Commons Zero license. Therefore, you do not have to attribute to use these in your own projects. OSHW licensing can be confusing at times, so at least you don't have to worry about this library.

Thanks for reading!

- Dan W.

Sunday, June 19, 2016

Designing a Mains Frequency Monitor, Part 2

This is the second in a series of posts about designing a mains frequency monitor using the Microchip PIC 16F1619 microcontroller. In this post we will take a look at the first revision of the board that I designed for the project and some of the features that it adds.

Be sure to read Part 1 of the project write-up if you haven't done so already.

First revision of the Mains Frequency Monitor board.

PCB Progress

I designed a PCB for this project a couple of weeks ago, and recently received the boards back from OSHPark. I think it turned out great! The board houses the microcontroller and 20MHz TCXO that we discussed in Part 1. For the power supply I opted for a Recom DC-DC converter to generate 5V from the rectified input from a 12V AC wall adapter. There is a programming port (PicKit3 compatible) for programming the microcontroller as well as a header to hook up the LCD.

I also added an opto-isolated terminal port that is compatible with common Serial-to-USB adapters such as the FTDI Friend, FTDI Basic Breakout, and all of the various clones available online. This is nice for capturing data in a log file and then analyzing it in a program such as TimeLab.

The PIC 16F1619 only has one USART, but I wanted to use the same serial LCD display I have been working with throughout the prototyping phase. I also needed the USART for the terminal interface. To get around this I added a SPDT analog switch (74LVC1G3157) to allow sharing of the USART with both ports. The serial LCD only needs the Tx line, so the Rx line from the USART connects directly to the terminal port.

 The Mains Frequency Monitor has three ports: programming, Serial LCD,
and an opto-isolated terminal port for data logging.

Here's a short video showing two of the boards in operation:


With assembled PCBs to test, I have been able to collect some data. Here is a frequency difference plot in TimeLab for a 12 hour run:

 Mains Frequency, 12 Hour Run, Frequency Difference

And here is the ADEV plot for the same run:

Mains Frequency, 12 Hour Run, ADEV

Much longer runs will be required in the future. Also, I plan to rig up a test with the board and a proper frequency counter measuring the same signal to allow for a good assessment of the board's performance. I've done some informal comparisons with a calibrated counter and I'm very confident in the accuracy of the readings from the board.

Design Files

I plan to wait until the project is finished before creating a project link on OSHPark, publishing the BOM, etc. Rev A of the board is working out well, but it might still be necessary to make some changes. Don't worry, everything will be shared and documented fully in Part 3 when we wrap up. For now, the design files are available in the GitHub repo if you would like to check them out. I have also updated the firmware version in the repo.
Here's the schematic of Revision A:

 Mains Frequency Monitor Revision A Schematic

Mains Frequency Monitor Revision A Layout

Measuring frequencies is fun for the whole family!


That's it for Part 2! I had hoped to make more progress on the firmware in this post, but the hardware took most of my time. I'm very happy with how the board turned out however. In Part 3, we will work on the code, sort out the clock functionality, and get the project finished up.

Please post any comments, suggestions, and feedback below.

Thanks for reading!

- Dan W.

Saturday, June 4, 2016

Cherry MX Keypad

In this post I will document an open-source, Arduino-compatible Cherry MX keypad that I designed using the ATmega32U4 microcontroller.

 A highly customizable Cherry MX keypad.


You have probably heard of Cherry MX keys in relation to gaming keyboards. They are very nice keys with excellent tactile feel. They are also extremely durable and rated for 50 million keystrokes. Products that use them are often top-tier and pricey, but come with cool features like multi-colored backlighting and re-programmable keys. Many people customize their keyboards by changing the key caps to have custom labels and colors. But why stop there? Let's design our own Cherry MX keypad from scratch!

Board Overview

The board that I designed includes four Cherry MX keys. I used MX Blues, but it is also compatible with other types such as Brown and Red. It's simply a matter of soldering on the ones you want. The keys are backlit by 3mm LEDs that sit in recesses in the sides of the keys. They are controlled via PWM to allow changing the brightness. The microcontroller running the show is an Atmel ATmega32U4. This is the same microcontroller used on the Arduino Leonardo. In fact, this board looks like a Leonardo to the Arduino IDE for programming. There is an ISP port for burning the bootloader with a programmer (Atmel ICE, USBtinyISP, etc), but you only need to do that once. Afterwards simply connect the board to your computer using the Micro USB connector for programming and normal usage.

The lovely ATmega32U4. Adding USB to the project with this chip couldn't be simpler.

The left side of the board with the microcontroller is a good example of a minimal setup for the 32U4. Despite the small number of components, we still have a good 16MHz crystal, reverse polarity protection on the 5V USB line, and the necessary bypass capacitors. If you modify this board to add more keys, you can bring over most of this layout as-is.


Using this board is super easy. After flashing the Leonardo bootloader, you can upload the example program on Github over USB from the Arduino IDE. You'll see from the example sketch that the code is simple and easy to modify. After uploading a program, the board immediately re-mounts as a USB input device. Pressing the keys sends the characters you have programmed to the computer just as if it were a keyboard or mouse. You could also program in character strings and complex combinations of key presses, mouse clicks, and delays. See this reference on the Arduino page to learn about all of the keyboard and mouse commands that you can use to program your own key functions.

Check out my YouTube video on the Cherry MX keypad to see it in action:


Not only is the programming of the keypad entirely customizable, the hardware is as well. This is shared as an open-source project. You can use the Eagle files as a template to make your own numeric keypad or even a full keyboard! Adding Cherry MX keys to your project really steps it up a level, especially if you create or 3D print a nice enclosure to mount them in. Remember that these keys are not just about tactile feel. They are extremely durable, and you can purchase or make your own custom keycaps to add the finishing touches to your project's interface.

Using Cherry MX keys in this project gives us access to all of the awesome
custom keycaps available. These metal arrow keys look and feel great.

I used the internal pull-ups on the 32U4 for the key switch circuits, and debouncing is done in software. There is plenty of space around the keys on the board for adding hardware debouncing if you like.

With only four keys on the board, I was able to connect each one to an individual pin of the microcontroller. However, if you make a large board with several keys, this will not be possible. You will need to switch over to row-and-column scanning to be able to handle something like a full keyboard. There are also some interesting things you could do with the backlighting. You could put the LEDs on a parallel charlieplexed grid, allowing you to turn on individual ones. This would be useful for key press indication, making games like Simon Says, and adding cool lighting effects.

Shared as Open Source Hardware (OSHW)

Here's the information you need to assemble your own Cherry MX keypads using the PCB I designed or design your own.

Eagle Files and Example Program: Shared on Github
Cherry MX Keypad: Order PCBs on OSHPark!

Cherry MX Keypad Schematic

 Cherry MX Keypad Layout

Parts List:

Microcontroller: Atmel Atmega32U4 TQFP
LEDs: 4x 3mm Green (or substitute with LEDs that have the same compact dimensions)
USB Connector: FCI 10103594-0001LF
D1: BAT20J or similar schottky diode, SOD-323 package
Q1: MMBT2222A NPN transistor, SOT-23 or similar NPN with same footprint
Y1: 16MHz, 5x3.2mm 4-lead SMD crystal
Programming Header: Standard AVR ISP 2x3 0.1" header (no need to actually solder it)
C1: 4.7uF 0603 SMD
C2: 100nF 0603 SMD
C3: 1uF 0603 SMD
C4, C5: 22pF 0603 SMD (or adjust value based on crystal load capacitance)
R1: 10k 0603 SMD
R2, R3: 20 ohm or 22 ohm 0603 SMD
R4, R5, R6, R7: 330 ohm 0603

Notes: Be sure to get the "PCB Mount" version of the Cherry MX keys, such as the part numbers shown in the links above. They have the necessary "fixation pins" for stability on the board. The 3mm LED needs to have a very small rim and short height to seat fully into the side of the MX key body. Any substitute needs to have similar dimensions to the part number linked above or it may protrude above the key body and interfere with the keycap.

Soldering Note: Be sure to examine the pictures, footprints, and part dimensions to ensure you can successfully assemble this board. I did use hot air for the crystal and USB connector. They can be done with an iron, but hot air and solder paste is more reliable.

Wrap Up

I hope you find this project interesting. As I said, it is really just a template for designing your own Cherry MX keypad. You can modify it to make it easier to solder, expand the board to include many more keys, or customize it to your intended enclosure. Tweet me a picture @sync_channel if you make some of these boards or design your own custom Cherry MX keypad. I'd love to see it!

Also let me know what you thought of the YouTube video. I have wanted to add video content to my articles for some time, and this is a first attempt at it. I have nothing close to a proper setup for making videos, so I apologize for the poor quality. Perhaps in the future I will invest in some better lighting and equipment to improve my videos. This written blog will always be my primary means of sharing my projects however.

Thanks for reading!

- Dan W.