Multi-Purpose IO Card

When we are working on a prototype, we always need access to pushbuttons, encoders and even displays to test our ideas in the real world. This Multi-Purpose IO Card was designed to help me do just that…

What is on the PCB?

This PCB was designed with my particular work style in mind. I use a lot of I2C devices, IO Expanders, Displays and sensors. It would thus make sense to have I2C on the PCB, to control an OLED display, as well as a PCF8574 IO expander, that is used to drive a 4×4 Matrix Keypad. Two Rotary encoders, as well as another 4 standard push buttons completes the PCB…

The features, summarised is as follows:

1x Matrix Keypad (4×4) Controlled via an PCF8574 IO expander with selectable addressing.
1x SSD1306 OLED I2C Display
4x Momentary pushbuttons, configured to be used with internal pullups – i.e pushing the button pulls the GPIO LOW
2x Rotary Encoders, with integrated Pushbutton, also configured as Active LOW

The board has all of the connectors and jumpers on the back, making it possible to mount it to an enclosure as a control panel.

I have also provided an additional I2C header to make it possible to add additional devices to the I2C bus easily

The PCB in Detail

PCB Top

Starting from left to right, we have two push-buttons, an OLED display, with two rotary encoders below the display, and another two momentary push buttons. On the Right, we have a 4×4 matrix keypad, and various pin headers for connection to a microcontroller of your choice.

On the back, we have the PCF8574 IO expander for the Matric keypad, addressing Jumpers for the IO expander, as well as the two pin headers for connections to and from a microcontroller…

The Pinouts of these are as follows:
Horizontal 15 pin 2.54mm connector
SDA I2C Data
SCA I2C Clock

GND

SW4 Momentary Push Button 4
SW3 Momentary Push Button 3
SW2 Momentary Push Button 2
SW1 Momentary Push Button 1

RE2-D Rotary Encoder 2 Push Button
RE2-B Rotary Encoder 2 Pin B
RE2-A Rotary Encoder 2 Pin A

RE1-D Rotary Encoder 1 Push Button
RE1-B Rotary Encoder 1 Pin B
RE1-A Rotary Encoder 1 Pin A

GND
VCC 3.3v to 5v DC

The Expansion header extends the I2C Bus, as well as proved access to the interrupt pin on the PCF8574. VCC and GND are also provided.

The Schematic


Manufacturing the PCB

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

Assembly and Testing

The assembly of this PCB was relatively easy, as it contains only a single SMD component. I do however have to alert you to a certain caveat…

On the PCB, the I2C OLED display pinout is, from left to right,

VCC GND SDC SDA

I have however come across similar displays that swap the GND and VCC pins… and some that even have SCL and SDA swapped…

It is thus quite important that you check your display BEFORE soldering it to this PCB…

Addressing the PCF8574 is also quite easy, with the jumper towards the top is a high, and towards the bottom is a low… They are marked A2 A1 A0 and thus, counting in binary, all low will be 0x20h and all high will be ox27h

Also, note that there are NO I2C Pullup resistors on the board. My microcontroller PCB’s usually have these already, and most I2C Sensors, including the OLED Display that we use, already include as well…
You should thus check what you have on your own hardware, as it is quite impossible to cater for every situation… In a future version, I may add selectable pullup resistors onto this board as well…

Coding and Firmware

The possible uses of this board is quite broad, and the code possibilities are thus also quite extensive. Since I mainly use ESPHome or the Arduino IDE with most of my projects, I wont be including any specialised code here. I think it is enough to say that almost all of the available PCF8574 Matrix Keypad libraries available for the Arduino IDE will fork with this board…

The pinouts are important, and thus :

Row 0 – P0
Row 1 – P1
Row 2 – P2
Row 4 – P3

Col 0 – P7
Col 1 – P6
Col 2 – P5
Col 3 – P4

As far as ESPHome goes, you will need to
1) Add an I2c bus for your device
2)Add a PCF8574 component
3)Add a Matrix Keypad component, and refer the rows and columns to the pins on the PCF8574 – See below for an example of how I have done that in a previous project.

#I2C bus

i2c:

sda: 4

scl: 5

scan: true

id: I2C_Bus

#
# In my case, SDA is on GPIO4 and SCL is on GPIO5
# This is similar to the standard configuration on a NodeMCU v2 Dev board
#

#
# The next step is to configure the actual IO Expander, which in my case is located 
# at address 0x27
#

#PCF8574

pcf8574:

- id: 'pcf8574_hub'

address: 0x27

pcf8575: false


#
# Now we can add the actual keypad interface to the YAML file
# Take note of the difference from the ESP32 file above.
#
#

#KEYPAD

matrix_keypad:

id: mykeypad

rows:

- pin:

pcf8574: pcf8574_hub

# Use pin number 0

number: 0

# In the ESP32 file, we wHereould specify a pin directly like:
#
# -pin: 17
#
# That approach will not work for us.
# The reason for that is that we have to redirect the GPIO to a 
# physical pin on the PCF8574 IO expander.
#
# That is done with the following syntax
#
# - pin:
#pcf8574: pcf8574_hub -- This is the ID of the PCF8574 device -
#number: 0 -- The actual pin number

- pin:

pcf8574: pcf8574_hub

# Use pin number 0

number: 1

- pin:

pcf8574: pcf8574_hub

# Use pin number 0

number: 2

- pin:

pcf8574: pcf8574_hub

# Use pin number 0

number: 3

columns:

- pin:

pcf8574: pcf8574_hub

# Use pin number 0

number: 7

- pin:

pcf8574: pcf8574_hub

# Use pin number 0

number: 6

- pin:

pcf8574: pcf8574_hub

# Use pin number 0

number: 5

- pin:

pcf8574: pcf8574_hub

# Use pin number 0

number: 4

keys: "123A456B789C*0#D"

has_diodes: false

The Rotary encoders and momentary push-buttons can be handled in the same manner, using standard libraries in the Arduino IDE, or a rotary encoder component in ESPHome…

The OLED display would also be handled as above, with a DISPLAY component in ESPHome…

Summary and next steps

The next steps, for me at least, would be to design and CNC cut a suitable enclosure for the IO panel/Control panel in order to make it easier to use…

The panel was designed to be a tool to aid me while designing, and part of my never-ending battle getting rid of breadboards.

It does its job well, at least so far, and works as I have intended it to.

An I2C Matrix Keypad

The completed I2C Matrix Keypad

In a previous post this month I introduced my 4×4 matrix keypad. That keypad was designed to be directly interfaced to a microcontroller’s GPIO pins or alternatively to an IO expander chip like the PCF8574. That design, while working very well had the problem of requiring 8 GPIO pins to function correctly.

GPIO pins on a microcontroller can be considered very precious resources, and it should then be logical to assume that we should find a way to use these GPIO pins in a more conservative way, to allow us to interface more peripherals.

I solved this problem by integrating the keypad with an IO Expander on the same PCB. That will allow us to get away with using only 2 GPIO pins, and also open up the option of adding more keypads to the I2C bus, in the event that we need that many keys for a particular project.

The Schematic

I2C 4×4 Matrix Keypad Schematic

Looking closely at the schematic, we can see that it is exactly the same basic keypad circuit that I used in the initial design. The only difference is that in this design, I have integrated a PCF8574 directly onto the PCB.

Some additional features include selectable I2C Pullup resistors ( usually my microcontroller development boards already include those) that can be activated with a jumper when needed. There are also a set of address selection jumpers, making it possible to stack keypads together into a bigger keyboard if you require something like that. Note that, in this version of the hardware, I did not include headers for stacking.

The keypad can be powered by a DC power source of 3.3v to 5v.

The PCB

I2C Keypad PCB
3D Render of the I2C Keypad

The PCB is a double-layer board of 68.8mm x 50.8mm. Male header pins provide access to the connections as well as address and pullup resistor jumpers. In my build, I have mounted these male headers on the back of the PCB. That makes it possible to mount the Keypad in an enclosure without having the jumpers “stick out” and get in the way.

The top layer of the I2C Keypad PCB
Bottom Layer

Manufacturing

I choose PCBWay for my PCB manufacturing.
This month, PCBWay is also celebrating its 9th anniversary, and that means that there are quite a lot of very special offers available.

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

Assembly

The assembly of this PCB was quite easy and quick. A stencil is not required. All SMD components are 0805 or bigger. It would thus be quite easy to solder them all by hand with a fine-tipped soldering iron.

I have however used soldering paste and hot air to reflow the components, as it is the fastest, in my opinion, and definitely looks neater than hand soldering.

After placing SMD components onto solder paste – ready for reflow soldering
After Reflow soldering with Hot Air

The board is now ready to solder the switches and header pins in place. As already mentioned above, I chose to assemble the headers on the back of the PCB to prevent them from interfering with any enclosure that I may later use with the keypad.

Final Assembly
Note that I assembled the headers onto the back of the PCB.

Testing and Coding

Testing the keypad consisted of a few steps, the first of which was ensuring that there were no short circuits, as well as that all the momentary switches worked.
This was done with a multimeter in continuity as well as diode mode, with probes alternatively on each column and row in turn, while pressing the buttons.

The next stage was testing the I2C IO Expander. This was done with a simple I2C Scanning sketch on an Arduino Uno. It did not do a lot, but, I could see that the PCF8574 is responding to its address and that the pullup resistors work when enabled. This test was repeated with my own ESP8266 and ESP32 boards, this time with pullup resistors disabled, as these boards already have them onboard.

Coding came next, and it was another case of perspectives. It seems like all commercial keypads do not have diodes. This affects the way that they work with a given library. It seems that software developers and hardware developers have different understandings of what a row and a column is.

This meant that, due to the fact that I have diodes on each switch, and the way that the library work – which pins are pulled high and which are set as inputs -, I had to swap around my rows and columns in the software to get everything to work. On a keypad with the diodes replaced with 0-ohm links, that was not needed.

A short test sketch follows below:

Note that with was run on an ESP8266-12E, therefore the Wire.begin() function was changed to Wire.begin(4,5); in order to use GPIO 4 and GPIO 5 for I2C

Another point to note is that the keypad Layout will seem strange. Remember that this is due to the diodes in series on each switch. That forces us to swap around the Rows and the Columns in the software, resulting in a mirrored and rotated left representation of the keypad. It looks funny, but believe me, it actually still works perfectly.

#include <Wire.h>
#include "Keypad.h"
#include <Keypad_I2C.h>

const byte n_rows = 4;
const byte n_cols = 4;

char keys[n_rows][n_cols] = {
    {'1', '4', '7', '*'},
    {'2', '5', '8', '0'},
    {'3', '6', '9', '#'},
    {'A', 'B', 'C', 'D'}};

byte rowPins[n_rows] = {4, 5, 6, 7};
byte colPins[n_cols] = {0, 1, 2, 3};

Keypad_I2C myKeypad = Keypad_I2C(makeKeymap(keys), rowPins, colPins, n_rows, n_cols, 0x20);

String swOnState(KeyState kpadState)
{
    switch (kpadState)
    {
    case IDLE:
        return "IDLE";
        break;
    case PRESSED:
        return "PRESSED";
        break;
    case HOLD:
        return "HOLD";
        break;
    case RELEASED:
        return "RELEASED";
        break;
    } // end switch-case
    return "";
} // end switch on state function

void setup()
{
    // This will be called by App.setup()
    Serial.begin(115200);
    while (!Serial)
    { /*wait*/
    }
    Serial.println("Press any key...");
    Wire.begin(4,5);
    myKeypad.begin(makeKeymap(keys));
}

char myKeyp = NO_KEY;
KeyState myKSp = IDLE;
auto myHold = false;

void loop()
{

    char myKey = myKeypad.getKey();
    KeyState myKS = myKeypad.getState();

    if (myKSp != myKS && myKS != IDLE)
    {
        Serial.print("myKS: ");
        Serial.println(swOnState(myKS));
        myKSp = myKS;
        if (myKey != NULL)
            myKeyp = myKey;
        String r;
        r = myKeyp;
        Serial.println("myKey: " + String(r));
        if (myKS == HOLD)
            myHold = true;
        if (myKS == RELEASED)
        {
            if (myHold)
                r = r + "+";
            Serial.println(r.c_str());
            myHold = false;
        }
        Serial.println(swOnState(myKS));
        myKey == NULL;
        myKS = IDLE;
    }
}

Conclusion

This project once again delivered what I set out to achieve. It has some quirks, but nothing serious. Everything works as expected, both in the Arduino IDE/platform IO realm, as well as in ESPHome. It is worth noting that in ESPHome, we do not need to swap the rows and columns to use the Keypad component. Do remember to leave the has_diodes flag to false though…

A Reliable Matrix Keypad

What is a matrix keypad?

A matrix keypad is a type of keypad that uses a matrix of wires to connect the keys to the microcontroller. This allows for a smaller and more compact keypad than a traditional keypad, which uses a single row and column of wires for each key. Matrix keypads are also more reliable than conventional keypads, as they are less susceptible to damage from dirt and moisture.

How does a matrix keypad work?

A matrix keypad is made up of a number of rows and columns of keys. Each key is connected to two wires, one for the row and one for the column. When a key is pressed, it completes a circuit between the row and column wires. The microcontroller can then determine which key is pressed by checking which row and column wires are connected.

Why use a matrix keypad?

There are a number of reasons why you might want to use a matrix keypad in your project. Here are a few of the most common reasons:

  • Smaller size and footprint.
  • Reliability.
  • Cost savings.

What makes my design different from most others out there?

While the matrix keypad in its simplest form is constructed from only wires and switches, that simple approach can sometimes have some unwanted effects, especially when pressing multiple keys at the same time – a phenomenon called ghosting – where you get phantom keypresses. This is easily eliminated by adding a diode in series with each switch, usually on the row connection.

That single component fixes ghosting reliably but does not come without its own problems, the most important of these being that a keypad with diodes becomes “polarised” – current can only flow in a single direction through a switch. This can cause problems with some third-party libraries, as the designer of the keypad and the designer of the library very often has quite different ideas of what a row and a column mean in a keypad.

This is important, – here we go down the rabbit hole; in my understanding of the keypad scanning routine, a column runs from top to bottom, and a row from left to right. Keeping this in mind, the microcontroller will alternatively set each column HIGH, and configure each row as an input. When a key is pressed, current will flow from the specific column GPIO, through the switch, and into the Row GPIO, sending the input pin HIGH…

It is also possible to configure the columns as inputs, with internal pullups enabled, and have each Row pin as an output, configured to sink ( pull current to ground). This will cause the specific column to go low – thus identifying the pressed key…

These different ways of handling the problem of reading a key, and believe me, there are actually more variations, create a few unique problems. We may have to swap rows and columns as far as pin connections and firmware are concerned, as well as define a custom “keymap” to assign values to each key.

The Schematic

As we can see above, the schematic is very basic. 16 switches, 16 diodes and a single 8-way header pin. Pin 1 to 4 on the header is connected to Columns 1 to 4, and Pin 5 to 8 is connected to Rows 1 to 4.

The diodes prevent “ghosting currents from flowing into other keys in a row when multiple keys are pressed together. They also seem to help with other stray signals and interference.

The PCB

The PCB is a simple double-layer board. All components are mounted on the top layer.

To limit interference from stray signals, I have routed rows and columns on opposite sides of the PCB where possible.

Manufacturing

I choose PCBWay for my PCB manufacturing.
This month, PCBWay is also celebrating its 9th anniversary, and that means that there are quite a lot of very special offers available.


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

Assembly

This project does not require a lot of specialised equipment to assemble. The SMD diodes can easily be soldered by hand, the same with the switches and 8-way header. In my case, I chose to solder the header pins on the back of the PCB, that way, I can later use the keypad in a suitable enclosure without having wires in the way.

Testing and Coding

Testing a matric keypad can sometimes be a challenge. In my case, a multimeter with clip leads, set to diode mode, with the leads connected to each column and row in turn, while minding the polarity, and pressing each key in that row in turn, verified continuity.

With that done, it was time to put my trusted Cytron Maker Uno to work, as this Arduino Clone has the added benefit of having LEDs on each of the GPIO lines, thus making it very easy to see what is happening.

I made use of a Keypad library in the Arduino IDE, mainly to cut down on the amount of coding, but also because it is easier to use a working piece of code, and then adapt that to my keypad.

Detailed Code examples for ESPHome are available on Patreon

/* @file CustomKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates changing the keypad size and key values.
|| #

Edited by MakerIoT2020, with minor changes to make it function correctly with my custom keypad.
I have also added a simple LED blinking routine to show that the Arduino is “alive” and that the Keypad code seems to be NON-blocking – which is quite important to me.

*/
#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the symbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{‘1′,’4′,’7′,’*’},
{‘2′,’5′,’8′,’0’},
{‘3′,’6′,’9′,’#’},
{‘A’,’B’,’C’,’D’}
};
byte rowPins[ROWS] = {2,3,4,5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6,7,8,9}; //connect to the column pinouts of the keypad
/*
* Due to libraries being written by different people, and our definitions about
* what a row and a column are, is different, note that the rows in the code
* is actually the columns on my PCB. This becomes true, due to the fact that my
* PCB has Diodes on each switch, and that thus makes current flow in only one
* direction///
*
* it also has the “side effect” that keys are layout in a strange “mirrored” and
* rotated way in the firmware.
* it does however NOT affect the correct operation of the Keypad Module at all
*
*/

const int LEDPin = LED_BUILTIN;
int ledState = LOW;
unsigned long prevmillis = 0;
const long interval = 1000;

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup(){
Serial.begin(115200);
pinMode(LEDPin,OUTPUT);
}

void loop(){
unsigned long currentMillis = millis();
if (currentMillis – prevmillis >= interval) {
prevmillis = currentMillis;
if (ledState == LOW) {
ledState = HIGH;
} else {
ledState = LOW;
}
digitalWrite(LEDPin,ledState);
}
char customKey = customKeypad.getKey();

if (customKey){
Serial.println(customKey);
}
}

This code works very well and allowed me to verify the correct operation of the keypad.

In conclusion

Making my own Keypad Module is a project that is long overdue. I have purchased a few online over the years, and as they were mostly of the membrane type, they did not last very long – it must be something to do with the ultra-cheap flexible PCB ribbon connector, since a quality membrane keypad can be quite expensive, and usually lasts quite a long time.

Having my own module available to experiment with will allow me to do some long-delayed improvements to many of my IoT modules. That code, mostly YAML for ESPHome, will be made available on Patreon.

CAN Bus support with the ATTiny1616

ATTiny1616 QFN with Can bus support on a breadboard

A short while ago, I started looking at alternatives to the ATMEGA328P ( the chip used in the standard Arduino Uno). That experiment turned out quite well,
with two of the three chips turning out to be useful, the ATTiny1616 and the Atmega 4808 – The ATTiny 202, while working great, has quite a few severe limitations, due to the size of its memory, as well as library support, limiting its actual useful use quite a bit for my purposes.

In this post, which is part of a two-part series, I will look at adding dedicated CAN Bus support to the 1616 and 8408. I am planning to add some gadgets to my car, and would like to have it controlled by a CAN bus interface, and just maybe, interfacing with the CAN bus on the car as well – at least in the future…

This experiment will thus consist of two prototypes with onboard CAN hardware, to be initially used on the bench while building and testing my gadgets – more on them later, if and when they work out the way that I imagine.

What is on the PCB

The ATTiny1616 microcontroller, in a QFN package, has been married to a MCP2515 and a TJA1050. These chips, while old, are still easy to get hold of,
and I have quite a few of them lying around from previous projects. It did thus seem to be a good starting point. The fact that their libraries also works perfectly with the ATTiny1616 and Atmega4808 also went a long way towards selecting them for the project.

The PCB is similar to the ATTiny1616 QFN breakout that I have designed before but with the addition of the CAN-related components.

ATTiny1616 QFN development board with CAN bus, after reflow soldering

Schematic and PCB Design

The schematic is a variation on the earlier breakout PBC, with the addition of the CAN-related components.

ATTiny1616 Schematic - MCU only,
Can bus related components - for use thie the ATTiny1616 MCU


The PCB design has also not changed a lot, I have just added the CAN components to the right hand side of the PCB, and adjusted the routing.

PCB layout design for the ATMEGA1616 with CAN bus Development PCB


3D render of the PCB, with the header pins in non-breadboard configuration – with the CAN bus connector not fitted.

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

Assembly

I usually can not wait to receive my creations back from the factory – I mean, how can somebody not get excited about receiving their own PCBs back from the factory, especially if you know they will be of the high quality that I have come to trust with all of my PCBWay orders?

This is especially true of the smaller PCBs, as well as those with smaller-sized QFN components, with this board definitely not being an exception.

ATTiny1616 QFN Dev board with Can Bus, in packaging - straight from the factory
PCBs in factory packaging
PCBs in protective wrapping, after opening
PCBs in protective wrapping, just after opening the package
Closeup view of the top side of the PCB
Closeup view of the top side of the PCB

This PCB once again requires the use of a stencil, to accurately apply just the right amount of solder paste to the pads, especially the small QFN package pads of the ATTiny 1616…

High quality stainless steel, laser cut stencil. High accuracy. Definitely worth the investment
High-quality stainless steel, laser cut stencil.

Stencils, at least from my point of view, can be a controversial subject, with some hobbyists arguing that they are not worth the additional expense… I do however believe that they actually save you a lot, in time that you don’t waste on reworking a PCB due to solder bridges, in the correct amount of solder paste that is applied, in the correct thickness, and also time not wasted on the cleanup of the mess that can result from manually applying solder paste.

After solder paste application, all the components are placed in their correct positions, ready to be reflow soldered.
PCB ready for reflow soldering, after manually placing the components in their respective places

The PCB is now reflow soldered with a hot plate, and allowed to slowly cool down afterwards, to reduce thermal shock damage to the joints, that may result from a too-quick cooldown cycle. While I do not own a dedicated reflow oven, the hotplate that I use, seems to match the reflow profile ramp-up of my solder paste, and most of the components perfectly. After achieving a complete solder melt, at about 223 degrees C, I usually switch of the hot plate, and carefully move the PCB towards the edge of the unit, that area is usually a bit cooler than the centre. leaving it there for about 5 to 8 minutes, allow the solder to slowly solidify, after which I remove it and place it on a silicone mat to cool completely.

Through-hole component soldering, and testing

The next step is soldering all the through-hole components, usually header pins and connectors into their respective places. The board is then placed onto a solderless breadboard, and various test sketches are uploaded via a homemade UPDI programmer.

These include the infamous blink sketch, to make sure the chip is alive and survived the reflow soldering. That is followed by a CAN loopback test, and then the actual CAN firmware… I make use of the excellent MCP Can library from Garry J Fowler, as well as the megaTinyCore Arduino core, from Spence Konde.

My thanks to both of these gentlemen, for their excellent and easy-to-use software. A special shoutout to Garry J Fowler, since his MCP Can library correctly releases the CE pin of the device when not in use, thus not locking up the spi bus. [ This is something that many other libraries do not bother to care about ] …

Conclusion

This was once again a fun project to design and assemble. The real testing and development can now start at full speed, as this is just meant to be a tool, with a further revision later down the line. It does of course help a whole lot that I can completely trust my PCB manufacturer, PCBWay, to deliver my PCBs to me EXACTLY as I designed them, and at extremely high quality and precision! Thank you for that!

ATMEGA4808 – An Improvement on my previous design? Or Not…

Atmega4808 Development Card in Acrylic Shell

When I first started playing around with the ATMEGA4808, I was impressed as well as disappointed by the Arduino Every “Clone” that I got online. Impressed with the Microprocessor, but disappointed in the way the development board worked, the lack of documentation etc.

I set out to change that by doing my own version, something that I do quite a lot. If I don’t like something, and it is in my ability to create/design my own version, minus any of the perceived(in my opinion mostly) flaws of the original design, I usually do just that.

With that mindset firmly in place, a few weeks ago, I did indeed redesign an ATMEGA4804-based development module, and it worked flawlessly…

As time went by, that little irritating voice in my head got louder and louder… add this, change that, what if it was like this etc… Many makers will know exactly which little voice I am talking about.

Two Atmega4808 Modules, side-by-side

So what did I change?

The short answer to that is a lot. the long and detailed, well let’s see…

  1. Added an additional LDO voltage regulator, to provide more current.
  2. A DC barrel jack was included, enabling us to power this from 7v to 12vDC
  3. Changeable logic level ( switching entire board between 3.3v and 5v operation )
    with a single jumper.
  4. Improved labelling of GPIO functions (on the back of the PCB), listing alternative functions etc for each GPIO
  5. Put all that into the standard Arduino Uno Footprint…

So, did any of that really matter?

Once again, two answers, one long, one short… so here goes…

The added DC barrel jack, with the two dedicated LDO voltage regulators, adds flexibility to power the device externally, opening up possibilities to use it in a stand-alone project, not only on the bench.

The Logic level switching, which at the time, seemed like a very very good idea, now no longer seems so important…

Using the Arduino Uno footprint, yeah, so what, it is a neat layout, but apart from using a somewhat ” traditional” footprint, is only cosmetic…

That leaves only the updated silkscreen on the back of the PCB, as well as better labelling on the front…

Back Silkscreen
Front silkscreen

As far as information goes, yes, this is a great help. It will definitely save some time reading datasheets and looking up other stuff…

Does this mean the project was a failure?

Definitely not. I am not negative, but instead, have a tongue-in-the-cheek attitude about how sidetracked I became. I mean, this is basically the exact same board, with just a different form factor. So, in that case, think about it in the context of an Arduino UNO and Arduino NANO. Both of them use the exact same processor but only differ in footprint. ( as well as a few other cosmetic things and functions – the nano having additional analog inputs etc.).\

I am sure that the new form factor will appeal to some, and others will feel it was a completely unneeded design.

The Schematic

ATMEGA4808 Schematic

The schematic does not contain any surprises. everything is basically similar to my initial breakout module design, with the exception of the power section. I tried something different, and the jury is still out on how well it actually worked.

When powered from USB, the 3.3v LDO Voltage regulator gets fed directly from the USB Voltage, through a protection diode of course.. Similarly, when powering the device using the DC power jack, both LDO regulators are once again fed separately… for the time being, it seems to work well. Time will tell if it was the correct way to do things.

PCB Design

Top Layer
Bottom Layer

A lot of care was taken to attempt routing of all tracks at the shortest distance possible, as well as using differential pairs for the UART, SPI and I2C peripherals. PCB heatsinks for the LDO regulators, as well as ground planes on both side of the PCB, was also implemented.

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

Assembly

The assembly of the ATMEGA4808 development card, as I named the creation, can be done entirely with a standard soldering iron and steady hands, but I chose to order a stencil with the PCB and reflow the PCB on a hotplate.

Stencil for SMD assembly

I prefer this way of assembly, as it is generally faster, looks neater, and ultimately uses less solder paste. This particular build did however give me a few headaches, which may be the underlying reason for my tongue-in-the-cheek attitude towards this PCB…

Let us take a look at some of the issues that I encountered

The Micro USB B connector that I used, seems to be quite sensitive to heat. I have a few different batches of these, and some are good, while others are just terrible. ( this happens because I did not buy them all from a reputable supplier, but opted for an online supplier instead – NOT LCSC as I normally do).

This resulted in having to change USB connectors a few times.

The second issue was the CH340N USB to Serial chip. Due to availability issues, I was once again forced to use an online supplier, and ended up receiving only two working chips out of a batch of 20! The fact that they were super cheap, with super fast shipping should have alerted me that something was wrong…

These two issues caused quite a lot of headaches and ultimately cost me an ATMEGA4808 chip, that for reasons unknown, died without any explanation, with the board pulling a crazy 3.5A at 5v for a few seconds. Subsequent testing revealed a failed 5.0v LDO regulator, which after being replaced by a new one, resulted in a perfectly working board. ( after sorting the CH340N and USB connector issue of course)

Conclusion

This build gave me a lot of problems, tested my diagnostic skills, as well as provided proof that you definitely get what you pay for. Electronics component supplies are still not quite at the level of availability that we are used to, with huge lead times and delays being a big issue.
This presents us with the tempting solution of buying a few components from dubious online companies; sometimes you get a good deal and sometimes you get only headaches like I was rudely reminded with this build.

As far as the PCB is concerned, there are absolutely no issues. Everything works as expected, and while no real changes were made between the two versions, It has already earned a permanent place on the bench, having replaced my old Arduino Uno clone as my goto development board when doing something ATMEGA related.

Some More Pictures

A complete ATTiny1616 Dev Solution

A few weeks ago, I started looking into alternative development solutions to reduce the effect of hard-to-get or more expensive-than-usual ATMEGA328 chips. One of the chips that I found to have potential was the ATTiny1616.

There seemed to be quite a lot of stock, and the prices were reasonable. Some additional hardware, like a dedicated UPDI programmer, had to be designed or bought, as the ATTiny1616 required UPDI to upload and flash code.

Setup to program ATTiny1616 Breakout Module – Power Module ( Left – Optional) ATTiny1616 Breakout – Center, UPDI programmer ( Right)

While the breakout worked flawlessly, I found the programming setup awkward and cumbersome. That was the cue to take the next step and create something that was easier to work with.

Old versus new. ATTiny1616 breakout module and programmer (Top) versus the all-new ATTiny1616 Development board, with all required hardware, included.

The new PCB offers a development cycle that is very similar to a standard Arduino UNO or Nano. Plug it into a USB port, write code, upload and repeat…

What is on the PCB?

Top view- In acrylic Case

Starting at the Top Lefthand corner, we have a USB port, with a CH340N Chip. Note that this IS NOT A SERIAL UART. This is an integrated UPDI programmer, that can also be used in stand-alone mode to program external devices. (by moving J3 to the left, and using the UPDI header).

Below that is the power supply section, featuring two LDO Voltage regulators, providing 3.3v and 5v DC to the system. A DC barrel jack is included, to supply between 7v and 12v external DC voltage to the system. ( NOT to be used together with a USB cable)

Jumper J2 (next to the DC barrel jack) is used to switch the entire board logic level between 3.3v and 5v DC. A power indicator LED, as well as a standard user LED ( on pin D16), is also included. The rest of the PCB is dedicated to the ATTiny 1616 -SF, this time in a TSOP form factor. ( The original breakout used a QFN, but I realised that that may push away a lot of potential users, as QFN packages are quite difficult to solder without the proper equipment. A TSOP package is more accessible to everyone)


A total of 17 GPIO ports are available, of which each is labelled with an Arduino compatible label (D0 – D15), PWM ~ capable pins, and alternate functions like UART, SPI and I2C. Please Note that the onboard USB port IS NOT A UART

Features on the PCB – Summary

  • Reset Circuit with Push button – The ATTiny1616 shares its Reset pin with the UPDI programming pin. This will cause problems, requiring an HV UPDI programmer to fix. To resolve this issue, a reset circuit, comprising of a p-channel logic level Mosfet, that is wired to be constantly on, is connected via a suitable resistor on its gate, to a push-button to ground. pressing the button pulls the gate to ground, switching off the Mosfet, and thus the supply voltage to the chip, which equates to a power cycle reset. It is worth noting that the UPDI programming sequence also auto-resets the chip after every upload.
  • DC barrel jack for powering the device from an external source – 7v to 12DC
  • Onboard I2C pull-up resistors, selectable with a jumper ( J1)
  • Onboard UPDI programmer, which can also be used in stand-alone mode.
  • Selectable voltage logic level between 3.3v and 5.0v ( J2)

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

Assembly

Stencil for Assembly

While this board can definitely be assembled completely by hand soldering, I chose to make use of a stencil, from PCBWay. This helps me by ensuring that the solder paste is applied in exactly the correct amount and place. Hot air or reflow soldering afterwards is a quick easy task. I prefer to use a hot plate to reflow the board, especially since it has a tiny USB connector, which can be quite a pain to solder with hot air, I won’t even go there with a normal soldering iron, as it is beyond what my eyes can handle at this stage.

Some more pictures

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

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.