Not Gonna lie, Im a big fan of what Mirko Pavleski does, and when I saw his simple capacitance sensor I knew I had to build my very own.
Right away, I noticed He is using an LCD screen that isnt in my stock pile, and Im not about to add another to my collection, when I already have a box full of them.
If you already have a ST7565 LCD screen, maybe just follow his instructions, I'm sure they'll work.
https://www.hackster.io/mircemk/how-to-make-simplest-possible-autorange-capacitance-meter-ea7f00
<br>
when I looked at Mirko's code, it reminded me of the way I used to code. The only comments are that which has been commented out. I'm not claiming to have wrote better code, only that what I wrote is more easily understandable to me.
<br>Anyway, the hardware I have on hand is a bunch of I2C LCD backpacks from adafruit, and a pile of 16x2 LCD panels. Some with back lights, others not.
It took me about an hour to figure out what Mirko's code is doing, and to make my initial conversion code. Once I figured it out, I wanted to approach it a bit differently, in a simpler sort of way.
So I'm using the fact that the line length is 16, and results from the Capacitor library are never longer than 7 digits. Also, units are always in ( F ) Farads.
#include <Adafruit_LiquidCrystal.h>
#include <Capacitor.h>
Capacitor cap1(7,A2); //both are 6th pin in from usb conector
Adafruit_LiquidCrystal lcd(0); //i2c lcd init
void clrLine(); //clear line 1
void setup() {
//using adafruit i2c Lcd
Serial.begin(115200);
// set up the LCD's number of rows and columns:
if (!lcd.begin(16, 2)) {
Serial.println("Could not init backpack. Check wiring.");
while(1);
}
Serial.println("Backpack init'd.");
lcd.setBacklight(HIGH);
lcd.print("CAPACITANCE");
}
void loop(){
float CPM = cap1.Measure(); //Cin pF
if(CPM<1){
Serial.println("No Connection");
lcd.setCursor(0,1);
lcd.print("NOT CONNECTED");
}
if(CPM < 1000 && CPM >= 1){
Serial.print(CPM);
Serial.println("pF");
lcd.setCursor(0,1);
lcd.print(CPM);
lcd.setCursor(6,1);
lcd.print(" pF ");
}
if(CPM >= 1000 && CPM < 1000000){
Serial.print(CPM);
Serial.println("nF");
lcd.setCursor(0,1);
lcd.print(CPM);
lcd.setCursor(6,1);
lcd.print(" nF ");
}
if(CPM >= 1000000){
Serial.print(CPM);
Serial.println("uF");
lcd.setCursor(0,1);
lcd.print(CPM);
lcd.setCursor(6,1);
lcd.print(" uF ");
}
delay(800); //slow down
}
Still not a lot of comments, ok fine.
Could I make this code even simpler?
yeah maybe, but I like using libraries, and I think this code is a lot easier to read.
Still trying to make a box up for this thing. This project was also an excuse to weed through my LCD screens, and see what works.
I made a variant using a Vellman vma203 and an arduino Uno, because Making a case for it seemed easier.
Here is a github repo for this project. Ill probably make the same number of variants, as LCD screens I have.
https://github.com/FOSSBOSS/TestCap/