Arduino RS485 and I2C at same time

Hi,

I have Arduino NANO connected with Domat MarkMMX PLC through the RS485 ( TX1, RX0 ). For data / register reading is in the PLC used Modbus RTU protocol. Is working OK. But when I connect light sensor ( with I2C communication ) and change the code to read value, Modbus RS485 communication hang up that time.

Could someone help me? Thank you.

Problem solved!!! No attention necessary.

If you were to provide a drawing of how you have wired up the various component parts to your Nano, and share your whole sketch - or a simpler sketch that demonstrates the problem, then you will have a better chance of getting a helpful reply.

EDIT: And please don't make duplicate posts.

Light sensor BH1750 connected to A4 &A5. TTL to RS485 converter connected as TX1 - DI, RX0 - RO, DE,RE - D4.

Shortened code:

#include <BH1750.h>
#include<ModbusRtu.h>
#include <Wire.h>

BH1750 lightMeter;

float lux;

Modbus bus;  

uint16_t modbus_array[] = {180,20,40};

void setup()
{
  Wire.begin();
  bus = Modbus(10,1,4);
  bus.begin(19200);
}

void loop()
{
   lux = lightMeter.readLightLevel();

   bus.poll(modbus_array,sizeof(modbus_array)/sizeof(modbus_array[0]));
   modbus_array[2] = lux;

  if (modbus_array[0] == 300)   
  {
    digitalWrite(led1,LOW);
  }
  else   
  {
    digitalWrite(led1,HIGH);
  }
}

Problem with RS485 hanging happens when I put the code for sensor value reading.
lux = lightMeter.readLightLevel();

@miluk,
I have deleted your other topic on the same subject, please post your questions once only.

Thank you.

OK. Thanks. Using forum for first time.... Sorry. Best regards.

What type of Arduino are you using? I cannot find a board that has I2C on A4/A5 but also has TX1 and RX0.

BTW, connecting the RS485 TX and RX to different serial ports is a very bad idea. Post a wiring diagram!

That connects Modbus to Serial1. As you connected the reception of the RS485 to RX0 you won't see any replies.