Hi,
I’m trying too run my capacitormeter on the arduino nano with a I2C-LCD display…
The only problem is that only the top row of the LCD light up, if i put the contrast on full… And all the pixels are on…
Do you see any problem in the code?
Also did a address test…
I2C Scanner
Scanning…
I2C device found at address 0x27 !
done
// Digitale capaciteitsmeter
// (C) 2013 Hackerstore
#include <Wire.h>
#include "LCDI2C4Bit.h"
#define ANALOGE_PEN A3 // Analoge pen tussen R1/R2 en de condensator
#define R1_PEN 2 // Pen aan R1 (22k-weerstand)
#define R2_PEN 3 // Pen aan R2 (1,5k-weerstand)
LCDI2C4Bit lcd(0x27,2,16); // LCD-Display met I2C-interface
void setup() {
pinMode(R1_PEN, OUTPUT);
digitalWrite(R1_PEN, LOW);
lcd.begin();
lcd.backLight(true);
lcd.clear();
}
void loop() {
Ontlaad();
// Meet de condensator
digitalWrite(R1_PEN, HIGH); // Laadt de condensator (indien er 1 is aangesloten tenminste) op
long tStart = millis();
while(analogRead(ANALOGE_PEN)<647);
long nDuur = abs(millis()-tStart);
// Bereken de waarde van de gemeten condensator
float fMicroFarad = ((float)nDuur/22000.0) * 1000;
// Toon de waarde op het LCD
if(fMicroFarad >= 1.0){
static char mf[3];
mf[0]=0xe4; // Dit is het micro-symbool (Griekse letter mu), voor microFarad
mf[1]='F';
mf[2]=0;
lcd.clear();
lcd.print(" ");
lcd.print(fMicroFarad);
lcd.print(" ");
lcd.print(mf);
delay(200);
}
else {
// Toon waarde in nF
lcd.clear();
lcd.print(" ");
lcd.print(fMicroFarad*1e3);
lcd.print(" ");
lcd.print("nF");
delay(500); // Iets langere delay dan bij uF!
}
}
void Ontlaad() { // Ontlaad de condensator zodat hij gereed is voor een volgende meting
digitalWrite(R1_PEN, LOW);
pinMode(R2_PEN, OUTPUT);
digitalWrite(R2_PEN, LOW);
while(analogRead(ANALOGE_PEN)>0);
pinMode(R2_PEN, INPUT);
}