Wire.read() not updating on Arduino Due

I am trying to interface Arduino Due with a IQS550EV02 touchpad. Found a code that works for it but it only returns the coordinates from the touchpad only one and then doesn't update. Keeps giving the same coordinates. Help would be greatly appreciated.

#include <Mouse.h>

#define PIN_RST 7
#define PIN_RDY 8

#define ADDR_APP 0x74
#define ADDR_BOOT 0x74^0x40

#include <Wire.h>
#include <stdint.h>

void setup()
{
  Serial.begin(115200);
     
  pinMode(PIN_RST, OUTPUT);
  pinMode(PIN_RDY, INPUT);
  
  digitalWrite(PIN_RST, LOW);
  delay(200);
  digitalWrite(PIN_RST, HIGH);
  delay(200);
  
  Wire.begin();
  Mouse.begin();
  Serial.print("PIN_RDY ");
  
  while (!digitalRead(PIN_RDY)) {
    delay(1);
    Serial.print("PIN_RDY1 ");
    Serial.println(digitalRead(PIN_RDY));
  }
  
  // config
  Wire.beginTransmission(ADDR_APP);
  Wire.write(0x10);
  Wire.write((1<<7)|(0<<6)|(1<<5)|(0<<4)|(0<<3)|(0<<2)|(0<<1)|0);
  Wire.write((1<<7)|(1<<6)|(1<<5)|(1<<4)|(1<<3)|(0<<2)|(0<<1)|0);
  Wire.endTransmission(false);
  
  while (!digitalRead(PIN_RDY)) {
    delay(1);

  }
  
  // channel setup
  Wire.beginTransmission(ADDR_APP);
  Wire.write(0x15);
  // disable tx channel 10 and rx channels 14,15 as they contain noise 
  Wire.write(9);
  Wire.write(13);
  Wire.write(9);
  Wire.write(13);
  Wire.write(0x40);
  Wire.write(0x7f);
  Wire.write(0xff);
  Wire.endTransmission(false);
}

byte addr = 1;
byte buf[80];
int16_t lastx = 0, lasty = 0;
byte ignore_next = 1;

void loop()
{
  int rdy = digitalRead(PIN_RDY);
  if (rdy) {
    Wire.beginTransmission(ADDR_APP);
    Wire.write(byte(addr));
    Wire.endTransmission(false);
    Wire.requestFrom(ADDR_APP,12);
  
    int i=0;
    while (Wire.available())
    {
      
      int f = Wire.read();
      //Serial.print('\t');
      buf[i++] = f;
      if (i>=36) break;
    }
    //Serial.print("\r\n");
    
    int16_t xpos = ((uint16_t)buf[4]<<8)|((uint16_t)buf[5]);
    int16_t ypos = ((uint16_t)buf[2]<<8)|((uint16_t)buf[3]);
    Serial.print(" xpos: ");
    Serial.print(xpos);
    Serial.print(" ypos: ");
    Serial.println(ypos);
    
    /*Serial.print(xpos);
    Serial.print('\t');
    Serial.print(ypos);
    Serial.print("\r\n");*/
    
    if (xpos>0 && ypos>0) {
      //if (xpos>=7) xpos-=6;
      //else if (xpos<7) xpos=-xpos;
      int16_t dx = xpos-lastx;
      int16_t dy = -(ypos-lasty);
      
      dx/=3;
      dy/=2;
      
      int sgnx=1;
      if (dx<0) sgnx=-1;
      int sgny=1;
      if (dy<0) sgny=-1;
      
      //dx*=(dx/2)*sgnx;
      //dy*=(dy/2)*sgny;
      Serial.println(dx);
      Serial.println(dy);
      if (!ignore_next) {
        if (dx || dy) {
          Mouse.move(dx,dy);
          Serial.println(dx);
          Serial.println(dy);
        }
      }
      ignore_next = 0;
      lastx = xpos;
      lasty = ypos;
    } else {
      ignore_next = 1;
    }
  }

}

Hello, do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation for your ask).

Why no stop condition?

The device expects 16 bit addresses. I'm not surprised that an 8bit address doesn't work. Because of the previous error you get values once but these are most probably not the ones you expected.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.