0.1.2 DMM

This commit is contained in:
rob tillaart 2023-02-04 14:10:04 +01:00
parent 7c34f6a280
commit 0c52a748b9
17 changed files with 210 additions and 39 deletions

View File

@ -6,7 +6,7 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update

View File

@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6

View File

@ -10,7 +10,7 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
with:

View File

@ -6,14 +6,22 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.1.2] - 2023-02-03
- add OHM measurements functions
- **setReferenceR(ohm), readOhm(times), readKiloOhm(times)**
- update GitHub actions
- update license 2023
- refactor
- update readme.md
## [0.1.1] - 2022-12-19
- initial release...
- renamed initial class to DMM
- add setGain() and getGain()
- add getNoise
- add **setGain()** and **getGain()**
- add **getNoise()**
- add examples
## [0.1.0] - eons ago
- initial version
- started as a VoltMeter only class

View File

@ -1,7 +1,7 @@
//
// FILE: DMM.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// VERSION: 0.1.2
// DATE: 2022-12-19
// PURPOSE: Library for a DMM class for Arduino UNO.
// URL: https://github.com/RobTillaart/DMM
@ -49,18 +49,28 @@ float DMM::getGain()
}
/////////////////////////////////////////////////
//
// READ VOLTAGE
//
float DMM::readVolts(uint8_t times)
{
uint32_t total = 0;
if (times == 0) times = 1;
if (times == 0)
{
times = 1;
}
for (int i = 0; i < times; i++)
{
total += analogRead(_pin);
}
float v = (total * _voltageStep) / times;
float volts = (total * _voltageStep) / times;
if (_gain != 1.0) v *= _gain;
return v;
if (_gain != 1.0)
{
volts *= _gain;
}
return volts;
}
@ -89,6 +99,32 @@ float DMM::readNoise(uint8_t times)
}
/////////////////////////////////////////////////
//
// READ OHM
//
void DMM::setReferenceR(float ohm)
{
_ReferenceR = ohm;
}
float DMM::readOhm(uint8_t times)
{
float voltage = readVolts(times);
float R = _ReferenceR / voltage * _maxVoltage - _ReferenceR;
// float R = (_maxVoltage - voltage) * _ReferenceR / voltage;
return R;
}
float DMM::readKiloOhm(uint8_t times)
{
return readOhm(times) * 0.001;
}
// -- END OF FILE --

View File

@ -2,7 +2,7 @@
//
// FILE: DMM.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// VERSION: 0.1.2
// DATE: 2022-12-19
// PURPOSE: Library for a DMM class for Arduino.
// URL: https://github.com/RobTillaart/DMM
@ -10,7 +10,7 @@
#include "Arduino.h"
#define DMM_LIB_VERSION (F("0.1.1"))
#define DMM_LIB_VERSION (F("0.1.2"))
class DMM
@ -20,22 +20,30 @@ public:
void begin(uint8_t pin, float maxVoltage, uint16_t maxSteps);
// CALIBRATION
void setMaxVoltage(float maxVoltage);
float getMaxVoltage();
// GAIN e.g. due to voltage divider
// a 25V to 5V divider has a factor = 5.
void setGain(float factor = 1.0);
float getGain();
// READ
// READ VOLTAGE
float readVolts(uint8_t times = 1);
float readMilliVolts(uint8_t times = 1);
float readNoise(uint8_t times = 1);
// READ OHM
void setReferenceR(float ohm);
float readOhm(uint8_t times = 1);
float readKiloOhm(uint8_t times = 1);
private:
uint8_t _pin = 14; // A0;
float _maxVoltage = 5.0;
@ -43,6 +51,8 @@ private:
float _voltageStep = _maxVoltage/_maxSteps;
float _gain = 1.0;
float _ReferenceR = 0;
};

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2022-2022 Rob Tillaart
Copyright (c) 2022-2023 Rob Tillaart
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -8,7 +8,7 @@
# DMM = Digital MultiMeter.
Arduino library for a DMM class.
Arduino library for a DMM (digital multimeter) class.
## Description
@ -20,38 +20,86 @@ The first version only works as a voltmeter, DC only.
It is meant to be extended in the future to be a complete Digital MultiMeter class.
that includes amps ohms, diode testing etc.
(this is an old 'toy' project, wrapped into a class)
This is an old 'toy' project, wrapped into a class.
Do not expect high precision or accuracy.
#### Related
#### Related
- https://github.com/RobTillaart/ACS712 (current measurement).
## Interface
```cpp
#include "DMM.h"
```
#### Constructor
- **DMM()** constructor.
#### Configuration
- **begin(uint8_t analogPin, float volts = 5.0, uint16_t maxADC = 1023)** configuration.
- **begin(uint8_t analogPin, float volts = 5.0, uint16_t maxADC = 1023)** configuration.
Note these are the specifications of the ADC used.
- **void setMaxVoltage(float maxVoltage)**
- **float getMaxVoltage()**
- **void setGain(float factor = 1.0)** GAIN e.g. due to voltage divider.
a 25V to 5V divider has a factor = 5.
A 25V to 5V divider has a factor = 5.
- **float getGain()** returns the set gain.
#### Read
- **float readVolts(uint8_t times = 1)** read voltage.
#### ReadVolts
One must connect GND of Arduino to the GND of the device.
```
[A0]---- V unknown
[GND]---- GND
or with a divider => setGain(x)
[A0]----[divider]---- V unknown
[GND]----[divider]---- GND
```
- **float readVolts(uint8_t times = 1)** read voltage.
Times can be set to average multiple measurements.
- **float readMilliVolts(uint8_t times = 1)** convenience wrapper.
- **float readNoise(uint8_t times = 1)** measure the noise on the wire.
Assumes connected to constant voltage e.g. GND.
#### ReadOhm
The schema for measuring resistors is based on a simple voltage divider.
See below. This schema can be extended with a selector switch that can
switch between different reference resistors.
```
[GND] ----[ R reference ]----[A0]----[ R unknown ]----[+5V]
```
- **void setReferenceR(uint32_t ohm = 1000)** set the reference resistor.
units are Ohm, default = 1K.
- **uint32_t readOhm(uint8_t times = 1)** read ohm.
Times can be set to average multiple measurements.
- **uint32_t readKiloOhm(uint8_t times = 1)** read ohm.
Times can be set to average multiple measurements.
Character ohm = Ω (ALT-234 or ALT-0216 might work)
#### Calibration
- **float readNoise(uint8_t times = 1)** get noise level for accuracy.
## Operation
Basic operation is to connect the Arduino GND to the projects GND (or -)
and use the configured analog pin to measure (positive) voltage.
Basic operation is to connect the Arduino GND to the projects GND (or - )
and use the configured analog pin to measure a (positive) voltage.
By adding a voltage divider one can measure larger voltages.
The divider factor can be set with **setGain(factor)**.
@ -63,20 +111,29 @@ To elaborate.
## Future
#### Functional
- AMPS (how -> measure voltage over a known resistor)
- OHM (how -> known divider)
- DIODE (how -> 5V or 0V)
- CAPS (how -> RC timing)
- RC (load 5 seconds)
- disconnect
- measure drop rate / time in micros.
- DIODE (how -> 5V or 0V)
- DigitalRead(INPUT PULLUP) => HIGH or LOW
- or 0.7 volt drop from 5V
#### Must
- update documentation
- update examples
- add use of AREF
- add use of AREF
- external or internal 1.1 Volt
- **float setOffset(float offset)** adjust the voltage used.
- this is not the voltage the ADC uses internally.
#### Should
- investigate noise
- analogReference(EXTERNAL) for external voltage for build in ADC
- support external ADC e.g. ADS1115 for 16 bit resolution.
@ -84,8 +141,9 @@ To elaborate.
#### Could
- multichannel compare
- schema for
- schema for
- scope functionality?

View File

@ -0,0 +1,48 @@
//
// FILE: DMM_ohm_demo.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo DMM
// URL: https://github.com/RobTillaart/DMM
//
// SCHEMA
//
// [GND] ----[ R reference ]----[A0]----[ R unknown ]----[+5V]
//
#include "DMM.h"
DMM dmm;
void setup()
{
while (!Serial);
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("DMM_LIB_VERSION: ");
Serial.println(DMM_LIB_VERSION);
dmm.begin(A0, 5.000, 1023); // Arduino UNO, adjust if needed
dmm.setReferenceR(998); // R reference, adjust if needed
}
void loop()
{
float voltage = dmm.readVolts();
float ohm = dmm.readOhm(3);
float Kohm = dmm.readKiloOhm(3);
Serial.print("voltage: ");
Serial.print(voltage);
Serial.print("\tohm: "); // Ω
Serial.print(ohm);
Serial.print("\tKohm: ");
Serial.print(Kohm);
Serial.println();
delay(1000);
}
// -- END OF FILE --

View File

@ -19,7 +19,7 @@ void setup()
Serial.print("DMM_LIB_VERSION: ");
Serial.println(DMM_LIB_VERSION);
dmm.begin(A0, 5, 1023);
dmm.begin(A0, 5.000, 1023);
}
@ -34,4 +34,4 @@ void loop()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -35,4 +35,4 @@ void loop()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -19,7 +19,7 @@ void setup()
Serial.print("DMM_LIB_VERSION: ");
Serial.println(DMM_LIB_VERSION);
dmm.begin(A0, 5, 1023);
dmm.begin(A0, 5.000, 1023);
}
@ -34,4 +34,4 @@ void loop()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -3,6 +3,8 @@
// AUTHOR: Rob Tillaart
// PURPOSE: demo DMM
// URL: https://github.com/RobTillaart/DMM
//
// add a 25 -> 5 volt converter before A0
#include "DMM.h"
@ -19,10 +21,14 @@ void setup()
Serial.print("DMM_LIB_VERSION: ");
Serial.println(DMM_LIB_VERSION);
dmm.begin(A0, 5, 1023);
dmm.begin(A0, 5.000, 1023);
// add a 25 -> 5 volt converter before A0
dmm.setGain(5);
// alternative
// dmm.begin(A0, 25.000, 1023);
}
@ -39,4 +45,4 @@ void loop()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -17,6 +17,10 @@ readMilliVolts KEYWORD2
readNoise KEYWORD2
setReferenceR KEYWORD2
readOhm KEYWORD2
readKiloOhm KEYWORD2
# Constants (LITERAL1)
DMM_LIB_VERSION LITERAL1

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/DMM.git"
},
"version": "0.1.1",
"version": "0.1.2",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=DMM
version=0.1.1
version=0.1.2
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=DMM (digital multimeter) library for Arduino.

View File

@ -36,6 +36,7 @@ unittest_setup()
fprintf(stderr, "DMM_LIB_VERSION: %s\n", (char *) DMM_LIB_VERSION);
}
unittest_teardown()
{
}
@ -53,4 +54,4 @@ unittest(test_first)
unittest_main()
// -- END OF FILE --
// -- END OF FILE --