Using Rs485 and I2C display together

96 views Asked by At

I am using rs485 to communicate between two Arduino nano. I have connected a 4 bit I2C display to one of the Arduino nano. When the nano receives data via Rs485 from the master nano, the data is displayed on the I2C display. But the issue is that I am only able to use one of those things i.e. if I am receiving data I am not able to display it on the I2C display and if I am displaying, then I am not able to receive the data. Has someone tried doing it together?

Code for master nano

// rs485 master
void setup() {
  Serial.begin(115200);
  pinMode(2,OUTPUT);  //DE/RE pin
}

int i;
String s = "s1b01n01";

void loop() {
  digitalWrite(2,HIGH);  // high for transmiting

  for(i=0;i<=8;i++) {
    Serial.print(s[i]);
  }

  digitalWrite(2,LOW);
}

Code for Slave nano

#include <TM1637Display.h>
#define CLK 4
#define DIO 16
#define ExtEnable 2  //DE/RE pin

TM1637Display display = TM1637Display(CLK, DIO); // Create display object of type TM1637Display:

const uint8_t data[] = {0xff, 0xff, 0xff, 0xff};// Create array that turns all segments on:
const uint8_t blank[] = {0x00, 0x00, 0x00, 0x00}; // Create array that turns all segments off:

int i = 0;
char add[8], c;
char address[] = {'s', '1', 'b', '0', '1', 'n', '0', '1'};

void setup() {
  Serial.begin(115200);
  pinMode(ExtEnable, OUTPUT); //DE/RE pin
  display.clear();
  delay(1000);
  display.setBrightness(7); // Set the brightness:
}

void loop() {
  digitalWrite(ExtEnable, LOW); // low for receiving
  
  if (Serial.available()) {
    c = Serial.read();
    Serial.print(c);
    add[i] = c;
    i++;
    digitalWrite(ExtEnable, HIGH);
    //display.showNumberDec(3); //print on display
  }

  Serial.print("add");
  Serial.println(add);

  if(add == address) { // to check 
    display.showNumberDec(3); //print on display
  }
}
0

There are 0 answers