Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:iot-open:practical:hardware:sut:esp32:emb2_1 [2024/04/20 08:11] – [Prerequisites] pczekalskien:iot-open:practical:hardware:sut:esp32:emb2_1 [2025/04/28 20:31] (current) – [Steps] pczekalski
Line 1: Line 1:
-<todo @pczekalski>DOkończyć</todo> 
 ====== EMB2: Using a digital potentiometer ===== ====== EMB2: Using a digital potentiometer =====
 Digital potentiometer DS1803 is an I2C-controlled device that can digitally control the potentiometer.\\ Opposite to the physical potentiometers, there are no movable parts.\\ Digital potentiometer DS1803 is an I2C-controlled device that can digitally control the potentiometer.\\ Opposite to the physical potentiometers, there are no movable parts.\\
Line 74: Line 73:
 ==== Steps ==== ==== Steps ====
 Below, we assume that you have embedded functions handling operations on the digital potentiometer as defined above in your source file. Remember to add ''Wire.h'' include! Below, we assume that you have embedded functions handling operations on the digital potentiometer as defined above in your source file. Remember to add ''Wire.h'' include!
-<note tip>NoteStep 5 presents some stub code for displaying data on an OLED display.</note>+<note tip>NoteStep 5 presents some stub code for displaying data on an OLED display.</note>
 === Step 1 === === Step 1 ===
-Define I2C bus GPIOs: clock (SCL) uses GPIO 4 and data (SDA) GPIO 5. ADC uses GPIO 7. Digital potentiometer chip DS1803 uses 0x28 I2C address. All definitions are present in the following code:+Define I2C bus GPIOs: clock (SCL) uses GPIO 4and data (SDA) uses GPIO 5. ADC uses GPIO 7. Digital potentiometer chip DS1803 uses 0x28 I2C address. All definitions are present in the following code:
 <code c> <code c>
 #define SCL 4 #define SCL 4
Line 86: Line 85:
 Declare an array of readings that fits an OLED display. Adjust for ePaper resolution (horizontal) if using it. OLED is 128x128 pixels: Declare an array of readings that fits an OLED display. Adjust for ePaper resolution (horizontal) if using it. OLED is 128x128 pixels:
 <code c> <code c>
-static volatile int16_t aGraphArray[128]; +static int16_t aGraphArray[128]; 
 </code> </code>
 === Step 3 === === Step 3 ===
Line 95: Line 94:
   Wire.begin(SDA,SCL);   Wire.begin(SDA,SCL);
   delay(100);   delay(100);
 +  ...
 +  
   pinMode(POT_ADC, INPUT);   pinMode(POT_ADC, INPUT);
 </code> </code>
 +
 +<note important>You need to initialise the I2C bus only once. If you're using other I2C devices in parallel, do not call ''Wire.begin(...)'' multiple times.</note>
  
 === Step 4 === === Step 4 ===
-Read the loopback characteristics of the digital potentiometer to ADC loop and store it in the array:+Read the loopback characteristics of the digital potentiometer to the ADC loop and store it in the array:
 <code c> <code c>
 for(byte i=0; i<128; i++) for(byte i=0; i<128; i++)
Line 109: Line 112:
  
 === Step 5 === === Step 5 ===
-Display on the OLED. Assume the following handler to the pointer to the display controller class for the ''SSD1306Wire& display'' OLED display. More information in the scenario [[en:iot-open:practical:hardware:sut:esp32:emb7_1|]].+Display on the OLED. Assume the following handler to the pointer to the display controller class:  
 +<code c> 
 +SSD1306Wire& display 
 +</code>  
 +More information in the scenario [[en:iot-open:practical:hardware:sut:esp32:emb7_1|]].
 Note, ADC measures in the 12-bit mode (we assume such configuration, adapt ''factor'' if using other sampling resolution), so values stored in an ''aGraphArray'' array are between 0 and 4095.  Note, ADC measures in the 12-bit mode (we assume such configuration, adapt ''factor'' if using other sampling resolution), so values stored in an ''aGraphArray'' array are between 0 and 4095. 
 <code c> <code c>
en/iot-open/practical/hardware/sut/esp32/emb2_1.1713600681.txt.gz · Last modified: 2024/04/20 08:11 by pczekalski
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0