Problems with i2c digital pot

103 views
Skip to first unread message

Jabberwock

unread,
Feb 4, 2013, 8:53:18 PM2/4/13
to ioio-...@googlegroups.com
I have problems driving a digital pot (DS1803, two channel) with IOIO... For starters I am trying just to cycle the values, but I cannot seem to get any response...

Here is my code:

    class Looper extends BaseIOIOLooper {
       
        private TwiMaster twi;
       
        @Override
        protected void setup() throws ConnectionLostException {
            twi = ioio_.openTwiMaster(1, TwiMaster.Rate.RATE_100KHz, false);
            }
       
        public void setpots(TwiMaster port, byte accel, byte brake) throws ConnectionLostException, InterruptedException {
           
            byte[] request = new byte[] { (byte) 0xAA, (byte) accel };
           
            byte[] response = new byte[0];
          
            port.writeRead(0x28, false, request, request.length, response, 0);
           
            byte[] request2 = new byte[] { (byte) 0xA9, (byte) brake };

            port.writeRead(0x28, false, request2, request2.length, response, 0);

            }

        @Override
        public void loop() throws ConnectionLostException, InterruptedException {
            for (byte i =1; i <= 255; i++) {
                setpots (twi, i, i);
            }
        }
    }
   

Ytai Ben-Tsvi

unread,
Feb 4, 2013, 9:09:16 PM2/4/13
to ioio-...@googlegroups.com

Did you tie all address lines to gnd?
Do you have a shared gnx with the IOIO?
Do you have pull ups on both i2c lines?
Did you try a read transaction to see what you're getting?

Unrelated:
1. Allocate buffers once.
2. No need for rx buffer if you're not receiving. Null if fine.

--
You received this message because you are subscribed to the Google Groups "ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ioio-users+...@googlegroups.com.
To post to this group, send email to ioio-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ioio-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jabberwock

unread,
Feb 4, 2013, 9:41:57 PM2/4/13
to ioio-...@googlegroups.com
1. Yes, they were already grounded in my Arduino project.
2. You mean ground? Yes, gnd is common for all components (coming back to the game racing wheel which is connected via USB. Voltage is also supplied from the wheel).
3. Yes, I used 4.7k. I am not sure what the value should be.
4. Reading from the pot is tricky - I would need to reverse the last bit of the address and I seem to remember you writing that only 7 bits are used.

Ytai Ben-Tsvi

unread,
Feb 4, 2013, 9:46:15 PM2/4/13
to ioio-...@googlegroups.com

writeRead() will do exactly what you want.

Jabberwock

unread,
Feb 5, 2013, 3:41:01 AM2/5/13
to ioio-...@googlegroups.com

Here is where I get confused... According to datasheet, the address of the chip (with two pots) should be 0101 (control code) + 000 (all adress lines to gnd) + R/W byte = 0x50. However, according to your explanations in this forum, IOIO lib skips the last bit so the actual address sent should be divided by two - 0x28 (it is the same with the Wire lib in Arduino). However, in order to read pots, I would need to change the last bit to 1 = 0x51. Is this the address I should use then?

Ytai Ben-Tsvi

unread,
Feb 5, 2013, 10:37:21 AM2/5/13
to ioio-...@googlegroups.com

No. The last bit is r/w, and is not considered part of the address in this context. The writeRead operation will do a write-followed-by-read transaction, exactly like the one described in the datasheet for reading values.

On Feb 5, 2013 12:41 AM, "Jabberwock" <manute...@gmail.com> wrote:

Here is where I get confused... According to datasheet, the address of the chip (with two pots) should be 0101 (control code) + 000 (all adress lines to gnd) + R/W byte = 0x50. However, according to your explanations in this forum, IOIO lib skips the last bit so the actual address sent should be divided by two - 0x28 (it is the same with the Wire lib in Arduino). However, in order to read pots, I would need to change the last bit to 1 = 0x51. Is this the address I should use then?

Jabberwock

unread,
Feb 5, 2013, 9:38:15 PM2/5/13
to ioio-...@googlegroups.com
Turns out it was a hardware problem after all. I must have borked something when I rewired the power supply - when I moved the chip to a new board and wired it properly it works. Now onto the programming... sigh. I must admit I find Java very initmidating...

Linus Anderberg

unread,
Mar 1, 2015, 12:35:01 PM3/1/15
to ioio-...@googlegroups.com
Im new to all this and i'm now experimenting with this digital potentiometer. Is it possible to see how you wired this to the ioio?

Cheers
Linus

Ytai Ben-Tsvi

unread,
Mar 2, 2015, 4:33:40 PM3/2/15
to ioio-...@googlegroups.com
You need to hook up:
  • Vcc (either 5V or 3V3) and GND.
  • A0/A1/A2 each to either Vcc or GND for selecting the I2C address.
  • SCL/SDA to the respective pins on one of the IOIO I2C (TWI) buses. Pull-up resistor on each of these lines to Vcc. Resistance anywhere between 2.2k-10k should be fine.
  • Outputs (H/L/W) as per your application requirements. 

--
You received this message because you are subscribed to the Google Groups "ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ioio-users+...@googlegroups.com.
To post to this group, send email to ioio-...@googlegroups.com.

Linus Anderberg

unread,
Mar 8, 2015, 12:42:55 PM3/8/15
to ioio-...@googlegroups.com
Thanks. Got it hooked up and works "fine" with my test board but for some reason the readwrite command halts my loop on my live project, no crash or anything it just stop looping. Trying to see if I can find out why.
Btw. How would this code look like if I dont need to read the pot?

port.writeRead(0x28, false, request, request.length, response, 0);

Ytai Ben-Tsvi

unread,
Mar 8, 2015, 12:45:05 PM3/8/15
to ioio-...@googlegroups.com

Exactly like that. You can pass in null as the response if you want, but a zero length response is executed as a write only transaction.

Reply all
Reply to author
Forward
0 new messages