Digital potentionmeter X9C104

Why do I use this module? There is a feedback resistor in Op-Amp negative amplifier and it is not handy when you use hand to adjust the feedback resistor so I decide to use digital potentionmeter as an auto-again adjustment (AAA)
Step 0: hardware connection

 pin 2, 3, 4 —> INC, U/D, CS

pin A0 –> RW

2 resistors 100Ω: pull-up at RH and pull-down at RL

Step 1: go to https://sites.google.com/site/tfagerscode/home/digipotx9cxxx download the library and paste it in your Arduino library.

Step 2:


/*
 * Date: Wed, 03/05/2017
 * Desc: Test digital potentionmeter X9C104
 * the initial pot_index will be zero
*/
#include <DigiPotX9Cxxx.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

DigiPot pot(2,3,4);

#define I2C_ADDR 0x3F 
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

char incomingChar;
int pot_index;
const int analogInPin = A0;
int sensorValue = 0; 
void setup() {
 // Return value of pot to zero
 for (int i=0; i<100; i++){ 
 pot.decrease(1);
 delay(10);
 }
 pot_index = 0;
 // Initial device
 Serial.begin(9600);
 Serial.println("Starting ...");

lcd.begin(16,2);
 lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
 lcd.setBacklight(HIGH);
 sensorValue = analogRead(analogInPin);
 display_lcd(pot_index, sensorValue);
 delay(1000);
}

void loop() {
 // receive '1' to increase, '0' to decrease
 if (Serial.available()){
 incomingChar = (char) Serial.read();
 if (incomingChar == '1'){ 
 if(pot_index >= 100){
 Serial.println("Pot index reaches maximum limit.");
 lcd.clear();
 lcd.print("Maximum limit"); 
 }else{
 pot.increase(1);
 pot_index ++;
 sensorValue = analogRead(analogInPin);
 display_lcd(pot_index, sensorValue);
 } 
 }
 else if (incomingChar == '0'){
 if (pot_index <= 0){
 Serial.println("Pot index reaches minimum limit.");
 lcd.clear();
 lcd.print("Minimum limit");
 }else{
 pot.decrease(1);
 pot_index --;
 sensorValue = analogRead(analogInPin);
 display_lcd(pot_index, sensorValue);
 } 
 }else{
 Serial.println("Something wrong happens.");
 lcd.clear();
 lcd.print("Error"); 
 } 
 }
}

void display_lcd(int p_index, int p_value){
 lcd.clear();
 lcd.print("pot index: ");
 lcd.setCursor(11,0);
 lcd.print(p_index);
 lcd.setCursor(0,1);
 lcd.print("pot value: ");
 lcd.setCursor(11,1);
 lcd.print(p_value);
}

There are two definition of pot, pot_index and pot_value. Pot_index will be from 0 to 100. That is the value of X9C104 we control. Pot_value is the analog feedback on pin A, it will be from 0 to 1023. However I added 2 resistor: pull-up resistor at pin RH and pull-down resistor at pin RL so the value of analog A0 will be from 8 to 1008 (or from 4 to 1004 ... ADC still has some tolerance, let's say)

 

Why needs amplifying? Something the signal is too small to determine is the reading value a noise or a real value? You will see the usefulness of digital potentionmeter in my project Dimmer with current feedback.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s