Hi all,
I am reading an ADC value 0-5V from a potentiometer. It is printing 0 to 5000mV on the serial monitor fine as per code below. I now want the reading to show 0.00 to 5.00V with all the values inbetween. I've tried dividing by 1000 and using a float but it just prints 0.00, 1.00, 2.00, etc in whole numbers only. Any help is appreciated!
/*!
@file readVoltage.ino
@brief connect ADS1115 I2C interface with your board (please reference board compatibility)
@n The voltage value read by A0 A1 A2 A3 is printed through the serial port.
@copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
@license The MIT License (MIT)
@author [luoyufeng](yufeng.luo@dfrobot.com),
@version V1.0
@date 2019-06-19
@url https://github.com/DFRobot/DFRobot_ADS1115
Works perfectly!
20.09.23
*/
#include <LCD_ST7032.h>// MIDAS MCCOG21605C6
LCD_ST7032 lcd;
#include <Wire.h>
#include <DFRobot_ADS1115.h>
DFRobot_ADS1115 ads(&Wire);
void setup(void)
{
lcd.begin();
lcd.setcontrast(24); //contrast value range is 0-63, try 25@5V or 50@3.3V as a starting value
Serial.begin(115200);
ads.setAddr_ADS1115(ADS1115_IIC_ADDRESS1); // 0x48
ads.setGain(eGAIN_TWOTHIRDS); // 2/3x gain
ads.setMode(eMODE_SINGLE); // single-shot mode
ads.setRate(eRATE_128); // 128SPS (default)
ads.setOSMode(eOSMODE_SINGLE); // Set to start a single-conversion
ads.init();
}
void loop(void)
{
if (ads.checkADS1115())
{
int16_t adc0, adc1, adc2, adc3;
adc0 = ads.readVoltage(0);
Serial.print("A0:");
Serial.print(adc0);
Serial.print("V, ");
lcd.setCursor(0, 0);
lcd.print("1:");
lcd.print(adc0);
lcd.print("mV ");
}
else
{
Serial.println("ADS1115 Disconnected!");
}
delay(1000);
}