Amplifier with i2c control

I got a little amplifier from adafruit which got build in i2c control. (http://learn.adafruit.com/adafruit-20w-stereo-audio-amplifier-class-d-max9744/digital-control)

But how do I make the imp communicate with it? I have attached Vi2c to the impee’s 3V3, SCL to pin 8, and SDA to pin 9.

I then tried to mess around a bit with this

hardware.i2c89.configure(CLOCK_SPEED_400_KHZ); hardware.i2c89.write(0x4B, "10");

But so far no luck, anyone with more knowledge of i2c who can help me with this?

I am also a bit new, but I will give it a try

page 17 of the datasheet

datasheet

The address 0x4B represents “1001011”

“1001” is standard, then “0”, then “11” indicating both pins that woudl create a configurable address are pulled high

This is a 7-bit address but a byte is 8 bits. you need to Left-shift this one

1001011_

and the “_” is replaced by 1 or zero depending whether you are reading or writing.

so

10010111 => 0x97 – I think read
or
10010110 => 0x96 - I think write

are the two addresses to use.

Then you have to add your command and value into a string. have a look at the i2c write documentation of imp for an example of how to append a command with data.

I like to use this tool for binary, hex and decimal conversions.

http://www.mathsisfun.com/binary-decimal-hexadecimal-converter.html

oh, sorry. just realized this is a simpler device and I can do better. try this.

again, new at this but have successfully talked spi and i2c branching off example code from others

`function testwritei2c(_volume) {

local address   = 0x96;
local volume = _volume;
if (volume>63){
    volume=63;
}
if (volume<0){
    volume=0;
}

hardware.i2c89.write(address, format("%c%c", volume>>8, volume&0xff));

}`

MikeyDK, as mjkuwp94 says, you need to multiply the given I2C address by 2 to use it with the Imp. I usually do it this way:

local device_address = 0x4B << 1; // Shift bits left by one bit i2c <- hardware.i2c89; i2c.configure(CLOCK_SPEED_400_KHZ);

You don’t have to worry about the value of the new bit zero; the imp will take care of that for you when you read or write data from/to your device.

Awesome!!! It works!! :smiley:

Used the code from mjkuwp94, then replaced the address with how smittytone does it, so it is easier for me to read. (looking exactly like in the tutorial)

Excellent! Well done.

You’ll soon be multiplying I2C addresses by 2 and keying the result straight into your code, but IMHO it’s still good to show in code how it works.