Breaking out of the Chip Shortage – Attempt #3

The ATMEGA4808 provides a very attractive solution to replace the trusted ATMEGA328 or standard Arduino UNO /NANO.

These chips are slightly more difficult to get hold of than the ATTiny chips, and cost a little bit more ( about the same as what the ATMEGA328 used to cost before the mess with COVID-19 and resulting supply chain shortages + inflated costs), but they offer all of the functions of the ATMEGA328, with a few other enhancements that will definitely be very useful.

The extras include:
– Hardware interrupts on ALL GPIO pins; This is way more than the standard 2 interrupts on the ATMEGA328 ( We are not talking about the Pin Change interrupts, but real hardware interrupts, that can be triggered on RISING, FALLING, CHANGE, HIGH and LOW state of each pin

– Up to eight (8) PWM pins as opposed to the 6 on the Arduino UNO
– Up to eleven Analog inputs
– An Analog Comparator module
– Configurable Custom Logic (CCL)
– EVENT System (EVSYS)
– Peripheral pin swapping

It is also worth mentioning that these chips have accurate internal oscillators, capable of clocking the chip at up to 20MHz, further reducing the number of external components required to get a minimal configuration running…

Order your own version of this development board

The Prototype PCB

While I have had a Nano Every “Clone” lying in a drawer for quite a while now, I did not really pay a lot of attention to it. That was, until I needed an ATMEGA328 for a project, and could not find any for sale, or at least at a price that I was willing to pay for it… That incident was the spark that ignited this entire exercise, to find a suitable replacement…

The Nano Every “Clone” in my possession, used the ATMEGA 4808 chip and turned out to be the Thinary Nano 4808. I had quite a lot of problems with the provided core, as well as getting peripherals like I2c and SPI to work. This led to further investigations, and finally, I decided on building my own and to use the MCUdude/MegaCoreX Arduino Core to program it.

This led to the following prototype:

ATMEGA4808 Development board prototype

I did not bother with too much detail on the silk screen here, as the goal was to get a working board, test it, and then later, design a refined PCB.

What is important to note is that the board runs at 5v, but provides a single 3.3v output as well. Logic levels on the GPIO is also 5v. Use level converters for 3.3v only addons…

The MEGA4808 is programmed via UPDI, so we have a UPDI Header on the right-hand side of the PCB. It is also possible to use the Optiboot Bootloader, to flash the board in true Arduino style through a USB connection to a computer.

A CH340N USB-to-Serial converter chip is used instead of the CH340G that is common on the UNO clones. The CH340N provides only the USB D+ D- signals, as well as Rx, TX and RTS. RTS is being used to auto-reset the chip after flashing…

In comparison to the CH340G, which also required a crystal oscillator, but provides all the modem control signals, which, are usually not even broken out, the CH340N made much more sense.

PCB Bottom.

A power LED, as well as an indicator LED on pin 7 was also included.

Assembled PCB, Top Layer.

Assembly and Soldering

I normally assemble all my projects by hand and reflow-solder them with a hot plate. for this project, I decided to do things a bit differently, which ended up being a bit awkward, but still resulted in a perfectly useable PBC.

As you will know by now, I only do written articles, as I don’t consider myself ready for the Youtube and video thing, as well as because I believe a well-written article, with detailed pictures, is easier to understand than a video…

Well, today, we will have both… This article, with its writeups and pictures, as well as a short assembly and soldering video, with no sound, sped up 5x, as I did not want to bore anyone with a 25-minute silent video…

Let us begin then…

PCB and Stencil

We start with a blank PCB and the laser-cut stainless steel stencil that I got from PCBWay.

Solder paste applied

Solder paste is then applied with the stencil and a scraper, and afterwards, the stencil is removed… The PCB is now ready for component placement…

From here on, we will go to the video footage… showing component placement, with some awkwardness due to the camera being in the way, as well as hot-air soldering, with the same awkwardness, as I was forced to use my right hand ( I am left-handed), not to block the camera view…

Begin quite new to the video thing, I have also not quite figured out the editing software, so the video is in native resolution… not zoomed…

After assembly

After assembly, I checked for solder bridges and was quite happy that there were none. This also meant that the board worked perfectly the first time around… as it should…

Order your own version of this development board

Manufacturing

I choose PCBWay for my PCB manufacturing. Why? What makes them different from the rest?

PCBWay‘s business goal is to be the most professional PCB manufacturer for prototyping and low-volume production work in the world. With more than a decade in the business, they are committed to meeting the needs of their customers from different industries in terms of quality, delivery, cost-effectiveness and any other demanding requests. As one of the most experienced PCB manufacturers and SMT Assemblers in China, they pride themselves to be our (the Makers) best business partners, as well as good friends in every aspect of our PCB manufacturing needs. They strive to make our R&D work easy and hassle-free.

How do they do that?

PCBWay is NOT a broker. That means that they do all manufacturing and assembly themselves, cutting out all the middlemen, and saving us money.

PCBWay’s online quoting system gives a very detailed and accurate picture of all costs upfront, including components and assembly costs. This saves a lot of time and hassle.

PCBWay gives you one-on-one customer support, that answers you in 5 minutes ( from the Website chat ) , or by email within a few hours ( from your personal account manager). Issues are really resolved very quickly, not that there are many anyway, but, as we are all human, it is nice to know that when a gremlin rears its head, you have someone to talk to that will do his/her best to resolve your issue as soon as possible.

Find out more here

Picture Gallery

Breaking out of the Chip Shortage – Attempt #2

The ATTiny1616 is a step up from the ATTiny202, having more GPIO, flash and RAM. This makes it ideal for bigger, but still medium size projects that do not need all the power of the traditional Arduino.

In Part 1 of this series, I took a quick look at the ATTiny202 MCU from Microchip. Having only 5 useable GPIO, with limited Flash and Ram, that little chip was still quite useful for some of those very small projects, where we did not really need a lot of peripherals and GPIO pins.

Today, we shall take a step up, and take look at a slightly bigger MCU, the ATTiny1616, this time with up to 17 GPIO pins, more flash and memory, and still quite easy and cheap to get hold of. (Current Prices are in the range of about $1USD to $2USD, depending on where you buy and how many you buy).

As I wanted to give myself a bit of a challenge with this project, I decided on using a QFN package this time, which, being extremely tiny, only 3mmx3mm, will give most Makers a pleasant challenge to solder correctly. ( I am planning a SOIC 20 version, but with a bit more external hardware onboard)

MakerIoT2020 ATTiny1616 Minimal Breadboard-friendly breakout

The ATTiny 1616 is part of the tinyAVR-1 series, which includes the 1614,1616, and 1617, and they have the following features ( copied from the datasheet link above)

The ATtiny1614/1616/1617 are members of the tinyAVR® 1-series of microcontrollers, using the AVR® processor with hardware multiplier, running at up to 20 MHz, with 16 KB Flash, 2 KB of SRAM, and 256 bytes of EEPROM in a 14-,20- and 24-pin package. The tinyAVR® 1-series uses the latest technologies with a flexible, low-power architecture, including Event System, accurate analog features, and Core Independent Peripherals (CIPs). Capacitive touch interfaces with Driven Shield+ and Boost Mode technologies are supported with the integrated Peripheral Touch Controller (PTC).

ATTiny 1616 Breakout – Bottom view

The PCB – Minimal working configuration – with a few extras

The PCB break-out all 18 of the GPIO pins, while it is only recommended to use 17 of them, unless, like in the case of the ATTiny202, you have access to an HV UPDI programmer. It also becomes possible, although still being quite tedious and awkward, to use the OptiBoot Bootloader on this chip, although it is still not quite recommended. Just using a UPDI programmer, with a separate USB-to-Serial adapter on another port is still definitely the easiest.

The Board contains an LED, on PIN_PA4, Arduino Pin 16, as well as onboard I2C pull-up resistors, selectable via a jumper. It is important to note that the current version DOES NOT contain a voltage regulator on the PCB. It is up to you to provide a regulated voltage source, in the range of 1.8v to 5.5v DC

It is recommended to clock the Chip at 16MHz when running at 5v ( 20Mhz is possible, But I did not bother to test that yet)
8Mhz when running at 3.3v
0-5Mhz when running at 1.8v

See the Datasheet, as well as the megaTinyCore documentation for exact details on this.

Commonly used peripherals, by myself, are listed on the back of the PCB for easy reference.

Order your own version here.

Programming the board

Programming is possible with Arduino IDE (and platformIO, ( I didn’t test that, as I find VS-Code tedious to use ), as well as MPLab from Microchip.
For the Arduino IDE, you have to install the megaTinyCore Arduino Core, as already mentioned above. ( This also apparently works for PlatformIO)

Full instructions, as well as some very useful other tips and information, is available in the core documentation, so do put in the effort to actually read the documentation. You won’t be sorry that you did.

The Schematic

Schematic

Design and Assembly

PCB layout

The board is designed as a double-layer PCB, with ground planes on both sides.

Due to the MCU package having a QFN footprint, using a proper SMD stencil is strongly recommended.

SMD Stencil – Make things a bit easier.

Hot-Air or a hotplate will also be quite useful to ensure success with this project. Passive components can be hand soldered though.

Manufacturing

I choose PCBWay for my PCB manufacturing. Why? What makes them different from the rest?

PCBWay‘s business goal is to be the most professional PCB manufacturer for prototyping and low-volume production work in the world. With more than a decade in the business, they are committed to meeting the needs of their customers from different industries in terms of quality, delivery, cost-effectiveness and any other demanding requests. As one of the most experienced PCB manufacturers and SMT Assemblers in China, they pride themselves to be our (the Makers) best business partners, as well as good friends in every aspect of our PCB manufacturing needs. They strive to make our R&D work easy and hassle-free.

How do they do that?

PCBWay is NOT a broker. That means that they do all manufacturing and assembly themselves, cutting out all the middlemen, and saving us money.

PCBWay’s online quoting system gives a very detailed and accurate picture of all costs upfront, including components and assembly costs. This saves a lot of time and hassle.

PCBWay gives you one-on-one customer support, that answers you in 5 minutes ( from the Website chat ) , or by email within a few hours ( from your personal account manager). Issues are really resolved very quickly, not that there are many anyway, but, as we are all human, it is nice to know that when a gremlin rears its head, you have someone to talk to that will do his/her best to resolve your issue as soon as possible.

Find out more here

Picture Gallery

Get Started with the ATMegaTiny202

As I have hinted in my recent two posts about UPDI programmers, I am currently looking for a solution to replace the ATMEGA328P chip used in standard Arduino devices, like the UNO and NANO.

The global chip shortage seems to be still hitting hard, with these devices (Arduino UNO, NANO), and even bare chips being quite hard to get hold of, and when you do, they are quite more expensive than they used to be.

This sent me on a new journey, to find a new chip, that is easy to use, inexpensive, and easy to get hold of. I have found 3 of these chips, starting today with the ATMEGATiny202,

ATMEGATiny 202



The ATtiny202 is a microcontroller using the 8-bit AVR® processor with a hardware multiplier, running up to 20 MHz and 2 KB Flash, 128B SRAM, and 64 bytes of EEPROM in an 8-pin package. The series uses the latest technologies from Microchip with a flexible and low-power architecture, including Event System and SleepWalking, accurate analog features and advanced peripherals.

With only 8 pins, of which we can practically use only 5 ( 6 if you have an HV UPDI programmer ). This makes it a desirable solution for small projects, with its current price of about 0.59 USD per chip ( SOIC8 PACKAGE, Element14 ) , not breaking the bank either. Not needing an external oscillator, and requiring only a single 100nf bypass capacitor, (not counting the UPDI resistor) it can indeed be a very very cheap way to get a project done… Providing of course that you don’t need a lot of Program memory or RAM, and are not trying to do too many super fancy or complicated things.

ATMegaTiny202 Minimal Breakout, on Breadboard with MakerIoT2020 Multipurpose Uart/UPDI Programmer

The wide operating voltage of 1.8v right up to 5.5v also makes it quite flexible.

My initial prototype

Getting started with a new chip is also a bit of an issue, as there are many new things to learn, recommended supporting components, and also firmware and cores that need to be installed. I have decided to build a quick breadboard-capable PCB, with all 8 pins broken out in a single row, feel free to change the straight header pins to a 90-degree version at your convenience, it takes up even less space that way.

The PCB contains only the bare minimum required components for the chip to function, but I also added onboard I2C pullup resistors, with a jumper to select them. ( Most I2C modules usually have these already, but as I build most of my own breakouts myself, I decided to include these).

A single LED brightens things up a bit, connected to pin PA3, making it possible to run a blink sketch…

The rest of the components include a 100nf bypass capacitor and the very important 470ohm UPDI resistor.

ATTiny202 Breakout-Blank PCB-Top
PCB Top view, unpopulated
PCB Bottom, unpopulated

Programming the board

I use the Arduino IDE quite a lot, and also assume that most makers and hobbyists out there will do the same. Luckily we have access to a special Arduino core, the megaTinyCore, that provides us with all we need to program this tiny little chip, provided of course that you have a UPDI programmer.

See the link above for installation instructions, as well as detailed documentation. Replicating all of that here will be an unnecessary task, as the author of the core, SpenceKonde, has already done an excellent job.

One very important thing to note on this board is that there is NO RESET PIN.
You have to manually cycle power to it, but, I have found that initiating a UPDI upload to a running chip works every time, and makes it unnecessary…

The reason for the lack of a reset pin lies in the fact that the reset is shared with the UPDI pin, and enabling it, will rob you of the UPDI functionality UNLESS you have an HV UPDI programmer, which at this time seems to be hard to find/expensive item ( Hope to build my own soon). Once again, see the above link to the core documentation for the full information on the reset pin issue…

I can not stress enough how important it is to sit down and READ the core documentation, with attention, before doing anything with this chip and core. you will learn a lot, about the chip, new features, possible problems, and how to avoid them, and also some customised GPIO functions etc…

Schematic

ATTiny202 Minimal Schematic

Manufacturing

PCB Layout

The PCB is a double-layer PCB, with the signal traces on the top layer, power traces, and the ground-plane, on the bottom layer. the Dimensions are 26.035mm x 18.669m. All SMD components are 0805. This board does not need a stencil for assembly and can be hand or hot-air soldered in a few minutes with no problems.

As many of my existing readers will know by now, I choose PCBWay for my PCB manufacturing. Why? What makes them different from the rest?

PCBWay‘s business goal is to be the most professional PCB manufacturer for prototyping and low-volume production work in the world. With more than a decade in the business, they are committed to meeting the needs of their customers from different industries in terms of quality, delivery, cost-effectiveness and any other demanding requests. As one of the most experienced PCB manufacturers and SMT Assemblers in China, they pride themselves to be our (the Makers) best business partners, as well as good friends in every aspect of our PCB manufacturing needs. They strive to make our R&D work easy and hassle-free.

How do they do that?

PCBWay is NOT a broker. That means that they do all manufacturing and assembly themselves, cutting out all the middlemen, and saving us money.

PCBWay’s online quoting system gives a very detailed and accurate picture of all costs upfront, including components and assembly costs. This saves a lot of time and hassle.

PCBWay gives you one-on-one customer support, that answers you in 5 minutes ( from the Website chat ) , or by email within a few hours ( from your personal account manager). Issues are really resolved very quickly, not that there are many anyway, but, as we are all human, it is nice to know that when a gremlin rears its head, you have someone to talk to that will do his/her best to resolve your issue as soon as possible.

Find out more here

Picture Gallery

Multipurpose USB UART Module

USB-to-Serial converters are some of the most used modules on my bench. I have quite a few of them, most of them are the cheap online type that can be had for a few dollars.

As part of my new project, where I am seriously looking for an alternative chip to replace the ATMEGA328, which has become almost impossible to get, and super expensive when you do get it, I needed to get hold of a UPDI programmer.

There are many available online, from cheap to more expensive, but I wanted to build my own, as it did not seem too difficult to do.

As another part of my daily tasks, I also use a lot of ESP-type chips, which have a particular procedure to upload code via an external serial adapter.

The idea was thus to design a USB UART module that has multiple purposes, as well as being easy and cheap to assemble.

  • Be able to program ATMEGA328 Chips via Serial
  • Be able to be used as a standard USB-to-UART adapter
  • Be a UPDI programmer
  • Have a selectable target voltage between 3.3v and 5v
  • Have all modem signals (RTS, CTS, DSR, DTR) broken out.
  • Be able to auto-flash and reset an ESP32 or ESP8266 device, or similar
Breadboard Prototype Multipurpose USB-to-UART/UPDI Programmer

What is on the PCB?

The PCB is powered by the PC USB port. The target device voltage is selectable between 3.3v and 5v. The device mode can be changed from UART to UPDI mode with a jumper. An additional header specifically for ESP32/ESP8266 devices is provided, giving access to the FLASH and reset signals for the ESP device.

The USB to serial conversion is taken care of by a CH340G Chip, which provides all the relevant modem signals as well.

All signals, with the exception of the “RING” signal, are broken out onto the main header.

Note that there are NO status or POWER LEDs on the board. This was on purpose, as these sometimes interfere with the UPDI programming mode.

Prototype PCB – Assembled

PCB – Top
PCB – Bottom

Connecting to different devices

ESP32 or ESP8266 Devices

When in UART mode, the device can be used to upload code to an ESP32/ESP8266 automatically, similar to a standard dev board, without requiring you to press and flash and reset buttons.

This is achieved by connecting the device as follows:

UART MODULE SET to 3v
UART VCC to ESP 3v
UART GND to ESP GND
UART RX to ESP TX
UART TX to ESP RX

(Connections for Auto Upload/Reset)
UART RST ( on ESP-Flash Header) to ESP RST
UART GPIO0 ( on ESP-Flash Header) to ESP GPIO0

It will now be possible to flash and auto reset the connected ESP device from the Arduino IDE, and possibly others as well…

Arduino (Atmega 328P)

In the current version of the prototype, you have to connect it as follows:

UART Target voltage set to 3v or 5v depending on what type of board you are uploading

UART Tx to Arduino Rx
UART Rx to Arduino Tx
UART VCC to Arduino 3v or 5v ( depending on the target voltage required by the board you are flashing)
UART GND to Arduino GND

To allow for auto flash/reset on the Arduino, a 100nf capacitor is required between the UART DTR line and the Arduino Reset pin. This capacitor has NOT yet been fitted onto the PCB, as I usually use ICSP to upload these. Future versions of the PCB shall have this included.

ATMEGA4808/4809 and or ATTiny with UPDI Interface

This device is currently an LV-only UPDI programmer. Connections are as follows:

Set Target voltage on J1 of the UART/UPDI programmer.
Set The Device mode on J2 to UPDI mode

Connect VCC and GND from the Programmer to the target chip/board
Connect Programmer UPDI pin( shared with RxD) to Target UPDI pin.

General use UART for use as Serial monitor/Terminal

Set target voltage on J1
Set device mode to UART on J2

Connect VCC, GND from UART to the target device,
UART Tx to Target Rx
Uart Rx to Target Tx

Optionally connect required modem signals, RTS, CTS, DTR, and DSR as needed

Manufacturing

The PCB for this project has been manufactured at PCBWay.
Please consider supporting them if you would like your own copy of this PCB, or if you have any PCB of your own that you need to have manufactured.

PCBWay

Some Links to things used in the project

MakerIoT SMD Prototyping Breadboard
Order this PCB from PCBWay

8Ch NMOS Breakout Module

As a companion module to my recently published 8Ch PMOD breakout board,
I decided to do a similar PCB, but with NMOS devices instead. This opens up more possibilities for proper testing and prototyping, as PMOS and NMOS devices has different use applications, and most importantly, can sometimes even be combined for a particular purpose, like an H-Bridge motor driver, for example.

8Ch NMOS Breakout

What is on the PCB?

As NMOS devices function quite differently from their PMOS counterparts, it did not make sense to reuse the PMOS board, and just change the devices… although some people may be tempted to think you could…

The N Channel Mosfet basically “works in mirrored mode” from a P Channel one, and is used to do so-called ” LOW Side switching” which means that your load connects to the positive power rail, and then to the DRAIN pin of the MOSFET, with the source being connected to ground… ( It can sometimes also be used the other way around… but lets not go there now….

The current prototype PCB contains 8 BSS138 NMOS Mosfets, in my case, with is capable of about 800mA of current… All source pins are internally connected to ground. This forces you to use this module as a low side switch…

Two 10-way 2.54mm headers are provided, with a ground pin on Pin 1 and 10 of each of these.

The Drain pins of each NMOS device is available on the top header, labeled D1 through D8, and the Gate pins of each respective NMOS device is available on the bottom header, labelled G1 through G8.

Each gate has a pull-down resistor to ground, to keep it from flapping around, as well as a gate resistor. In my case, I selected to use a 10k pulldown, and a 1k gate resistor, as that is sufficient for my general needs…

Each NMOS device also has a LED signal indicator, to assist in visual confirmation of a specific channel’s state.

PCB Top Side

The Schematic

Schematic

Using the breakout

The module is very easy to use, and as briefly mentioned above, you are only required to connect one side of your load to the positive supply rail, and the other side to the drain pin of your choice.

Connect the ground pins of the module to your ground rail.

The Gate pin, with a corresponding number to the drain you have selected, can now be connected to your GPIO of choice on a microcontroller.

Drive the pin High to switch on the load, drive it log to switch off. Easy.

Please note: While the NMOS devices used on the board can handle quite a lot of current, (800mA in the case of the BSS138), it is not recommended to try and pull too much current through a single channel. The PCB traces can safely handle about a maximum of 300 to 400mA per channel.

PCB Bottom

Manufacturing

The PCB for this project has been manufactured at PCBWay.
Please consider supporting them if you would like your own copy of this PCB, or if you have any PCB of your own that you need to have manufactured.

PCBWay

Example code for using the breakout (Arduino)

// Example code for 8Ch NMOS breakout
int Gate1 9;
int Gate2 10;

void setup() {
  // drive the two gate pins low to ensure NMOS devices
  // are in a positively known state at startup
  digitalWrite(Gate1,LOW);
  digitalWrite(Gate2,LOW);
  // Set gpio to output mode
  pinMode(Gate1,OUTPUT);
  pinMode(Gate2,OUTPUT);

}

void loop() {
  // Toggle the two channels in an alternating pattern
  digitalWrite(Gate1,!digitalRead(Gate1));
  digitalWrite(Gate2,!digitalRead(Gate1));
  delay(1000);  

}

8-Ch P-Mos Breakout

While prototyping our projects, we Makers often need to interface devices with a higher current draw, like motors, or RGB lights, to our microcontrollers. These typically are unsuitable for connecting directly to an Arduino, ESP32 or Raspberry Pi’s GPIO pins. This is usually the time when we start grabbing transistors or MOSFETs.

While I normally keep a few leaded transistors and MOSFETs in the lab, These are not always convenient to use, as they may be in big packages or have the wrong specifications for the task that we are trying to perform.

SMD versions are more common in my lab, but they come with the problem of being small, and also completely unfriendly to the breadboard environment.


I have thus been playing with an idea to make a series of dedicated breakout boards for just this purpose. Having an easy way to test a specific MOSFET for a design, and having more than one of them handy, without all the wiring issues, and using the bare minimum of those DuPont wires!

I came up with the following prototype, which, while not completely optimised yet, already makes things easier. The breakout board provides 8 P-Channel Mosfets, with a single source connection, and individually broken-out Drain and Gate pins.

LED indicators on each channel provide a visual indication of the status of each P-Mos device, and the breakout can also be mounted directly into an enclosure if needed.

What is on the PCB?

Each channel comprises a P-Channel Mosfet, in this case, a SI2301, which has a suitably low gate voltage, a pullup resistor on the gate, to keep it from floating, a status-indicating LED and a current-limiting resistor for the LED.

No gate resistor was added, as this would change depending on the actual MOSFET, as well as the microcontroller that you use. The Gate pullup resistor can also be left unpopulated, in case you need to do something specific there.

Two rows of 10-way, 2.54 header pins are at the top and bottom of the PCB, to make using the breakout on a breadboard possible.

The Pinouts are as follows

H2 – Top V+ D1 D2 D3 D4 D5 D6 D7 D8 GND
with Dx corresponding to the Drain pin of each MOSFET. All the Source pins are internally connected together, as I assumed that I will use the same source voltage on each channel anyway.

H1 – Bottom V+ G1 G2 G3 G4 G5 G6 G7 G8 GND
with Gx corresponding to the gate pin of each MOSFET.

V+ and GND for each header is internally connected, to make it possible to supply V+ and Gnd on any of the two headers.

PCB Top Layer

The Schematic

Schematic

Using the Breakout

Using the breakout is straightforward. Connect a source voltage to either of the V+ pins and Ground to either of the GND pins. ( the ground is used internally for the status LEDs)

Connect your load, with the positive to a drain pin, let us say D1, and the load ground to your breadboard, or power supply ground. Connect the corresponding gate pin, in our case G1, to the microcontroller pin of your choice, through a suitable gate resistor, and pull it high at setup, to ensure that the MOSFET stays off. Pull low to activate as needed.

Please note that you should not try to switch excessively large currents through a single MOSFET Channel, as the PCB traces can realistically only handle approximately 300 to 400mA per channel.

Note 2: If you are driving an inductive load, it is considered good practice to add a flywheel diode on the load as well. This will protect the MOSFET from back EMF when the MOSFET is switched off.

PCB Back

Manufacturing

The PCB for this project has been manufactured at PCBWay.
Please consider supporting them if you would like your own copy of this PCB, or if you have any PCB of your own that you need to have manufactured.

PCBWay

Example code for using the breakout (Arduino)

// Declare Gate driving GPIO pins
int gate1 = 10; 
int gate2 = 11;


void setup() {
// Set the GPIO pins as outputs and drive them HIGH
// This keeps the channels switched "OFF"
  digitalWrite(gate1,HIGH);
  digitalWrite(gate2,HIGH);
  pinMode(gate1,OUTPUT);
  pinMode(gate2,OUTPUT);

// Writing to the GPIO's before setting their pin Mode,ensures that the
// GPIO's are in fact initiated in a know correct state.

  Serial.begin(115200);

}

void loop() {
// In the loop, we just toggle the GPIOs, thus
// alternatively switching the channels on or off
  digitalWrite(gate1,!digitalRead(gate1));
  digitalWrite(gate2,!digitalRead(gate1));
  delay(1000);
  }

Redesigning my MCP23017 breakout

In a previous post, I designed a breadboard-friendly MCP23017 breakout module. A few months have passed, and after using the module for a while, some issues came to light…

In this post, I will show you how I have fixed those issues, and then I can continue testing/using the new generation prototype, and hopefully, it can become the final revision of this project.

Old Versus New

Let us start by looking at the old and new PCB designs…

Old style MCP23017 Breakout – Top view
New style MCP23017 Breakout – Top view

There will not be a lot of obvious differences at first, but if we look closely, here are the changes:
– In the old version, due to the size of the SOIC28 footprint, I had to place the bypass capacitors, as well as I2C pullup resistors on the bottom layer of the PCB.

  • The new design, using the more readily available ( at least where I live) SSOP28 footprint, leaves enough space for these components on the top layer, thus resulting in a mostly single-layer layout, with only a few tracks on the bottom layer.
  • I2C pull-up resistors can now be controlled by a jumper, enabling or disabling them completely… This helps when adding a few devices to the I2C bus, and rather having the pull-up’s close to the MCU ( as is generally recommended anyway )
  • Other cosmetic changes involve the separation of the data ports (A and B) from the interrupts, reset, Vcc and ground pins. On initial testing of this on a breadboard, it makes using the device a bit easier, and access to the io pins faster. ( In my biased opinion anyway )
MCP23017 Breakout Module
MCP23017 Breakout – New version

Pinouts and connections

I have tried to make all the connections easy to find and use, with the IO ports ( A and B) on opposite sides of the breakout, Numbered A7 to A0 on the top, and B7 to B0 on the bottom.
VCC, GND, SCL and SDA are on a separate 4-way header pin, with the two interrupt pins (I-A and I-B) together with the reset (RST) pin on a 3-way header opposite the power and signal header..

Addressing pins are in the centre of the PCB, marked with a 2 1 0 ( for AD2, AD1, and AD0 respectively), Jumpers to the bottom ( towards port B) pull the pins to ground, where the opposite side will pull the address pins high.

To the right of that, another 3-way jumper enables or disables the I2C pull-resistors on the module, which in this case is set at 4k7.

Manufacturing

The PCB for this project has been manufactured at PCBWay.
Please consider supporting them if you would like your own copy of this PCB, or if you have any PCB of your own that you need to have manufactured.

PCBWay

Some More Pictures

PWM Controller with R/E

Last month I spent quite a lot of time on expansion modules for use with the ESP-12E I2C Base Card. While the system worked exceptionally well as a prototyping and firmware testing platform ( as originally intended ), I immediately saw that the physical size of everything ( base board, with the cards) would be a problem inside any enclosure, when used with a real-world project.

At the same time, I have an ongoing need to design and manufacture a device for a friend, that will have very limited space inside the enclosure due to other essential components.

I have thus decided to combine the functionality of two of the IO Expander cards into a more compact design, on a single PCB ( Which I plan to use to power and control an Air Assist blower on my desktop CNC/Laser cutter, as well as function as a next step prototype for my other project.

The PCB

Let us take a quick look at the PCB.

Starting from the top left, we have the Blower/Fan Header.
This supplies 12v DC to the Blower/Fan motor, as well as the PWM signal to control the speed. ( Level converted up from 5v DC to 12V, and then reduced to 3.3v ) This may seem strange.

Let me explain for some more clarity…
The PWM input on the Blower/Fan is internally pulled HIGH to 12v ( by the motor driver circuitry – I can not change that, as it is a commercial unit.) The datasheet however calls for a 0v to 3.3v PWM signal to control the speed.

There is also a further input from the fan, which is a pulsed speed indicator (Fan RPM). This signal is 5v.

Next to that header, is a UART Header, with Rx, Tx and DTR signals, with a ground. I do no longer add USB-to-UART chips to my designs because they are not used a lot, take up unnecessary space, and I tend to program with ICSP anyway.

On the right of that, (Red/Blue/Yellow Header) are 5v, Gnd and 6 Analog inputs(A0-A3, A6,A7) [A4 and A5 being used for I2C]

The ICSP programming header is below that,
with a jumper to select PCF8574 interrupt on Pin D2 or not

This is followed by 6 GPIO (P2-P7) from the IO Expander, and
additional GPIO (D10, D11, D12, D13) , as well as (D7,D8,D9) [To be used with a Rotary Encoder]

Another 6way Ground header, as well as the 12v input (red), follows.

Finally, we have J1 and J2, which will switch 12v through BSS138 Mosfets to control static speed 12v cooling Fans (Only one of these is PWM capable)


The 2 Relays are optically isolated from the controller and mains isolation cutouts are provided to further keep DC and AC voltages well away from each other. [ they really don’t play well together, don’t they ?]

This wraps up the quick PCB description.

Schematic

The Schematic is below, along with a download link ( zip format, with PNG image files)

Some more pictures

I use stencils with almost all of my SMD assembly. It saves a lot of time, makes for even solder paste application, and prevents the mess associated with applying solder paste with a syringe, or even worse a skewer-stick or something similar. They do cost extra though, but I find it well worthwhile in comparison to the mess and time that they save.

Manufacturing

Over the past eight years, PCBWay has continuously upgraded their MANUFACTURING plants and equipment to meet higher quality requirements, and now THEY also provide OEM services to build your products from ideas to mass production and access to the market.


The PCB for this project has been manufactured at PCBWay.
Please consider supporting them if you would like your own copy of this PCB, or if you have any PCB of your own that you need to have manufactured.

PCBWay

If you would like to have PCBWAY manufacture one of your own, designs, or even this particular PCB, you need to do the following…
1) Click on this link
2) Create an account if you have not already got one of your own.
If you use the link above, you will also instantly receive a $5 USD coupon, which you can use on your first or any other order later. (Disclaimer: I will earn a small referral fee from PCBWay. This referral fee will not affect the cost of your order, nor will you pay any part thereof.)
3) Once you have gone to their website, and created an account, or login with your existing account,

4) Click on PCB Instant Quote

5) If you do not have any very special requirements for your PCB, click on Quick-order PCB

6) Click on Add Gerber File, and select your Gerber file(s) from your computer. Most of your PCB details will now be automatically selected, leaving you to only select the solder mask and silk-screen colour, as well as to remove the order number or not. You can of course fine-tune everything exactly as you want as well.

7) You can also select whether you want an SMD stencil, or have the board assembled after manufacturing. Please note that the assembly service, as well as the cost of your components, ARE NOT included in the initial quoted price. ( The quote will update depending on what options you select ).

8) When you are happy with the options that you have selected, you can click on the Save to Cart Button. From here on, you can go to the top of the screen, click on Cart, make any payment(s) or use any coupons that you have in your account.

Then just sit back and wait for your new PCB to be delivered to your door via the shipping company that you have selected during checkout.

Using a Rotary Encoder

As part of an ongoing project, I recently designed an expander card for my ESP-12E I2C Base. I am referring to this device( Atmega 328P Base PWM Controller Card). At the time of writing that article, I have not released any of the code for the project. This is a very short post, showing one possible way to implement a rotary encoder onto that particular device. (It can also be adapted for other devices, of course)

Arduino Style Code for using a rotary encoder

// Constants and Variables
const int encFWD = 8;
const int encREV = 7;
int aState;
int aLastState;
int encDir;
int encTurned = LOW;
int encLastState;
int encValue = 0;
int lastEncValue;
const int encInc = 10;

unsigned long lastEncDebounce = 0;
unsigned encDebounceDelay = 50;
const int encBtn = 9;
int encButtonState;
int lastEncBtnState = LOW;
int EncBtnValue = LOW;
int encBtnState;

void setup() {
  //Rotary Encoder
  pinMode(encFWD,INPUT_PULLUP);
  pinMode(encREV,INPUT_PULLUP);
  pinMode(encBtn,INPUT_PULLUP);
  // Init the pins in UNPUT Pullup Mode
  encTurned = LOW; // Flag for encoder

  encLastState = digitalRead(encFWD);
  //Serial
  Serial.begin(115200);
  //Status LED on D13
  pinMode(13,OUTPUT);
  digitalWrite(13,LOW);
}

void loop() {
  lastEncValue = encValue;
 //Handle the Encoder Push Button
 encBtnState = digitalRead(encBtn);
 if (encBtnState != lastEncBtnState) {
    lastEncDebounce = millis();
 }
 if ((millis() - lastEncDebounce) > encDebounceDelay) {
    if (encBtnState != encButtonState) {
        encButtonState = encBtnState;
        if (lastEncBtnState == LOW) {
          EncBtnValue = !EncBtnValue; // Toggle the button Value
        }
    }
 }
 lastEncBtnState = encBtnState;
 // Handle the Rotary Encoder Dial
 aState = digitalRead(encFWD);
 if (aState != aLastState) {
    if (digitalRead(encREV) != aState) {
       if (encTurned == LOW) {
          encLastState = encTurned;
          encTurned = HIGH; // Set Flag
// Setting this flag will get rid of double value entries caused by contact
// bounce inside the encoder. I found it easier to implement this way
// as opposed to using software debouncing as with the button

       } else {
          encTurned = LOW; // Set Flag low
// This will ensure that the value is increased only once per "click"
       }
       if ((encValue < 300) && (encDir == 0)){
          if ((encLastState == LOW) && (encTurned == HIGH)){
            encValue = encValue + encInc;
            encDir = 1;
          }
       }
      
    } else {
      if (encTurned == LOW) {
        encLastState = encTurned;
        encTurned = HIGH;  
      } else {
        encTurned = LOW;
      }
      if ((encValue > 0) && (encDir == 0)){
          if ((encLastState == LOW) && (encTurned == HIGH)){
            encValue = encValue - encInc;
            encDir = 2;
          }
      }
    }
    encLastState = encTurned;
}
aLastState = aState;
encDir = 0;
// Print Some Status
if (encValue != lastEncValue) {
  Serial.print("Encoder Value Changed from ");
  Serial.print(lastEncValue);
  Serial.print(" to ");
  Serial.println(encValue);
}
digitalWrite(13,EncBtnValue);



}

I hope that this will be useful to somebody.

ATMega 328P Based PWM controller Card

As part of my recent ESP-12E I2C Base Board project, I designed an ATMega 328P Based PWM controller card, that can be used as an add-on card with the existing project, or standalone as a custom Arduino Nano compatible development board.

What is on the PCB?

The PWM controller card contains standard Arduino Nano circuitry running at 16MHz, without the USB to Serial converter, as well as a 3v to 5v level converter on the I2C port ( A4 and A5 ), as well as another 12v to 5v level converter, with a build in resistor-divider circuit, used to drive a 12v blower with 3.3v PWM control circuitry.

All analog inputs are broken out to make attaching additional sensors easier.

All the other unused GPIO pins are also broken out, either directly to headers on the PCB (D6~,D7,D8,D9~), D11,D12,D12 (ISCP Header) and D3 ( Marked RPM on the Fan Header)

Most of these pins are also additionally broken out onto the 2x20p female header at the bottom of the card ( See schematic for more details)

The board is designed to be powered from 12v DC (via the VIN pins on the 2x20p header) which is internally regulated down to 5v via an LDO voltage regulator.


External 3.3v should also be supplied to the 2x20Pin header to enable the I2C level converters on the same header. I2C is not directly broken out onto the PCB in this version of the PCB.

A reset button, and power led, as well as the standard led on D13 is also provided.

Manufacturing the PCB


Over the past eight years, PCBWay has continuously upgraded their MANUFACTURING plants and equipment to meet higher quality requirements, and now THEY also provide OEM services to build your products from ideas to mass production and access to the market.


The PCB for this project has been manufactured at PCBWay.
Please consider supporting them if you would like your own copy of this PCB, or if you have any PCB of your own that you need to have manufactured.

PCBWay

If you would like to have PCBWAY manufacture one of your own, designs, or even this particular PCB, you need to do the following…
1) Click on this link
2) Create an account if you have not already got one of your own.
If you use the link above, you will also instantly receive a $5 USD coupon, which you can use on your first or any other order later. (Disclaimer: I will earn a small referral fee from PCBWay. This referral fee will not affect the cost of your order, nor will you pay any part thereof.)
3) Once you have gone to their website, and created an account, or login with your existing account,

4) Click on PCB Instant Quote

5) If you do not have any very special requirements for your PCB, click on Quick-order PCB

6) Click on Add Gerber File, and select your Gerber file(s) from your computer. Most of your PCB details will now be automatically selected, leaving you to only select the solder mask and silk-screen colour, as well as to remove the order number or not. You can of course fine-tune everything exactly as you want as well.

7) You can also select whether you want an SMD stencil, or have the board assembled after manufacturing. Please note that the assembly service, as well as the cost of your components, ARE NOT included in the initial quoted price. ( The quote will update depending on what options you select ).

8) When you are happy with the options that you have selected, you can click on the Save to Cart Button. From here on, you can go to the top of the screen, click on Cart, make any payment(s) or use any coupons that you have in your account.

Then just sit back and wait for your new PCB to be delivered to your door via the shipping company that you have selected during checkout.