0

I2C pot and LCD shield not getting along
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

I2C pot and LCD shield not getting along

by TheIronCrown on Tue Jun 22, 2021 5:39 pm

Hello all,

I'm trying to use an LCD shield https://learn.adafruit.com/rgb-lcd-shield/overview along with a digital potentiometer https://learn.adafruit.com/ds3502-i2c-potentiometer/overview.

I've combined the test code of these two tutorials to try and adjust the pot using the buttons of the shield. When it runs, the LCD shield works as expected, but the pot doesn't seem to respond. Running the pot disconnected from the screen shows it to work properly. The default I2C addresses seem to be different. Code inserted below. Using setWiper to manually set to a different value does not change the voltage displayed. The shield and pot are connected to the same power line, SCL, and SDA. Everything is wired as per the tutorial, except that the shield and pot are both wired to SCL and SDA, not A4 and A5 as suggested. Both do not work if connected to A4 and A5.

Any insight would be helpful!

Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include <Adafruit_RGBLCDShield.h>
#include <utility/Adafruit_MCP23017.h>
#include <Adafruit_DS3502.h>
// The shield uses the I2C SCL and SDA pins. On classic Arduinos
// this is Analog 4 and 5 so you can't use those for analogRead() anymore
// However, you can connect other I2C sensors to the I2C bus and share
// the I2C bus.
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
Adafruit_DS3502 ds3502 = Adafruit_DS3502();
// These #defines make it easy to set the backlight color
#define OFF 0x0
#define ON 0x1
#define WIPER_VALUE_PIN A0
int wiper_set[] = {0, 15, 30, 45, 60, 75, 90, 105, 120, 137};
int wiper_current = 9;


void setup() {
  // put your setup code here, to run once:
// Debugging output
  Serial.begin(9600);
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);

  // Print a message to the LCD. We track how long it takes since
  // this library has been optimized a bit and we're proud of it :)
  lcd.print("Hello, world!");
  lcd.setCursor(0,1);
  lcd.print("Took "); lcd.print(millis()); lcd.print(" ms");
  lcd.setBacklight(ON);
  delay(1000);
  ds3502.setWiper(0);
}

void loop() {
  // put your main code here, to run repeatedly:
   // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  float wiper_value = analogRead(WIPER_VALUE_PIN);
  wiper_value *= 5.0;
  wiper_value /= 1024;
  Serial.println(wiper_value);
  lcd.print("Wiper="); lcd.print(wiper_set[wiper_current]); lcd.print(" V="); lcd.print(wiper_value);
  delay(500);
 
uint8_t buttons = lcd.readButtons();

  if (buttons) {
    lcd.clear();
    lcd.setCursor(0,0);
    if (buttons & BUTTON_UP) {
      if (wiper_current < 9){
        wiper_current++;
        ds3502.setWiper(wiper_set[wiper_current]);
        lcd.print("R up to "); lcd.print(wiper_set[wiper_current]);
      }
      else{
        lcd.print("R is already max!");
      }
    }
    if (buttons & BUTTON_DOWN) {
      if (wiper_current > 0){
        wiper_current--;
        ds3502.setWiper(wiper_set[wiper_current]);
        lcd.print("R down to "); lcd.print(wiper_set[wiper_current]);
      }
      else{
        lcd.print("R is already min!");
      }
    }
  }
}

TheIronCrown
 
Posts: 6
Joined: Thu Jun 17, 2021 4:46 pm

Re: I2C pot and LCD shield not getting along

by dastels on Wed Jun 23, 2021 12:56 pm

Yes, the I2C addresses look ok. What board do you have them connected to? And can you post clear photos of your connections?

Dave

dastels
 
Posts: 6873
Joined: Tue Oct 20, 2015 3:22 pm

Re: I2C pot and LCD shield not getting along

by TheIronCrown on Wed Jun 23, 2021 2:30 pm

Hello Dave,

Here's the photos: https://photos.app.goo.gl/mWmJhkY4ZsGHvL7BA
The picture is on a stainless steel table, but I do keep all terminations isolated from it with a non-conductive surface. The board is a Metro 328. Hope the photos are clear enough. I've tried connecting the two devices by connecting the pins of the pot as per the tutorial, as well as the 4 cable connectors that plug into the pot.

TheIronCrown
 
Posts: 6
Joined: Thu Jun 17, 2021 4:46 pm

Re: I2C pot and LCD shield not getting along

by dastels on Wed Jun 23, 2021 2:53 pm

OK. It looks fine. You've double and triple checked the wiring? You could try using different rows on the breadboard... they don't always make a solid connection (stretch, corrosion, etc, etc), try different wires. Disconnect and reconnect the wires (again push on connectors sometimes don't make a good connection). Basically, don't trust anything that isn't soldered :)

My general guideline is that if it looks like it should work and it doesn't, it's quite often a connection.

Dave

dastels
 
Posts: 6873
Joined: Tue Oct 20, 2015 3:22 pm

Re: I2C pot and LCD shield not getting along

by TheIronCrown on Wed Jun 23, 2021 3:13 pm

The wiring should be good. Running the example code for the individual components works fine with the wiring as is.

TheIronCrown
 
Posts: 6
Joined: Thu Jun 17, 2021 4:46 pm

Re: I2C pot and LCD shield not getting along

by dastels on Wed Jun 23, 2021 4:14 pm

Oh. With everything hooked up each works fine?

Can you paste your code that's failing?

Dave

dastels
 
Posts: 6873
Joined: Tue Oct 20, 2015 3:22 pm

Re: I2C pot and LCD shield not getting along

by TheIronCrown on Fri Jun 25, 2021 10:33 am

Yep, works all fine with the code from their respective examples. The code that's failing is anything that has a
Code: Select all | TOGGLE FULL SIZE
ds3502.setWiper(0);
. I tried adding that bit of code to the beginning to see if maybe the LCD was constantly taking up "bandwidth" or "not giving a turn" to the pot, looks like that is not the case, as it reads 2.5 V no matter what, whereas I expect 5 with the wiper at 0. I tried initializing the pot before the LCD as well, no improvement, still starts with the wiper in the middle. I even edited the code to alternate between pot states automatically, and unplugged the LCD entirely. Still no change, and if I plug in the LCD back, it does show the wiper position changing. Seems to me that it's a code issue, but again I just don't see where it might be...

TheIronCrown
 
Posts: 6
Joined: Thu Jun 17, 2021 4:46 pm

Re: I2C pot and LCD shield not getting along

by dastels on Fri Jun 25, 2021 10:37 am

Again. can you post your code?

Dave

dastels
 
Posts: 6873
Joined: Tue Oct 20, 2015 3:22 pm

Re: I2C pot and LCD shield not getting along

by TheIronCrown on Fri Jun 25, 2021 12:17 pm

Ah, my bad. It's the same as the one above. Here it is after I tried adjusting the pot based on time.

Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include <Adafruit_RGBLCDShield.h>
#include <utility/Adafruit_MCP23017.h>
#include <Adafruit_DS3502.h>
// The shield uses the I2C SCL and SDA pins. On classic Arduinos
// this is Analog 4 and 5 so you can't use those for analogRead() anymore
// However, you can connect other I2C sensors to the I2C bus and share
// the I2C bus.
Adafruit_DS3502 ds3502 = Adafruit_DS3502();
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
// These #defines make it easy to set the backlight color
#define OFF 0x0
#define ON 0x1
#define WIPER_VALUE_PIN A0
int wiper_set[] = {0, 15, 30, 45, 60, 75, 90, 105, 120, 137};
int wiper_current = 0;


void setup() {
  // put your setup code here, to run once:
// Debugging output
  Serial.begin(9600);
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);

  // Print a message to the LCD. We track how long it takes since
  // this library has been optimized a bit and we're proud of it :)
  lcd.print("Hello, world!");
  lcd.setCursor(0,1);
  lcd.print("Took "); lcd.print(millis()); lcd.print(" ms");
  lcd.setBacklight(ON);
  delay(1000);
  ds3502.setWiper(0);
}

void loop() {
  // put your main code here, to run repeatedly:
   // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  float wiper_value = analogRead(WIPER_VALUE_PIN);
  wiper_value *= 5.0;
  wiper_value /= 1024;
  Serial.println(wiper_value);
  if (wiper_current <=5) wiper_current += 5;
  else wiper_current -=5;
  lcd.print("Wiper="); lcd.print(wiper_set[wiper_current]); lcd.print(" V="); lcd.print(wiper_value);
  delay(500);
 
uint8_t buttons = lcd.readButtons();

  if (buttons) {
    lcd.clear();
    lcd.setCursor(0,0);
    if (buttons & BUTTON_UP) {
      if (wiper_current < 9){
        wiper_current++;
        ds3502.setWiper(wiper_set[wiper_current]);
        lcd.print("R up to "); lcd.print(wiper_set[wiper_current]);
      }
      else{
        lcd.print("R is already max!");
      }
    }
    if (buttons & BUTTON_DOWN) {
      if (wiper_current > 0){
        wiper_current--;
        ds3502.setWiper(wiper_set[wiper_current]);
        lcd.print("R down to "); lcd.print(wiper_set[wiper_current]);
      }
      else{
        lcd.print("R is already min!");
      }
    }
  }
}

TheIronCrown
 
Posts: 6
Joined: Thu Jun 17, 2021 4:46 pm

Re: I2C pot and LCD shield not getting along

by dastels on Fri Jun 25, 2021 12:23 pm

Look like you're missing the begin call in setup():
Code: Select all | TOGGLE FULL SIZE
  if (!ds3502.begin()) {
    Serial.println("Couldn't find DS3502 chip");
    while (1);
  }


Dave

dastels
 
Posts: 6873
Joined: Tue Oct 20, 2015 3:22 pm

Re: I2C pot and LCD shield not getting along

by TheIronCrown on Fri Jun 25, 2021 1:23 pm

Aha, that seems to have done it. I didn't think much of that line, thought it was just checking for the chip.

Thank you for all your help, Dave!

TheIronCrown
 
Posts: 6
Joined: Thu Jun 17, 2021 4:46 pm

Re: I2C pot and LCD shield not getting along

by dastels on Fri Jun 25, 2021 1:48 pm

No, the begin functions often to quite a bit of initialization, setting up buffers, etc.

Dave

dastels
 
Posts: 6873
Joined: Tue Oct 20, 2015 3:22 pm

Please be positive and constructive with your questions and comments.