├── .gitattributes ├── .gitignore └── ADC_Test.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 | -------------------------------------------------------------------------------- /ADC_Test.ino: -------------------------------------------------------------------------------- 1 | #include // Arduino LCD library 2 | #include 3 | #include 4 | 5 | // pin definition for the Uno 6 | #define cs 10 7 | #define dc 9 8 | #define rst 8 9 | 10 | char buff[10]; 11 | 12 | TFT TFTscreen = TFT(cs, dc, rst); 13 | 14 | void setup() { 15 | Serial.begin(115200); 16 | initTFT(); 17 | pinMode(A0, INPUT); 18 | } 19 | 20 | void loop() { 21 | 22 | // read normal Arduino value 23 | 24 | int in0 = analogRead(A0); 25 | float val0 = in0 * 5.0 / 1024.0; 26 | 27 | // read correct supply voltage 28 | 29 | float supply = readVcc() / 1000.0; 30 | float val0Corrected = supply / 5 * val0; 31 | 32 | TFTscreen.background(0, 0, 0); 33 | 34 | dtostrf(val0, 4, 3, buff); 35 | TFTscreen.text("Orig: ", 0, 10); 36 | TFTscreen.text(buff, 100, 10); 37 | 38 | dtostrf(supply, 4, 3, buff); 39 | TFTscreen.text("VCC: ", 0, 30); 40 | TFTscreen.text(buff, 100, 30); 41 | 42 | dtostrf(val0Corrected, 4, 3, buff); 43 | TFTscreen.text("Corr: ", 0, 50); 44 | TFTscreen.text(buff, 100, 50); 45 | 46 | delay(500); 47 | } 48 | 49 | 50 | void initTFT() { 51 | // Put this line at the beginning of every sketch that uses the GLCD: 52 | TFTscreen.begin(); 53 | 54 | // clear the screen with a black background 55 | TFTscreen.background(0, 0, 0); 56 | // write the static text to the screen 57 | // set the font color to white 58 | TFTscreen.stroke(255, 255, 255); 59 | // set the font size 60 | TFTscreen.setTextSize(2); 61 | } 62 | 63 | long readVcc() { 64 | long result; 65 | // Read 1.1V reference against AVcc 66 | #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) 67 | ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); 68 | #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) 69 | ADMUX = _BV(MUX5) | _BV(MUX0); 70 | #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) 71 | ADMUX = _BV(MUX3) | _BV(MUX2); 72 | #else 73 | ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); 74 | #endif 75 | delay(2); // Wait for Vref to settle 76 | ADCSRA |= _BV(ADSC); // Convert 77 | while (bit_is_set(ADCSRA, ADSC)); 78 | result = ADCL; 79 | result |= ADCH << 8; 80 | result = 1126400L / result; // Calculate Vcc (in mV); 1126400 = 1.1*1024*1000 81 | return result; 82 | } 83 | --------------------------------------------------------------------------------