PT2257 and Arduino stuck from the start

hello, i am stuck with PT2257. i am trying to use it with arduino but i am really stuck. maybe someone can provide some code i really new in I2C and Wire lib. Main question how to send commands for chip coz i dont understand first i use 7bit code for address in datasheet its 88 HEX but when i use 7bit its 44HEX and later i need to send 8bit instructions. I would really appreciate some help. this is the datasheet of PT2257. http://www.princeton.com.tw/Portals/0/Product/PT2257.pdf And btw I2C scanner can find the device and show me that its 44 address so i think its connected already. Thank you in advance

Hi kimasgold

I2C scanner can find the device and show me that its 44 address so i think its connected already.

That's a good start - there can be problems just getting I2C devices to respond :)

when i use 7bit its 44HEX and later i need to send 8bit instructions.

The 7-bit thing can be confusing - no need to worry about it, the Wire library takes care of it. Use 0x44 as the address when you start each transmission to the PT2257, and then you can send 8-bit values. For example:

Wire.begin();
...
Wire.beginTransmission(0x44);
Wire.write(0b10101010);            // sends one byte - just an example value !!!
Wire.endTransmission();

There are example programs in the Arduino IDE for the Wire library.

The PT2257 datasheet has the commands you can send and what they do. It might be sensible to start by sending some simple commands. For example, set the attenuation for both channels to 0dB, then wait for a few seconds, then set the attenuation to -79dB, then wait for a few seconds, and repeat.

What do you have connected to the PT2257 for testing it?

Regards

Ray

Hi Ray Thanks for explaining how to send 8bit i didnt knew that i need to put 0b before. but all i can hear from start its just heavy booooop signal. i hooked audio signal in and out coz i dont have special equipment. i will do some other test but still dont get it why its like this.

Kimas

i didnt knew that i need to put 0b before

You can put the data in different formats: decimal (66), hex (0x42) or binary (0b01000010). Using binary can make it easier to work out what value to send when you copy the information in the datasheet.

but now the question why signal is like that no sound just heavy buzzing

Can you post a diagram of how you have your hardware connected.

And post the code you are using.

i am attaching schematics there is more connected to arduino but it doesnt matters its just relays. and i used simple code. like you provided but no result. and before sending Wire commands i put delay coz datasheet tells me that i need to wait 500ms before i send it and arduino turns on voltage to chip. the arduino ground connected to supply ground as well they have different supply. and even i dont send anything its same beeep when voltage is on chip.

Thanks for the diagram.

Can you post the code you are using.

What are using to check the audio output of the PT2257? And what audio source are you using on the input?

the arduino ground connected to supply ground

Do you have the grounds of the audio input and output also connected to the Arduino / regulator ground?

all ground is connected. and i am using regular music as input from my laptop and LM3886 amps as output. everything works as charm except regulator.

#define Volume_address 0x44
void setup() {
  Serial.begin(9600);
  pinMode(power_rele, OUTPUT);
  Wire.begin();
  delay(500);
}
void loop() {
  Wire.beginTransmission(Volume_address);
  Wire.write(0b01111001);           
  Wire.endTransmission();
  delay(2000);
  Wire.beginTransmission(Volume_address);
  Wire.write(0b01111000);           
  Wire.endTransmission();
}

and i have tryed sending other bytes as well not just mute on/off but various other.

oh sorry i missed some elements to write. like in the end of loop delay(2000); and digitalWrite(power_rele, HIGH); sorry about mistakes.

Any change if you listen to the audio output with headphones rather than using the amplifiers?

Try these changes to your code in loop(). This sets low attenuation and then full attenuation, and also prints the return code from the transmissions. What values do you see on serial monitor?

  Wire.beginTransmission(Volume_address);
  Wire.write(0b011100000);    // set low attenuation      
  Serial.print("result 1: "); 
  Serial.println(Wire.endTransmission());
  delay(2000);
  Wire.beginTransmission(Volume_address);
  Wire.write(0b11111111);  // set full attenuation           
  Serial.print("result 2: ");
  Serial.println(Wire.endTransmission());

still hear same sound even with headphones. and result is 0 on both so i guess the code finds his way to the chip. so the question why sound doesnt go through on each channel

I'm out of ideas, I'm afraid :(

I found this message last year from someone who was using the PT2257. Might be worth sending him a message to see if he can help.

http://forum.arduino.cc/index.php?topic=164221.msg1228989#msg1228989

yes i have send it msg to him, but without success i think he has stopped using his acc

And thank you for your help i am really appreciate for that. Really thank you Ray for helping me :)

I know this is a little old, but I was having trouble with similar symptoms so I may offer a solution for others. It may seem obviuous to some, but I was running the voltage for the PT2257 from the VCC pin on the arduino and it was not working. Try switching the voltage source to RAW on the arduino, or accessing from a fresh source. Working like a dream.

Adding a note for anyone else who finds this thread: if you're using the Wire library to talk to the PT2257, remember that the Wire library expects 7-bit addresses while the PT2257 datasheet specifies an 8-bit address. The solution is simply to shift the 8-bit address right one place and give that to the Wire library, so the 0x88 address in the datasheet should be 0x44 in your code. That totally fixed my problem.

Just thinking aloud here but I think binary notation in Arduino is B10110011 not 0b10110011

Have a look at the arduino constants and the special quote they have


Warning

It is possible to generate a hard-to-find bug by (unintentionally) including a leading zero before a constant and having the compiler unintentionally interpret your constant as octal.

J-M-L: Just thinking aloud here but I think binary notation in Arduino is B10110011 not 0b10110011

Have a look at the arduino constants and the special quote they have


Warning

It is possible to generate a hard-to-find bug by (unintentionally) including a leading zero before a constant and having the compiler unintentionally interpret your constant as octal.

But for gcc,

6.64 Binary Constants using the ‘0b’ Prefix

Integer constants can be written as binary constants, consisting of a sequence of ‘0’ and ‘1’ digits, prefixed by ‘0b’ or ‘0B’. This is particularly useful in environments that operate a lot on the bit level (like microcontrollers).

The following statements are identical:

i = 42; i = 0x2a; i = 052; i = 0b101010;

@aarg

interesting thanks. so let's find out :-)

byte zerob161 = 0b10100001;  // this is 161 in decimal
byte B161 = B10100001; // this is 161 in decimal

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);

  Serial.print("with 0b: 0b");
  Serial.print(zerob161, BIN);
  Serial.print(" = ");
  Serial.println(zerob161, DEC);

  Serial.print("with  B:  B");
  Serial.print(B161, BIN);
  Serial.print(" = ");
  Serial.println(B161, DEC);

  if (zerob161 == B161) Serial.println("They are the same!"); else Serial.println("They are different!");
}

void loop() {
  // put your main code here, to run repeatedly:

}

and the output on the console is

with 0b: 0b10100001 = 161
with  B:  B10100001 = 161
They are the same!

so you are right, it does not matter :)