First forgive the code you see, Im a mechanic and like most on here im self taught and fumbling my way thro this hobby.
The code is bits and bobs I have grabbed from various sources and somehow mashed into working examples.
I had searched for examples to run this chip but didnt find anything that worked so these examples will allow someone to quickly get up and running with output from the chip (or input from the volume pot if you bought the same kit I did) which can then be modified to suit your needs.
The kit I have is http://store3.sure-electronics.com/aa-ab41116 .
To start reading the volume pot seems to need a fairly fast arduino, Im no doubt using a clumsy method to do so as I basically canibalised an I2C sniffer example to get this code, it wouldnt work on an uno, but did work fine on a teensy3.1 and assume therefore it would work on a mega or similar. TBO if you want to read a rotary encoder there are far better ways but its here for completeness none the less: -
#include <Wire.h>
//can read volume output!!!
#define SLAVE_ADDRESS 0x44 //slave address, any number from 0x01 to 0x7F
#define REG_MAP_SIZE 14
#define MAX_SENT_BYTES 10
int x=0;
/********* Global Variables ***********/
byte registerMap[REG_MAP_SIZE];
byte registerMapTemp[REG_MAP_SIZE - 1];
byte receivedCommands[MAX_SENT_BYTES];
void setup()
{
Wire.begin(SLAVE_ADDRESS);
Wire.onRequest(requestEvent);
Wire.onReceive(receiveEvent);
Serial.begin(115200);
while (!Serial);
Serial.println("stuff has started");
}
void loop()
{
}
void requestEvent()
{
Wire.write(registerMap, REG_MAP_SIZE); //Set the buffer up to send all 14 bytes of data
}
void receiveEvent(int bytesReceived)
{
for (int a = 0; a < bytesReceived; a++)
{
if ( a < MAX_SENT_BYTES)
{
receivedCommands[a] = Wire.read();
Serial.printf("0x%02X,",receivedCommands[a]);
}
else
{
Wire.read(); // if we receive more data then allowed just throw it away
}
}
Serial.println ();
}
the slave address is 0x44 as the P2259 has a slave address of 0x88, but apparently cause its a 7 bit number not 8 bit, addressing (or listening on ) 0x44 is how it is accessed on a system with 8 bit addresses. I dont fully understand this but I2c sniffer picked up the PT2259 as 0x44 and some references online echo'd this.
This code was taken from here (DssCircuits.com is for sale | HugeDomains) and modified to give a more read-able output over serial. this was with a teensy 3.1 and pins 16 and 17. Serial output providing the output.
Driving the PT2259.
This doesnt require anything special, my UNO had no trouble, the example initialises the PT2259 (begin, 0xf0, end)
Then initialises teh volumes
Wire.beginTransmission(PT_ADDR); //begin
Wire.write(0xF0); //clear registers
Wire.write(0x74); //all channels mute off
Wire.write(0xE0); //set the "tens" in the attenuation. in this case 0
Wire.write(0xD0); //set the "ones" in attenuation. In this case 0 i.e. -00db attenuation. ie. full volume
Wire.endTransmission(); //end
in the example below it then loops between -00dB and -66dB, the IC will accept -00 to -79dB
#include "Wire.h"
#define PT_ADDR 0x44
void setup() {
Wire.begin();
Wire.beginTransmission(PT_ADDR);
Wire.write(0xF0);
Wire.endTransmission();
delay(100);
Serial.begin(115200);
while (!Serial);
Serial.println("started");
Wire.beginTransmission(PT_ADDR);
Wire.write(0xF0);
Wire.write(0x74);
Wire.write(0xE0);
Wire.write(0xD0);
Wire.endTransmission();
}
void loop() {
Wire.beginTransmission(PT_ADDR);
Wire.write(0xF0);
Wire.write(0x74);
Wire.write(0xE6);
Wire.write(0xD6);
Wire.endTransmission();
Serial.println("part1");
delay(1300);
Wire.beginTransmission(PT_ADDR);
Wire.write(0xF0);
Wire.write(0x74);
Wire.write(0xE0);
Wire.write(0xD0);
Wire.endTransmission();
Serial.println("part2");
delay(1300);
}
this code was adapated from "pylon"s code on this thread communicate with PT2258 Volume controller - Networking, Protocols, and Devices - Arduino Forum
Hopefully this will save someone the 2 days of headbanging I suffered.
The datasheet is required to get all the right values, there is 2 floating around on the internet , its the 15 page one you need, mine was called pt2259-s.pdf although there are many versions with the same name and only 4 pages.
at the time of writing this was a source : - PT2259-S Princeton Technology Corp., PT2259-S Datasheet
cheers,
denis.