mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-19 16:46:11 -04:00
0.1.0 AD5263
This commit is contained in:
parent
392b865332
commit
cf1e405a05
27
libraries/AD5263/.arduino-ci.yml
Normal file
27
libraries/AD5263/.arduino-ci.yml
Normal 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/AD5263/.github/FUNDING.yml
vendored
Normal file
4
libraries/AD5263/.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: RobTillaart
|
||||
|
13
libraries/AD5263/.github/workflows/arduino-lint.yml
vendored
Normal file
13
libraries/AD5263/.github/workflows/arduino-lint.yml
vendored
Normal 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
|
17
libraries/AD5263/.github/workflows/arduino_test_runner.yml
vendored
Normal file
17
libraries/AD5263/.github/workflows/arduino_test_runner.yml
vendored
Normal 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
|
18
libraries/AD5263/.github/workflows/jsoncheck.yml
vendored
Normal file
18
libraries/AD5263/.github/workflows/jsoncheck.yml
vendored
Normal 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$"
|
||||
|
247
libraries/AD5263/AD5263.cpp
Normal file
247
libraries/AD5263/AD5263.cpp
Normal file
@ -0,0 +1,247 @@
|
||||
//
|
||||
// FILE: AD5263.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: Arduino library for I2C digital potentiometer AD5263 and compatibles.
|
||||
// DATE: 2023-10-09
|
||||
// URL: https://github.com/RobTillaart/AD5263
|
||||
|
||||
|
||||
#include "AD5263.h"
|
||||
|
||||
|
||||
#define AD5263_RDAC0 0x00
|
||||
#define AD5263_RDAC1 0x20
|
||||
#define AD5263_RDAC2 0x40
|
||||
#define AD5263_RDAC3 0x60
|
||||
#define AD5263_RESET 0x10
|
||||
#define AD5263_SHUTDOWN 0x08
|
||||
#define AD5263_O1_HIGH 0x04
|
||||
#define AD5263_O2_HIGH 0x02
|
||||
|
||||
|
||||
AD5263::AD5263(const uint8_t address, TwoWire *wire)
|
||||
{
|
||||
_address = address;
|
||||
_wire = wire;
|
||||
|
||||
// power on reset => mid position
|
||||
_pmCount = 4;
|
||||
for (int i = 0; i < _pmCount; i++)
|
||||
{
|
||||
_lastValue[i] = AD5263_MIDPOINT;
|
||||
}
|
||||
_O1 = _O2 = 0;
|
||||
}
|
||||
|
||||
|
||||
bool AD5263::begin()
|
||||
{
|
||||
if (! isConnected()) return false;
|
||||
reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool AD5263::isConnected()
|
||||
{
|
||||
_wire->beginTransmission(_address);
|
||||
return ( _wire->endTransmission() == 0);
|
||||
}
|
||||
|
||||
|
||||
uint8_t AD5263::reset()
|
||||
{
|
||||
for (int i = 1; i < _pmCount; i++)
|
||||
{
|
||||
write(i, AD5263_MIDPOINT);
|
||||
}
|
||||
return write(0, AD5263_MIDPOINT, LOW, LOW);
|
||||
}
|
||||
|
||||
|
||||
uint8_t AD5263::zeroAll()
|
||||
{
|
||||
for (int i = 1; i < _pmCount; i++)
|
||||
{
|
||||
write(i, 0);
|
||||
}
|
||||
return write(0, 0, LOW, LOW);
|
||||
}
|
||||
|
||||
|
||||
uint8_t AD5263::write(const uint8_t rdac, const uint8_t value)
|
||||
{
|
||||
if (rdac >= _pmCount) return AD5263_ERROR;
|
||||
|
||||
uint8_t cmd = AD5263_RDAC0;
|
||||
if (rdac == 1) cmd = AD5263_RDAC1;
|
||||
if (rdac == 2) cmd = AD5263_RDAC2;
|
||||
if (rdac == 3) cmd = AD5263_RDAC3;
|
||||
|
||||
// apply the output lines
|
||||
cmd = cmd | _O1 | _O2;
|
||||
_lastValue[rdac] = value;
|
||||
return send(cmd, value);
|
||||
}
|
||||
|
||||
|
||||
uint8_t AD5263::write(const uint8_t rdac, const uint8_t value, const uint8_t O1, const uint8_t O2)
|
||||
{
|
||||
if (rdac >= _pmCount) return AD5263_ERROR;
|
||||
|
||||
_O1 = (O1 == LOW) ? 0 : AD5263_O1_HIGH;
|
||||
_O2 = (O2 == LOW) ? 0 : AD5263_O2_HIGH;
|
||||
|
||||
uint8_t cmd = AD5263_RDAC0;
|
||||
if (rdac == 1) cmd = AD5263_RDAC1;
|
||||
if (rdac == 2) cmd = AD5263_RDAC2;
|
||||
if (rdac == 3) cmd = AD5263_RDAC3;
|
||||
|
||||
// apply the output lines
|
||||
cmd = cmd | _O1 | _O2;
|
||||
_lastValue[rdac] = value;
|
||||
return send(cmd, value);
|
||||
}
|
||||
|
||||
|
||||
uint8_t AD5263::setO1(const uint8_t value)
|
||||
{
|
||||
_O1 = (value == LOW) ? 0 : AD5263_O1_HIGH;
|
||||
uint8_t cmd = AD5263_RDAC0 | _O1 | _O2;
|
||||
return send(cmd, _lastValue[0]);
|
||||
}
|
||||
|
||||
|
||||
uint8_t AD5263::setO2(const uint8_t value)
|
||||
{
|
||||
_O2 = (value == LOW) ? 0: AD5263_O2_HIGH;
|
||||
uint8_t cmd = AD5263_RDAC0 | _O1 | _O2;
|
||||
return send(cmd, _lastValue[0]);
|
||||
}
|
||||
|
||||
|
||||
uint8_t AD5263::getO1()
|
||||
{
|
||||
return (_O1 > 0);
|
||||
}
|
||||
|
||||
|
||||
uint8_t AD5263::getO2()
|
||||
{
|
||||
return (_O2 > 0);
|
||||
}
|
||||
|
||||
|
||||
uint8_t AD5263::read(const uint8_t rdac)
|
||||
{
|
||||
if (rdac >= _pmCount) return 0x00;
|
||||
return _lastValue[rdac];
|
||||
}
|
||||
|
||||
|
||||
uint8_t AD5263::readBackRegister()
|
||||
{
|
||||
_wire->beginTransmission(_address);
|
||||
_wire->endTransmission();
|
||||
_wire->requestFrom(_address, (uint8_t)1);
|
||||
return _wire->read();
|
||||
}
|
||||
|
||||
|
||||
uint8_t AD5263::midScaleReset(const uint8_t rdac)
|
||||
{
|
||||
if (rdac >= _pmCount) return AD5263_ERROR;
|
||||
|
||||
uint8_t cmd = AD5263_RESET;
|
||||
if (rdac == 0) cmd |= AD5263_RDAC0;
|
||||
if (rdac == 1) cmd |= AD5263_RDAC1;
|
||||
if (rdac == 2) cmd |= AD5263_RDAC2;
|
||||
if (rdac == 3) cmd |= AD5263_RDAC3;
|
||||
|
||||
// apply the output lines
|
||||
cmd = cmd | _O1 | _O2;
|
||||
_lastValue[rdac] = AD5263_MIDPOINT;
|
||||
return send(cmd, AD5263_MIDPOINT);
|
||||
}
|
||||
|
||||
|
||||
// read datasheet P.20
|
||||
uint8_t AD5263::shutDown()
|
||||
{
|
||||
uint8_t cmd = AD5263_SHUTDOWN; // TODO TEST & VERIFY
|
||||
return send(cmd, 0);
|
||||
}
|
||||
|
||||
|
||||
uint8_t AD5263::pmCount()
|
||||
{
|
||||
return _pmCount;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//
|
||||
// PROTECTED
|
||||
//
|
||||
uint8_t AD5263::send(const uint8_t cmd, const uint8_t value)
|
||||
{
|
||||
_wire->beginTransmission(_address);
|
||||
_wire->write(cmd);
|
||||
_wire->write(value);
|
||||
return _wire->endTransmission();
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DERIVED CLASSES
|
||||
//
|
||||
/*
|
||||
AD5280::AD5280(const uint8_t address, TwoWire *wire) : AD5263(address, wire)
|
||||
{
|
||||
_pmCount = 1;
|
||||
}
|
||||
|
||||
|
||||
uint8_t AD5280::write(const uint8_t value)
|
||||
{
|
||||
// apply the output lines
|
||||
uint8_t cmd = AD5263_RDAC0 | _O1 | _O2;
|
||||
_lastValue[0] = value;
|
||||
return send(cmd, value);
|
||||
}
|
||||
|
||||
|
||||
uint8_t AD5280::write(const uint8_t value, const uint8_t O1, const uint8_t O2)
|
||||
{
|
||||
_O1 = (O1 == LOW) ? 0 : AD5263_O1_HIGH;
|
||||
_O2 = (O2 == LOW) ? 0 : AD5263_O2_HIGH;
|
||||
|
||||
// apply the output lines
|
||||
uint8_t cmd = AD5263_RDAC0 | _O1 | _O2;
|
||||
_lastValue[0] = value;
|
||||
return send(cmd, value);
|
||||
}
|
||||
|
||||
|
||||
uint8_t AD5280::write(const uint8_t rdac, const uint8_t value)
|
||||
{
|
||||
return AD5263::write(rdac, value);
|
||||
}
|
||||
|
||||
|
||||
uint8_t AD5280::write(const uint8_t rdac, const uint8_t value, const uint8_t O1, const uint8_t O2)
|
||||
{
|
||||
return AD5263::write(rdac, value, O1, O2);
|
||||
}
|
||||
|
||||
|
||||
AD5242::AD5282(const uint8_t address, TwoWire *wire) : AD5263(address, wire)
|
||||
{
|
||||
_pmCount = 2;
|
||||
}
|
||||
*/
|
||||
|
||||
// -- END OF FILE --
|
||||
|
103
libraries/AD5263/AD5263.h
Normal file
103
libraries/AD5263/AD5263.h
Normal file
@ -0,0 +1,103 @@
|
||||
#pragma once
|
||||
//
|
||||
// FILE: AD5263.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE:
|
||||
// DATE: 2023-10-09
|
||||
// URL: https://github.com/RobTillaart/AD5263
|
||||
// based upon AD524X interface.
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "Wire.h"
|
||||
|
||||
|
||||
#define AD5263_LIB_VERSION (F("0.1.0"))
|
||||
|
||||
|
||||
#define AD5263_OK 0
|
||||
#define AD5263_ERROR 100
|
||||
|
||||
|
||||
#define AD5263_MIDPOINT 128 // by datasheet.
|
||||
|
||||
|
||||
class AD5263
|
||||
{
|
||||
public:
|
||||
AD5263(const uint8_t address, TwoWire *wire = &Wire);
|
||||
|
||||
bool begin();
|
||||
bool isConnected();
|
||||
|
||||
// RESET
|
||||
uint8_t reset(); // reset all channels to AD5263_MIDPOINT and O1/O2 to LOW
|
||||
uint8_t zeroAll(); // set all channels to 0 and O1/O2 to LOW
|
||||
|
||||
// READ WRITE
|
||||
uint8_t read(const uint8_t rdac);
|
||||
uint8_t write(const uint8_t rdac, const uint8_t value);
|
||||
uint8_t write(const uint8_t rdac, const uint8_t value, const uint8_t O1, const uint8_t O2);
|
||||
|
||||
|
||||
// IO LINES
|
||||
uint8_t setO1(const uint8_t value = HIGH); // HIGH (default) / LOW
|
||||
uint8_t setO2(const uint8_t value = HIGH); // HIGH (default) / LOW
|
||||
uint8_t getO1();
|
||||
uint8_t getO2();
|
||||
|
||||
uint8_t midScaleReset(const uint8_t rdac);
|
||||
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();
|
||||
|
||||
|
||||
protected:
|
||||
uint8_t _pmCount = 4;
|
||||
|
||||
uint8_t send(const uint8_t cmd, const uint8_t value);
|
||||
|
||||
uint8_t _address;
|
||||
uint8_t _lastValue[4];
|
||||
uint8_t _O1;
|
||||
uint8_t _O2;
|
||||
|
||||
TwoWire* _wire;
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DERIVED CLASSES
|
||||
//
|
||||
/*
|
||||
// ONE CHANNEL
|
||||
class AD5280 : public AD5263
|
||||
{
|
||||
public:
|
||||
AD5280(const uint8_t address, TwoWire *wire = &Wire);
|
||||
|
||||
uint8_t write(const uint8_t value);
|
||||
uint8_t write(const uint8_t value, const uint8_t O1, const uint8_t O2);
|
||||
|
||||
uint8_t write(const uint8_t rdac, const uint8_t value);
|
||||
uint8_t write(const uint8_t rdac, const uint8_t value, const uint8_t O1, const uint8_t O2);
|
||||
};
|
||||
|
||||
|
||||
// TWO CHANNEL
|
||||
class AD5282 : public AD5263
|
||||
{
|
||||
public:
|
||||
AD5262(const uint8_t address, TwoWire *wire = &Wire);
|
||||
};
|
||||
*/
|
||||
|
||||
// -- END OF FILE --
|
||||
|
11
libraries/AD5263/CHANGELOG.md
Normal file
11
libraries/AD5263/CHANGELOG.md
Normal file
@ -0,0 +1,11 @@
|
||||
# Change Log AD5263
|
||||
|
||||
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-10-09
|
||||
- initial version (based upon AD524X library)
|
||||
|
21
libraries/AD5263/LICENSE
Normal file
21
libraries/AD5263/LICENSE
Normal 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.
|
158
libraries/AD5263/README.md
Normal file
158
libraries/AD5263/README.md
Normal file
@ -0,0 +1,158 @@
|
||||
|
||||
[![Arduino CI](https://github.com/RobTillaart/AD5263/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
||||
[![Arduino-lint](https://github.com/RobTillaart/AD5263/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/AD5263/actions/workflows/arduino-lint.yml)
|
||||
[![JSON check](https://github.com/RobTillaart/AD5263/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/AD5263/actions/workflows/jsoncheck.yml)
|
||||
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/AD5263.svg)](https://github.com/RobTillaart/AD5263/issues)
|
||||
|
||||
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/AD5263/blob/master/LICENSE)
|
||||
[![GitHub release](https://img.shields.io/github/release/RobTillaart/AD5263.svg?maxAge=3600)](https://github.com/RobTillaart/AD5263/releases)
|
||||
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/AD5263.svg)](https://registry.platformio.org/libraries/robtillaart/AD5263)
|
||||
|
||||
|
||||
# AD5263
|
||||
|
||||
Arduino library for I2C digital potentiometer AD5263 and compatibles.
|
||||
|
||||
|
||||
## Description
|
||||
|
||||
**Experimental** needs testing with hardware.
|
||||
|
||||
The AD5263 is a digital potentiometer with 4 channels.
|
||||
This digital potentiometers come in 20, 50 and 200 kΩ
|
||||
and can be set in 256 steps.
|
||||
|
||||
This library only implements the I2C interface.
|
||||
|
||||
An important property of the device is that it defaults
|
||||
to their mid position at startup.
|
||||
|
||||
The library also defines **AD5263_MIDPOINT** == 128.
|
||||
To be used to set to defined mid-point.
|
||||
|
||||
(Library is based on datasheet Rev.F )
|
||||
|
||||
|
||||
#### Related
|
||||
|
||||
This library is related to
|
||||
|
||||
- https://github.com/RobTillaart/AD524X single/dual port digital potentiometer.
|
||||
- https://github.com/RobTillaart/AD5245 single port digital potentiometer.
|
||||
- https://github.com/RobTillaart/AD520X multi port digital potentiometer.
|
||||
- https://www.analog.com/media/en/technical-documentation/data-sheets/ad5263.pdf
|
||||
|
||||
|
||||
#### Compatibles
|
||||
|
||||
The AD5280 and AD5282 are one and two channel devices that might be compatible.
|
||||
Not tested yet. See future.
|
||||
|
||||
|
||||
## I2C
|
||||
|
||||
#### Address
|
||||
|
||||
The AD5263 has two address lines to configure the I2C address. 0x2C - 0x2F
|
||||
|
||||
| Addr(dec) | Addr(Hex) | AD0 | AD1 |
|
||||
|:----------:|:-----------:|:-----:|:-----:|
|
||||
| 44 | 0x2C | GND | GND |
|
||||
| 45 | 0x2D | GND | +5V |
|
||||
| 46 | 0x2E | +5V | GND |
|
||||
| 47 | 0x2F | +5V | +5V |
|
||||
|
||||
Note the AD5263 uses the same range as the AD524X devices.
|
||||
|
||||
|
||||
#### Performance
|
||||
|
||||
- TODO
|
||||
- table
|
||||
- test sketch
|
||||
|
||||
|
||||
## Interface
|
||||
|
||||
```cpp
|
||||
#include "AD5263.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
|
||||
|
||||
- **AD5263(uint8_t address, TwoWire \*wire = &Wire)** constructor,
|
||||
creates an instance with 4 potentiometer.
|
||||
- **bool begin()** if connected **begin()** resets the device,
|
||||
otherwise returns false.
|
||||
- **bool isConnected()** See if address set in constructor is on the bus.
|
||||
|
||||
|
||||
#### Basic IO
|
||||
|
||||
- **uint8_t write(uint8_t rdac, uint8_t value)** set channel rdac 0..3 to value 0..255.
|
||||
- **uint8_t write(uint8_t rdac, uint8_t value, uint8_t O1, uint8_t O2)** idem + set output lines O1 and O2 too.
|
||||
- **uint8_t read(uint8_t rdac)** read back set value.
|
||||
rdac should be 0..3.
|
||||
- **uint8_t setO1(uint8_t value = HIGH)** value = HIGH (default) or LOW.
|
||||
- **uint8_t setO2(uint8_t value = HIGH)** value = HIGH (default) or LOW.
|
||||
- **uint8_t getO1()** read back O1 line.
|
||||
- **uint8_t getO2()** read back O2 line.
|
||||
|
||||
|
||||
#### Misc
|
||||
|
||||
- **uint8_t zeroAll()** sets potentiometer's to 0 and I/O to LOW.
|
||||
- **uint8_t reset()** sets potentiometer's to midpoint == 127 and I/O to LOW. (startup default)
|
||||
- **uint8_t midScaleReset(uint8_t rdac)** resets one potentiometer to midpoint == 127.
|
||||
- **uint8_t readBackRegister()** read register back, for debugging.
|
||||
|
||||
|
||||
#### Experimental
|
||||
|
||||
- **uint8_t shutDown()** check datasheet, not tested, use at own risk.
|
||||
|
||||
|
||||
## Error codes
|
||||
|
||||
| define | value |
|
||||
|:---------------|:-------:|
|
||||
| AD5263_OK | 0 |
|
||||
| AD5263_ERROR | 100 |
|
||||
|
||||
|
||||
## Future
|
||||
|
||||
#### Must
|
||||
|
||||
- update documentation.
|
||||
- get hardware (breakout or so).
|
||||
- test with hardware.
|
||||
|
||||
|
||||
#### Should
|
||||
|
||||
|
||||
#### Could
|
||||
|
||||
- investigate AD5280/82 compatibility.
|
||||
- improve error handling.
|
||||
- sync with AD520X / AD524X library
|
||||
- optimize footprint **write()** and **midScaleReset()**
|
||||
|
||||
|
||||
#### 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,
|
||||
|
@ -0,0 +1,50 @@
|
||||
//
|
||||
// FILE: AD5263_followA0.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: AD5263 demo program
|
||||
// URL: https://github.com/RobTillaart/AD5263
|
||||
|
||||
|
||||
#include "AD5263.h"
|
||||
|
||||
AD5263 AD01(0x2C); // AD0 & AD1 == GND
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.println(__FILE__);
|
||||
Serial.println();
|
||||
Serial.println(AD5263_LIB_VERSION);
|
||||
|
||||
Wire.begin();
|
||||
Wire.setClock(400000);
|
||||
|
||||
bool b = AD01.begin();
|
||||
Serial.println(b ? "true" : "false");
|
||||
Serial.println(AD01.isConnected());
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
int x = analogRead(A0);
|
||||
Serial.print(x);
|
||||
Serial.print('\t');
|
||||
Serial.print(x/4);
|
||||
|
||||
int rv = AD01.write(1, x/4);
|
||||
Serial.print('\t');
|
||||
Serial.print(rv);
|
||||
|
||||
rv = AD01.write(0, x/4);
|
||||
Serial.print('\t');
|
||||
Serial.println(rv);
|
||||
|
||||
delay(100);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -0,0 +1,38 @@
|
||||
//
|
||||
// FILE: AD5263_isConnected.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: AD5263 demo program
|
||||
// URL: https://github.com/RobTillaart/AD5263
|
||||
|
||||
|
||||
#include "AD5263.h"
|
||||
|
||||
AD5263 AD01(0x2C); // AD0 & AD1 == GND
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.println(__FILE__);
|
||||
Serial.println();
|
||||
Serial.println(AD5263_LIB_VERSION);
|
||||
|
||||
Wire.begin();
|
||||
Wire.setClock(400000);
|
||||
|
||||
bool b = AD01.begin();
|
||||
Serial.println(b ? "true" : "false");
|
||||
Serial.println(AD01.isConnected());
|
||||
|
||||
Serial.println("\nDone...");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -0,0 +1,51 @@
|
||||
//
|
||||
// FILE: AD5263_midScaleReset.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: AD5263 demo program
|
||||
// URL: https://github.com/RobTillaart/AD5263
|
||||
|
||||
|
||||
#include "AD5263.h"
|
||||
|
||||
AD5263 AD01(0x2C); // AD0 & AD1 == GND
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.println(__FILE__);
|
||||
Serial.println();
|
||||
Serial.println(AD5263_LIB_VERSION);
|
||||
|
||||
Wire.begin();
|
||||
Wire.setClock(400000);
|
||||
|
||||
bool b = AD01.begin();
|
||||
Serial.println(b ? "true" : "false");
|
||||
Serial.println(AD01.isConnected());
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.println(255);
|
||||
AD01.write(1, 255);
|
||||
delay(1000);
|
||||
|
||||
Serial.println("midScaleReset(1)");
|
||||
AD01.midScaleReset(1);
|
||||
delay(1000);
|
||||
|
||||
Serial.println(0);
|
||||
AD01.write(1, 0);
|
||||
delay(1000);
|
||||
|
||||
Serial.println("midScaleReset(1)");
|
||||
AD01.midScaleReset(1);
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
47
libraries/AD5263/examples/AD5263_read/AD5263_read.ino
Normal file
47
libraries/AD5263/examples/AD5263_read/AD5263_read.ino
Normal file
@ -0,0 +1,47 @@
|
||||
//
|
||||
// FILE: AD5263_read.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: AD5263 demo program
|
||||
// URL: https://github.com/RobTillaart/AD5263
|
||||
|
||||
|
||||
#include "AD5263.h"
|
||||
|
||||
AD5263 AD01(0x2C); // AD0 & AD1 == GND
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.println(__FILE__);
|
||||
Serial.println();
|
||||
Serial.println(AD5263_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 --
|
@ -0,0 +1,58 @@
|
||||
//
|
||||
// FILE: AD5263_readBackRegister.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: AD5263 demo program
|
||||
// URL: https://github.com/RobTillaart/AD5263
|
||||
|
||||
|
||||
#include "AD5263.h"
|
||||
|
||||
AD5263 AD01(0x2C); // AD0 & AD1 == GND
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.println(__FILE__);
|
||||
Serial.println();
|
||||
Serial.println(AD5263_LIB_VERSION);
|
||||
|
||||
Wire.begin();
|
||||
Wire.setClock(400000);
|
||||
|
||||
bool b = AD01.begin();
|
||||
Serial.println(b ? "true" : "false");
|
||||
Serial.println(AD01.isConnected());
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
for (int rdac = 0; rdac < 4; rdac++)
|
||||
{
|
||||
for (int val = 0; val < 255; val++)
|
||||
{
|
||||
test(rdac, val);
|
||||
}
|
||||
}
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
void test(uint8_t rdac, uint8_t val)
|
||||
{
|
||||
Serial.print(val);
|
||||
AD01.write(rdac, val);
|
||||
delay(100);
|
||||
|
||||
int x = AD01.read(rdac);
|
||||
int y = AD01.readBackRegister();
|
||||
Serial.print('\t');
|
||||
Serial.print(x);
|
||||
Serial.print('\t');
|
||||
Serial.println(y);
|
||||
delay(100);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
@ -0,0 +1,42 @@
|
||||
//
|
||||
// FILE: AD5263_sawtooth.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: AD5263 demo program
|
||||
// URL: https://github.com/RobTillaart/AD5263
|
||||
|
||||
|
||||
#include "AD5263.h"
|
||||
|
||||
AD5263 AD01(0x2C); // AD0 & AD1 == GND
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.println(__FILE__);
|
||||
Serial.println();
|
||||
Serial.println(AD5263_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);
|
||||
Serial.println(val);
|
||||
delay(20);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
51
libraries/AD5263/examples/AD5263_setO/AD5263_setO.ino
Normal file
51
libraries/AD5263/examples/AD5263_setO/AD5263_setO.ino
Normal file
@ -0,0 +1,51 @@
|
||||
//
|
||||
// FILE: AD5263_setO.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: AD5263 demo program
|
||||
// URL: https://github.com/RobTillaart/AD5263
|
||||
|
||||
|
||||
#include "AD5263.h"
|
||||
|
||||
AD5263 AD01(0x2C); // AD0 & AD1 == GND
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.println(__FILE__);
|
||||
Serial.println();
|
||||
Serial.println(AD5263_LIB_VERSION);
|
||||
|
||||
Wire.begin();
|
||||
Wire.setClock(400000);
|
||||
|
||||
bool b = AD01.begin();
|
||||
Serial.println(b ? "true" : "false");
|
||||
Serial.println(AD01.isConnected());
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
int x = 10 + analogRead(A0);
|
||||
AD01.setO1(LOW);
|
||||
AD01.setO2(HIGH);
|
||||
Serial.print(AD01.getO1());
|
||||
Serial.print('\t');
|
||||
Serial.println(AD01.getO2());
|
||||
delay(x);
|
||||
|
||||
x = 10 + analogRead(A0);
|
||||
AD01.setO1(HIGH);
|
||||
AD01.setO2(LOW);
|
||||
Serial.print(AD01.getO1());
|
||||
Serial.print('\t');
|
||||
Serial.println(AD01.getO2());
|
||||
delay(x);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
50
libraries/AD5263/examples/AD5263_write/AD5263_write.ino
Normal file
50
libraries/AD5263/examples/AD5263_write/AD5263_write.ino
Normal file
@ -0,0 +1,50 @@
|
||||
//
|
||||
// FILE: AD5263_write.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: AD5263 demo program
|
||||
// URL: https://github.com/RobTillaart/AD5263
|
||||
|
||||
|
||||
#include "AD5263.h"
|
||||
|
||||
AD5263 AD01(0x2C); // AD0 & AD1 == GND
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.println(__FILE__);
|
||||
Serial.println();
|
||||
Serial.println(AD5263_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);
|
||||
if (val == 200)
|
||||
{
|
||||
AD01.write(1, val, HIGH, LOW);
|
||||
}
|
||||
if (val == 0)
|
||||
{
|
||||
AD01.write(1, val, LOW, LOW);
|
||||
}
|
||||
Serial.println(val);
|
||||
delay(20);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
30
libraries/AD5263/keywords.txt
Normal file
30
libraries/AD5263/keywords.txt
Normal file
@ -0,0 +1,30 @@
|
||||
# Syntax Colouring Map For AD523X
|
||||
|
||||
# Data types (KEYWORD1)
|
||||
AD5263 KEYWORD1
|
||||
|
||||
# Methods and Functions (KEYWORD2)
|
||||
begin KEYWORD2
|
||||
reset KEYWORD2
|
||||
zeroAll KEYWORD2
|
||||
|
||||
read KEYWORD2
|
||||
write KEYWORD2
|
||||
|
||||
setO1 KEYWORD2
|
||||
setO2 KEYWORD2
|
||||
getO1 KEYWORD2
|
||||
getO2 KEYWORD2
|
||||
|
||||
midScaleReset KEYWORD2
|
||||
pmCount KEYWORD2
|
||||
shutDown KEYWORD2
|
||||
|
||||
|
||||
# Constants (LITERAL1)
|
||||
AD5263_LIB_VERSION LITERAL1
|
||||
|
||||
AD5263_OK LITERAL1
|
||||
AD5263_ERROR LITERAL1
|
||||
AD5263_MIDPOINT LITERAL1
|
||||
|
0
libraries/AD5263/klein groen bordje.txt
Normal file
0
libraries/AD5263/klein groen bordje.txt
Normal file
23
libraries/AD5263/library.json
Normal file
23
libraries/AD5263/library.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "AD5263",
|
||||
"keywords": "I2C,digital,PotentioMeter, AD5241, AD5242",
|
||||
"description": "Library to control digital potentiometer AD5263 and compatibles.",
|
||||
"authors":
|
||||
[
|
||||
{
|
||||
"name": "Rob Tillaart",
|
||||
"email": "Rob.Tillaart@gmail.com",
|
||||
"maintainer": true
|
||||
}
|
||||
],
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/AD5263"
|
||||
},
|
||||
"version": "0.1.0",
|
||||
"license": "MIT",
|
||||
"frameworks": "*",
|
||||
"platforms": "*",
|
||||
"headers": "AD5263.h"
|
||||
}
|
11
libraries/AD5263/library.properties
Normal file
11
libraries/AD5263/library.properties
Normal file
@ -0,0 +1,11 @@
|
||||
name=AD5263
|
||||
version=0.1.0
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino Library for AD5263
|
||||
paragraph=Library to control digital potentiometer AD5263 and compatibles.
|
||||
category=Signal Input/Output
|
||||
url=https://github.com/RobTillaart/AD5263
|
||||
architectures=*
|
||||
includes=AD5263.h
|
||||
depends=
|
155
libraries/AD5263/test/unit_test_001.cpp
Normal file
155
libraries/AD5263/test/unit_test_001.cpp
Normal file
@ -0,0 +1,155 @@
|
||||
//
|
||||
// FILE: unit_test_001.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2023-01-09
|
||||
// PURPOSE: unit tests for I2C digital potentiometer AD5263 and compatibles.
|
||||
// https://github.com/RobTillaart/AD5263
|
||||
// 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 "AD5263.h"
|
||||
|
||||
|
||||
unittest_setup()
|
||||
{
|
||||
fprintf(stderr, "\nAD5263_LIB_VERSION: %s\n", (char *) AD5263_LIB_VERSION);
|
||||
}
|
||||
|
||||
|
||||
unittest_teardown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
unittest(test_constants)
|
||||
{
|
||||
assertEqual(0, AD5263_OK);
|
||||
assertEqual(100, AD5263_ERROR);
|
||||
assertEqual(128, AD5263_MIDPOINT);
|
||||
}
|
||||
|
||||
|
||||
unittest(test_constructors)
|
||||
{
|
||||
Wire.begin();
|
||||
|
||||
AD5263 ADx(0x2C); // AD0 & AD1 == GND
|
||||
assertEqual(128, ADx.read(0));
|
||||
assertEqual(128, ADx.read(1));
|
||||
assertEqual(128, ADx.read(2));
|
||||
assertEqual(128, ADx.read(3));
|
||||
}
|
||||
|
||||
|
||||
unittest(test_reset)
|
||||
{
|
||||
AD5263 ADx(0x2C); // AD0 & AD1 == GND
|
||||
Wire.begin();
|
||||
|
||||
assertEqual(128, ADx.read(0));
|
||||
assertEqual(128, ADx.read(1));
|
||||
assertEqual(128, ADx.read(2));
|
||||
assertEqual(128, ADx.read(3));
|
||||
|
||||
ADx.zeroAll();
|
||||
assertEqual(0, ADx.read(0));
|
||||
assertEqual(0, ADx.read(1));
|
||||
assertEqual(0, ADx.read(2));
|
||||
assertEqual(0, ADx.read(3));
|
||||
|
||||
ADx.reset();
|
||||
assertEqual(128, ADx.read(0));
|
||||
assertEqual(128, ADx.read(1));
|
||||
assertEqual(128, ADx.read(2));
|
||||
assertEqual(128, ADx.read(3));
|
||||
|
||||
ADx.zeroAll();
|
||||
assertEqual(0, ADx.read(0));
|
||||
assertEqual(0, ADx.read(1));
|
||||
assertEqual(0, ADx.read(2));
|
||||
assertEqual(0, ADx.read(3));
|
||||
|
||||
ADx.midScaleReset(0);
|
||||
assertEqual(128, ADx.read(0));
|
||||
ADx.midScaleReset(1);
|
||||
assertEqual(128, ADx.read(1));
|
||||
ADx.midScaleReset(0);
|
||||
assertEqual(128, ADx.read(0));
|
||||
ADx.midScaleReset(1);
|
||||
assertEqual(128, ADx.read(1));
|
||||
}
|
||||
|
||||
|
||||
unittest(test_write_read)
|
||||
{
|
||||
AD5263 ADx(0x2C); // AD0 & AD1 == GND
|
||||
Wire.begin();
|
||||
|
||||
assertEqual(128, ADx.read(0));
|
||||
assertEqual(128, ADx.read(1));
|
||||
assertEqual(128, ADx.read(2));
|
||||
assertEqual(128, ADx.read(3));
|
||||
|
||||
ADx.write(0, 42);
|
||||
assertEqual(42, ADx.read(0));
|
||||
assertEqual(128, ADx.read(1));
|
||||
assertEqual(128, ADx.read(2));
|
||||
assertEqual(128, ADx.read(3));
|
||||
|
||||
ADx.write(1, 42);
|
||||
assertEqual(42, ADx.read(0));
|
||||
assertEqual(42, ADx.read(1));
|
||||
assertEqual(128, ADx.read(2));
|
||||
assertEqual(128, ADx.read(3));
|
||||
}
|
||||
|
||||
|
||||
unittest(test_O1_O2)
|
||||
{
|
||||
AD5263 ADx(0x2C); // AD0 & AD1 == GND
|
||||
Wire.begin();
|
||||
|
||||
assertEqual(0, ADx.getO1());
|
||||
assertEqual(0, ADx.getO2());
|
||||
|
||||
ADx.setO1();
|
||||
assertEqual(1, ADx.getO1());
|
||||
assertEqual(0, ADx.getO2());
|
||||
|
||||
ADx.setO2();
|
||||
assertEqual(1, ADx.getO1());
|
||||
assertEqual(1, ADx.getO2());
|
||||
|
||||
ADx.setO1(0);
|
||||
assertEqual(0, ADx.getO1());
|
||||
assertEqual(1, ADx.getO2());
|
||||
|
||||
ADx.setO2(0);
|
||||
assertEqual(0, ADx.getO1());
|
||||
assertEqual(0, ADx.getO2());
|
||||
|
||||
ADx.write(0, 0, 1, 1);
|
||||
assertEqual(1, ADx.getO1());
|
||||
assertEqual(1, ADx.getO2());
|
||||
}
|
||||
|
||||
|
||||
unittest_main()
|
||||
|
||||
|
||||
// -- END OF FILE --
|
Loading…
Reference in New Issue
Block a user