Category Archives: Electronics

RADIO REPEATER MONITOR

#132 Designing a Radio Repeater Monitoring PCB

3D model of the PCB

About a year ago I realized the need for a dedicated repeater monitor that’s isolated from my clubs ham radio repeater equipment. E.G (power supply VOTER and Radio equipment). Having a dedicated monitoring PCB with a few extra complimentary features like remote control switching and reading/triggering capabilities would be very useful for largely remote and isolated places, also I get to test out and make some cool stuff.

PCB design

So I convinced myself to make the RRM V1.0 radio repeater monitor based around the well known and beloved ESP8266. Well what about the ESP32 you may ask? Yes I have made a new and improved version with asynchronous reporting and many other hardware improvements however I intend to sell that as a commercial product and thus I will not be giving away to many details for free but for a small fee you too could have one in your hands so now hopefully you see my simple strategy.

Soldered PCB

Though I designed this board for monitoring repeaters it can also be used to measure current temperature and control inputs and outputs for a number of other appliances like monitoring the current, temperature and input outputs of a vehicle. With the WiFi capability the device can be connected to as an Access Point as well for mobile operations, of course connections to the internet through WiFi is required to send the sensor and peripheral data to the server so that reports and nice colourful charts can display the data in a useful logical manner.

Here you can watch a YouTube video where I discuss the design at our Ham radio bimonthly meeting a few months ago

I decided to make a version 1 SMD PCB with large 1206 components as a prototype just to see that everything works correctly. I chose KiCad as my design software and got to work.

My requirements were:

  • 1206 SMT Parts
  • Current Measurement
  • Internet Capability
  • Reed In Detect
  • Digital Input
  • Digital Output
  • Voltage In Detect
  • Battery Back Up
  • Temperature Sensors
  • High Resolution ADS1115 ADC
  • IO Expander
  • OLED Screen
  • Reset Button
  • Control Button
  • M3 sized Screws
  • USB-C
  • Buzzer
  • Notification LEDs
3D back of PCB

So I got down to work and created a prototype around the an ESP8266 module. Note: although this module has been around for a while there’s a lot of different variants available however the EPS32 will be used in my commercial version as it has much better performance and features as well as long term support.

Designing the PCB took a few weeks of fulltime checking and double checking and then triple checking XD. Then eventually I send the PCBs to be manufactured. I soldered everything myself and confirmed everything was working correctly. Next I just experimented a bit with different components, led colours and temp sensors etc.

Bare PCB

Now I was ready to Install the module for tests at my local repeater site. We have WiFi and power at the site so I was able to connect all the hardware up and make things look neat.

Everything worked well and has been for over a year now so the project is a success I just need to monitor it long term.

FLUX DANGERS

#131 Flux causing strange IC behaviour

Low solids runny liquid flux is the best

When I ran out of my professional electronics flux I decided to try and use some off the shelf flux from the local construction store.

The flux was quite thick and seemed to work quite well when soldering parts but after cooling down some time later it forms a gunky wax that is conductive and causes all kinds of interference(Guess how I know) and worst of all it gets under IC’s and is almost impossible to remove entirely without de-soldering cleaning and then re soldering while using a very runny flux.

I tried cleaning with paint thinners and alcohol multiple times but in the end I had to remove the whole IC and clean it thoroughly

Even after multiple cleans you can still see the stubborn flux gunk on the pins as soon as i desoldered the IC
Side view of the gunk shorting out pins (Very difficult to remove when the IC is soldered on the PCB even after multiple washes and scrubs)

When the flux dries it can cause a few issues: gunk up of the pins and getting trapped under the IC

Backside is also gunky
This flux caused electrical issues on my IC’s pins…

DIY ROBOREMOTE REMOTE

#129 Building a DIY Robo remote

My prototype using a LAN cable breakout enclosure made it small and nifty.

A few years ago while using many wireless systems on a large remote property I had the problem of testing the signals in varies areas before installing my hardware like: Roboguards or my own custom devices that have the ability to communicate with the RoboGuard ecosystem.

Front view of the PCB. It fits perfectly into an ABS enclosure.

So I decided to create a dedicated remote that uses the ASK protocol used with these devices. This makes my life so much easier because it allows me to test multiple requirements at once.

I’m able to test:

  • Signal strength in the area
  • 433 modules I want to use
  • Antennas I want to use
  • The transmission logic I want to use
  • Different ASK protocols

All this with a wireless, rechargeable and easily customizable package. At the moment this is not a commercial product however I have many other devices that work with the Roboguard ecosystem that have commercial applications.

Back view of the PCB. This was made around the ATtiny212 MCU and the SYN1115 transmitter.

DIY ENEGIZER

#128 making a simple energizer

Since I’ve been living in a rural area for the past few years I’ve had to come up with some affordable solutions to problems unique to my situation. One of these problems is keeping animals out of certain areas with methods that wont cause permanent harm but will definitely be effective. So the logical solution was to use electricity in the form of electro shocks. I searched for commercial solutions and found a few but they were a bit overkill/overpriced and of course not very hacker friendly… so I decided to make my own which I can always scale up with microcontrollers/relays/monitoring and all those nice to have features but for this one I wanted it to be plain old dumb without any programming required.

So I did my research and came up with a suitable schematic found the correct parts and settled on the good old 555 timer. Designed a very small PCB and got it manufactured a voila the idea became a reality and after a few tests it works perfectly fine.

Now the shock is created by the collapsing fields of the ignition coil I used for the project. I got the most basic simple coil that is driven by a suitable N-FET at a frequency and strength that I can fine adjust via a potentiometer on the PCB. The whole system runs on a 12V battery and consumes very little current.

I took inspiration for this device and modified and created my own flavour. Like everything in life no one can do everything by themselves so I would like to credit the source which got me started here.

With that being said I had a lot of fun making this device and it’s been working well I was also able to adjust the voltage to a very humane jolt so smaller animals know not to enter the area but also don’t get fatally hurt.

CUSTOM UPDI PCB

#124 Making a Custom Programmer

Fake CH340N IC on the left real on the right

While looking for a good example PCB project I decided upon a simple UPDI programmer PCB for the well known new ATtiny ICs.
I had a few prerequisites I wanted to satisfy for the project.

  • Design must work but also have room for improvement
  • small SMD PCB design
  • BOM list and prices
  • simple schematic using KiCad
  • 1206 component size sop-8 IC size
  • USB-C
  • 2 sided PCB
  • all standard sizes for PCB manufacture
  • PCB panel example
Front
Back

I wanted the project to cover many of the basic and intermediate PCB manufacturing practices of course the IC is not very sophisticated and there is no impedance matching or equal length traces etc. However it shows how designing, quick and affordable manufacturing can be achieved in South Africa. Designing for manufacturing, thinking of the capabilities of the manufacturer and keeping best practices in mind at least to the best of my knowledge at that specific time.

In the project I keep things as standard as I can using metric measurements and easy milling panel design for the panel (no fancy curved edges or designs) although many interesting looking designs can be made surprisingly simple, it takes experience plus CAD artistic intuition. That being said I wanted this to be a simple and practical example I could use for teaching references later.

Getting to the component choices for a small UPDI programmer I chose the CH340N IC. It needs very little external components and has an internal crystal. Small and lightweight and perfect for my UPDI project. It is missing other pins like the reset pin but in my case this was not an issue. Always double check your IC datasheets and capabilities.

KiCad modal front
KiCad modal back

On that note I did receive some FAKE CH340N ICs and I tested them. They only worked on lower baud rates and adding LED indicator resistors to the TX and RX made them unstable. Unfortunately in this day and age fake ICs are very common you need to recognize them and weigh the balance between using them or not. Sometimes there’s a “good fake” so as a maker I may use this test projects or make throwaway projects but the characteristics of the IC are now different so any calculations are incorrect… so it’s a balancing act that no-one can escape. For production always use IC’s from the original manufacturer the stores are easily found online and it’s worth it in the end.

Simple schematic

All other components are very basic 1206 (easy to solder) SMD capacitors, resistors, TX/RX LEDs, power indication led, a diode 16-pin USB-c connector with 5k1 sense resistors keep the PCB copper balanced on both sides also saves etching chemicals for the manufacturer I also added some example fiducials and the copper stops 1mm from the edge of the PCB creating a small protection layer all around.

Since there is a USB-C connector I chose not to include any ESD or fuse but I would add these components to a commercial variant.

Also this v1.0 has the TX/RX LEDs on the wrong indication pins. I would change them to the USB side instead.

Overall I think it’s a good introductory example showing a simple design including some errors and fixes.

Panel front
Panel back
KiCad panel back

IO EXPANDERS

#123 Looking at some common IO expanders

What to do when you are using n 8-pin MCU to to the job of a 16pin ore even a 20pin MCU? Well it depends.. but if all you are doing is using IO’s to switch for example relays or similar tasks where the amount of IO’s is important, and not the capabilities of the IOs then you may be able so save costs by purchasing an IO expander instead of an abundantly pin gifted MCU.

These come in all shapes and package sizes and don’t increase the project size too much. Also I tend to use I2C much more then SPI but IO expanders can support both these packages.

Examples like the PCF8574, MCP23017, 74LVC595 and the MCP23S17 which uses SPI if you want to use that instead. The expanders support interrupts but always double check the datasheet before purchasing!

Something similar but not an expander more of a multiplexer IC is the MC14051B Analog Multiplexer/Demultiplexer this is quite common and affordable at least in South Africa and allows analogue pins to be expanded instead of digital.

Some Links to shops in South Africa that sell these expanders:

PCF8574

MCP23017

74LVC595

  • not common in South Africa

MCP23S17

328P PORT MANIPULATION

#122 ATMEGA 328P Port Manipulation

Port manipulation was not important to me when I started working with microcontrollers, in fact I didn’t even know it existed and never felt the need for it especially after programming mostly in java script and PHP using functions like digitalread(pin); or digitalwrite(pin); etc. was second nature and speed or efficiency considerations were not really necessary or thought about that much.

Then after intermittently playing around with embedded ICs I got serious during the corruption virus of 2019 during lockdowns and other dilemmas while a lot of corrupt and diabolical cronies enriched themselves. I had a lot of time to focus on a few different things. There was no way I was going to let the circumstances get to me I made sure I was achieving at least one big goal each year and not get bogged down.

I took a look at the IC market and even though there was a chip shortage there were some IC’s available. This mad me try and get into efficient code and cost per IC. I came to the conclusion that I could get hold of IC’s with low memory + flash and very affordable prices. However in order to use them I would have to learn to use port manipulation, macros and interrupts in very efficient ways to the best of my ability at the time.

Now I needed to find new and comprehensive writeups of the principal and so I found the SpenceKonde
megaTinyCore
for the new at the time tinyAVR 0/1/2-series IC’s. The core has a lot explained over the years and was very helpful and easy enough to understand but took a bit of time and real world practical implementations which made learning way more fun and easy. I always need to do practical with theory when it comes to learning I find it very hard to picture learning anything without using it practically.

Now this is about port manipulation on the 328P and I’ll get into the actual implementation now without further ado.

The ATMEGA 328P has 3 ports namely B, C, D with B (digital pin 8 to 13), C (Analog input pins) and D (digital pins 0 to 7).

For the basics you only need to understand 3 types of registers you will be manipulating.

For example:

Port B
PORTBMaps to Arduino digital pins 0 to 7 Data Register – read/write
DDRBThe Port B Data Direction Register – read/write
PINBThe Port B Input Pins Register – read only

Port C
PORTCMaps to Arduino digital pins 8 to 7 Data Register – read/write
DDRC The Port C Data Direction Register – read/write
PINCThe Port C Input Pins Register – read only

Port D
PORTDMaps to Arduino digital pins 14 to 19 Data Register – read/write
DDRDThe Port D Data Direction Register – read/write
PINDThe Port D Input Pins Register – read only

So an example using DDRD (Data Direction Register) to set input and output pins:

Another example is to set digital pins 7,5,3 high:

Now you can do port manipulation with a bit shift instead of binary or hex. this makes things a bit more readable… excuse the pun. 🙂

For example to set the input or output of a single pin you could use:

Example using hexadecimal:

Now to initiate a pullup on a single pin you could use:

Example using hexadecimal:

Example using binary:

Looking at how to read a pin you can use the Input Pins Register PINB:

it is also possible to toggle a pin and there’s different ways. Some are faster then others:

You can also easily write to a pin low or high:

There’s also an atomic operation to writing low or high:

So now that we understand the basics we can get into making life easy by creating macros

Below are 4 functions made easy to iterate over all the pins in each port B, C, D

set_PIN_HIGH(pin);
set_PIN_LOW(pin);
read_PIN_STATE(pin);
toggle_PIN_STATE(pin);

This makes it easy to call the function without having to define the port each time and it’s still fast.

See the example below:

Links:

328P PIN CHANGE INTERRUPTS

#120 ATMEGA 328P Pin Change Interrupts

The 328P has 3 ports B, C, D you will need to know the basics of how they work to before reading this.

The 328P only has 2x external interrupts however there are also 23x pin change interrupts and I will be focusing on the latter for now.

INTx (external interrupts) can report events under four situations: low, any, falling, rising. PCINTx (pin change interrupts) can report events on only one situation: any, which is basically a change in the pin so we can categorise the 23x as change interrupts only.

Using these pin change interrupts are surprisingly easy but require a few steps. However once they are configured code size and complexity can be reduced significantly. Also never forget you paid for the IC and it’s hardware peripherals.. so USE THEM.

You can run a loop checking button states with multiple variables including timing and state variables etc. or…. you can run a similar reduced loop with the use of the pin change interrupts making your life so much easier while not compromising much resources.

So to get started you need to follow 3 steps:

  1. Turn the pin change interrupts on
  2. Choose the pins to interrupt
  3. Use the ISR for the chosen pins

STEP 1:

To turn on the pin change interrupts you will need to use the PCICR register.

Writing 1 to bit 0 will turn on the portB (PCINT0 – PCINT7)
Writing 1 to bit 1 will turn on the portC (PCINT8 – PCINT14)
Writing 1 to bit 2 will turn on the portD (PCINT16 – PCINT23)
From bit 3 onwards (from right to left) bits are ignored.

STEP 2:

Now you need to choose which pins you want to interrupt.
You will need to use a mask and the 328P has 3 masks: PCMSK0, PCMSK1, and PCMSK2
These masks are set in the same way as the PCICR register was set.

STEP 3:

Now you need to use the correct ISR for the chosen pins.
make sure to keep the ISR as fast as possible and use as little code as possible in the ISR.
Also if you have any variables in the ISR make sure to make them volatile. This tells the compiler that it could change at any time and to reload it each time instead of optimizing it.

Full Super Simple Example:

Links:

DIFFERENT PROGRAMMERS

#118 A look at different types of programmers

Different programmers for different IC’s some work with others.. some don’t

Over the years I have used different programmers for PIC,AVR,ST,ESP and WCH microcontrollers from simple FTDI TX RX programming to more advanced PICKit 5 dedicated programmers.

All the different types have their pros and cons but by far the most used by me is the cheap FTDI and serial TTL types for example programmers using the CH340, PL2303 and FT232 IC’s

Though the PL2303 is outdated there’s still many floating around and certain applications require the IC like when interfacing with old radios.

PICKit3, PICKit3.5 and the new PICKit5

With that being said you may ask why do we need a dedicated programmer? Well it depends…

Using the cheap common options I just mentioned above is good enough for a hobbyist but when you design a product you want something that’s is reliable common and has a guaranteed life span with support for the foreseeable future so that you will always have parts available for projects and the programmer.

USBasp AVR Programmer using SPI
STM Programmer


WCH-LinkE programmer can also program STM IC’s

Another big point is uniformity, dedicated programmers will usually be using parts with certain thresholds and voltages + current etc. all that data will be kept constant and accurate while a cheap programmer will most likely have a huge threshold..

A very important point is the ISP + debugging. A dedicated programmer will be able to do programming and debugging easily with a few pins. While a cheap programmer will require more pins and many times 2x programmers… 1 for debugging and 1 for programming.

BUS PIRATE can program with SPI
Arduino Nano with built in CH340 IC for serial programming
A n old DIY programmer of mine based on the CH340N IC

Dedicated programmers also have full support by the IC company as long as you have an original also they offer some really useful features like the PicKit5’s blue tooth option and stand alone programming or changing of source binaries on a phone.

All you need is the programmer and a phone is optional if you need to change things like binaries but really you can give a pickit5 to any technician and they can easily update supported IC’s without needing to mess around on a desktop/laptop computer. This is a very useful feature.

Now there also are EEPROM programmers and true universal programmers that can do EEPROMS and MCU’s like the old TL866II Plus which has a list here of all the supported IC’s. These programmers work well and allow easy access for single IC’s some can also read and write when an IC is in circuit but others require de-soldering. These programmers are usually quite large with Zif sockets.

EEPROM Programmer CH341B
Universal programmer the TL866II Plus

Now I just mentioned a few examples there is much more to talk about but I’m not going to be writing books here…

DIY UPDI PROGRAMMER

#117 A DIY UPDI plug and play board

Making fast and crude but reliable programmers

When getting into the new ATtiny series (tinyAVR-0 tinyAVR-1 tinyAVR-2 IC’s) of microcontrollers a few years ago I noticed how easy it had become to program them with only a few extra components.

I started out with just a 4.7k resistor and a cheap CH340 programmer. Then 3 wire hook-ups later I could easily program my IC’s. The only downside was that I had to sacrifice the UPDI pin to the dedicated Pin gods.. so I couldn’t use that pin unless I wanted to make my life more difficult.

Well this was okey for me and ever since I always have the UPDI pin open only for programming. So all my designs incorporate this principal. If I really need more pins I would use an affordable IO expander IC.

Now with that being said it’s all good and well programming with a mini rats nest… but I wanted to create a simple plug and play DIY programmer with commonly available parts and plug and play compatibility.

So I came up with a small circuit that’s easy to build on stripboard. I created a few versions over the years. Since I was the only one using this contraption I didn’t think of creating a professionally made PCB but that will come in future..

Front of the stripboard
Back of the stripboard

How do I use this?

Basically I solder the SMD package ATtiny to a suitable breakout PCB then I plug the ATtiny breakout PCB into my programmers female headers making sure the orientation is correct and presto all I need to do is upload my firmware. Then I can just remove the PCB and Plug it into my project

Simple and to the point… plus it’s been working for years.