This is an old revision of the document!
[pczekalski]DOkończyć
Digital potentiometer DS1803 is an I2C-controlled device that can digitally control the potentiometer.
Opposite to the physical potentiometers, there are no movable parts.
DS1803 has two digital potentiometers controlled independently. We use just one with the lower cardinal number (index 0). In our example, it is a 100k spread between GND and VCC, and its output is connected to the ADC (analogue to digital converter) input of the ESP32 MCU. This way, the potentiometer's wiper is controlled remotely via the I2C bus.
The device's I2C address is 0x28, and the ADC input GPIO pin is 7.
The digital potentiometer in our laboratory node forms then a loopback device: it can be set (also read) via I2C, and the resulting voltage can be measured on the separate PIN (ADC) 1. This way, it is possible, e.g. to draw a relation between the potentiometer setting and ADC readings to check whether it is linear or forms some other curve.
Reading of the ADC is possible using the regular analogRead(pin)
function.
To implement this scenario, it is advised to get familiar with at least one of the following scenarios first:
They enable you to present the data on the display (i.e. readings).
To handle communication with the DS1803 digital potentiometer, we use bare I2C programming. For this reason, we need to include only the I2C protocol library:
#include <Wire.h>
Below, we present a sample control library that you need to include in your code:
#define POT_ADC 7 //GPIO 7 in ESP32 #define DS1803_ADDRESS 0x28 //I2C Address enum POT_LIST {POT_1 = 0xA9, POT_2=0xAA, POT_ALL=0xAF}; //We have only POT_1 connected typedef enum POT_LIST POT_ID; //Prototypes void setPotentiometer(TwoWire& I2CPipe, byte potValue, POT_ID potNumber); byte readPotentiometer(TwoWire& I2CPipe, POT_ID potNumber); //Implementation void setPotentiometer(TwoWire& I2CPipe, byte potValue, POT_ID potNumber) { I2CPipe.beginTransmission(DS1803_ADDRESS); I2CPipe.write(potNumber); I2CPipe.write(potValue); I2CPipe.endTransmission(true); }; byte readPotentiometer(TwoWire& I2CPipe, POT_ID potNumber) //reads selected potentiometer { byte buffer[2]; I2CPipe.requestFrom(DS1803_ADDRESS,2); buffer[0]=I2CPipe.read(); buffer[1]=I2CPipe.read(); return (potNumber==POT_1?buffer[0]:buffer[1]); };
readPotentiometer(…)
function does not read the voltage over ADC. It returns a set value (the same as provided by setPotentiometer(…)
), which is on the digital side of the DS1803 device. Analogue input (a resulting voltage converted to the digital representation) can be obtained simply using regular analogRead(pin)
that reads from the ADC.
Iterate over the potentiometer settings, read related voltage readings via ADC, and present them in graphical form. As the maximum resolution is 256, you can use a plot of 256 points or any other lower value covering all ranges. Present graph (plot) on either ePaper or OLED display, and while doing the readings, you should present data in the LCD (upper row for a set value, lower for a reading of the ADC).
Check if you can see all the displays. Remember to use potentiometer 1 (index 0) because only this one is connected to the ADC input of the ESP32 MCU.
Write some extra information if, i.e. some steps are optional; otherwise, cancel this paragraph (but do not remove the header).
Describe activities done in Step 1.
…
Describe activities done in Step n.
Provide some result validation methods for self-assessment.
This section is to be extended as new questions appear.
When using the printed version of this manual, please refer to the latest online version of this document to obtain the valid and up-to-date list of the FAQ.
Provide some FAQs in the following form:
Question?: Answer.
This Intellectual Output was implemented under the Erasmus+ KA2.
Project IOT-OPEN.EU Reloaded – Education-based strengthening of the European universities, companies and labour force in the global IoT market.
Project number: 2022-1-PL01-KA220-HED-000085090.
Erasmus+ Disclaimer
This project has been funded with support from the European Commission.
This publication reflects the views of only the author, and the Commission cannot be held responsible for any use that may be made of the information contained therein.
Copyright Notice
This content was created by the IOT-OPEN.EU Reloaded consortium, 2022,2024.
The content is Copyrighted and distributed under CC BY-NC Creative Commons Licence, free for Non-Commercial use.