0

I'm trying to use I2C to send and receive commands between an Arduino UNO R3 and an Arduino Mega R3, with a 3.5" TFT display connected to the Mega. I have verified that my display is fully functional without using I2C by running the MCUFRIEND_kbv graphics tests where they perform exactly as I expect, but when I try to use I2C in combination with the TFT shield, I run into an issue where the display goes completely white and does not change. Could this be caused by the I2C interrupting the tft functions causing it to fail? Any advice would be greatly appreciated!

Here is the i2c code on the mega:

void sendInputs(){
  for(int i = 0; i < NUM_BUTTONS; i++){
    btnArr[i] = digitalRead(btnPinArr[i]);
    Wire.write(btnArr[i]);
  }
  digitalWrite(13, HIGH);
  p = ts.getPoint();
  digitalWrite(13, LOW);
  tsArr[0] = p.x;
  tsArr[1] = p.y;
  tsArr[2] = (p.z > MINPRESSURE && p.z < MAXPRESSURE);
  for(int i = 0; i < NUM_TS_INPUTS; i++){
    Wire.write(tsArr[i]);
  }
}    


void getDrawData(){
 graphicsBufferSize = Wire.read();
 for(int i = 0; i < graphicsBufferSize; i++){
    graphicsBuffer[i] = Wire.read();
 }
 drawGraphicsBuffer();
}

Where drawGraphicsBuffer(); parses the array of ints into draw functions

The I2C code on the Arduino UNO is:

void sendGraphics(){
     Wire.beginTransmission(slaveID);
      Wire.write(graphicsBufferSize);
      for(int i = 0; i < graphicsBufferSize; i++){
        Wire.write(graphicsBuffer[i]);
      }
      Wire.endTransmission();
      graphicsBufferSize = 0;
    }

void getInputs(){
  Wire.requestFrom(8, NUM_BUTTONS + NUM_TS_INPUTS);
  for(int i = 0; i < NUM_BUTTONS; i++){
    btnArr[i] = Wire.read();
  }
  for(int i = 0; i < NUM_TS_INPUTS; i++){
    tsArr[i] = Wire.read();
  }
}

void loop(){
  getInputs();
  delay(1000);
  if(btnArr[0]){
    screen.addFillScreen(0);
  }
  if(btnArr[1]){
    screen.addCircle(50, 50, 50, 50);
  }
  screen.sendGraphics();
}

Where the screen methods just populate the graphicsBuffer array to be sent to the Arduino mega.

Edit: Here is the exact screen I'm using

  • I ran into a very similar problem. I used an UNO. I simply replaced a TFT from a different brand, and it worked perfectly. Some brands have conflicting i2C pins I guess. – Irfanuddin Jun 4 at 4:24
  • Can you recommend me a brand to try? – CoderWithADream Jun 4 at 14:20
  • I used this one – Irfanuddin Jun 5 at 6:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.