Instability: Attiny85 + MAX7219 + 4-digit 7segments + 18650

I’m building a completely pointless hobby project: a speedometer for my bicycle from red 7-segment displays. This display is driven by an attiny85 connected to a MAX7219. I’m also using a reed switch to detect the magnetic pulses from the wheel.

When I prototyped the code using a digispark powered by USB, it all worked fine and I got sensible readings on the display. When I switched to the attiny85 built on a dedicated circuit board, the display is erratic and the digits display nonsense.

I tried a test script to cycle through numbers on the screen in sequence, and it seems that the attiny is resetting at regular intervals, or at least soft-reseting. It’s slightly more stable when I power it through an arduino nano’s 5V out line, which makes me think that the unit is drawing too close to 500mA for a USB power supply to safely supply.

My original plan was to power this from a 18650 cell via a TP4056, but that performs even worse: the LEDs flicker at random and the sensor output is meaningless, even though that board is supposed to supply 1A.

Here is an extremely crude circuit diagram:

I’ve added a 0.1uF capacitor across the power and ground of the attiny85, but I don’t know if something bigger would be enough, or if I need to look into dedicated power supplies for this project.

Your description is typical of a power-starved, or power-unstable circuit. To diagnose,

  • proper schematic. You could do better than that with a pen, piece of paper, and a smart phone to take a picture and post it. Be sure to identify all components, values, etc. From the looks of it, more capacitance will be essential, but not necessarily sufficient.
  • photo of as-assembled circuit is probably going to be needed
  • software is probably optional, though looking at what you’ve got would allay some doubts.

Fuse settings?

/RESET floating?

Recommended 10uF and 0.1uF caps as close to V+ and GND of the 7219 as stated in the datasheet?

Measured current?

Debouncing of reed switch?

Rset value?

It smells powering problems.

Please create a real schematics showing pin names, power supply etc.

The minimum operating voltage of the MAX7219 is 4V. It is not designed to run from an 18650 cell.

No bypass caps. 0.1uF ceramic, close to the power pins of each bare chip. Your Digispark would have had one on its PCB.

Also a 10uF electrolytic for the max chip as recommended in the data sheet, as already pointed out.

Fully charged, the Li-ion battery will output 4.2V but will quickly drop to < 4V which is the minimum that the max chip is designed for.

What clock speed is your attiny running at? I don't think they are guaranteed to run at 16MHz with only 3.7V. Suggest you run the attiny at 8MHz (internal clock).

TP4056 is a charging chip. It won't protect your battery from over-discharging, which can be dangerous. Some TP4056 boards also contain over-discharge protection chips, but not all do.

Thanks for all the responses. Diagramming isn’t my strong point but I’ll try to sketch it out for those interested. Rset on the max7219 is 10k.

For clarity: I’ve got the 0.1uF cap across the power rails supplying both the attiny85 and max7219 - the chips are 5mm apart on the circuit board so I didn’t think I needed one per chip. I’ve since added a 10uF cap on the same place, but not seeing any difference.

I have no other voltage regulation. The max7219 and attiny85 are connected to common 5V and GND pins, which I then connect to my external power source.

In terms of power supply: the tp4056 I’m using has an additional USB-out which can supply 5V, so I shouldn’t be experiencing issues caused by undervoltage (3.7-4.2 from the 18650). No matter whether I connect this tp4056, or two different USB power banks, the board fails to work properly. HOWEVER, if I connect exactly the same power supply to an arduino nano’s VIN pin, and then power this board from the same arduino’s 5V pin, then the board works fine.

I could try adding an lm1117 to the board’s power supply but I thought the voltage difference from a USB battery bank would be too low to provide any regulation.

is a charging chip.
It looks that your device has lot more going on.
Post a link to your actual module you use.

It looks like this but with micro-usb instead of USB-C:


But that board is not really the issue since two other off-the-shelf USB power banks also don’t work directly with my board, but they do if I use an arduino nano in-between.

That device is a power bank module. So you have 3 power banks not working. Be aware that many power banks are built to turn off, if they see very low current draw.
Arduino in-between might help to pass that threshold.

You know and we know that make no sense, so you must be doing something else wrong.

You do. And the bypass caps each need to be nearer their chip than the chips are to each other, otherwise they can't perform their function, which is to prevent the chips adversely affecting each other or themselves.

I agree that makes no sense. The minimum voltage for a "classic" Nano's Vin pin is around 6.5-7V. If you connect 5V to Vin, you won't get 5V from the 5V pin of the Nano, probably only around 3.5V, because of the voltage drop from its on-board regulator (which is not the "low drop-out" kind).

Ok all, so it seems like it’s a PEBKAC error rather than a flaw in the overall design. I’ll double-check all my connections and let you know where I messed up.

Thank you all for chiming in.