Hi guys. I've been using USB power banks to power my long range RF/Nano projects for years and use transistor circuitry to defeat auto-shutdown. Using RF I can not only send/receive data and reboot but also shutdown the board entirely. An Eagle pic of my pc board design: www.4gto.com/Nano_powerbank_pcb.jpg
IMHO the CH32V003 and its siblings (CH32V203 in particular) are far more promising for the price point and size. It has far more capable peripherals, is less expensive, and also has a far more capable CPU if/when you need it!
@@MUSTARDTIGERFPV I was thinking exactly the same. Perfect for simple sensing and controlling tasks Do you know any good free and scalable framework for controllers and sensors? I'm playing with creating my own but want to be sure I'm not reinventing the wheel
I fiddled with AVRs in the past and wanted to store state information on a power failure. I used a diode feeding a largish cap on the power pins and monitored the incoming power before the diode for a power failure using a second diode connected to a sense pin with an interrupt set up to trigger when it went low. When the interrupt was triggered, I immediately stored the state information to the EEPROM, and the energy in the cap was enough to get that done before the AVR ran out of power. This saved needing to constantly write data to the EEPROM in case the power died, because there was quite a lot of data to store and the 100,000 cycles would be used up within a year if I kept writing that data to the EEPROM every second. Wear levelling wasn't an option.
Because the power consumption is to little - one diode, one electrolytic capacitor and small change in code: if ADC doesn't see 5V - subtract a 'some safe amount of seconds' and save this number into EEPROM and rise the flag (to avoid any trashy values when the capacitor voltage goes down the safe voltage region) On start you can type this value into Serial for debug purpose. CC: @AndreasSpiess
I was thinking this pretty much as soon, if not slightly before he introduced the battery idea, lol and I don't even mess with any microcontroller stuff, lol
I'd look for a proper low power controller, STM32U-series or TI MSP430, that will run circles around the mA numbers from the video, and run at low input voltage. Pair it with a mF supercap and you should have plenty of run time for re-triggering and storing timing data
It’s my job to design rather sophisticated industrial controls. But, even with the best tools, good firmware and reasonable budgets, I still try to sneak in the occasional 555 and/or 2N3904/3906 (b/c I have an appreciation for the classics) and one 90 degree trace - just to drive the “electrons are going to slide off around the corner” (even at DC) crowd crazy. This probably says terrible things about me as a person, but at least I can inject a bit of harmless fun into my work. Haha Long live the (timer) King - the 555.
Love it, classically trained tech trolling. Been in tech for decades, in security now, I often toss out TCL and Perl scripts to mess with the younguns, they have no idea how to deal with anything but Python.
@@c1ph3rpunkto be extra naughty you could use pascal or forth or cobol, lol latest cobol spec is from 2023, and there is a fully gnu cobol compiler! >;P
I like videos that shows how to use dedicated chips instead of using always an esp or arduino. Small projects will be cheaper and more power efficient. 👍
@@elguido Yes, but most ready-made ESP/Arduino boards have things like power LEDs, UART-USB-bridges or linear voltage regulators with pool quiescent current, which aren't really bothered by the MCUs sleep mode.
The thing I really like about these (relatively) new devices is that FINALLY we have low pin-count devices with serial peripherals. Just what you need to convert a simple sensor or actuator into a serial bus device using I2C, CAN or LIN etc. (although the latter two will also require a bus driver chip). I have waited twenty years for this day, and suggested it to Microchip on numerous occasions! Two pins for power, one for reset/programming, two for the serial bus, you still have three to connect your sensor/actuator which is plenty in most cases. The Chinese chips are presumably copies at the mask level or reverse engineered. Does not seem worth the risk when they are readily available at reasonable prices from reputable western stockists (one of which has actually popped up as an ad over this video!)
A friend of mine approached me with an interesting ATtiny challenge. He had to develop a certain small&smart device for a musician; the ATtiny85 was the perfect companion. The challenge was to make the final fine-tuning on the field while rehearsing: how to quickly reprogram the ATtiny without dissembling or swapping the device? "Use a DIP switch or jumpers" was my spontaneous answer. I'm glad he succeeded with it with such small and spontaneous advice.
Adding impedance to the pins AFTER the bifurcation to the ISP connection usually solves most of the issues with ISP interference. Attiny Pin -----> ISP Header ----> Resistor ----> Peripheral. This ensures that the ISP has a lower impedance towards the ATTiny Pin. The exact value of the resistor depends on the overall circuit impedance, but I have experienced seeing anything from 10R to 22R working well for IC to IC communication.
Some interesting things about the Attiny 1-series: 1. The internal oscillator is much more accurate than on the older AVR chips. 2. They support a wide voltage input range especially at lower clock rate. 3. The ADC is actually quite good (this is more subjective).
Thank you for the additional info. Indeed, I run my chip on the lowest clock speed (internal). But of course, precise timing is not a big issue in this project.
A good ADC is handy on low pin count devices like this, because you can do things like use resistor ladders to hook up a bunch of buttons or switches (DIP or otherwise) to a single pin, saving you I/O for other functions.
“If something looks simple and straightforward, it often is not.” I found this out the hard way, trying to complete a project that I thought would be finished in three months, has taken almost eight years 😂
@@AndreasSpiess I think the payoff will be worth it. SecureFarm, security in the back yard for the small homesteader. Whoa did I have a lot of roadblocks. Your videos helped :-)
s/w only I have previously said the team could have the functionality done in a month (elapsed). To have it production quality would take a bit longer. These days I find doubling the estimate, adding the fudge factor and doubling again is still an underestimate, but then my team these days is very different standard. (Did anyone see the video add in recent months about "you too could be an embedded software developer in a few weeks [repeat embedded software developer about a hundred times]" - that's the quality of people we seem to see these days).
It would be super cool if Great Scott now took your design and improved it even further. The most epic type of battle ever And a learning experience for is viewers😊
Nice introduction to the new ATtinys - however, regarding your criticism of the old SPI-programming interface: I never had a problem using all 5 pins (excluding reset, vcc and gnd) on the 8-pin chips with in-circuit programming. Yes, you are double-using those pins, but only during programming. And then it normally doesn't matter if you send invalid codes to an also attached SPI-slave devide, blink some LEDs or have push-buttons attached (as long as you don't press these buttons during programming).
Yeah, that's what I found too, just take a little care to avoid a large load to the programming pins, but like he said, the new way is a lot nicer. I found myself using the 20 pin ATTINYs when an 8 pin would do, just because I knew I wouldn't run out of pins in any case.
Both you guys have taught me so much. I love being able to take the basics of a concept, develop it into a working project and then move it onto the next level to really cement my understanding.
Your interface can be simplified: - enter characterization mode if nothing is connected to the output otherwise enter supply mode - in characterization mode, while the power supply is active keep an led on (it will switch off when power is cut indicating to the user that it is done and they can plug in their load) - in supply mode, turn on a different led (or different color, to indicate a different mode) This would completely free up the user to do user things in parallel =)
How do you plan to detect if something is connected to the output? The usb has no detect pin so one of the only ways you can do it is to measure current which itself adds complexity, requiring either a low side shunt resistor or a Hall effect current sensor.
There are power banks with a low power mode that can be activated by double-clicking on some Anker products. This is required, for example, to charge True Wireless Earbuds or smart watches. Edit: It's called Trickel Charge Mode at Anker. It says that it deactivates after 2 hours of non-use. It is questionable how exactly they can measure whether this is used or not.
I accidentally discovered this, one of the charge indicator LEDs switched from blue to green when I pressed the button twice. Strangely this was not documented in the manual.
I have spent a lot of time using the ATTiny85 and the micronucleus bootloader to get an additional pin. They don't have full hardware uart support like these newer ones do so these look like a nice alternative as an upgrade.
There is an 8-pin SO version of the super-cheap Risc-V CH32V003. More everything than the ATTiny for a third of the cost - not sure offhand about the sleep performance though
@@AndreasSpiess No - used the manufacturer's tools. I think there is now an Arduino setup for it though. Another nice thing about that MCU is it needs only one wire for programming and debug
Doing the chip 'supply shortage' these were the only cheap chips I could find, so I had to figure out how to use them, there was not a lot of youtubers using them yet. Great to see even the favorite channel is using them.
Hi Andreas - great to see you getting into the ATTINYs - brilliant little chips, and Spence Kondes Core works like a charm. One thinng about the programmer: you don't need to sacrifice an NANO: UPDI is possible with any cheap USB-2-Serial based adapter. The ones with the CH340 chips work quilte nicely and are normally a dollar a pop. One resistor between TX and RX and you're game; I did a video on that toppic some time ago. Keep up the good work!
Why measure and store instead of just reacting? Decouple the ATtiny a big so it keeps running a tiny bit after the power-down of the battery-pack. That way when the power goes low it can record the time and trigger it again (maybe repeat a second time for more confidence).
He covered that I think: there was no easy way for the ATtiny to turn the power bank back on once it had gone into "low output" mode. I might have missed something, but I think that was the problem.
After playing around with Arduinos dor a few years, I came across this series of newer microcontrollers about 7 months ago. I use them now for all smaller projects. The required hardware for programming is so simple and cheap, and still no bootloader required. Quite accurate timers without external oscillator. I love it!
A capacitor to delay a brown-out and a 5V input that would have down-edge triggered interrupt might save you from saving every value into EEPROM -> just write one value during IRQ just before the chip dies...
Great video today, I also watched Great Scott's video. BTW the debug switching was a trick I learned many years ago when I first learned to program in C, thanks for sharing! Much love, happiness, and success to you!
@@AndreasSpiessMy intent was not to disparage the technique at all, it merely surprised me to hear anyone talking about it. Without tricks like that, I would still be an assembler programmer. Love your program and have been watching and enjoying my front-row seat for a long time. Thanks again Andreas for all you do!
This is exactly how my projects go. As an example Ive been trying to make a pi based nightvision camera using the Argon POD case. The goal was simple - have a no IR camer output to the PODs SPI display. After quite a bit of experimentation I sacked off the spi display for a small hdmi connected display which does exactly what I want - full screen camera - with a lot less coding than the spi display. In summary never be frighten of changing what you're doing especially of you can achieve the same goal with less hassle.
I had no idea atmel had an improved attiny that was easier to program. No having to remove it from the test circuit 100 times. Imagine that! Thank you Mr speiss. Your channel is a huge help to the pursuit of getting things to work!!
Another direction to look into! I am 76YO and split my time too many ways. 🤣Maybe limit myself to 5 or 6 projects at a time? When I am 80YO, it may be just not drooling🤔. Another great video Andreas.
i'm in my 40s, already significant mental cycles dedicated to _drooling-prevention-subroutine._ When i'm in 80s i hope to drool at 2x existing capabilities 🤤🌊 !!
I just reached 76 yesterday. My first step into the "micro-controller-world" was designing the hardware around an Intel 8080 and the programming it using a teletype, byte for byte. Not even a floppy disc -> everything had to be stored onto a paper tape until the prom could be programmed. Still, the end product moved paper or film to and fro, accurately for a type setting machine. I am still using micro-controllers - or maybe I should say, using them again - for laser based projects. No paper tape though.
@@alistairgill5538 People might be interested in seeing videos (or just twitter updates w' photos) on your projects. I'm always amazed at the subcultures & passion that exists out there for specific sub-fields of interest. Doesn't have to be well filmed, always remember: The people interested in this subject, are likely people just like you - who film/narrate things JUST LIKE YOU TOO! they don't mind 😄
@@roidroid It has occurred to me to do something like that. I have given quite a few talks locally - 30 to 40 minutes - on various topics. Thanks for the suggestion. I'll think about it.
Seducingly pleasant presentation format. Your structuring of the video is highly enjoyable. Found myself almost not skipping back and forth because you laid it out in a sensible sequence which kept my interest up. The layout progressed nicely. Good job! Also: Great Scott is awesome.
If you ever need to measure the voltage at the supply pin, some AVR microcontrollers have the internal bandgap reference wired as an input to the analog multiplexer, which means you can measure the voltage reference voltage using the main supply voltage. This is equivalent to measuring the supply voltage with the internal bandgap reference, just with swapped values in the formula. This will spare an analog input pin. I don't remember however if the ATtiny41x have that feature.
I love the Attiny412 (correction: i used the 402) so much, I bought 100 of them. They are already in: - a DIY battery management system/balancer (one attiny for each cell) - IR remote controlled RGB D&D props - a battery adapter (DC-DC converter) for my robot vacuum so it runs off standard 18650s edit: seems like the one I used is the 402, but same things apply: cheap, only 1 programming pin, easy to use.
I use Tiny212/412 for few years and with internal 32k oscillator as main clock it takes around 6-10uA even without sleeping (of course if you enable ADC or DAC references -> hundreds of uA. Or if you forget to disable unused pins - then it's in milliamps). With MicroUpdi programmer and Microchip studio (it needs to disable "only supported devices") you can do full On chip debugging (or many others with UPDI like AVR Dx)
@@AndreasSpiess It probably isn't in the Arduino IDE. Just Microchip studio + MicroUpdi or other Microchip debugger. For Mega4809 i just created template with arduino core and I can just switch between 808/809 ... 4808/4809 (libraries are quite anoying as it doesn't have common mcu setting in the Microchip studio). And for the tiny212/412 memory is so small I almost run out of the flash just using floats (uint32_t wasn't much better) :D
Lots of goodies in this video! Those new ATTiny chips looks promising, I've heard about them but this is the first video I see them in use. Thanks for sharing!
1:43 Most power banks actually include a mode that keeps them on while using low power draw devices. It usually involves double clicking or press and holding the button that checks the battery level. EG Anker power banks will go into low draw mode by press and holding the batter check button for 3-5 seconds; then the battery light will illuminate green and it will stay on. Even the cheap battery banks I have received for free for various reasons have this feature so it may not be totally ubiquitous, but it isn't that uncommon.
Thank you so much, Andreas, for yet another inspiring video. Your channel is motivating me to live a healthier life (cut back calories, improve my condition, etc..) because I keep adding your projects to my "I MUST try this before I die" list and I'm only ever going to get through that list if I don't add years to my life. Thank you so much for motivating me.
Maybe an explanation. It would be good to declare it in the description (if it is a different chip or only a different signature that easily could be fixed during upload)
"Open source and UA-cam is the right place to foster innovation" are exactly my words! Great video and hopefully you will start to see more content from our community - AeroRust. I wish I had a bit more knowledge in electronics but I'm very comfortable with embedded software at this point and want to do exactly this - make open-source and learning materials for aerospace development.
Thank you for this video. I have been a fan of Atmel chips for many years. These new chips will be very useful. My solution to the power bank problem was to design my own power banks with an on-off switch. Then made power banks for my battery powered camping fridge (my BougeRV fridge has been in constant use for almost two years now) . I build the packs in 400W/Hr increments. I get 1 to 2 days fridge operating time out of each pack.
Can you recommend where or how to get low power BMS system for these packs? Last one I bought was off Amazon and my pack now has 2 series banks of cells that are below safe voltage (less than 1 volt) while the third bank is at 4.2 volts... the battery went dead and then I could not get it to charge... Now I know why. But I tested all the cells by charging them all and leaving them for a month, all within 0.1 volts of full which is what I measured when I took them off the charger, my meter sucks so close enough. I have also had other issues like a low max current (can't do 5 amps even with 18 cells in parallel)... even these cells can easily do 1 amp easily so that sucks. I considered using an AVR to control them but I need to find a way to kill power to the AVR when the pack goes dead so it doesn't keep draining the cells. Or do you just use a hard switch to kill all power and then make sure to shut them off when dead?
Hello Andreas, very interesting project. Where can I find the (final) schematic and the arduino code? Why do you use the battery cell anymore? In the schematic you connect the 5V to the 3,0V battery. Why? best regards Frank
Thanks Andreas. What I do with SMD chips is use one of the SMD sockets then solder the programmed chip to my board. Some chips will work with the 6 pin connector on the board but you have to be careful what pins you use. I've fixed circuits with mosfets controlling devices by using a resistor on the gate from the programmer, 10k to 100k usually work.
Great video, I gave you a like. At 9:38 EEPROM cells don't always last for 100,000 writes per memory address (location), many work on memory pages (sections), say 256 bytes in many EEPROMs but this one is only 128 bytes total, so you should experiment to find out if 100,000 writes to the first EEPROM address will wear out the first address only or its entire EEPROM in these tiny devices. 100,000 writes is guaranteed, many can last a bit more before they finally fail. But 100,000 "learning" sessions is a LOT, the USB contacts are more likely to wear out before then.
This reminds me of one important lesson my lab teacher taught me: "Is the reduction of material expense or the software's efficiency worth the R&D time?" Sometimes a quick (and ugly) solution is much better than clean code and few components. That new mindset helped me complete assignments on time, at the same time that started a trend of me doing assignments twice, once in the required way, once in my way, because I often wouldn't be satisfied by the solutions I found on the spot.
I agree: All depend on the numbers. For a small series, material cost is not the issue. But if you create an iPhone, a few cents can make a difference. Here it is a hobby, and its main product should be fun. So it might be a bit different...
I work in a company where people from long before I joined used to think like that. Now we pay a heavy price in tech debt where our old projects are almost unmaintainable. We spend days sometimes analyzing old code because when we need to make a simple change and it breaks everything. Pretty much all of the code is kept in a "functions.c" file with a lot of inline #ifdefs for product variants and a LOT of global variables that are cryptically named and reused across multiple functions and stuff like 6800 LCD display logic and switch matrix scanning mixed in with actual presentation logic. It's almost like programming in assembly but in C and the global variables are your registers or something like that (I guess maybe the guy who made that code probably learned to code in ASM before C for MCUs was even a thing, and made the jump to C but kept the same programming mindset). The same goes for the hardware as sometimes they didn't even bother connecting I2C lines to the actual I2C pins in the MCU, so then someone had to make a bitbang I2C code for it. Thankfully upper management realized how much of a problem it was causing and now we're rewriting and redesigning our products from scratch one by one
I love these new ATtinys, they are my go-to MCUs now for small tasks. Even the 202/402, I wouldn't say they're outdated, they just don't have a DAC which is an awesome feature. As for the odd fakes, my guess is that there was a mistake in production (wrong die?), and someone raided the trash can, picked up that batch and offered it for sale per the marking 😀
Very nice with the new way of programming, certainly makes hobby projects much easier. As for automatic adjustment... wouldn't it be possible to have a capacitor keep the ATTiny alive for long enough to write a new cutoff value, reset the USB and come back up with a new interval to peak at? Of course this would only work going from a longer interval to a shorter. So on first power-up it would always need to start with a long interval and wait for the first cutoff, adjust and reset the USB. You could make a switch that could discharge the capacitor if you hold it for 2-3 seconds while disconnected, so you're sure that it "starts over" if you switch between banks quicker than it can use the charge. The electronics around the uC isn't my strong point, but I love playing around with the uC software. So I'm just suggesting something I could imagine could work.
regarding the question at 8:37: To save to relevant time i would add a big capacitor on IC supply and measure the 5V, if the voltage starts to drop i would write the value to Eeprom
@sSpiess i stole this idea from a safety (not security) related project, where a brownout or total power out had to be logged. So this is kind of battle tested. The cap was in the range of 560µF but i do not remember if it was directly on 3v3 or on a higher voltage level. But this project had 2 redundant µControllers and an external memory to log this power issue. So the power draw was quite huge compared to a single µC
I have also done something like this. But i want to find out the set voltage and current in a power supply when the power goes off. So i used a large capacitor in the input and measure the voltage. So when the power goes off the voltage will reduce periodically so i can detect the voltage drop and save it to the eeprom. 😃
Great Video Andreas. I do something similar in my gaming LED controllers over on terraintronics. I use the Wemos D1 Mini as a brain, and drive a 47Ohm to GND using a mosfet as you've done. The little innovation that I love is the "count and save" you have to characterize the battery. A simple idea, but brilliant. I currently have A0 unpopulated. I think I'll update the code to check A0 on startup, and IF it's 3V3, assume it's in characterization mode.
After a severe head trauma, Great Scott, Andreas Spiess, Big Clive, and Nick from The Linux Experiment, have helped me to come back. Now I'm helping to build the AI Museum in Stockholm, Sweden =)
If I remember right ATTiny 2313, 13 and 85 supported debug wire for programming but first programming needed to do with spi and enable it. DW used the reset pin.
interesting idea.. short question. didn't you try to put a capacitor on the tiny's power line to keep it running just enough to write to eeprom after power was lost?
I think I would try to put a diode and a capacitor bigger enough (I am not sure how much) to provide power for the ATTiny so it can detect the powerbank has shut off through the GPIO and emit a signal to the current FET. (or maybe write the time to the EEPROM). I think thisway the writes to the EEPROM can be reduced.
Great video. In addition the latest ATTiny 2-series have an excellent ADC configurable up to 17 bits and can work in differential mode accepting rail voltages (direct current measurement with a shunt resistor) . Unfortunatelly the smallest in this family is 14 pin part.
Very interesting approach for you. I have great respect for both channels. I'm also a hardware design engineer. But a perfect solution would be a solution that doesn't lose any power. So I prefer to see a solution without the resistor to ground. So use a kind of buck/boost converter setup to trigger the current monitor in the power bank and release the energy to the connection that uses a small amount of current. Maybe I'm making this project more complex than needed, but that would be a perfect solution.
Well. I had some minutes to think about it. Storing energy temporarily in a coil/capacitor could be a solution, but if it stores that with 100% efficiency (which it doesn't do!), we have still a problem. What is the real energy usage (E=P*t) of the device connected on the output? If the energy usage is less than the energy that we draw each full period (Ton+Toff) from the power bank to keep it alive, than an extra resistor is still needed. Please ignore my solution 😜
This reminds me greatly of my adventures with the 10f200 (6 pin IC). "I'll start so small, it'll be easy!" oh that caused such a headache with the pin multiplexing. I had to figure out how to repurpose the /RST line as input, the other 3 GPIO pins charliplexed 6 LEDs. One cool side effect was by using the /RST like I did, the project uses no real power while off, as a micro-solar cell actually holds it in a halt state, being used as a light sensor basically. Not enough to power anything, but enough to bias an input pin.
The UPDI programming looks super convenient. I've usually been able to get away with re-flashing chips in-circuit using an SPI programmer, but I'm always holding my breath and hoping it works. Cool to see the next logical step for such an easy series of chips to program.
Another feature we need: Some power banks will give you battery voltage, say 3.7-4.1 to the usb when there is a tiny load, then turn on the booster to 5v when load increases. I would be nice to control that.
@@AndreasSpiess I'm not thinking about 5v or 12v, but rather getting a micro-watt of battery power to power a sleeping esp32 or a pir, without burning out the battery by constantly boosting it to 5v. I could power a circuit with a couple AA batteries for months, or drill a hole into the powerbank and get the 18650 power (on the safe side of the over-discharge circuit) for my micro-watt, but it would be nice to get the microwatt through the usb with the booster shut off, and then get the real 5v power when the esp32 wakes up and turns something on and we need real power. Maybe a couple AAs for the microwatt, and rechargeable powerbank for the reak power.
I use the new AVRs too, the 1614 basically has the specs of a 328p, plus it has better timers, more versatile GPIO, a DAC, and even a custom logic system that I haven’t figured out yet. But I will note that they’re a pain to use with AVR-gcc, you need to get fils out of MPLABX for it, and I couldn’t get EEPROM working since it uses a somewhat different memory address space. I use SerialUPDI instead of the arduino sketch, all it takes is modifying a USB to serial dongle. As for the older ATtiny programming problem, it’s less of an issue than you make it out to be. You can use the 4 programming pins for other things, so long as the programming process won’t interfere with them. Even the reset pin can be used as an analogue input, so long as the voltage on it doesn’t go below the going-low threshold.
Thank you for sharing your experience. I agree with your comment about the ATTINY85 (otherwise, they would not be very useful). Still, as you write, you always have to pay attention to what you connect to these pins.
Could an easier solution to both the 555 and ATtiny options be simply to create a basic buffer/psu circuit using capacitors to draw higher power very briefly and which only recharges once almost drained and would also work with all types of power banks/not need a supplement too?
I call that Bad Dreams because If i wake Up i have to repeat what i did during my sleep ... Thats working twice and to be Safe you have to think twice too. Greatz from Germany and have a nice Day opo
I thought i was buying bad power banks . Drives me nuts . Plug in something, walk away and it randomly stops charging . Ridiculous ! Thanks for solving this issue
Some time back I used a Digistump for the same purpose. It is a ready made ATiny85 board with easy programming and plugs into an USB-A connection of the powerbank. I created ~100mA over 500ms just through 2 GPIOs, with 100 Ohm to GND each. Works without magic smoke ;-).
Maybe I'm missing something but can't you just directly connect to the battery within the powerbank and draw as little current as you like? Even if the rest of the charging PCB is still active to properly charge it if needed?
@@AndreasSpiess I thought about if it's possible to connect the charger to the battery and in parallel you connect any project that needs energy to the battery aswell. With this it gets charged but for discharging you do not use the outlet of the charger (that gets shut down) but access the battery directly.
instead of using a push button, would it be an option to connect/disconnect the device multiple times to put device in 'learning mode' ? thanks for amazing video btw!
I've been looking for a small alternative for the attiny85, which I have been finding expensive and rather hard to find around here, and this video opened my eyes for this new ATtiny series
Very interesting approach! However, you could avoid the constant writing to eeprom by detecting the powerloss. A common way I do it is isolate the supply of the MCU via a diode if there is extra load on the system and add a capacitor on the supply-pin of the MCU. Then I use a pin on the MCU as detector for the powerloss by setting it up as a falling flank interrupt. This allows the fastest detection time and at this point you can store your data. You can test the timing by using an oscilloscope and setting a pin high once the storing is finished and watch this pin vs the flank of the power pin to see how long it took. If you know your power consumption including the storage needs you can calculate a capacitor required, otherwise it is easy to test with scope. Remember to use 10X probe or more to reduce load on rail.
Great video again. I love the "new" attiny series 0 and 1. 👍 In 2022, I made a small dev board with ATtiny1604 and ATtiny1614. They are superior in all aspects compared to the older Attiny.
Indeed, I saw it. This fake maybe is not a real fake as anohter commenter wrote. These chips were even sold by Mouser, etc... But of course, I do not know.
I needed a protection circuit for 12V lead battery overdischarging, but couldn't find anything, only for Li-Ion. I made a simple one with ATTiny85, similar to the circuit you made, only different purposes. I could use software serial for debugging. It consumes really low amount of power when sleeping. However this new version makes it even more interesting, thank you for the video!
Some power banks have a feature that will keep the output on without needing a minimum load. I have one with this feature, and it seems to be unadvertised. If I double-click the charge display button, it switches to this "always-on" mode.
Here's an abstract based on the transcript. I used Gemini Advanced 1.0 to create it: *Abstract* This project aims to improve upon an existing USB power bank trigger design (originally using a 555 timer) by leveraging a modern ATtiny microcontroller. Challenges in power bank behavior are addressed, primarily concerning their auto-shutoff at varying low-load thresholds. The solution employs the ATtiny to characterize power bank behavior, storing parameters in EEPROM for automatic power-on triggering to maintain operation. The project highlights the advantages of new ATtiny chips (UPDI programming, Serial.print), the adaptability of open-source hardware (Arduino Nano as a programmer), and the importance of iterative design when encountering unexpected complexities.
Thanks really enjoyed this. Not done any electronic (or even thought about) for too long now so was a nice exercise to read your circuit diagram (and pleased I still could!). I think in my own version, given the voltage input tolerance of ATTINY chips (the 85s at least) I would have experimented with a beefy capacitor on the input and use your "voltage" to look for a drop off. This way hopefully, one could cut out the need to record/time/trigger the "stimulate" and "run on air" as it were (the capacitor) when the power cuts which would hopefully be enough time to trigger/sustain the stimulate load to turn the thing on. Ideally then you'd only get a very momentary cut of power to the main device being powered. If that isn't acceptable though, could just use the cap that one time for the initial measurement, then go back to timing/triggering an early (before cut off) stimulate. I've had this cut off issue with USB lights before on power packs and indeed it's irritating so a nice idea from Great Scott to make a work around.
I kinda expected you to count the time but also have a second counter that gets reset to 0 after a few minutes of runtime. Gets counted up un init and of its at a count of 3 it tries to update the time. The new way to program the microcontrollers sounds great.
Thank you for showing the new attiny :) I am approaching a similar project with storing values before switching off the chip. Do you know how the microchip behaves, when the chip is turned off while writing to the eeprom? Or does the capacitor store enough energy to complete the writing step?
Love Microchip. I launched one of the very first high volume PIC designs in Michigan in the late 80's in the hundreds of thousands per year (PIC16C54) on vehicle remote transmitters. One Time Programmable only, but this was revolutionary then as most parts were mask ROM at the time. They even put those devices into SOT packages. They were marketed as micros but were used as "ASIC fixers" to fix small hardware bugs in complex ASICs. Cool company!
Extremely helpful. I like the supercap idea. Also you might need to tell the difference between the mains and the battery. You might could assume that you are hooked to mains unless you see the pulse which case you know you have a battery. This could also be the basis for an uninterrupted power supply circuit!
I don't know enough to properly make a development board for the 412s. Right now, the price of a 412 on a development board seem sky high. Like $12. Other mini chips like esp32 or rp2040 seem a lot cheaper. Why is that? Has the 412 not been out long enough for cloners?
Partial fake issue: the factory orders or makes a big lot of ATTiny416 chips (wafers). Then they take what they have and put them into different packagings as they need - some have 20 pins, some have 14, some have 8. The unused ports are not connected to packaging pins. Maybe the unused ports could be used as additional bit memory?
@@AndreasSpiess interesting. Did they publish wrong codes or manufatured wrong packages? The latter would be the case of putting the wrong silicon into packaging.
If i had to guess about the 'fake' chips, maybe they were flawed 416s put in a smaller package so as to not expose the non-working pins. I think they do a similar thing with CPUs, pack a number of cores and depending how many of them work, sell them as the corresponding variant. In the ATtiny case, they must've forgot to flash the correct identifier afterwards.
Actually there is no need for the voltage divider for measuring the input voltage. Modern AVR chips allow to select VCC as the ADC reference voltage, and can use the internal reference voltage (e.g. 1.024v or 1.1v) as the ADC voltage, so you can calculate the VCC using Vcc=adc_reading*Vref*1023 to get the supply voltage without using any GPIO pin and voltage divider. MegaTinyCore library comes with an example for reading the Vcc voltage and internal temperature sensor. I love the tinyAVR series and have been using it since 2017.
Love to see other approaches to one problem. Pretty cool ATTiny as well. Might use it in the future as well ;-)
Bitluni has some in depth reviews about the reasons why the attiny fits his purpose so well
Nice to see you commenting like that! You see, you are an inspiration even for old men ;-)
Hi guys. I've been using USB power banks to power my long range RF/Nano projects for years and use transistor circuitry to defeat auto-shutdown. Using RF I can not only send/receive data and reboot but also shutdown the board entirely. An Eagle pic of my pc board design:
www.4gto.com/Nano_powerbank_pcb.jpg
IMHO the CH32V003 and its siblings (CH32V203 in particular) are far more promising for the price point and size. It has far more capable peripherals, is less expensive, and also has a far more capable CPU if/when you need it!
@@MUSTARDTIGERFPV I was thinking exactly the same. Perfect for simple sensing and controlling tasks
Do you know any good free and scalable framework for controllers and sensors? I'm playing with creating my own but want to be sure I'm not reinventing the wheel
Great Scott, a guy with a Swiss accent, a vintage high tech NE555... and now ATtiny's... what an awesome Sunday morning entertainment.
Glad you enjoyed it!
😊😊😊😅😢😊😢😢@@AndreasSpiess
I think he is German, not Swiss.
@@ikemkrueger Indeed, Great Scott is from Germany. Andreas is the guy with the Swiss accent, he's definitely from Switzerland.
Who cares about his accent, he has great IDEARS 0:15. 😆
We chose to do the things we do, not because they are easy, but because we thought they were going to be easy.
Precisely. Like making children ;-)
@NomenNescio99 Even Linux exists for that very reason
So true... And I feel very identified with this, going down the Klipper way instead of sticking with Marlin for my 3D printer 😂
@AndreasSpiess making the children is the easy part. Keeping them alive and growing them up not to be assholes, is the hard part. 🤣
@@jjones503 From a male perspective!
I fiddled with AVRs in the past and wanted to store state information on a power failure. I used a diode feeding a largish cap on the power pins and monitored the incoming power before the diode for a power failure using a second diode connected to a sense pin with an interrupt set up to trigger when it went low. When the interrupt was triggered, I immediately stored the state information to the EEPROM, and the energy in the cap was enough to get that done before the AVR ran out of power. This saved needing to constantly write data to the EEPROM in case the power died, because there was quite a lot of data to store and the 100,000 cycles would be used up within a year if I kept writing that data to the EEPROM every second. Wear levelling wasn't an option.
what i was thinking, great
A good idea to avoid wearing! Here, these additional parts were not relly needed as I do not use the "calibration function" a lot.
Could you keep the uC running off a capacitor long enough to trigger a pulse, so that you don't need a battery?
Nice idea!
Because the power consumption is to little - one diode, one electrolytic capacitor and small change in code: if ADC doesn't see 5V - subtract a 'some safe amount of seconds' and save this number into EEPROM and rise the flag (to avoid any trashy values when the capacitor voltage goes down the safe voltage region) On start you can type this value into Serial for debug purpose.
CC: @AndreasSpiess
A good idea!
I was thinking this pretty much as soon, if not slightly before he introduced the battery idea, lol
and I don't even mess with any microcontroller stuff, lol
I'd look for a proper low power controller, STM32U-series or TI MSP430, that will run circles around the mA numbers from the video, and run at low input voltage. Pair it with a mF supercap and you should have plenty of run time for re-triggering and storing timing data
It’s my job to design rather sophisticated industrial controls. But, even with the best tools, good firmware and reasonable budgets, I still try to sneak in the occasional 555 and/or 2N3904/3906 (b/c I have an appreciation for the classics) and one 90 degree trace - just to drive the “electrons are going to slide off around the corner” (even at DC) crowd crazy. This probably says terrible things about me as a person, but at least I can inject a bit of harmless fun into my work. Haha Long live the (timer) King - the 555.
I agree. An electronics part that survives such a long time must be good!
You Rebel scum!
(Only joking ofcoz, Always sneak in the classics, keeping it analog "Because" we are Rebel Scum!)
😊@@AndreasSpiess
Love it, classically trained tech trolling. Been in tech for decades, in security now, I often toss out TCL and Perl scripts to mess with the younguns, they have no idea how to deal with anything but Python.
@@c1ph3rpunkto be extra naughty you could use pascal or forth or cobol, lol
latest cobol spec is from 2023, and there is a fully gnu cobol compiler! >;P
I like videos that shows how to use dedicated chips instead of using always an esp or arduino. Small projects will be cheaper and more power efficient. 👍
I agree
A dedicated chip is not necessarily more power efficient. If you put the microcontroller to sleep it consumes very little power
@@elguido Yes, but most ready-made ESP/Arduino boards have things like power LEDs, UART-USB-bridges or linear voltage regulators with pool quiescent current, which aren't really bothered by the MCUs sleep mode.
The thing I really like about these (relatively) new devices is that FINALLY we have low pin-count devices with serial peripherals. Just what you need to convert a simple sensor or actuator into a serial bus device using I2C, CAN or LIN etc. (although the latter two will also require a bus driver chip). I have waited twenty years for this day, and suggested it to Microchip on numerous occasions! Two pins for power, one for reset/programming, two for the serial bus, you still have three to connect your sensor/actuator which is plenty in most cases. The Chinese chips are presumably copies at the mask level or reverse engineered. Does not seem worth the risk when they are readily available at reasonable prices from reputable western stockists (one of which has actually popped up as an ad over this video!)
These devices are already several years old. The one used in the video is at least 4 years old already.
@@backgammonbacon Hence '(relatively)'.
Attiny's have had USI (I2C/SPI/UART) for ages, for example, attiny85 that was introduced in 2005.
@@osmanpasha_diy On the eight pin ones?
@@john_hind yep
A friend of mine approached me with an interesting ATtiny challenge. He had to develop a certain small&smart device for a musician; the ATtiny85 was the perfect companion. The challenge was to make the final fine-tuning on the field while rehearsing: how to quickly reprogram the ATtiny without dissembling or swapping the device? "Use a DIP switch or jumpers" was my spontaneous answer. I'm glad he succeeded with it with such small and spontaneous advice.
Indeed, such switches were a good idea for the ATTINY85...
You need to say AI device, not smart device. "smart" is so 2010....
@cdjxwubcyex;
And AI is so overused for many cases of natural stupidity 😅
Adding impedance to the pins AFTER the bifurcation to the ISP connection usually solves most of the issues with ISP interference.
Attiny Pin -----> ISP Header ----> Resistor ----> Peripheral. This ensures that the ISP has a lower impedance towards the ATTiny Pin. The exact value of the resistor depends on the overall circuit impedance, but I have experienced seeing anything from 10R to 22R working well for IC to IC communication.
@@cdjxwubcyex X'D
Some interesting things about the Attiny 1-series: 1. The internal oscillator is much more accurate than on the older AVR chips. 2. They support a wide voltage input range especially at lower clock rate. 3. The ADC is actually quite good (this is more subjective).
Thank you for the additional info. Indeed, I run my chip on the lowest clock speed (internal). But of course, precise timing is not a big issue in this project.
A good ADC is handy on low pin count devices like this, because you can do things like use resistor ladders to hook up a bunch of buttons or switches (DIP or otherwise) to a single pin, saving you I/O for other functions.
“If something looks simple and straightforward, it often is not.” I found this out the hard way, trying to complete a project that I thought would be finished in three months, has taken almost eight years 😂
That is a long time for a project. I admire your stamina!
@@AndreasSpiess I think the payoff will be worth it. SecureFarm, security in the back yard for the small homesteader. Whoa did I have a lot of roadblocks. Your videos helped :-)
If only more managers understood that lol. "Looks simple... it'll take me between 4 hours and 4 weeks."
s/w only I have previously said the team could have the functionality done in a month (elapsed). To have it production quality would take a bit longer.
These days I find doubling the estimate, adding the fudge factor and doubling again is still an underestimate, but then my team these days is very different standard. (Did anyone see the video add in recent months about "you too could be an embedded software developer in a few weeks [repeat embedded software developer about a hundred times]" - that's the quality of people we seem to see these days).
Please, more ATtiny stuff.
Excellent show.
Thank you!
It would be super cool if Great Scott now took your design and improved it even further.
The most epic type of battle ever
And a learning experience for is viewers😊
If they find defects or holes in each other's designs, would that make the collaboration...
Swiss Cheese?
He already commented that he might use the chip in the future. Bu probably for a different project...
Thank you for the update on the new ATtiny
My pleasure!
Nice introduction to the new ATtinys - however, regarding your criticism of the old SPI-programming interface: I never had a problem using all 5 pins (excluding reset, vcc and gnd) on the 8-pin chips with in-circuit programming. Yes, you are double-using those pins, but only during programming. And then it normally doesn't matter if you send invalid codes to an also attached SPI-slave devide, blink some LEDs or have push-buttons attached (as long as you don't press these buttons during programming).
I agree that it does not always crete issues if you pay attention what you connect to the pins. Still, I like the new method better.
Yeah, that's what I found too, just take a little care to avoid a large load to the programming pins, but like he said, the new way is a lot nicer. I found myself using the 20 pin ATTINYs when an 8 pin would do, just because I knew I wouldn't run out of pins in any case.
Both you guys have taught me so much. I love being able to take the basics of a concept, develop it into a working project and then move it onto the next level to really cement my understanding.
I always try to stand on the "shoulders of giants" ;-)
Your interface can be simplified:
- enter characterization mode if nothing is connected to the output otherwise enter supply mode
- in characterization mode, while the power supply is active keep an led on (it will switch off when power is cut indicating to the user that it is done and they can plug in their load)
- in supply mode, turn on a different led (or different color, to indicate a different mode)
This would completely free up the user to do user things in parallel =)
Detecting if output is connected requires a lot more effort, so it complicates the design
How do you plan to detect if something is connected to the output? The usb has no detect pin so one of the only ways you can do it is to measure current which itself adds complexity, requiring either a low side shunt resistor or a Hall effect current sensor.
@conorstewart2214 @osmanpasha96 Yes, a bit more complexity would be required... I was thinking on measuring current, should be the simplest approach.
Good ideas. Maybe you try it to prove if they work?
There are power banks with a low power mode that can be activated by double-clicking on some Anker products. This is required, for example, to charge True Wireless Earbuds or smart watches. Edit: It's called Trickel Charge Mode at Anker. It says that it deactivates after 2 hours of non-use. It is questionable how exactly they can measure whether this is used or not.
I accidentally discovered this, one of the charge indicator LEDs switched from blue to green when I pressed the button twice. Strangely this was not documented in the manual.
Good info. Thank you!
I have spent a lot of time using the ATTiny85 and the micronucleus bootloader to get an additional pin. They don't have full hardware uart support like these newer ones do so these look like a nice alternative as an upgrade.
Definitively, the one pin programming as well as the UART are extremely useful.
There is an 8-pin SO version of the super-cheap Risc-V CH32V003. More everything than the ATTiny for a third of the cost - not sure offhand about the sleep performance though
Another commenter also mentioned it. Did you try it with the Arduino IDE?
@@AndreasSpiessThe easy of use of the Arduino IDE is kinda wiped out by the janky harness needed to program it.
@@AndreasSpiess No - used the manufacturer's tools. I think there is now an Arduino setup for it though. Another nice thing about that MCU is it needs only one wire for programming and debug
Doing the chip 'supply shortage' these were the only cheap chips I could find, so I had to figure out how to use them, there was not a lot of youtubers using them yet. Great to see even the favorite channel is using them.
Indeed, they were available for quite some time…
Your channel and the Great Scott one are my two favourites !! Thanks a lot for sharing your knowledge
You are welcome!
Hi Andreas - great to see you getting into the ATTINYs - brilliant little chips, and Spence Kondes Core works like a charm.
One thinng about the programmer: you don't need to sacrifice an NANO: UPDI is possible with any cheap USB-2-Serial based adapter. The ones with the CH340 chips work quilte nicely and are normally a dollar a pop. One resistor between TX and RX and you're game; I did a video on that toppic some time ago.
Keep up the good work!
Indeed, you can also use an usb to serial adapter. I tried it after other commenters wrote it.
Thanks!
My project queue is so big already. Your channel keeps adding to the list. Thanks for another great video!
Here it is different: After a video, I can delete one item on my list ;-)
Why measure and store instead of just reacting? Decouple the ATtiny a big so it keeps running a tiny bit after the power-down of the battery-pack. That way when the power goes low it can record the time and trigger it again (maybe repeat a second time for more confidence).
He covered that I think: there was no easy way for the ATtiny to turn the power bank back on once it had gone into "low output" mode.
I might have missed something, but I think that was the problem.
@@tjwatts100 That was with an external power source and he talked about how it worked but he decided to go a different path.
@tjwatts100 is right: The power banks did not switch off even with the lightest power draw.
After playing around with Arduinos dor a few years, I came across this series of newer microcontrollers about 7 months ago. I use them now for all smaller projects. The required hardware for programming is so simple and cheap, and still no bootloader required. Quite accurate timers without external oscillator. I love it!
Thank you for sharing your experience!
A capacitor to delay a brown-out and a 5V input that would have down-edge triggered interrupt might save you from saving every value into EEPROM -> just write one value during IRQ just before the chip dies...
Was about to make this same comment
I agree. But it would be one part more ;-)
Great video today, I also watched Great Scott's video. BTW the debug switching was a trick I learned many years ago when I first learned to program in C, thanks for sharing! Much love, happiness, and success to you!
Indeed, the debugging trick is old. Still, beginners might not know it and it is important for such small chips.
@@AndreasSpiessMy intent was not to disparage the technique at all, it merely surprised me to hear anyone talking about it. Without tricks like that, I would still be an assembler programmer. Love your program and have been watching and enjoying my front-row seat for a long time. Thanks again Andreas for all you do!
This is exactly how my projects go. As an example Ive been trying to make a pi based nightvision camera using the Argon POD case. The goal was simple - have a no IR camer output to the PODs SPI display. After quite a bit of experimentation I sacked off the spi display for a small hdmi connected display which does exactly what I want - full screen camera - with a lot less coding than the spi display. In summary never be frighten of changing what you're doing especially of you can achieve the same goal with less hassle.
Nice story with the same learnings!
I had no idea atmel had an improved attiny that was easier to program. No having to remove it from the test circuit 100 times. Imagine that! Thank you Mr speiss. Your channel is a huge help to the pursuit of getting things to work!!
You are welcome! Indeed, removing the chip was quite anoying for me, too
Atmel is now Microchip Technology Inc.
Another direction to look into! I am 76YO and split my time too many ways. 🤣Maybe limit myself to 5 or 6 projects at a time? When I am 80YO, it may be just not drooling🤔. Another great video Andreas.
Having the choice to say "no" is very relaxing, I think. I also have to pay attention to this word...
i'm in my 40s, already significant mental cycles dedicated to _drooling-prevention-subroutine._
When i'm in 80s i hope to drool at 2x existing capabilities 🤤🌊 !!
I just reached 76 yesterday. My first step into the "micro-controller-world" was designing the hardware around an Intel 8080 and the programming it using a teletype, byte for byte. Not even a floppy disc -> everything had to be stored onto a paper tape until the prom could be programmed. Still, the end product moved paper or film to and fro, accurately for a type setting machine. I am still using micro-controllers - or maybe I should say, using them again - for laser based projects. No paper tape though.
@@alistairgill5538 People might be interested in seeing videos (or just twitter updates w' photos) on your projects. I'm always amazed at the subcultures & passion that exists out there for specific sub-fields of interest. Doesn't have to be well filmed, always remember: The people interested in this subject, are likely people just like you - who film/narrate things JUST LIKE YOU TOO! they don't mind 😄
@@roidroid It has occurred to me to do something like that. I have given quite a few talks locally - 30 to 40 minutes - on various topics. Thanks for the suggestion. I'll think about it.
Seducingly pleasant presentation format. Your structuring of the video is highly enjoyable. Found myself almost not skipping back and forth because you laid it out in a sensible sequence which kept my interest up. The layout progressed nicely. Good job!
Also: Great Scott is awesome.
Thank you for your kind words!
If you ever need to measure the voltage at the supply pin, some AVR microcontrollers have the internal bandgap reference wired as an input to the analog multiplexer, which means you can measure the voltage reference voltage using the main supply voltage. This is equivalent to measuring the supply voltage with the internal bandgap reference, just with swapped values in the formula. This will spare an analog input pin. I don't remember however if the ATtiny41x have that feature.
I did not look at the ADC (I just used it). But I once made a video abour using the internal bandgap reference of the 328P...
I love the Attiny412 (correction: i used the 402) so much, I bought 100 of them.
They are already in:
- a DIY battery management system/balancer (one attiny for each cell)
- IR remote controlled RGB D&D props
- a battery adapter (DC-DC converter) for my robot vacuum so it runs off standard 18650s
edit: seems like the one I used is the 402, but same things apply: cheap, only 1 programming pin, easy to use.
The difference seems to be that the 402 does not have a DAC. So no issue if you do not need it...
I use Tiny212/412 for few years and with internal 32k oscillator as main clock it takes around 6-10uA even without sleeping (of course if you enable ADC or DAC references -> hundreds of uA. Or if you forget to disable unused pins - then it's in milliamps). With MicroUpdi programmer and Microchip studio (it needs to disable "only supported devices") you can do full On chip debugging (or many others with UPDI like AVR Dx)
Thank you for the additional info.
Debugging is a neat feature! I did not check if it is already supported by the new Arduino IDE.
@@AndreasSpiess It probably isn't in the Arduino IDE. Just Microchip studio + MicroUpdi or other Microchip debugger. For Mega4809 i just created template with arduino core and I can just switch between 808/809 ... 4808/4809 (libraries are quite anoying as it doesn't have common mcu setting in the Microchip studio). And for the tiny212/412 memory is so small I almost run out of the flash just using floats (uint32_t wasn't much better) :D
Excellent! I've used PICs since they were first made, and this single pin programming looks to be a game changer.
But these are no PICs. They are AVRs.
Lots of goodies in this video! Those new ATTiny chips looks promising, I've heard about them but this is the first video I see them in use. Thanks for sharing!
My pleasure!
My pleasure!
1:43 Most power banks actually include a mode that keeps them on while using low power draw devices. It usually involves double clicking or press and holding the button that checks the battery level. EG Anker power banks will go into low draw mode by press and holding the batter check button for 3-5 seconds; then the battery light will illuminate green and it will stay on. Even the cheap battery banks I have received for free for various reasons have this feature so it may not be totally ubiquitous, but it isn't that uncommon.
never tried that. mostly some LED turns on by long holding the button
Other commenters also mentioned this function. It seems to be common on the Anker brand. Unfortunately, it does not work on my 2 power banks :-(
Thanks Andreas, this was another great video! You’ re a star, keep being awesome!
My pleasure!
Thank you so much, Andreas, for yet another inspiring video. Your channel is motivating me to live a healthier life (cut back calories, improve my condition, etc..) because I keep adding your projects to my "I MUST try this before I die" list and I'm only ever going to get through that list if I don't add years to my life. Thank you so much for motivating me.
We all live longer these days. And you will get a lot of time if you will be retired ;-)
Shortage perhaps lead to those chips, where they chose to package a different die in the 8 pin package..
Maybe an explanation. It would be good to declare it in the description (if it is a different chip or only a different signature that easily could be fixed during upload)
First I thought the sound of Scott´s voice is imitated intentionally and I was waiting for mocked intro -> Leeet´s get started :)
Actually, we have a similar "basic language" that creates our accent...
This was such an amazing demonstration. Thank you for an elaborate video. Because of this I have learned a completely new thing tonight.
Wonderful!
Great way to start the week! I love these kinds of videos, thank you for sharing
My pleasure!
I love the ATTiny. Using them for many years. Always having a lot of them in stock for new projects. Did not know about the new ones!
I am sure you will like them, too!
"Open source and UA-cam is the right place to foster innovation" are exactly my words!
Great video and hopefully you will start to see more content from our community - AeroRust.
I wish I had a bit more knowledge in electronics but I'm very comfortable with embedded software at this point and want to do exactly this - make open-source and learning materials for aerospace development.
I just googled. The only time I had to do with your industry is when I had a project at Emirates Airways...
Thank you for this video. I have been a fan of Atmel chips for many years. These new chips will be very useful.
My solution to the power bank problem was to design my own power banks with an on-off switch.
Then made power banks for my battery powered camping fridge (my BougeRV fridge has been in constant use for almost two years now) .
I build the packs in 400W/Hr increments. I get 1 to 2 days fridge operating time out of each pack.
Your packs are probably a bit bigger than mine ;-) Mine would not drive a fridge for a long time.
Can you recommend where or how to get low power BMS system for these packs? Last one I bought was off Amazon and my pack now has 2 series banks of cells that are below safe voltage (less than 1 volt) while the third bank is at 4.2 volts... the battery went dead and then I could not get it to charge... Now I know why. But I tested all the cells by charging them all and leaving them for a month, all within 0.1 volts of full which is what I measured when I took them off the charger, my meter sucks so close enough. I have also had other issues like a low max current (can't do 5 amps even with 18 cells in parallel)... even these cells can easily do 1 amp easily so that sucks.
I considered using an AVR to control them but I need to find a way to kill power to the AVR when the pack goes dead so it doesn't keep draining the cells. Or do you just use a hard switch to kill all power and then make sure to shut them off when dead?
Great project!
Interesting new chip, that can give new possibilities for projects.
Thanks for sharing your experience with All of us 👍😃
My pleasure!
Hello Andreas,
very interesting project. Where can I find the (final) schematic and the arduino code?
Why do you use the battery cell anymore?
In the schematic you connect the 5V to the 3,0V battery. Why?
best regards
Frank
I did not publish the code or the diagram becasue it is very simple. I removed the battery and powered the chip directly from the power bank.
Thanks Andreas.
What I do with SMD chips is use one of the SMD sockets then solder the programmed chip to my board. Some chips will work with the 6 pin connector on the board but you have to be careful what pins you use. I've fixed circuits with mosfets controlling devices by using a resistor on the gate from the programmer, 10k to 100k usually work.
Thank you for your tips! I also used SMD socket for programming. However, I found it easier to program and test the chips in the real environment.
After this video I need to search the web for some opensource powerbank project capable of USB PD charging. Great work, have a nice day!
I am pretty sure you will find one.
Omg !! Clash of TITANS 🤩🤩! Two of my favorite UA-camrs !
No clash. Collaboration ;-)
Great video, I gave you a like. At 9:38 EEPROM cells don't always last for 100,000 writes per memory address (location), many work on memory pages (sections), say 256 bytes in many EEPROMs but this one is only 128 bytes total, so you should experiment to find out if 100,000 writes to the first EEPROM address will wear out the first address only or its entire EEPROM in these tiny devices. 100,000 writes is guaranteed, many can last a bit more before they finally fail. But 100,000 "learning" sessions is a LOT, the USB contacts are more likely to wear out before then.
Thank you for the "like". Indeed, EEPROM wearing is probably not an issue for this application.
there's 1 rewrite per second, so that's. 100k sessions / (number of seconds measured), bringing it down to a much lower 100s or 1000s of sessions
This reminds me of one important lesson my lab teacher taught me: "Is the reduction of material expense or the software's efficiency worth the R&D time?" Sometimes a quick (and ugly) solution is much better than clean code and few components. That new mindset helped me complete assignments on time, at the same time that started a trend of me doing assignments twice, once in the required way, once in my way, because I often wouldn't be satisfied by the solutions I found on the spot.
I agree: All depend on the numbers. For a small series, material cost is not the issue. But if you create an iPhone, a few cents can make a difference.
Here it is a hobby, and its main product should be fun. So it might be a bit different...
I work in a company where people from long before I joined used to think like that. Now we pay a heavy price in tech debt where our old projects are almost unmaintainable. We spend days sometimes analyzing old code because when we need to make a simple change and it breaks everything. Pretty much all of the code is kept in a "functions.c" file with a lot of inline #ifdefs for product variants and a LOT of global variables that are cryptically named and reused across multiple functions and stuff like 6800 LCD display logic and switch matrix scanning mixed in with actual presentation logic. It's almost like programming in assembly but in C and the global variables are your registers or something like that (I guess maybe the guy who made that code probably learned to code in ASM before C for MCUs was even a thing, and made the jump to C but kept the same programming mindset). The same goes for the hardware as sometimes they didn't even bother connecting I2C lines to the actual I2C pins in the MCU, so then someone had to make a bitbang I2C code for it. Thankfully upper management realized how much of a problem it was causing and now we're rewriting and redesigning our products from scratch one by one
I love these new ATtinys, they are my go-to MCUs now for small tasks. Even the 202/402, I wouldn't say they're outdated, they just don't have a DAC which is an awesome feature. As for the odd fakes, my guess is that there was a mistake in production (wrong die?), and someone raided the trash can, picked up that batch and offered it for sale per the marking 😀
Somebody wrote that it was a mistake Microchip made and even Mouser had them on sale ;-)
Very nice with the new way of programming, certainly makes hobby projects much easier.
As for automatic adjustment... wouldn't it be possible to have a capacitor keep the ATTiny alive for long enough to write a new cutoff value, reset the USB and come back up with a new interval to peak at?
Of course this would only work going from a longer interval to a shorter.
So on first power-up it would always need to start with a long interval and wait for the first cutoff, adjust and reset the USB.
You could make a switch that could discharge the capacitor if you hold it for 2-3 seconds while disconnected, so you're sure that it "starts over" if you switch between banks quicker than it can use the charge.
The electronics around the uC isn't my strong point, but I love playing around with the uC software. So I'm just suggesting something I could imagine could work.
Best is always to try it. These powerbanks are quite tricky...
regarding the question at 8:37: To save to relevant time i would add a big capacitor on IC supply and measure the 5V, if the voltage starts to drop i would write the value to Eeprom
Good idea!
@sSpiess i stole this idea from a safety (not security) related project, where a brownout or total power out had to be logged. So this is kind of battle tested. The cap was in the range of 560µF but i do not remember if it was directly on 3v3 or on a higher voltage level. But this project had 2 redundant µControllers and an external memory to log this power issue. So the power draw was quite huge compared to a single µC
I have also done something like this.
But i want to find out the set voltage and current in a power supply when the power goes off.
So i used a large capacitor in the input and measure the voltage.
So when the power goes off the voltage will reduce periodically so i can detect the voltage drop and save it to the eeprom.
😃
Good idea!
Great Video Andreas. I do something similar in my gaming LED controllers over on terraintronics. I use the Wemos D1 Mini as a brain, and drive a 47Ohm to GND using a mosfet as you've done. The little innovation that I love is the "count and save" you have to characterize the battery. A simple idea, but brilliant. I currently have A0 unpopulated. I think I'll update the code to check A0 on startup, and IF it's 3V3, assume it's in characterization mode.
I am not sure if the 3.3V method works. I only have to press the button if I know I use a different power bank.
After a severe head trauma, Great Scott, Andreas Spiess, Big Clive, and Nick from The Linux Experiment, have helped me to come back. Now I'm helping to build the AI Museum in Stockholm, Sweden =)
Excellent! Good luck!
If I remember right ATTiny 2313, 13 and 85 supported debug wire for programming but first programming needed to do with spi and enable it. DW used the reset pin.
I thought that DebugWire only was supported by the Atmel programmers. At least, I never saw it with the Arduino IDE.
interesting idea.. short question. didn't you try to put a capacitor on the tiny's power line to keep it running just enough to write to eeprom after power was lost?
I am sure this could be done. But it would need two more parts...
I think I would try to put a diode and a capacitor bigger enough (I am not sure how much) to provide power for the ATTiny so it can detect the powerbank has shut off through the GPIO and emit a signal to the current FET. (or maybe write the time to the EEPROM). I think thisway the writes to the EEPROM can be reduced.
Good idea!
Great use of Artificial Intelligence! You're really making that machine learn. What a virtual reality we live in!
Great video. In addition the latest ATTiny 2-series have an excellent ADC configurable up to 17 bits and can work in differential mode accepting rail voltages (direct current measurement with a shunt resistor) . Unfortunatelly the smallest in this family is 14 pin part.
I also was looking for the -2 series and did not find a lot of chips available. This is why I did not mention them.
Very interesting approach for you. I have great respect for both channels. I'm also a hardware design engineer. But a perfect solution would be a solution that doesn't lose any power. So I prefer to see a solution without the resistor to ground. So use a kind of buck/boost converter setup to trigger the current monitor in the power bank and release the energy to the connection that uses a small amount of current. Maybe I'm making this project more complex than needed, but that would be a perfect solution.
Well. I had some minutes to think about it. Storing energy temporarily in a coil/capacitor could be a solution, but if it stores that with 100% efficiency (which it doesn't do!), we have still a problem. What is the real energy usage (E=P*t) of the device connected on the output? If the energy usage is less than the energy that we draw each full period (Ton+Toff) from the power bank to keep it alive, than an extra resistor is still needed. Please ignore my solution 😜
This reminds me greatly of my adventures with the 10f200 (6 pin IC). "I'll start so small, it'll be easy!" oh that caused such a headache with the pin multiplexing. I had to figure out how to repurpose the /RST line as input, the other 3 GPIO pins charliplexed 6 LEDs. One cool side effect was by using the /RST like I did, the project uses no real power while off, as a micro-solar cell actually holds it in a halt state, being used as a light sensor basically. Not enough to power anything, but enough to bias an input pin.
Indeed, 6pins is not a lot for a microprocessor!
The UPDI programming looks super convenient. I've usually been able to get away with re-flashing chips in-circuit using an SPI programmer, but I'm always holding my breath and hoping it works. Cool to see the next logical step for such an easy series of chips to program.
I agree, it is much simpler!
Another feature we need: Some power banks will give you battery voltage, say 3.7-4.1 to the usb when there is a tiny load, then turn on the booster to 5v when load increases. I would be nice to control that.
If you need variable voltage, I would go with USB-C PD. There, you can ask for a big variety of voltages up to 20V
@@AndreasSpiess I'm not thinking about 5v or 12v, but rather getting a micro-watt of battery power to power a sleeping esp32 or a pir, without burning out the battery by constantly boosting it to 5v. I could power a circuit with a couple AA batteries for months, or drill a hole into the powerbank and get the 18650 power (on the safe side of the over-discharge circuit) for my micro-watt, but it would be nice to get the microwatt through the usb with the booster shut off, and then get the real 5v power when the esp32 wakes up and turns something on and we need real power. Maybe a couple AAs for the microwatt, and rechargeable powerbank for the reak power.
I use the new AVRs too, the 1614 basically has the specs of a 328p, plus it has better timers, more versatile GPIO, a DAC, and even a custom logic system that I haven’t figured out yet. But I will note that they’re a pain to use with AVR-gcc, you need to get fils out of MPLABX for it, and I couldn’t get EEPROM working since it uses a somewhat different memory address space. I use SerialUPDI instead of the arduino sketch, all it takes is modifying a USB to serial dongle. As for the older ATtiny programming problem, it’s less of an issue than you make it out to be. You can use the 4 programming pins for other things, so long as the programming process won’t interfere with them. Even the reset pin can be used as an analogue input, so long as the voltage on it doesn’t go below the going-low threshold.
Thank you for sharing your experience.
I agree with your comment about the ATTINY85 (otherwise, they would not be very useful). Still, as you write, you always have to pay attention to what you connect to these pins.
Could an easier solution to both the 555 and ATtiny options be simply to create a basic buffer/psu circuit using capacitors to draw higher power very briefly and which only recharges once almost drained and would also work with all types of power banks/not need a supplement too?
I do not know. Maybe you try it and report back?
As a machinery Engineer, i find these videos fun to watch
Thank you!
That fact, after you had a good sleep - suddenly you have all the answers. Our biggest enemy is our tired brain.
I agree!
When you have thought yourself into a corner, you have to wait for the paint to dry.
This so true. I often go to bed with an open issue, no solution to a problem. Next day, as by magic, I know what to do.
@@BerndFelsche... no need to wait for the paint to dry if you are Tom (Tom and Jerry). You just paint a door on the wall, open it and exit.
I call that Bad Dreams because If i wake Up i have to repeat what i did during my sleep ... Thats working twice and to be Safe you have to think twice too.
Greatz from Germany
and have a nice Day
opo
I thought i was buying bad power banks . Drives me nuts . Plug in something, walk away and it randomly stops charging . Ridiculous !
Thanks for solving this issue
If it has more than one port, try different ports
Indeed, it was astonishing to me, too.
These new ATtinys look awesome: thanks for the update good sir 👍😀
Glad you like them!
The AT tiny is a wonderful chip! Perfect for very simple tasks!
I agree!
Sometimes bad batches get out into the "aftermarket" and get sold whoknowswhere. That could be the case for those t416 vs t412.
Maybe that is the reason...
Some time back I used a Digistump for the same purpose. It is a ready made ATiny85 board with easy programming and plugs into an USB-A connection of the powerbank. I created ~100mA over 500ms just through 2 GPIOs, with 100 Ohm to GND each. Works without magic smoke ;-).
Cool!
Maybe I'm missing something but can't you just directly connect to the battery within the powerbank and draw as little current as you like? Even if the rest of the charging PCB is still active to properly charge it if needed?
I do not understand your proposal. But most powerbanks switch off if you only draw a small current (most of our projects are low-power).
@@AndreasSpiess I thought about if it's possible to connect the charger to the battery and in parallel you connect any project that needs energy to the battery aswell. With this it gets charged but for discharging you do not use the outlet of the charger (that gets shut down) but access the battery directly.
@@MaxDiscere Most banks stop the output when they are charged. Only very few continue 😞
instead of using a push button, would it be an option to connect/disconnect the device multiple times to put device in 'learning mode' ? thanks for amazing video btw!
Also a good idea. But then you would need a way to keep the time between the insertions.
Thanks Andreas! Great video! I learn so much from you and Great Scott :)
Glad you enjoyed it!
At 11:28, the 47kΩ resistor added to D6 is a pull-up or pull-down?
Thank you for the great video!
I've been looking for a small alternative for the attiny85, which I have been finding expensive and rather hard to find around here, and this video opened my eyes for this new ATtiny series
None. The resistor is between the two boards.
Very interesting approach!
However, you could avoid the constant writing to eeprom by detecting the powerloss. A common way I do it is isolate the supply of the MCU via a diode if there is extra load on the system and add a capacitor on the supply-pin of the MCU. Then I use a pin on the MCU as detector for the powerloss by setting it up as a falling flank interrupt. This allows the fastest detection time and at this point you can store your data. You can test the timing by using an oscilloscope and setting a pin high once the storing is finished and watch this pin vs the flank of the power pin to see how long it took. If you know your power consumption including the storage needs you can calculate a capacitor required, otherwise it is easy to test with scope. Remember to use 10X probe or more to reduce load on rail.
I agree, this could be done. But it would add 2 more parts... A good idea for other applications!
@@AndreasSpiess A capacitor on the supply pin is a minimum though, and always recommended.
Great video again. I love the "new" attiny series 0 and 1. 👍
In 2022, I made a small dev board with ATtiny1604 and ATtiny1614. They are superior in all aspects compared to the older Attiny.
Thank you for sharing your experience!
Asianometry did a great Video about fake ICs and recycled ICs
Indeed, I saw it. This fake maybe is not a real fake as anohter commenter wrote. These chips were even sold by Mouser, etc... But of course, I do not know.
I needed a protection circuit for 12V lead battery overdischarging, but couldn't find anything, only for Li-Ion.
I made a simple one with ATTiny85, similar to the circuit you made, only different purposes. I could use software serial for debugging. It consumes really low amount of power when sleeping.
However this new version makes it even more interesting, thank you for the video!
A good idea to use an ATTINY for such a project!
Some power banks have a feature that will keep the output on without needing a minimum load. I have one with this feature, and it seems to be unadvertised. If I double-click the charge display button, it switches to this "always-on" mode.
Others also described this function. I did not know and mine ddo not have it. So, as you write, this function is unadvertised :-(
Here's an abstract based on the transcript. I used Gemini Advanced 1.0 to create it:
*Abstract*
This project aims to improve upon an existing USB power bank trigger
design (originally using a 555 timer) by leveraging a modern ATtiny
microcontroller. Challenges in power bank behavior are addressed,
primarily concerning their auto-shutoff at varying low-load
thresholds. The solution employs the ATtiny to characterize power bank
behavior, storing parameters in EEPROM for automatic power-on
triggering to maintain operation. The project highlights the
advantages of new ATtiny chips (UPDI programming, Serial.print), the
adaptability of open-source hardware (Arduino Nano as a programmer),
and the importance of iterative design when encountering unexpected
complexities.
Thanks really enjoyed this. Not done any electronic (or even thought about) for too long now so was a nice exercise to read your circuit diagram (and pleased I still could!). I think in my own version, given the voltage input tolerance of ATTINY chips (the 85s at least) I would have experimented with a beefy capacitor on the input and use your "voltage" to look for a drop off. This way hopefully, one could cut out the need to record/time/trigger the "stimulate" and "run on air" as it were (the capacitor) when the power cuts which would hopefully be enough time to trigger/sustain the stimulate load to turn the thing on. Ideally then you'd only get a very momentary cut of power to the main device being powered. If that isn't acceptable though, could just use the cap that one time for the initial measurement, then go back to timing/triggering an early (before cut off) stimulate.
I've had this cut off issue with USB lights before on power packs and indeed it's irritating so a nice idea from Great Scott to make a work around.
Indeed, a cap would power the ATTINY for a moment to save the value in EEPROM.
@@AndreasSpiess surely flipping a pin to get the power going again though would be even faster... then just keep in RAM
@@AndreasSpiess really does make me want to experiment to see what the art of the possible is...
I kinda expected you to count the time but also have a second counter that gets reset to 0 after a few minutes of runtime. Gets counted up un init and of its at a count of 3 it tries to update the time.
The new way to program the microcontrollers sounds great.
That could for sure be included in the sketch.
@@AndreasSpiess could also over engineer it with a buffer battery or so...
Thank you for showing the new attiny :)
I am approaching a similar project with storing values before switching off the chip. Do you know how the microchip behaves, when the chip is turned off while writing to the eeprom? Or does the capacitor store enough energy to complete the writing step?
You can increase the value of the cap to make sure this does not happen. But it will be a very rare event in my setup.
Love Microchip. I launched one of the very first high volume PIC designs in Michigan in the late 80's in the hundreds of thousands per year (PIC16C54) on vehicle remote transmitters. One Time Programmable only, but this was revolutionary then as most parts were mask ROM at the time. They even put those devices into SOT packages. They were marketed as micros but were used as "ASIC fixers" to fix small hardware bugs in complex ASICs. Cool company!
I learned about the first steps of Microchip from an interview on the Amphour podcast (with the former CEO). Very interesting!
Extremely helpful. I like the supercap idea. Also you might need to tell the difference between the mains and the battery. You might could assume that you are hooked to mains unless you see the pulse which case you know you have a battery. This could also be the basis for an uninterrupted power supply circuit!
Good ideas for a second revision!
Ok the one pin program thing of the new chip actually sounds super cool and useful :O
It is!
I don't know enough to properly make a development board for the 412s. Right now, the price of a 412 on a development board seem sky high. Like $12. Other mini chips like esp32 or rp2040 seem a lot cheaper. Why is that? Has the 412 not been out long enough for cloners?
I do not know. As shown, I just use a small PCB for a few cents.
Partial fake issue: the factory orders or makes a big lot of ATTiny416 chips (wafers). Then they take what they have and put them into different packagings as they need - some have 20 pins, some have 14, some have 8. The unused ports are not connected to packaging pins. Maybe the unused ports could be used as additional bit memory?
Another commenters wrote that Microchip made an error with these codes and even RS components sold them...
@@AndreasSpiess interesting. Did they publish wrong codes or manufatured wrong packages? The latter would be the case of putting the wrong silicon into packaging.
@@ok4rm Just the wrong code on the chip.
If i had to guess about the 'fake' chips, maybe they were flawed 416s put in a smaller package so as to not expose the non-working pins. I think they do a similar thing with CPUs, pack a number of cores and depending how many of them work, sell them as the corresponding variant. In the ATtiny case, they must've forgot to flash the correct identifier afterwards.
It seems they are 412s with a wrong code. So they should be ok for Makers.
Love your spicy humor in this one. I wanted to build such a device like GreatScott, maybe it will be two now. :D
Thank you!
And abter building both, you can dedide which one you like better ;-)
Actually there is no need for the voltage divider for measuring the input voltage. Modern AVR chips allow to select VCC as the ADC reference voltage, and can use the internal reference voltage (e.g. 1.024v or 1.1v) as the ADC voltage, so you can calculate the VCC using Vcc=adc_reading*Vref*1023 to get the supply voltage without using any GPIO pin and voltage divider. MegaTinyCore library comes with an example for reading the Vcc voltage and internal temperature sensor. I love the tinyAVR series and have been using it since 2017.
Did you see that I powered the ATTINY with a 3V coin cell and wanted to measure the 5V of the power bank?