OLED USB Voltage and Current Meter - UPDATED!

These devices can be bought for a few Euros, but I'm a DIYer and wanted to try to make it work with a small OLED display, an ATtiny85 microcontroller and a few passive components.
These devices can be bought for a few Euros, but I'm a DIYer and wanted to try to make it work with a small OLED display, an ATtiny85 microcontroller and a few passive components.
Thanks to these libraries ,TinySSD1306 and TinyWireM, to manage the display functions through the I2C interface and effective smoothing routine, all found on the net, I didn’t get a precision instrument but a result I find interesting.
The basic idea is to read the voltage drop across a low value resistor in series with the load on the ground side, due to the Attiny85 ADC, set as Unipolar Differential Conversion mode, 20x gain, Vref 1.1V internal, to calculate the current through the load.
With a 0.1 Ohm Rsense you can read a maximum current of about 500 mA with a resolution of 10 mA before saturating the ADC input. For higher currents the ADC is set for a unitary gain, a kind of autorange.
The maximum reading can be 10 A but the Rsense dissipation and the USB connectors current capacity are to be considered, so I think that 1 A is quiet enough.
To read the voltage the ADC is set as Single Ended Conversion mode and the input voltage divider is set at Vcc level from vccOut pin, which remains grounded during the current measurement.
The current and voltage’s reading occurs sequentially within the Loop with a delay, determining the number of readings, which basically depends on the display routine. The smoothing function helps to have a more stable data visualization. Accuracy also depends on the actual Vref and voltage divider values, which can be experimentally varied to improve.
UPDATE 13-02-2016
- Added a 3.3 Volt voltage regulator to isolate the microcontroller power supply from the usb Vcc bus, improving the internal reference voltage stability and thus the precision of the measurement.
- Added a mosfet to drive the voltage divider and calculated it again to obtain a useful measurement range from 4.00 to 6.00 Volt (a screenshot is attached to better explain the operation).
- Added the measurement of instantaneous power (Watt) and total electric charge (mAh).
- Some minor code fixes.
More details in the code comments and in the Attiny85 datasheet.
The code has been written using Arduino IDE 1.6.6 plus ATtiny Boards Manager and loaded via USBasp.
I'll attach some pictures, schematics, libraries, the sketch and the firmware of the project.
Best regards, Anto
Discussie (4 opmerking(en))
locomotiva64 3 maanden geleden
I made the circuit and uploaded the sketch.
I power the circuit, the display always shows 1.13V.
the supply voltage is 5v.
Where did I go wrong?
thanks, Floriano
anto 3 maanden geleden
thank you for your interest in my project. It is very old, almost 10 years and I would need some time to recreate the working environment. In the meantime, Arduino IDE has reached version 2.3.4 and the core for ATtiny is also out of date. This could create some problems, also because I don't know your current configuration. In the first step, I would like to ask you if you have set the clock frequency to 8MHz, either through FUSE or the appropriate option in the Arduino IDE. By default, the clock of the ATtiny85 is 1MHz.
I hope this helps in some way.
Anto
Noob Sam 2 jaar geleden
anto 2 jaar geleden
Spyros mr Loukakis 7 jaar geleden
I have stuck to programing the Attiny I have use anything and digispark board but I can
How to do. ...?
Spyros mr Loukakis 8 jaar geleden
anto 5 jaar geleden
Anto
Anil K Sethi 5 jaar geleden
ALSO - if ou EVER need help making a PCB for any of your projects, i will help you make a PCB ALL FOR FREE !
you would get the PCB's in batches of 5 or 10 and would only need to pay for the cost of the PCB's from the manufacturer that i use (elecrow.com) and then sit back and wait for your PCB'S to arrive !
or if you need me to solder SMD parts, id ship the PCB's to me, solder the parts, then ship it to you :)
Anil K Sethi 5 jaar geleden
really wanted to say thank so very very much for the reply, i am truly grateful !!!
My skills are really rudimentary for Arduino but if tutorials like yours are clearly written, have the FULL code listed and/or downloadable, i can follow instructions to the letter and get by, i am really trying to understand the arduino code but its really difficult for me at present (under a LOT of hourly pain killers..)
So i must congratulate you on the b-e-a-utifully written tutorials youve made that go to inspite and help folks like me, i make it a point to always thank people like you who have the knowledge and ability to write such awesome pages on the internet !!!
Also as for the commercial product, i have some of those and sad to say they are way too big for my use in my project.
My project box is 60x36x26mm so its a tiny space to incorporate this tiny voltmeter - also
I LOVE SMD SOLDERING - if i have a PCB made up, i would always use SMD Components, i can solder down to 0402 with the help of a magnifier, but can solder 0603 parts without a magnifier.
The Atmel microcontroller i'd end up using, like a dead-bug way, would be the SMD Atmega328P-AU
i also dont have that tiny OLED yet either, its in the post, so when it arrives i will try your suggesstions and probably show you my progress too if you'd like :)
But, once again, i cannot thank you enough, there are times when words just arnt enough !!!
Keep up the most-excellent & inspiring tutorials !!
anto 5 jaar geleden
thank you for your interest in my project!
The display you've chosen is similar to mine ( the I2C one, with four pins),
but the resolution is lower (70 x 40 instead of 128 x 64) and the library used
does not handle it correctly. Unfortunately I don't have a display of this type
to try any changes to suggest you.
Regarding the code, to display only voltage and current, simply comment on the lines
relating to Power value and mAh value, just before the end of the Loop.
To do this, you need to be able to modify the code (it's a sketch for Arduino IDE),
recompile it and program the ATtiny85 microcontroller (I don't know your skills!).
In the end, this project is pretty nice, but has been conceived as it is, as a simple USB meter.
For your needs you could perhaps consider a very interesting commercial product like this one:
https://it.aliexpress.com/item/32824062417.html?spm=a2g0y.search0104.3.9.46715ac10C2ANE&ws_ab_test=searchweb0_0%2Csearchweb201602_6_10065_10068_319_317_10696_10084_453_10083_454_10618_10304_10307_10820_10821_537_10302_536_10843_10059_10884_10887_321_322_10103%2Csearchweb201603_52%2CppcSwitch_0&algo_expid=048f1342-793d-4e59-8dca-4f30c2b3685a-1&algo_pvid=048f1342-793d-4e59-8dca-4f30c2b3685a
I hope this helped in some way!
Best regards,
Anto
Anil K Sethi 5 jaar geleden
just wanted to say thank you so very much for making this project open source and for the time taken to propely document it and have it available most importantly with the code and schematic !
You are AWESOME !
1 Quick question, can i use a really tiny OLED that has only just started production these days, its really small, 70x40:
https://www.aliexpress.com/item/Highlight-0-42-inch-OLED-Display-Screen-LCD-Module-72-40-OLED-Module-IIC-SPI-Interface/33008298116.html?spm=2114.search0104.3.3.1f542648ofCZv1&ws_ab_test=searchweb0_0,searchweb201602_6_10065_10130_10068_10547_319_317_10548_10696_10192_10190_453_10084_454_10083_10618_10307_10820_10301_10821_10303_537_536_10059_10884_10887_321_322_10103,searchweb201603_52,ppcSwitch_0&algo_expid=2bf5646c-c2e5-4397-963c-8223f95d1880-0&algo_pvid=2bf5646c-c2e5-4397-963c-8223f95d1880
Sorry for the long link, i dont know how to shorten these lol
What would i need to change in the code, could you kindly help supply the code to help display just the voltage and current in the most simplest way because the OLED is so small, only limited data will be displayed
This is because im wanting to make this into an existing tool i made, really simple MT3608 adjustable DC to DC step up converter and i wanted this project to display the output voltage and current.
the same i wanted to incorporate this into a few other DC to DC converter projects, all only upto 5amps, probably wont get any higher and maybe upto 30 volts max for the voltage reading.
Would you be able to help please please ?
the reason why i need this tiny OLED is because i will make a homebrew PCB for it and space is severely LIMITED :(
No rush at all, please take your time, id be extremely grateful for the help
PS i use cadsoft Eagle for my homebrew PCB's
Thanks loads in advance, you are my HERO !!!!
Spyros mr Loukakis 8 jaar geleden
anto 8 jaar geleden
the code can display up to 9999mA (10A). But if you really need to measure larger values, I don't think that this project is the right way, because it should be completely revised. It was indeed designed to measure the small current of typical USB devices like smartphones, hard drives and so on. IMHO you might consider tu use a DC Voltmeter Ammeter readily available on eBay like this
http://www.ebay.it/itm/DC-100V-50A-Voltmeter-Ammeter-Red-Green-LED-Dual-Digital-Volt-Meter-Gauge-TE525-/222426150037?hash=item33c9a1b495:g:DFoAAOSwuxFYtxGK (search for DC Voltmeter Ammeter if the link is broken). I hope it can be useful,
Anto
Spyros mr Loukakis 8 jaar geleden
The code is the same.?
Regards
Spyros
anto 8 jaar geleden
the current reading depends on the value of R1 (0.1 ohm). With a value of 0.01 ohm you can theoretically read up to 100 amps, but not through the USB connectors! You'd need a current sense resistor like this and very strong terminals.
http://www.mouser.it/ProductDetail/Ohmite/TGHGCR0100FE/?qs=sGAEpiMZZMtlleCFQhR
I hope this helped somehow,
Anto