This is the code used in the following Tweet.

 * Blink.cpp
 * Created: 27/08/2019 18:57:18
 * Author : HiboTronix

// 8MHz Internal Oscillator
#define F_CPU 8000000UL

#include <avr/io.h>
#include <util/delay.h>
#include <string.h>
#include "delay_timer.h"
#include "Serial.h"

int main(void) {
	CCP = 0xD8; // CCP_IOREG_gc Set The Configuration Change Protection 
	            // Register To 0xD8 And Change CLKPSR Within 4 Clock Cycles 
	CLKPSR = 0; // Set Clock Prescaler To 1 For 8MHz Internal Clock
	DDRA = 0x20; // PA5 as output, Led Cathode Connected To Pin
	PORTA |= (1<<5); // PA5 High = Led Off
    while (1) {  // Equivilent To The Arduino Loop
		PORTA |= (1<<5); // PA5 High = Led Off
		Serial_println("Led Off");
		PORTA &= ~(1<<5); //PA5 Low = Led On
		Serial_println("Led On");
 * Serial.h
 * Created: 27/08/2019 18:57:18
 * Author : HiboTronix

void Serial_Init() {
	UBRR = 0x33; // Set Baud To 9600
	UCSRA = (0<<U2X) | (0<<MPCM); // MCPM Off, Single Speed
	UCSRB = (1<<RXEN) | (1<<TXEN) | (0<<UCSZ2); // Enable Receiver And Transmitter
	UCSRC = (0<<UMSEL1) | (0<<UMSEL0) | (0<<UPM1) | (0<<UPM0) | (0<<USBS) | (1<<UCSZ1) | (1<<UCSZ0) | (0<<UCPOL); // Set Frame Format: 8N1

void Serial_Write(char data ) {
	/* Wait for empty transmit buffer */
	while (!(UCSRA & (1<<UDRE))) {}
	/* Put data into buffer, sends the data */
	UDR = data;

void Serial_Print(const char c[]) {
	for (uint8_t i = 0; i < strlen(c); i++) { // Loop Through Each Char

void Serial_PrintLn(const char c[]) {
	for (uint8_t i = 0; i < strlen(c); i++) { // Loop Through Each Char
	Serial_Write(13); // CR, Carriage Return
	Serial_Write(10); // LF, Line Feed	

unsigned char Serial_ReadByte( void ) {
	/* Wait For Data To Be Received */
	while (!(UCSRA & (1<<RXC))) {}
	/* Get And Return Received Data From Buffer */
	return UDR;

void Serial_Flush( void ) {
	unsigned char dummy;
	while (UCSRA & (1<<RXC)) {
		dummy = UDR;
 * Delay_Timer.h
 * Created: 27/08/2019 18:57:18
 * Author : HiboTronix

void delay_ms(uint16_t ms){

Download “Blink.cpp” – Downloaded 52 times – 1 KB

Tagged with: , , , , ,

Over the years my obsession with sensing my environment has only deepened with the advent of new sensors and/or the availability of them to Makers.

The BME280 from Bosch got my attention because of its ability to measure temperature, humidity and pressure in a rather small (albeit expensive) form factor.

At the time I was playing around with the RFM69 ISM band radio modules from HopeRF and one evening I said to myself “I could make a wireless sensor, surely RF isn’t that hard”.  I fired up Eagle and set to work designing a PCB, all the time thinking about the form factor, did I want a shield for an Arduino Uno? How was I going to power it? What Antenna was I going to use?

I have often designed a PCB first then designed an enclosure to 3D print on my Ultimaker2, the results were always satisfactory but not quite “Consumer Grade” and knowing my better-half’s dislike of my projects spread strategically around the house I knew it had to look good if I was to have a few scattered around in different rooms.

Hammond 1551V3

The Hammond 1551V3 enclosure was perfect, it looked the part and was designed exactly for the purpose so I ordered 5 and set about refactoring the PCB to fit inside.  I knew because of its size and the fact it had to be coin cell powered I needed to use the lower-powered RFM69CW variant to get reasonable battery life.  While reading the RFM69 datasheet I noticed the TX current requirement, at full TX power it could demand 45mA!

45mA TX Power Requirement

The requirement of 45mA from a CR2032 (which I had already chosen based on size and Power availability) was a bit much even to my basic knowledge in the battery arena.  I looked at many datasheets but all the data for “Operating Voltage vs. Load Resistance” started at a minimum of a 1KΩ load, I needed ~67Ω load worst case!

This is the best data I could find!

After careful testing and measurement with a working prototype, I concluded that 2x CR2032 cells in parallel would just about give me the pulsed load I needed with a negligible voltage drop on fresh new cells, considering the very short period of the TX pulse.  The unknown, however, was how long these cells would last.

The brains of the operation were already chosen too, the venerable ATMega328P running at 8MHz maximum and utilizing LowPowerLabs Moteino Library by Felix Russo.  Ths library includes a sleep mode when not transmitting bringing the quiescent current to ~6µA.

At this point in my journey, I had a working prototype with a wire antenna knowing that if I wanted to retain the almost professional look I wanted for a happy household I needed a better solution for an antenna.

The choice of antenna quickly boiled down to:

  • Ceramic Chip Antenna
  • Folded Metal Type
  • Coiled Spring Type
  • PCB Antenna

It soon became clear the choice of the antenna was going to be based on lots of variables, cost, size, the complexity of implementation etc.  Somewhat risk-averse, and let’s face it, nobody likes failure, I opted to fail “fast and cheap” and settled on a PCB antenna.  The almost endless information on the dark art of PCB antenna design started to consume all of my spare time so I chose a reference design based on a meandering monopole style.  I carefully transposed the design onto my PCB and sent them for manufacture.

My plan, based on discussions with my like-minded maker friends was to order enough PCB’s to fulfil my requirements then sell the remaining on my Tindie store to recoup some of the costs of the project, in essence, making my sensors free!  To accomplish this I needed to be confident that these devices performed as desired, the hardware was established but I feared the antenna was a weak point.

Cheap Antenna Analyser

The first test of the newly assembled device was horrible, missing packets and a 6-8ft range.  I had used a cheap Chinese Vector Impedance Analyser to test the PCB antenna knowing that getting my matching network even remotely in the ballpark would increase the range as other users of the RFM69CW had written of ranges in excess of 300ft line of sight.  My range increased by 2-4ft but the packet loss was just as horrible.

It was time for professional assistance, my fail fast and cheap attitude went out the window, I don’t like to fail, but when I do I need to know how badly, hoping I was close, as to soften the blow.  I found a particularly friendly RF Engineer near me who indulged my inexperience and helped me investigate.


Return Loss Of Assembled Unit As I Gave It To Him

The first reports were in, and they were as horrible as I imagined.  From memory, it had a VSWR of around 12 which meant upwards of 70% of the power was being reflected.  I failed spectacularly. The poor RF guy was probably as horrified as I was that such an antenna exists.  I asked him to calculate the correct matching network and run it a second time.

Return Loss Of Assembled Unit With Correct Matching Network

From my day job I was aware that anything under a VSWR of 2:1 was acceptable to most commercial installations I deal with so the sight of this familiar-looking dip was encouraging.  Again from memory, the VSWR was around 1.5:1, excellent, but VSWR isn’t even half the story.  To have reliable packet delivery I also needed a good bandwidth margin and also the radiation pattern needed would also have to be suitable for the intended application.

One of the observations from the RF guy was that while the antenna was “matched” inside the enclosure, removal of the front cover completely de-tuned the antenna, something he was fully aware of, but a valid lesson for an RF newbie like myself.

Matched Network With Front Of Enclosure Removed

The antenna centre frequency shifted from 868MHz to ~900MHz by simply removing the cover, this just reinforced my new found respect for everything RF, a truly dark art.  The bandwidth was about 15MHz which was OK but the RF guy said he frequently aims for, and achieves, 100MHz bandwidth for his regular customers.  He also highlighted the fact that a “narrow” bandwidth also makes the component choice for the matching network quite important suggesting I used a tighter tolerance product.

Almost at the end of my RF adventure, I had to see the 3D plots of the radiation pattern, while researching PCB antennas I was greeted with almost perfect doughnut shapes radiating outwards, did I even manage it?

3D Radiation Pattern

Yes, I did 🙂

At the time of writing the Completed devices (2 of) have both been Working In my house on the same batteries and without a single missed packet since May 2019.  They both report Temperature, Pressure and Humidity, every 15 Minutes to my Raspberry Pi 3 with an Adafruit Radio Bonnet.

Although the devices work for my needs, I made the decision not to offer these for sale,  I don’t have the RF expertise to support my customers and although they work perfectly in the locations and at the distances I chose, I couldn’t guarantee they would work universally.

Would I start another RF project?  Hell yeah, but I’d consult with a professional first!

Tagged with: , , , , , , ,

This guide will show you how to add a lithium-ion cell or lithium polymer battery to the ATMega328P SMD ProtoBoard I sell on Tindie.

What You Will Need?

Assemble the charger board using this post as a guide.


After many years of trying to document and share my projects, good and bad, welcome to what I hope to be a valuable resource for other makers. I hope to share electronics projects, 3D printer files, my journey through the minefield of desktop CNC’s.

For many years I have been tinkering with electronics, from through-hole matrix boards, up to more recently custom PCB’s I have designed using SMD components. With the cost of PCB’s the lowest they have ever been from China I often order more boards than I need so I will offer them for sale in my Tindie shop.

I sell on Tindie