Monday, December 30, 2019

Making a Magnetic Loop Antenna

I've been using my recently acquired SDR for a while now hooked to a simple wire antenna, but as you might expect the results were far from ideal.  So, I made the decision to build (not buy) my own magnetic loop antenna.  The big advantages of this type of antenna over others are their small size, portability and decent bandwidth.

The antenna consists of a large, outer resonant loop for picking up the RF signals and a smaller, magnetically coupled, inner loop that connects to the radio.  See diagram below left:

(Source: http://www.aa5tb.com/loop.html)
For the large loop I used 10' of 1/4" copper tubing inserted inside an identical length of 1/2" PEX tubing to aid in stiffness and durability.  Pigtails were soldered to either end of the copper and then connected to an air variable capacitor I had in my junk box (thanks Bob, WA1EDJ), creating a parallel resonant circuit. The measured inductance of the copper loop was ~3.25uH and the variable cap I had selected had a range of ~10-200pF.  This gave me a calculated tuneable bandwidth of ~6.2MHz to 27.9MHz.

A 2' length of copper tubing was then formed into a smaller loop with one end connected to the center conductor of a length of RG-58 coax while the other end was connected to the outer braid.  The other end of the coax was mated with a BNC connector to hook up with the receiver. This inner loop was then positioned in close proximity to the outer loop and secured in place with zip ties.

Some close ups of the various construction details:

Copper tubing inside PEX (large loop)
with a soldered pigtail on one end

Coax connected to ends of small
copper (inner) loop

Inner loop positioned closely to outer tube

Vertical support strut added
Tee connector at bottom of large loop




Completed antenna minus tuning capacitor

After assembly, I hooked it up to the radio to see if reception had improved.  Definitely!!  I also took measurements to determine the actual tuneable bandwidth.  It seemed to show signal peaks at ~6MHz on the low end and ~18.5MHz on the high end.  This corresponds roughly to the 40-17m amateur bands.  I can only attribute the difference in high end response (27.9MHz calculated vs 18.5MHz actual) to additional parasitic capacitance of ~13pF.

I'm not worried about weather proofing the variable cap since the entire antenna unit can easily be moved indoors at a moments notice in case of rain or snow.  The next task at hand will be to make additional antennas to cover different bands.

Thursday, December 19, 2019

Software Defined Radio

This Christmas I thought I'd splurge on a Software Defined Radio (SDR) from SDRPlay (SDRplay.com).  I chose the RSP1A model for ~$100.00 that includes the software to setup and run the user interface.  It covers the radio spectrum from 1kHz to 2GHz with a displayable bandwidth of  up to 10MHz.  All that's needed is a PC to run the software and an external antenna and its ready to go. I plan on making my own antenna soon (probably a magnetic loop), but for now I'll just string a wire from the unit and hope for the best.

Here is the unit showing the USB interface on the right along with a length of wire attached to the antenna port on the left.  That's it!...The PC does all the data and display processing.

RSP1A

This image is a screenshot of the SDRuno software user interface.  This can be customized by each user to meet their particular needs (filter selection, spectrum bandwidth, band/mode of interest, etc).

Here I'm listening in on a CW signal on the 40m band (7.044.5MHz).

Looking forward to hours of experimenting (aka playing) and exploring the rich feature set available.

Friday, September 6, 2019

Data Logging with a Raspberry Pi

A major limitation to the PC board I created for my ESP-WROOM-02 module described in the previous post was that it could only support one digital input (even though the ESP module itself supports many).  This was done intentionally to keep things simple.  In a real-world application, however, this would not be very useful.  Therefore, I decided to go with a different approach for round two.

I chose a Raspberry Pi 3B+ with battery backup to monitor, control and display everything.  This small but powerful platform would allow me to gather data from multiple sensors with plenty of capacity for future expansion.  The actual task of gathering sensor information and then processing it involved installing four pieces of software onto the RPi:

1) Collecting the data from each wireless sensor - I chose Aedes to serve as my MQTT broker/server.  MQTT is a messaging protocol ideally suited for the Internet of Things.  Devices connected to the service (clients) can transmit data (publish) and/or receive data (subscribe).  The broker essentially acts like a post office, handling all messages between devices while providing a level of security.  Note - at the moment only one of my sensors is wireless (a motion detector), while the rest (temperature and humidity) are hard wired directly to the Raspberry Pi via an I2C interface so no MQTT messaging is required.

2) Data manipulation - Node Red was my choice for handling all data once it was received.  It is essentially a visual programming tool consisting of nodes (units of pre-developed code) that perform a specific task such as writing to a database, converting raw data into a visual gauge or bar chart, filtering data, and so on.  Nodes are connected via virtual wires to create a flow.  The following image is part of a flow I created specifically for this project:

Node Red flow

In this example, the reddish-brown node in the center retrieves the hard wired sensor data (temperature and humidity) for the outside and basement sensors, the light orange nodes perform some post retrieval processing and the light brown nodes on the far right forward all processed data to the database software for storage.

3) Database storage and 4) Visualization - I decided upon InfluxDB for storing all my sensor data and Grafana for the user display.  InfluxDB is a time series database that allows for easy data logging and when coupled with additional software like Grafana provides a user friendly way to visualize data in real time.  The screenshot below shows my basement temperature and humidity over a 24hr period along with maximum, minimum and average values:

Grafana dashboard

A final touch was to create a simple web page that could display this information in real time using the browser on my smartphone, home computer, etc.  Node Red made adding this feature a snap.  Below is a screenshot of the display (I chose to show temperature only to keep things simple):

To access the page I just type in the IP Address of the Raspberry Pi (assigned by my WiFi router on initial startup).  Code for the gauge templates came from "canvas-gauges.com" but everything else was written by me.  This setup works fine when I'm around the house in range of our WiFi network but what about when I'm not at home?  The solution was to create a VPN (virtual private network) so that I could access this info anywhere in the world that has internet access.  I simply setup the RPi as a VPN server using a YouTube tutorial I found and it was ready to go.

Below is a picture of the Raspberry Pi (lower left) along with the battery charger (from DFRobot) and a +12V sealed lead acid battery enclosed in a plastic storage container kept in the basement.  The wires connected to the RPi go to my environmental sensors.


Update (Spring 2022)
I decided to completely overhaul my webpage by adding a few more bells and whistles as seen in the screenshot below.  The current temperature and rainfall values still come from my onsite sensors, but the 12-hour forecast readings come from an AccuWeather API.  I also added two temperature charts: one to show the hourly values throughout the day and one to show the daily low and high values for the week.  Finally, I added a background image to provide an interesting backdrop.  This came from a picture taken on one of our hikes near the Asheville area.



Saturday, June 15, 2019

Using a Sensor with an ESP8266

After playing with my newly acquired Sonoff switch I got the bug to explore additional wireless uses.  This time I wanted to hook up an environmental sensor to a WiFi capable device and then send the acquired data to a Blynk app for display.  

For the controller I chose an inexpensive ESP-WROOM-02 module (based upon the ESP8266 WiFi microchip).  When the ESP module first arrived I quickly realized I would need to either purchase or make my own break-out board in order to access the pins since the unit was an SMD device.  I knew it would be quicker if I bought a pre-made adapter but what fun would that be, so I used my PC board layout software to create a custom design, then etched and drilled a copper board.  The pictures below show a finished blank board alongside a fully populated one:

Break-out board
Fully populated board
If you look closely, you can see the embedded WiFi antenna running along the upper blue region of the board.

For testing purposes I decided to use a DHT22, which is one of the many inexpensive, single wire temperature and humidity sensors commonly available on the market.

After writing and compiling my program, the next step was to apply power, then flash the code into the chip and check for functionality.  It worked (no smoke!) but I soon discovered that the WiFi module was resetting itself periodically.  After much agonizing over potential coding issues I found that many other people were having the same problem.  It seems that when the module is in transmit mode the extra current demand causes a sudden drop in voltage from the power supply that randomly forces a hard reset.  The fix was to add two, 220uF capacitors in parallel across the chip's power and ground pins to smooth out the voltage spikes.  For extra insurance I also added a .1uF capacitor to reduce any high frequency noise.  Both additions seemed to do the trick.  Pretty exciting to finally see this working!  

Update (Late Fall 2019)
My module is now officially off the grid!  I decided to add some circuitry to eliminate the need to power my module from line voltage.  Taking a 6V solar panel I had purchased years ago, I added a 3.7V Lipo battery pack and a Lipo battery charger (from DFRobot) to create a stable 3.7-4.2V reference that would work 24/7.  Next, I fed this into a 3.3V LDO voltage regulator to provide the correct voltage for the ESP module and I was all set.

Initial testing was disappointing to say the least.  The 1700mAH battery was only lasting a few hours before it needed recharging.  In idle (receive) mode the circuitry consumes ~75mA while during data transmission it jumps to over 250mA.  The poor battery never had a chance.  After researching ideas on the web I found I could perform a software activated deep sleep operation on the chip, effectively shutting down most of the ESP module circuitry for a fixed period of time.  The only part of the chip still active would be a real time clock.  In this state the WiFi module consumes less than 1mA.  Then, when the time period expires (defined in software), a specific I/O pin on the module sends a signal (pulse) needed by the reset pin to wake up the chip.  All I had to do was add a couple of lines of code and hard wire the two pins together.  I decided that sleeping for 15 minutes, then waking up and processing data for 15-20 seconds before resuming another sleep cycle would be a good compromise for my project.

The nearly completed unit, mounted to the base of a plastic enclosure is shown below.  The Wifi module is actually on the underside of the copper board so it is not visible.

Friday, May 31, 2019

Making PC Boards

I've always enjoyed making my own PC boards for custom projects but have struggled mightily with the process over the years . Either the board design wouldn't transfer or stick properly to the copper or if it did it would end up pitted after etching.  Well, I finally hit upon a formula that appears almost full-proof.  Some of this came about from trial and error on my part and some from other people's ideas.  The image below shows the results of my first board:

Not perfect by any means but pretty darn good for my needs.  I will list the steps that work for me in hopes that others might find them useful.








PC Board Production Steps
• layout board with ExpressPCB or similar software
• print design onto special toner transfer paper (print on shiny side) using laser
       printer (Staples, etc. will do this); note - I use paper from PulsarProFX but
       glossy magazine paper should work as well
prep and clean copper board (scrub with Scotch-Brite pad, wash with soap and
       water then clean with alcohol)
apply a few drops of an acetone:alcohol mixture (3:8) to board, then spread
       evenly with fingers (this mixture will cause the toner to release from the paper
       and stick to the copper); note - this mixture is the critical part of the whole
       process
position paper design onto board and gently press into place
apply a few more drops of mixture onto paper until thoroughly covered then wait
       5-10 seconds
apply even hand pressure with a paper towel for ~90 seconds, then remove towel
       and wait ~30 seconds
place board with paper into a cold-water bath for ~2 minutes then peel off paper
       backing
wait ~15-20 minutes for toner to dry then turn on laminator set on low heat
       (3mm setting, I use a model GBC H220)
once laminator is ready, cover board with green TRF film (front side taped to
       board and shiny side up); note - this material is also from PulsarProFX and
       helps to reduce pitting of the copper
run board thru laminator once then allow to air cool for ~15-20 minutes
gently remove green TRF film
patch voids with fingernail polish if needed (must be done after using green TRF
       film)
now ready for etching with hydrogen peroxide:muriatic acid mixture (2:1)

Thursday, April 25, 2019

Sonoff Smart Switches

The Sonoff series of smart switches (produced by Itead) are based upon the ESP8266 and ESP8285 microcontrollers.  They are Wi-Fi compatible thus making them useful for interfacing remotely with iOS and Android devices via a number of commonly available apps such as Blynk, eWeLink, etc.

Basic R2
For basic switching operations, these units are designed to work right out of the box using their standard, built in firmware.  All you need is to load an app onto your phone for controlling it and you're all set.  The app sends a command to the Sonoff which in turn activates a relay on the board, thus controlling the power delivered to a load.  However, I wanted to go one step further and use custom firmware to make the device self contained (no app required).

I purchased a basic model (Sonoff Basic R2) for ~$7.00 and begin experimenting with different code libraries freely available on the web.  The goal was to turn an external device hooked to the Sonoff on and off at a predetermined time each day.  I found a library that contained code for accessing an NTP (Network Time Protocol) server.  This allowed me to fetch the current time off the web.  Next, I hard coded specific times for turning my device on and off.  The drawback to using fixed times is they can only be changed by altering the program and recompiling it.  For now this will work fine, but down the road I might use an app on my Smartphone to program an on time and off time on the fly.  This, of course would require a one-time modification to the program.

In order to load (flash) the compiled code onto the Sonoff board I needed an interface between the computer and the ESP chip.  This was because the USB end uses 5.0V while the ESP circuitry uses 3.3V.  I purchased an FTDI based USB to TTL interface board from Amazon, transferred my code and was up and running in no time.

Neat little devices.

Update (June 2019)
After using my Sonoff for a while with hardcoded on/off times embedded in the firmware, I finally decided to experiment with the Blynk app on my Smartphone to allow for dynamic changes to the on/off parameters.  Blynk comes with coding examples already written for specific applications so I used one suited for my needs and simply copied and pasted the appropriate sections into my existing program.   I also made sure to store any changes to the on/off parameters into non-volatile memory to ensure the Sonoff would work when power was lost and then restored.  After loading the newly compiled code into the Sonoff chip, it ran w/o any hiccups.  So easy!  Now I can change the on/off times if needed w/o reprogramming the chip and the Sonoff will respond accordingly.

Wednesday, April 3, 2019

Wireless Communications Using 433MHz RF Modules

As a compliment to my previous project (TFT LCD clock), I decided to build another TFT/Arduino unit that would serve as a remote station.  I could then make use of commonly available 433MHz RF xmt/rcv modules and wirelessly connect between the two units.  I also wanted an excuse to experiment with these wireless devices by playing with antenna orientation, configuration (coiled vs straight), etc. to establish their maximum range and transmission accuracy.  The base station located in another room of our home would transmit time information every few seconds which, in turn would be received by the remote station located in my ham shack (currently a spare bedroom).

The RF units (STX882/SRX882) were purchased from banggood.com for ~$3.00.  Next, I located an excellent resource and code library focused on wireless interfaces (RadioHead) and used their ASK (Amplitude Shift Key) drivers for my project.  This type of modulation provides a simplified, one way channel for transmitting and receiving data with decent data integrity.
                                                                                     
433MHz Receiver and Transmitter Modules
Each RF module connects to its respective Arduino unit via a single digital I/O pin.  This allowed for easy initial checkout by directly hard wiring the transmitting Arduino to the receiving Arduino (ie. the RF interface was bypassed), then sending a test message.  After ensuring message data was properly dis-assembled by the receive station, I removed the direct connection and plugged in the RF modules.  It actually worked the first time!!!  I did not check for maximum range but it works fine for the moment with a separation of ~50ft (from one end of our home to the other) so I am quite pleased.  As shown in the following image, I also added support for an environmental sensor to display the room temperature:


Thursday, January 31, 2019

TFT LCD Clock

The market seems to be flooded lately with the versatile TFT (thin film transistor) LCD color displays so I thought it was time to put one to use in a new project.  I needed (wanted) an accurate digital display for my ham shack that could show time in two formats: 12-hr (eastern) and 24-hr (UTC).  I chose a 2.8" screen (320 x 240  pixels) with touch capability that could directly connect to an Arduino Uno w/o a shield interface.  These are dirt cheap if purchased from China (~$11.00 including shipping).  I also decided to use an RTC (real time clock) that could be programmed with the current time and date w/o having to perform any calculations.  Adafruit has an RTC module available based upon the Maxim DS3231 chip which is not only highly accurate (+-2ppm) but also capable of automatically adjusting for leap years up to the year 2100.  As a bonus, it also offers a battery backup feature so that reprogramming only needs to be done every 4-5 years or so.

The items were ordered and then I used public domain software from Github, Adafruit and others for controlling the various hardware interfaces.  I designed and  wrote the specific code for controlling the visual display elements and user interface.  The biggest challenge was selecting fonts that would "fit" into the memory space of the Uno (32kB).  I wanted a large font (55pt) for the main time display but it consumed over 5kB of memory just for the "0-9" and ":" characters alone.

Another software issue concerned the support of the different time formats (along with the additional memory demands).  I wanted to include UTC format because its commonly used in amateur radio communications when logging a QSO.  Since the eastern time zone (where I live) is 5 hours behind UTC time, every time I switched between the two time formats there would be a difference in not only the displayed hour but also potentially the day and month (actually the year could be different as well).  When eastern time format was selected, I would need to contend with another problem: daylight savings time.  Instead of scratch writing something that might or might not work (might not was the more likely outcome), I decided to search for public domain code that might address these issues.  Surely others have had these same concerns at some point?  Sure enough I eventually found a "timezone" library that handled the time differential in UTC mode and automatically adjusted the time twice a year when switching between regular and daylight savings time  (thanks to Github/JChristensen).  I simply extracted the appropriate code sections and pasted them into my code.  After a bit of tweaking everything worked as it should.

After struggling with the memory issue for a bit I finally decided to use a platform with greater memory...the Arduino Mega 2560 (256kB).  I purchased a cheap clone from China for ~$16.00 (regular price $38.00) and got started on code development.  I finally came up with what looked to me like an overall nice layout, color scheme and font selections as seen in the image below:


An added touch (pun intended) is the touch screen feature that allows me to press the screen to select between UTC and eastern time.