![]() |
Serial Wombat Arduino Library
|
A class to make resistance measurements with the Serial Wombat 18AB chip. More...
#include <SerialWombatResistanceInput.h>
Public Member Functions | |
SerialWombatResistanceInput (SerialWombatChip &SerialWombat) | |
Constructor for the SerialWombatResistanceInput class. More... | |
int16_t | begin (uint8_t pin) |
Initialize a resistance input on a given pin. More... | |
int16_t | begin (uint8_t pin, uint16_t averageSamples, uint16_t filterConstant) |
Initialize a resistance input on a given pin. More... | |
int16_t | begin (uint8_t pin, uint16_t averageSamples, uint16_t filterConstant, ResistanceInputPublicDataOutput output) |
Initialize a resistance input on a given pin. More... | |
uint16_t | readFilteredOhms () |
Retreive a filtered Resistance measurement. More... | |
uint16_t | readAveragedOhms () |
Retreive an averaged Resistance measurement. More... | |
uint16_t | readMaximumOhms (bool resetAfterRead) |
Retreive the maximum single sample Resistance value in Ohms. More... | |
uint16_t | readMinimumOhms (bool resetAfterRead) |
Retreive the maximum single sample Resistance value in Ohms. More... | |
![]() | |
SerialWombatPin (SerialWombatChip &serialWombatChip) | |
Instantiates a Serial Wombat Pin. More... | |
SerialWombatPin (SerialWombatChip &serialWombatChip, uint8_t pin) | |
Instantiates a Serial Wombat Pin. More... | |
uint16_t | readPublicData () |
Read the 16 Bit public data associated with this pin. More... | |
void | pinMode (uint8_t mode) |
Set pin to INPUT or OUTPUT. More... | |
void | pinMode (uint8_t mode, bool pullDown, bool openDrain) |
Set pin to INPUT or OUTPUT, with options for pull Ups and open Drain settings. More... | |
void | digitalWrite (uint8_t val) |
Set output pin High or Low. More... | |
int | digitalRead () |
Reads the state of the Pin. More... | |
uint16_t | writePublicData (uint16_t value) |
Write a 16 bit value to this pin. More... | |
uint8_t | pin () |
Returns the current SW pin number. Used primarily for virtual calls by derived classes. More... | |
uint8_t | swPinModeNumber () |
Returns the Mode number. Used primarily by derived classes to populate packet data. More... | |
Additional Inherited Members | |
![]() | |
uint8_t | _pin = 255 |
SerialWombatChip & | _sw |
uint8_t | _pinMode = 0 |
A class to make resistance measurements with the Serial Wombat 18AB chip.
The SerialWombatResistanceInput class is used to make resistance measurements on a given pin up to about 60 kOhm.
This pin mode is only available on the SerialWombat 18AB chip
Any analog-capable pin may be used to make a measurement (0-4, 16-19).
Averaging of samples and first order IIR filtering (20 Hz sampling) of input are available
For a good explanation of 1st order FIR filter calculations, see: https://www.monocilindro.com/2017/04/08/how-to-implement-a-1st-order-iir-filter-in-5-minutes/
Filtering adds lag. The higher the filter constant value, the longer it takes for the filter to settle when given a steady input.
Declare and initialize a SerialWombatResistanceInput instance for each pin being used as a resistance input.
A tutorial is available here:
SerialWombatResistanceInput::SerialWombatResistanceInput | ( | SerialWombatChip & | SerialWombat | ) |
Constructor for the SerialWombatResistanceInput class.
SerialWombat | a reference to the Serial Wombat chip on which the Resistance Input will be measured |
int16_t SerialWombatResistanceInput::begin | ( | uint8_t | pin | ) |
Initialize a resistance input on a given pin.
This intialization turns on sample averaging to 64 samples
pin | The Serial Wombat pin to set. Must be an analog pin (0-4, 16-19) |
int16_t SerialWombatResistanceInput::begin | ( | uint8_t | pin, |
uint16_t | averageSamples, | ||
uint16_t | filterConstant | ||
) |
Initialize a resistance input on a given pin.
pin | The Serial Wombat pin to set. Must be an analog pin (0-4, 16-19) |
averageSamples | Number of samples to average. |
filterConstant | First Order IIR filter constant, expressed as 1/65536ths . Values closer to 65536 give heavier filtering. Sample frequency is 20Hz. |
int16_t SerialWombatResistanceInput::begin | ( | uint8_t | pin, |
uint16_t | averageSamples, | ||
uint16_t | filterConstant, | ||
ResistanceInputPublicDataOutput | output | ||
) |
Initialize a resistance input on a given pin.
pin | The Serial Wombat pin to set. Must be an analog pin (0-4, 16-19) |
averageSamples | Number of samples to average. |
filterConstant | First Order IIR filter constant, expressed as 1/65536ths . Values closer to 65536 give heavier filtering. Sample frequency is 20 Hz. |
publicDataOutput | What to output as pin public data |
uint16_t SerialWombatResistanceInput::readAveragedOhms | ( | ) |
Retreive an averaged Resistance measurement.
Conversion is based on the most recent averaged Resistance value taken by the Serial Wombat at the command time.
uint16_t SerialWombatResistanceInput::readFilteredOhms | ( | ) |
Retreive a filtered Resistance measurement.
Conversion is based on the most recent filtered Resistance value taken by the Serial Wombat at the command time.
uint16_t SerialWombatResistanceInput::readMaximumOhms | ( | bool | resetAfterRead | ) |
Retreive the maximum single sample Resistance value in Ohms.
The maximum value the Serial Wombat chip has seen on that pin since last reset of Min/Max
resetAfterRead | If True, maximum value is set to 0 after read so that subsequent values become maximum. Also resets minimum to next sample. |
uint16_t SerialWombatResistanceInput::readMinimumOhms | ( | bool | resetAfterRead | ) |
Retreive the maximum single sample Resistance value in Ohms.
The maximum value the Serial Wombat chip has seen on that pin since last reset of Min/Max
resetAfterRead | If True, maximum value is set to 0 after read so that subsequent values become maximum. Also resets minimum to next sample. |