Hello. I'm trying to program a digipot, and I could not figure out how to convert the commands in bits to Arduino code. I looked at some examples and tried to mimic them, but it did not work.
I'm currently using TI's TPL1401, and the update sequence is "Address byte-Command byte-Data byte-Data byte". The data I wanted to input for each section was 74 for the Address byte, 0x21 for the command byte, and 0x09 and 0x40 for the 2 data bytes.
but it did not work as intended, since the brightness of the LED that was connected did not change. When I checked for the data via requestFrom() and available(), it seemed like no data was written on the chip at all. So, I wonder what did I do wrong in converting the command to Arduino code.
You may have to re-read a few times in order to figure out the command and how to interpret the data. Most I2C need an Slave address / Device address. and this device have registers. So you have to point them out in order to extract data. Work like the DS1307. Same principle.
The device address is : B01001000 to B01001111. Page 24 of the datasheet. The next page is the register addresses.
Wire.endTransmission() does actually return a value to indicate its success or otherwise.
From that linked manpage:
Many years ago I had trouble writing to an I2C EEPROM and it was suggested that I add a delay(5); after the Wire.endTransmission();. It worked for me then, but as I say that was EEPROM; may not be an issue with a pot though. But worth a try?
Run a I2C Scanner sketch, show us the output of that.
Try to read the VERSION_ID (0x00) and DEVICE_ID (0x14). They are part of the 16-bit status register. Don't forget the "repeated start" which is mentioned in the datasheet. Show us your sketch.
There is a better option: Buy a digital potentiometer which has already a working and tested library and buy it from a good seller: https://www.adafruit.com/product/4286
When I use I2C scanner, I got 0x50 as the address. However, this is different from any of the device addresses I see on the datasheet. Do you know why this is happening?
Hmm.
With AO tied to AGND, The three address bits will be 0. Therefore, your address is, per page 24, 01001000, or 48 hex; not sure why you're getting 50, that would imply, possibly, bit3 is appearing as bit4, but it may have something to do with that funky tying of the A0 pin to various active signals.
Based on that, I'd try talking to address 48h. If that works, we may have a case where the device address isn't getting properly read back in the i2c scan code, which would be troubling - but if so, it's more likely an i2c timing violation by your e-pot, rather than an Arduino code issue.
C
Please show a full sketch.
The Wire.requestFrom() should not have Wire.beginTransmission() and Wire.endTransmission() around it. Try requesting 2 bytes instead of 7. Read two bytes instead of one. Implement the repeated start.
Not easy for a beginner(probably need an o'scope, and an authoritative document about I2C, and the source code of the I2C scanner, and other stuff), so I'd advise trying to read something from the device at a range of addresses. E.g.
for(int address = 0x40;address<0x80; address++)
{
read register
print result
}
(obviously, the above is not actually code, you'll have to write something similar though).
and see what you get. It might be garbage, or you might get a consistent value for all but one address; if that happens, then try reading other registers at that address. Sorry, it's brute force. However, I'm not sure we're chasing the right ghost, so let us know what happens. If you can identify an address at which the device responds, you'll be a lot further ahead.
C
I have implemented repeated start, and verified that the slave address is 0x50, or 80. Also, since the register is 16-digit binary data, I requested 2 bytes, but both bytes still return 255.