Skip to content

Instantly share code, notes, and snippets.

@mcgodfrey
Last active January 1, 2016 04:25
Show Gist options
  • Save mcgodfrey/b389f9d20d11c400ffe1 to your computer and use it in GitHub Desktop.
Save mcgodfrey/b389f9d20d11c400ffe1 to your computer and use it in GitHub Desktop.
Code for power supply display
/*
* Voltage and current monitor for lab supply
*
* LCD and analog input pin assignments as shown below
*
* Matt Godfrey, 2015
*/
#include <LiquidCrystal.h>
int Vset = A7;
int Iset = A6;
int Vmeas = A5;
int Imeas = A4;
// (RS, EN, D4, D5, D6, D7)
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void setup() {
//lcd setup
lcd.begin(20, 4);
lcd.clear();
//ADC pin setup
pinMode(Vset, INPUT);
pinMode(Vmeas, INPUT);
pinMode(Iset, INPUT);
pinMode(Imeas, INPUT);
analogReference(DEFAULT); //use power supply reference (5V)
}
void loop() {
//meaure values. Note the calibration factors (5.64) which were
//calculated by measuring the output with a multimeter
float set_voltage = 5.64*5.0/1024.0*analogRead(Vset);
float meas_voltage = 5.64*5.0/1024.0*analogRead(Vmeas);
float set_current = analogRead(Iset)*(5.0/1024.0);
float meas_current = analogRead(Imeas)*(5.0/1024.0);
//update the lcd
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Vmeas = ");
lcd.setCursor(8, 0);
lcd.print(meas_voltage);
lcd.setCursor(0, 1);
lcd.print("Vset = ");
lcd.setCursor(8, 1);
lcd.print(set_voltage);
lcd.setCursor(0, 2);
lcd.print("Imeas = ");
lcd.setCursor(8, 2);
lcd.print(meas_current);
lcd.setCursor(0, 3);
lcd.print("Iset = ");
lcd.setCursor(8, 3);
lcd.print(set_current);
delay(50);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment