0.1.0 AD5248

This commit is contained in:
Rob Tillaart 2023-12-27 17:07:56 +01:00
parent 4f0fcccc37
commit 88342c236b
20 changed files with 876 additions and 0 deletions

View File

@ -0,0 +1,27 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
# - due
# - zero
# - leonardo
- m4
- esp32
- esp8266
# - mega2560
- rpipico

4
libraries/AD5248/.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1,4 @@
# These are supported funding model platforms
github: RobTillaart

View File

@ -0,0 +1,13 @@
name: Arduino-lint
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update
compliance: strict

View File

@ -0,0 +1,17 @@
---
name: Arduino CI
on: [push, pull_request]
jobs:
runTest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- run: |
gem install arduino_ci
arduino_ci.rb

View File

@ -0,0 +1,18 @@
name: JSON check
on:
push:
paths:
- '**.json'
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
with:
pattern: "\\.json$"

133
libraries/AD5248/AD5248.cpp Normal file
View File

@ -0,0 +1,133 @@
//
// FILE: AD5248.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: Library for I2C digital potentiometer AD5243 + rheostat AD5248
// DATE: 2023-12-12
// URL: https://github.com/RobTillaart/AD5248
#include "AD5248.h"
#define AD5248_RDAC0 0x00
#define AD5248_RDAC1 0x80
#define AD5248_RESET 0x40
#define AD5248_SHUTDOWN 0x20
AD5248::AD5248(uint8_t address, TwoWire *wire)
{
_address = address;
_wire = wire;
// power on reset => mid position
_lastValue[0] = _lastValue[1] = AD5248_MIDPOINT;
_pmCount = 2;
}
bool AD5248::begin()
{
if (! isConnected()) return false;
reset();
return true;
}
bool AD5248::isConnected()
{
_wire->beginTransmission(_address);
return ( _wire->endTransmission() == 0);
}
uint8_t AD5248::reset()
{
write(0, AD5248_MIDPOINT);
return write(1, AD5248_MIDPOINT);
}
uint8_t AD5248::zeroAll()
{
write(0, 0);
return write(1, 0);
}
uint8_t AD5248::write(const uint8_t rdac, const uint8_t value)
{
if (rdac >= _pmCount) return AD5248_ERROR;
uint8_t cmd = (rdac == 0) ? AD5248_RDAC0 : AD5248_RDAC1;
_lastValue[rdac] = value;
return send(cmd, value);
}
uint8_t AD5248::read(const uint8_t rdac)
{
return _lastValue[rdac];
}
uint8_t AD5248::readBackRegister()
{
_wire->beginTransmission(_address);
_wire->endTransmission();
_wire->requestFrom(_address, (uint8_t)1);
return _wire->read();
}
uint8_t AD5248::midScaleReset(const uint8_t rdac)
{
if (rdac >= _pmCount) return AD5248_ERROR;
uint8_t cmd = AD5248_RESET;
if (rdac == 1) cmd |= AD5248_RDAC1;
_lastValue[rdac] = AD5248_MIDPOINT;
return send(cmd, _lastValue[rdac]);
}
// read datasheet P.??
uint8_t AD5248::shutDown()
{
uint8_t cmd = AD5248_SHUTDOWN; // TODO TEST & VERIFY
return send(cmd, 0);
}
uint8_t AD5248::pmCount()
{
return _pmCount;
}
//////////////////////////////////////////////////////////
//
// PROTECTED
//
uint8_t AD5248::send(const uint8_t cmd, const uint8_t value)
{
_wire->beginTransmission(_address);
_wire->write(cmd);
_wire->write(value);
return _wire->endTransmission();
}
//////////////////////////////////////////////////////////////
//
// DERIVED CLASS AD5243 potentiometer
//
AD5243::AD5243(TwoWire * wire) : AD5248(0x2C, wire)
{
_pmCount = 2;
}
// -- END OF FILE --

75
libraries/AD5248/AD5248.h Normal file
View File

@ -0,0 +1,75 @@
#pragma once
//
// FILE: AD5248.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: Library for I2C digital potentiometer AD5243 + rheostat AD5248
// DATE: 2023-12-12
// URL: https://github.com/RobTillaart/AD5248
#include "Arduino.h"
#include "Wire.h"
#define AD5248_LIB_VERSION (F("0.1.0"))
#define AD5248_OK 0
#define AD5248_ERROR 100
#define AD5248_MIDPOINT 127
class AD5248
{
public:
AD5248(uint8_t address, TwoWire * wire = &Wire);
bool begin();
bool isConnected();
// RESET
uint8_t reset(); // reset both channels to AD524X_MIDPOINT
uint8_t zeroAll(); // set both channels to 0
// READ WRITE
uint8_t read(const uint8_t channel);
uint8_t write(const uint8_t channel, const uint8_t value);
uint8_t midScaleReset(const uint8_t channel);
uint8_t pmCount();
// DEBUGGING
uint8_t readBackRegister(); // returns the last value written in register.
// experimental - to be tested - use at own risk
uint8_t shutDown(); // datasheet P15
protected:
uint8_t _pmCount = 2;
uint8_t send(const uint8_t cmd, const uint8_t value);
uint8_t _lastValue[2];
uint8_t _address;
TwoWire * _wire;
};
//////////////////////////////////////////////////////////////
//
// DERIVED CLASSES AD5248 rheostat
//
class AD5243 : public AD5248
{
public:
AD5243(TwoWire *wire = &Wire);
};
// -- END OF FILE --

View File

@ -0,0 +1,11 @@
# Change Log AD5248
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.1.0] - 2023-12-12
- initial versions

21
libraries/AD5248/LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023-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
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

140
libraries/AD5248/README.md Normal file
View File

@ -0,0 +1,140 @@
[![Arduino CI](https://github.com/RobTillaart/AD5248/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/AD5248/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/AD5248/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/AD5248/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/AD5248/actions/workflows/jsoncheck.yml)
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/AD5248.svg)](https://github.com/RobTillaart/AD5248/issues)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/AD5248/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/AD5248.svg?maxAge=3600)](https://github.com/RobTillaart/AD5248/releases)
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/AD5248.svg)](https://registry.platformio.org/libraries/robtillaart/AD5248)
# AD5248
Arduino library for I2C digital potentioMeter AD5243 + rheostat AD5248
## Description
The AD5243 is a digital potentiometer, the AD5248 is a digital rheostat.
| device | channels | steps | ranges KΩ | notes :|
|:--------:|:----------:|:------:|:------------------:|:--------:|
| AD5243 | 2 | 256 | 2.5, 10, 50, 100 | potentioMeter
| AD5248 | 2 | 256 | 2.5, 10, 50, 100 | rheostat
Both IC's have two "channels" and they do not have the output lines
some other IC's in these series have e.g. like the AD5242.
The AD5243 has a fixed address (0x2F = 47) while the AD5248 has 2 address pins
giving 4 possible addresses. See table.
| Addr(dec)| Addr(Hex) | AD1 | AD0 |
|:--------:|:---------:|:-----:|:-----:|
| 44 | 0x2C | GND | GND |
| 45 | 0x2D | GND | +5V |
| 46 | 0x2E | +5V | GND |
| 47 | 0x2F | +5V | +5V |
An important property of the devices is that they defaults
to their mid position at startup.
The library defines AD5243_MIDPOINT == 127.
To be used to set to defined mid-point.
#### Related
- https://github.com/RobTillaart/AD520x
- https://github.com/RobTillaart/AD524X
- https://github.com/RobTillaart/AD5245
- https://github.com/RobTillaart/AD5144A
- https://github.com/RobTillaart/AD5263
- https://github.com/RobTillaart/X9C10X
#### Compatibles
If you know compatible devices please let me know.
## Interface
```cpp
#include "AD5248.h"
```
The library has a number of functions which are all quite straightforward.
One can get / set the value of (both) the potentiometer(s), and the O1 and O2 output lines.
#### Constructors
- **AD5243(TwoWire \*wire = &Wire)** constructor base class,
creates an instance with 2 potentiometers.
- **AD5248(uint8_t address, TwoWire \*wire = &Wire)** create an instance with 2 rheostats.
- **bool begin()** initialization of the object.
Note the user must call **wire.begin()** or equivalent before calling **begin()**.
- **bool isConnected()** See if the address set in constructor is on the I2C bus.
#### REad write
- **uint8_t read(uint8_t channel)** read back the set value.
- **uint8_t write(uint8_t channel, uint8_t value)** set channel 0/1 to value 0..255.
- **uint8_t zeroAll()** sets all potentiometer's to 0 and I/O to LOW.
- **uint8_t reset()** sets all potentiometer's to midpoint == 127. (startup default)
- **uint8_t midScaleReset(uint8_t channel)** resets one potentiometer to midpoint == 127.
- **uint8_t readBackRegister()** read register back, for debugging.
#### Experimental
- **uint8_t shutDown()** check datasheet, not tested yet, use at own risk.
## Operation
The examples show the basic working of the functions.
## Error codes
| define | value |
|:---------------|:-------:|
| AD5248_OK | 0 |
| AD5248_ERROR | 100 |
## Future
#### Must
- improve documentation.
- buy hardware
- test
#### Should
- sync with AD524X library.
#### Could
#### Wont
## Support
If you appreciate my libraries, you can support the development and maintenance.
Improve the quality of the libraries by providing issues and Pull Requests, or
donate through PayPal or GitHub sponsors.
Thank you,

View File

@ -0,0 +1,48 @@
//
// FILE: AD5243_read.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// URL: https://github.com/RobTillaart/AD5248
//
#include "AD5248.h"
AD5243 AD01;
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println(__FILE__);
Serial.print("AD5248_LIB_VERSION: ");
Serial.println(AD5248_LIB_VERSION);
Wire.begin();
Wire.setClock(400000);
bool b = AD01.begin();
Serial.println(b ? "true" : "false");
Serial.println(AD01.isConnected());
}
void loop()
{
for (int val = 0; val < 255; val++)
{
Serial.print(val);
AD01.write(1, val);
delay(100);
int x = AD01.read(1);
Serial.print('\t');
Serial.println(x);
delay(100);
}
delay(1000);
}
// -- END OF FILE --

View File

@ -0,0 +1,43 @@
//
// FILE: AD5243_write.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// URL: https://github.com/RobTillaart/AD5248
//
#include "AD5248.h"
AD5243 AD01;
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println(__FILE__);
Serial.print("AD5248_LIB_VERSION: ");
Serial.println(AD5248_LIB_VERSION);
Wire.begin();
Wire.setClock(400000);
bool b = AD01.begin();
Serial.println(b ? "true" : "false");
Serial.println(AD01.isConnected());
}
void loop()
{
for (int val = 0; val < 255; val++)
{
AD01.write(1, val);
AD01.write(0, 255 - val);
Serial.println(val);
delay(20);
}
}
// -- END OF FILE --

View File

@ -0,0 +1,27 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
# - uno
# - due
# - zero
# - leonardo
# - m4
- esp32
# - esp8266
# - mega2560
# - rpipico

View File

@ -0,0 +1,43 @@
//
// FILE: AD5243_write_ESP32.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// URL: https://github.com/RobTillaart/AD5248
//
#include "AD5248.h"
AD5243 AD01(&Wire1);
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println(__FILE__);
Serial.print("AD5248_LIB_VERSION: ");
Serial.println(AD5248_LIB_VERSION);
Wire1.begin(21, 22); // adjust if needed
Wire1.setClock(400000);
bool b = AD01.begin();
Serial.println(b ? "true" : "false");
Serial.println(AD01.isConnected());
}
void loop()
{
for (int val = 0; val < 255; val++)
{
AD01.write(0, val);
AD01.write(1, 255 - val);
Serial.println(val);
delay(20);
}
}
// -- END OF FILE --

View File

@ -0,0 +1,27 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
# - uno
# - due
# - zero
# - leonardo
# - m4
# - esp32
# - esp8266
# - mega2560
- rpipico

View File

@ -0,0 +1,45 @@
//
// FILE: AD5243_write_RP2040.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// URL: https://github.com/RobTillaart/AD5248
//
#include "AD5248.h"
AD5243 AD01(&Wire1);
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println(__FILE__);
Serial.print("AD5248_LIB_VERSION: ");
Serial.println(AD5248_LIB_VERSION);
Wire1.setSDA(12); // adjust if needed
Wire1.setSCL(13); // adjust if needed
Wire1.begin();
Wire1.setClock(400000);
bool b = AD01.begin();
Serial.println(b ? "true" : "false");
Serial.println(AD01.isConnected());
}
void loop()
{
for (int val = 0; val < 255; val++)
{
AD01.write(1, val);
AD01.write(0, 255 - val);
Serial.println(val);
delay(20);
}
}
// -- END OF FILE --

View File

@ -0,0 +1,27 @@
# Syntax Colouring Map For AD5248
# Data types (KEYWORD1)
AD5243 KEYWORD1
AD5248 KEYWORD1
# Methods and Functions (KEYWORD2)
begin KEYWORD2
reset KEYWORD2
zeroAll KEYWORD2
read KEYWORD2
write KEYWORD2
midScaleReset KEYWORD2
pmCount KEYWORD2
shutDown KEYWORD2
# Constants (LITERAL1)
AD5248_LIB_VERSION LITERAL1
AD5248_OK LITERAL1
AD5248_ERROR LITERAL1
AD5248_MIDPOINT LITERAL1

View File

@ -0,0 +1,23 @@
{
"name": "AD5248",
"keywords": "I2C,digital,potentiometer, rheostat, AD5243, AD5248",
"description": "Library for I2C digital potentiometer AD5243 + rheostat AD5248.",
"authors":
[
{
"name": "Rob Tillaart",
"email": "Rob.Tillaart@gmail.com",
"maintainer": true
}
],
"repository":
{
"type": "git",
"url": "https://github.com/RobTillaart/AD5248"
},
"version": "0.1.0",
"license": "MIT",
"frameworks": "*",
"platforms": "*",
"headers": "AD5248.h"
}

View File

@ -0,0 +1,11 @@
name=AD5248
version=0.1.0
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Library for I2C digital potentiometer AD5243 + rheostat AD5248
paragraph=
category=Signal Input/Output
url=https://github.com/RobTillaart/AD5248
architectures=*
includes=AD5248.h
depends=

View File

@ -0,0 +1,123 @@
//
// FILE: unit_test_001.cpp
// AUTHOR: Rob Tillaart
// DATE: 2023-12-12
// PURPOSE: unit tests for I2C digital PotentioMeter AD5243 + rheostat AD5248
// https://github.com/RobTillaart/AD5243_RT
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
//
// supported assertions
// ----------------------------
// assertEqual(expected, actual)
// assertNotEqual(expected, actual)
// assertLess(expected, actual)
// assertMore(expected, actual)
// assertLessOrEqual(expected, actual)
// assertMoreOrEqual(expected, actual)
// assertTrue(actual)
// assertFalse(actual)
// assertNull(actual)
#include <ArduinoUnitTests.h>
#include "AD5248.h"
unittest_setup()
{
fprintf(stderr, "\nAD5248_LIB_VERSION: %s\n", (char *) AD5248_LIB_VERSION);
}
unittest_teardown()
{
}
unittest(test_constructors)
{
Wire.begin();
AD5243 ADx;
assertEqual(127, ADx.read(0));
assertEqual(127, ADx.read(1));
AD5248 AD1(0x2C);
assertEqual(127, AD1.read(0));
assertEqual(127, AD1.read(1));
}
unittest(test_pmCount)
{
Wire.begin();
AD5243 ADx;
assertEqual(2, ADx.pmCount());
AD5248 AD1(0x2C);
assertEqual(2, ADx.pmCount());
}
unittest(test_reset)
{
AD5243 AD;
Wire.begin();
assertEqual(127, AD.read(0));
assertEqual(127, AD.read(1));
AD.zeroAll();
assertEqual(0, AD.read(0));
assertEqual(0, AD.read(1));
AD.reset();
assertEqual(127, AD.read(0));
assertEqual(127, AD.read(1));
AD.zeroAll();
assertEqual(0, AD.read(0));
assertEqual(0, AD.read(1));
AD.midScaleReset(0);
assertEqual(127, AD.read(0));
assertEqual(0, AD.read(1));
AD.midScaleReset(1);
assertEqual(127, AD.read(0));
assertEqual(127, AD.read(1));
}
unittest(test_write_read)
{
AD5243 AD;
Wire.begin();
assertEqual(127, AD.read(0));
assertEqual(127, AD.read(1));
AD.write(0, 42);
assertEqual(42, AD.read(0));
assertEqual(127, AD.read(1));
AD.write(1, 42);
assertEqual(42, AD.read(0));
assertEqual(42, AD.read(1));
}
unittest(test_constants)
{
assertEqual(0, AD5248_OK);
assertEqual(100, AD5248_ERROR);
assertEqual(127, AD5248_MIDPOINT);
}
unittest_main()
// -- END OF FILE --