Using I2C communication and LCD touchscreen

Hello Guys,

I'm building a pills distributor for a school project and I'm in charge of everything concerning User-Machine interactions. In our project we have to include RFID tags and an RFID reader.

So I'm using an Arduino Uno with TFT LCD touchscreen ILI9488 as the user interface. And an other Arduino with an AdaFruit PN532 RFID/NFC shield to retrieve data from RFID cards.

I already programmed the GUI on the screen and managed to store and retrieve data from the RFID cards. But now I would like to connect both and make the first arduino (screen) display data retrieved from the second arduino.

So I thougt using I2C would be a good idea since SCL and SDA are the only pins left on the first arduino where the screen is connected. But he problem is whenever a I2C connection happens between them and data is sent over, the screen turns blank and I really don't know how to manage it. Since Data is nicely transfered (I can see it on the Serial port) but the screen ShutsOff.

Is the screen already using I2C trough Pins A4 and A5 and thus I can't use it or is the problem somewhere else? Tell me if you want me to post my code.
Thank's for reading me

When you configured the second, slave I2C Arduino you gave it a unique address? Is that address the one you're using to get the data via I2C or have you used some default address that is the same as the LCD (which would probably confuse it)?

Incidentally, whilst this is a school project and hence you're not too concerned about general design, a single UNO would be more than capable of doing both tasks, thus saving you a board. But as I say, it's probably more about the learning experience.

Posting (even a hand-drawn) block diagram of your project would assist in diagnosis.

Alright so here I made a very simplified example of my code that illustrates the problem:

Arduino Uno + RFID code: #include <Wire.h>#include <Adafruit_PN532.h>#define PN532_IRQ (2)#defi - Pastebin.com

Arduino + LCD touchscreen code: #include <Adafruit_GFX.h>#include <MCUFRIEND_kbv.h>#include <TouchScreen.h> - Pastebin.com

And a Quick Video showing what happens when I try to read the RFID tag and what happens with the screen: Youtube Link

Blue wire is SCL
Red Wire is SDA
and White Wire is ground.

When I scan the tag and data is sent to the Slave reader (Arduino with LCD) via I2C the screen just stops refreshing. And I know data is retrieved by the slave because it's displayed with Serial.println(Name);

From what you describe and looking at your code and the video, it seems that when you scan the data is received (correctly) via the receiveEvent() but then the LCD goes blank (when you would expect both the received data AND the 'test' string).

Which means either your program is now stopped (hung) or the communication with the LCD has stopped. By placing a Serial.print in the main loop you will be able to determine whether the loop is still running after receiving data. I also suggest you put in a delay otherwise you will get reams of stuff being sent to the serial window. Comment out the print of Name.c_str() and see whether your 'test' string still display or whether it gets hung up on displaying that string.

Also, what you can do initially is suspend the fob reading part and just write some data down the I2C bus from the master:

byte x = 0;

void loop() {
  Wire.beginTransmission(8); // transmit to device #8
  Wire.write("x is ");        // sends five bytes
  Wire.write(x);              // sends one byte
  Wire.endTransmission();    // stop transmitting

  x++;
  delay(500);
}

(taken from Arduino example: https://www.arduino.cc/en/Tutorial/MasterWriter)

See whether this is:

  1. Received as expected
  2. Stops the LCD just like the fob does, even when you don't try printing it on the LCD

If you then figure out what is happening inside your main loop (eg still running but LCD not showing anything) you can reinstate the fob reading and it will 'just work'.

If the LCD hangs then we know where to focus our attention; if the loop continues to print to the serial monitor we know that it's the LCD comms that is shot.

Also your bit rate of 115200 is very fast; I've had 'issues' with that in the past and tend to use 9600 now as it's fast enough to see what's happening on the serial monitor.

Same problem here, find an solution?

I use a tft touch screen shield on an Uno and I want to send data to an other arduino.
The touchscreen works perfect and the slave recieves data.

But when i push a 'button' on my touchscreen ( and so send data to the slave) the screen goes fully white and the slave stops recieving...

master:

#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
#include <Wire.h>
MCUFRIEND_kbv tft;
#include <TouchScreen.h>
#define MINPRESSURE 200
#define MAXPRESSURE 1000
int straf = 5;
int drank;

// ALL Touch panels and wiring is DIFFERENT
// copy-paste results from TouchScreen_Calibr_native.ino
const int XP = 6, XM = A2, YP = A1, YM = 7; //240x320 ID=0x1505
const int TS_LEFT = 935, TS_RT = 152, TS_TOP = 922, TS_BOT = 129;
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
Adafruit_GFX_Button knop1_btn, knop2_btn, knop3_btn, knop4_btn, knop5_btn, knop6_btn;


int pixel_x, pixel_y;     //Touch_getXY() updates global vars
bool Touch_getXY(void)
{
  TSPoint p = ts.getPoint();
  pinMode(YP, OUTPUT);      //restore shared pins
  pinMode(XM, OUTPUT);
  digitalWrite(YP, HIGH);   //because TFT control pins
  digitalWrite(XM, HIGH);
  bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE);
  if (pressed) {
    pixel_x = map(p.x, TS_LEFT, TS_RT, 0, tft.width()); //.kbv makes sense to me
    pixel_y = map(p.y, TS_TOP, TS_BOT, 0, tft.height());
  }
  return pressed;
}

#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

void setup(void)
{

  // open the serial port at 9600 bps:
  Serial.begin(9600);
  Wire.begin(); // join i2c bus (address optional for master)
  tft.begin(0x1505);
  tft.setRotation(2);            //PORTRAIT
  tft.fillScreen(BLACK);

  knop1_btn.initButton(&tft,  120, 34, 200, 34, WHITE, CYAN, BLACK, "baco", 3); //x,y,breedte,hoogte
  knop2_btn.initButton(&tft, 120, 87, 200, 34, WHITE, CYAN, BLACK, "ginto", 3);
  knop3_btn.initButton(&tft, 120, 140, 200, 34, WHITE, CYAN, BLACK, "wodtea", 3);
  knop4_btn.initButton(&tft, 30, 200, 40, 40, WHITE, CYAN, BLACK, "-", 3);
  knop5_btn.initButton(&tft, 210, 200, 40, 40, WHITE, CYAN, BLACK, "+", 3);
  knop6_btn.initButton(&tft, 120, 270, 220, 40, WHITE, CYAN, BLACK, "maak", 3);

  knop1_btn.drawButton(false);
  knop2_btn.drawButton(false);
  knop3_btn.drawButton(false);
  knop4_btn.drawButton(false);
  knop5_btn.drawButton(false);
  knop6_btn.drawButton(false);

}


void loop(void)
{
  bool down = Touch_getXY();

  straf = min(straf, 9);
  straf = max(straf, 0);

  knop1_btn.press(down && knop1_btn.contains(pixel_x, pixel_y));
  knop2_btn.press(down && knop2_btn.contains(pixel_x, pixel_y));
  knop3_btn.press(down && knop3_btn.contains(pixel_x, pixel_y));
  knop4_btn.press(down && knop4_btn.contains(pixel_x, pixel_y));
  knop5_btn.press(down && knop5_btn.contains(pixel_x, pixel_y));
  knop6_btn.press(down && knop6_btn.contains(pixel_x, pixel_y));

  //zorgt voor flikkern knop
  if (knop1_btn.justReleased())
    knop1_btn.drawButton();
  if (knop2_btn.justReleased())
    knop2_btn.drawButton();
  if (knop3_btn.justReleased())
    knop3_btn.drawButton();
  if (knop4_btn.justReleased())
    knop4_btn.drawButton();
  if (knop5_btn.justReleased())
    knop5_btn.drawButton();
  if (knop6_btn.justReleased())
    knop6_btn.drawButton();

  // zorgt voor actie zelf
  if (knop1_btn.justPressed()) {
    knop1_btn.drawButton(true);
    drank = 10;
    Serial.println(drank);
  }

  if (knop2_btn.justPressed()) {
    knop2_btn.drawButton(true);
    drank = 120;
    Serial.println(drank);

  }

  if (knop3_btn.justPressed()) {
    knop3_btn.drawButton(true);
    drank = 30;
    Serial.println(drank);
  }

  if (knop4_btn.justPressed()) {
    knop4_btn.drawButton(true);
    Serial.println("min");
    straf--;
    delay(50);

  }
  if (knop5_btn.justPressed()) {
    knop5_btn.drawButton(true);
    Serial.println("plus");
    straf++;
    delay(50);
  }
  if (knop6_btn.justPressed()) {
    knop6_btn.drawButton(true);
    Serial.println("maak");
    drank = drank + straf;
    delay(50);
    tft.setTextColor(RED, BLACK);
    tft.setTextSize(2);
    tft.setCursor(5, 300);
    tft.print(drank);
    Wire.beginTransmission(64); // transmit to device #8
    Wire.write(drank);              // sends one byte
    Wire.endTransmission(64);    // stop transmitting
    delay(3000);
    drank = 0;
    straf = 5;
  }


  tft.setTextColor(RED, BLACK);
  tft.setTextSize(5);
  tft.setCursor(75, 185);
  tft.print(straf);
  tft.setCursor(115, 185);
  tft.print("cl");



}

slave

#include <Wire.h>
int LED = 13;
int x = 0;
void setup() {
  Serial.begin(9600);
  // Define the LED pin as Output
  pinMode (LED, OUTPUT);
  // Start the I2C Bus as Slave on address 9
  Wire.begin(64);
  // Attach a function to trigger when something is received.
  Wire.onReceive(receiveEvent);
}
void receiveEvent(int bytes) {
  x = Wire.read();    // read one character from the I2C
}
void loop() {
  Serial.println(x);
}