Problems with Arduino Nano I2C + PT2258

Hi. I’m, let’s say, a noob. Trying to get my PT2258 digital pot to work. But for some reason, when I connect it up to pins A4, A5 it is not working. The whole cycle stops at:

Wire.beginTransmission(PT_ADDR);
  Wire.write(0xC0);
  Wire.endTransmission();
  Serial.println("loading Wrire");

I’m not sure why… seems like the library has some problems, or?

The whole code:

/*
  Arduino Controled Amp

 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 6
 * LCD D5 pin to digital pin 5
 * LCD D6 pin to digital pin 4
 * LCD D7 pin to digital pin 3
 * LCD R/W pin to ground

*/

int lcd_backlight = 1;
int lcd_backlight_pin = 2;
int lcd_rs_pin = 12;
int lcd_enable_pin = 11;
int lcd_data_4_pin = 10;
int lcd_data_5_pin = 9;
int lcd_data_6_pin = 8;
int lcd_data_7_pin = 7;

int IC_power_pin = 4;

// include the library code:
#include <LiquidCrystal.h>
#include <TimedAction.h>
#include <Wire.h>

#define PT_ADDR 0x40

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(lcd_rs_pin, lcd_enable_pin, lcd_data_4_pin, lcd_data_5_pin, lcd_data_6_pin, lcd_data_7_pin);

TimedAction ampInit = TimedAction(2000,amp_init);
TimedAction blah = TimedAction(1,test);

uint8_t bases[] = { 0x80, 0x40, 0x00, 0x20, 0x60, 0xA0 };

void setup() {
  Serial.begin(9600);
  
  //Set up LCD
  lcd.begin(16, 2);
  lcd.print("Arduino Amp");
  lcd.setCursor(0, 1);
  lcd.print("loading...");
  Serial.println("loading...");
  
  pinMode(lcd_backlight_pin, OUTPUT);
  pinMode(IC_power_pin, OUTPUT);
}

void loop() {
  digitalWrite(lcd_backlight_pin,HIGH); //Turn backlight on on start
  digitalWrite(IC_power_pin,HIGH); //Give the IC power
  ampInit.check();
}

void amp_init() {
  Serial.println("loaded!");
  
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("IN: AUX");
  Serial.println("input: aux");
  lcd.setCursor(0, 1);
  lcd.print("OUT: Speakers");
  Serial.println("output: speakers");
  ampInit.disable();

  Wire.begin();
  Wire.beginTransmission(PT_ADDR);
  Wire.write(0xC0);
  Wire.endTransmission();
  Serial.println("loading Wrire");
  
  blah.check();
}

void rewrite_lcd() {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("IN: AUX");
  lcd.setCursor(0, 1);
  lcd.print("OUT: Speakers");
}

void test() {

  uint8_t i;
  for (i = 70; i; i--) {
    set_volume(i, 1);
    
    rewrite_lcd();
    lcd.setCursor(14, 1);
    lcd.print(i);
    
    delay(200);
  }
  for (i = 1; i <= 70; i++) {
    set_volume(i, 1);
    
    rewrite_lcd();
    lcd.setCursor(14, 1);
    lcd.print(i);
    
    delay(200);
  }
  blah.check();
  
}

void set_volume(uint8_t value, uint8_t channel) {
  uint8_t tens = value / 10;
  uint8_t ones = value % 10;
  uint8_t base = bases[channel -1];
  Wire.beginTransmission(PT_ADDR);
  Wire.write(0x80 | tens);
  Wire.write(0x90 | ones);
  Wire.endTransmission();
}

There is I2C scanner code on Nick Gammon's web site. You should find that, and make sure that your I2C device is connected correctly, and that it has the address you think it does. Before you know that, you're wasting your time trying to debug your code.

Check if the SDA and SCL are perhaps shortcut to each other, or if one of them is shortcut to ground. Can you measure the voltages. Does the PT2258 have power ?

So I've put in the code from here: Gammon Forum : Electronics : Microprocessors : I2C - Two-Wire Peripheral Interface - for Arduino to test for I2C devices and it stuck at num 8:

I2C scanner. Scanning ...

I disconnected the IC and suddenly there in the serial monitor appeared:

Done.
Found 0 device(s).

So I'm not sure why everything stucks at the point when trying to Wire.beginTransmission.... Any ideas?

I'm not sure, but this might help you:

My IC (PT2258) is connected as followed:

Nano pin +5V -> pin 16 (VCC)
Nano pin GND -> pin 4 (CODE2), pin 5 (DGND), pin 17 (CODE1)
Nano pin A4 -> pin 7 (SDA)
Nano pin A5 -> pin 6 (SCL)

anything wrong here?

I think that als GND should be connected to GND.
Is the PT2258 still okay ? Perhaps the chip is shortcutting the SCL and SDA.

Can you make a photo of it ? So we can see the wiring ?

Here: https://dl.dropboxusercontent.com/u/66389935/_DSC1910.JPG

The IC is new, and working, I replaced it with another one (same as this) but it's the same result..

Thanks for the photo, as far as I can see it is okay.

Perhaps you can do a little test.
Run the i2c_scanner : Either the Nick Gammon version or the Playground version : http://playground.arduino.cc/Main/I2cScanner
Remove the SDA and SCL and let the i2c_scanner run.
I can't find a thing, that is good.
Connect only the SDA and after that only the SCL, which one makes the sketch halt ? That one is shortcut to ground.
When they both make the sketch halt, add pullup resistors of 4k7 from SDA to 5V and from SCL to 5V.

If that doesn't help. Remove all the wires, get a new breadboard, and start all over again....

Thanks! I'm going to play with it a little bit :slight_smile:

So....I tried to scan for devices without SDA/SCL but no luck.. Also tried the pull up resistors... I think the IC is shorted out... when I connected code1 to ground the led on arduino dimmed and the IC heated up... but it was okay before... probably gonna buy new ones.. and then I would appreciate some kind of a full tutor on how to set it up :smiley: please :slight_smile: that would realy help me :slight_smile: thanks anyways for your help :slight_smile:

I think you did not do something wrong, so I have not tips how to do it better.
Perhaps you made a mistake and the chip was damaged. It happens, forget it and move on :stuck_out_tongue:

Perhaps you better remove all the wires, and build your project from scratch. Check also for solder drops or bad soldering on the Nano board.

Before you test with a new PT2258, can you test with an other I2C device ? An EEPROM or sensor, anything is good. To test that at least the I2C bus is okay and the Nano is still okay.
When the i2c_scanner detects something, the I2C bus is okay.

A Arduino Uno board is easier, would that be possible ?

Are you using 4.7 k ohm pullups on A4 & A5 ?

Hi,

commenting on old topic, I just faced the same situation. My IC is also not detected in i2c scanner by nick. I tried with 4.7k pullups , immediate no device found result. with 15k it stucks at scanning, I have double checked my breadboard from datasheet schematic.
also tried without pullups with no good situation. My uno is good as its detecting other devices on i2c (also double checked with pro micro , same results)

Perhaps the IC might be bad, I have ordered few more ICs to tinker. meanwhile if anyone knows of a good 6 channel volume controller with I2C, that would be awesome, google isnt returning relevant results.

well I got my hands on new one and its not appearing in i2c scanner either, I am planning trying sending it low and high volume code and check if it works.