├── .gitattributes ├── .gitignore └── BatteryTesterAttiny.ino /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear on external disk 35 | .Spotlight-V100 36 | .Trashes 37 | 38 | # Directories potentially created on remote AFP share 39 | .AppleDB 40 | .AppleDesktop 41 | Network Trash Folder 42 | Temporary Items 43 | .apdisk 44 | -------------------------------------------------------------------------------- /BatteryTesterAttiny.ino: -------------------------------------------------------------------------------- 1 | /* BatteryTesterAttiny.ino - 2 | 2015 Copyright (c) Andreas Spiess All right reserved. 3 | 4 | Author: Andreas Spiess 5 | 6 | This program is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | */ 17 | 18 | #include 19 | #include 20 | 21 | // ATtiny Pin 5 = SDA ATtiny Pin 6 = (D1) to LED2 22 | // ATtiny Pin 7 = SCK ATtiny Pin 8 = VCC (2.7-5.5V) 23 | 24 | #define FET 1 // ATtiny Pin 6 25 | #define ADCVOLT A2 // ATtiny Pin 3 26 | #define ADCCURRENT A3 // ATtiny Pin 2 27 | 28 | const float FACTOR = 2.2; // Adjust for 2:1 Voltage divider and internal reference 29 | 30 | 31 | int emptyRaw ; 32 | int emptyOld ; 33 | float empty ; 34 | int loadRaw ; 35 | int currRaw ; 36 | float load ; 37 | float curr ; 38 | int emptySum; 39 | int loadSum; 40 | 41 | 42 | void setup() { 43 | analogReference(INTERNAL); // use precise internal reference 44 | 45 | OzOled.init(); //initialze OLED display 46 | 47 | OzOled.clearDisplay(); //clear the screen and set start position to top left corner 48 | OzOled.setNormalDisplay(); //Set display to Normal mode 49 | 50 | OzOled.sendCommand(0xA1); // set Orientation 51 | OzOled.sendCommand(0xC8); 52 | 53 | pinMode(FET, OUTPUT); 54 | } 55 | 56 | void loop() { 57 | 58 | digitalWrite(FET, LOW); 59 | 60 | // wait till value stable 61 | do { 62 | emptyOld = emptyRaw; 63 | emptyRaw = analogRead(ADCVOLT); 64 | } while (abs(emptyRaw - emptyOld) > 3); 65 | 66 | // Average over 10 cycles 67 | emptySum = 0; 68 | for (int i = 0; i < 10; i++) { 69 | emptySum = emptySum + analogRead(ADCVOLT); 70 | delay(1); 71 | } 72 | empty = emptySum / 10230.0 * FACTOR; 73 | digitalWrite(FET, HIGH); // switch load on 74 | 75 | 76 | do { 77 | emptyOld = loadRaw; 78 | loadRaw = analogRead(ADCVOLT); 79 | } while (abs(loadRaw - emptyOld) > 3); 80 | 81 | currRaw = analogRead(ADCCURRENT); 82 | curr = currRaw * 1.1 / 1023.0; 83 | 84 | // Average over 10 cycles 85 | loadSum = 0; 86 | for (int i = 0; i < 10; i++) { 87 | loadSum = loadSum + analogRead(ADCVOLT); 88 | delay(1); 89 | } 90 | load = loadSum / 10230.0 * FACTOR ; 91 | 92 | digitalWrite(FET, LOW); // switch load off 93 | 94 | displayOLED(); 95 | 96 | delay(500); 97 | OzOled.clearDisplay(); 98 | } 99 | 100 | void displayOLED() { 101 | char tmp[10]; 102 | dtostrf(empty, 1, 2, tmp); 103 | OzOled.printBigNumber(tmp, 0, 0, 4); 104 | dtostrf(load, 1, 2, tmp); 105 | OzOled.printBigNumber(tmp, 0, 4, 4); 106 | } 107 | 108 | --------------------------------------------------------------------------------