Same code working differently on Nano 33 IoT and Mega

I am using I2C. How can I check if communication is working correctly? Thanks Alex.