I installed the newest version of Adruino IDE 1.8.19. I have four I2C LCD screens 24, 25, 26, 27. They work fine when the code is in void setup. When I set using void loop, I get artifacts across all four LCDs. I stripped the 9 Arduino devices 14 to 1C down to 14 (Master) and 15 (Slave). I
added 10K pull up resistors to SCL and SDA to the 5V rail A few posted the issue is with the IDE.
Scanning…
I2C device found at address 0x15 !
I2C device found at address 0x24 !
I2C device found at address 0x25 !
I2C device found at address 0x26 !
I2C device found at address 0x27 !
done
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd20x4_24 = LiquidCrystal_I2C(0x24, 20, 4);
LiquidCrystal_I2C lcd20x4_25 = LiquidCrystal_I2C(0x25, 20, 4);
LiquidCrystal_I2C lcd20x4_26 = LiquidCrystal_I2C(0x26, 20, 4);
LiquidCrystal_I2C lcd20x4_27 = LiquidCrystal_I2C(0x27, 20, 4);
int x = 0;
int LED = 13;
int find_devices = 1;
int init_welcome = 0;
int init_address = 1;
void setup()
{
// Initiate the LCD:
lcd20x4_24.init();
lcd20x4_24.backlight();
lcd20x4_25.init();
lcd20x4_25.backlight();
lcd20x4_26.init();
lcd20x4_26.backlight();
lcd20x4_27.init();
lcd20x4_27.backlight();
// I2C counter for LEDs
pinMode (LED, OUTPUT);
// Start the I2C Bus as Master
Wire.begin();
// I2C counter for LEDs
// I2C Scanner Code
Serial.begin(9600);
if (find_devices == 1)
{
while (!Serial); // wait for serial monitor
Serial.println("\nI2C Scanner");
// I2C Scanner Code
delay(1000);
lcd20x4_24.clear();
lcd20x4_25.clear();
lcd20x4_26.clear();
lcd20x4_27.clear();
delay(2000);
// LCD I2C 20x4_24
}
Wire.beginTransmission(0x24);
lcd20x4_24.setCursor(0, 0);
lcd20x4_24.print("0x24");
lcd20x4_24.setCursor(0, 1);
lcd20x4_24.print("0x24");
lcd20x4_24.setCursor(0, 2);
lcd20x4_24.print("0x24");
lcd20x4_24.setCursor(0, 3);
lcd20x4_24.print("0x24");
Wire.endTransmission();
Wire.beginTransmission(0x25);
lcd20x4_25.setCursor(0, 0);
lcd20x4_25.print("0x25");
lcd20x4_25.setCursor(0, 1);
lcd20x4_25.print("0x25");
lcd20x4_25.setCursor(0, 2);
lcd20x4_25.print("0x25");
lcd20x4_25.setCursor(0, 3);
lcd20x4_25.print("0x25");
Wire.endTransmission();
Wire.beginTransmission(0x26);
lcd20x4_26.setCursor(0, 0);
lcd20x4_26.print("0x26");
lcd20x4_26.setCursor(0, 1);
lcd20x4_26.print("0x26");
lcd20x4_26.setCursor(0, 2);
lcd20x4_26.print("0x26");
lcd20x4_26.setCursor(0, 3);
lcd20x4_26.print("0x26");
Wire.endTransmission();
Wire.beginTransmission(0x27);
lcd20x4_27.setCursor(0, 0);
lcd20x4_27.print("0x27");
lcd20x4_27.setCursor(0, 1);
lcd20x4_27.print("0x27");
lcd20x4_27.setCursor(0, 2);
lcd20x4_27.print("0x27");
lcd20x4_27.setCursor(0, 3);
lcd20x4_27.print("0x27");
Wire.endTransmission();
}
void loop() {
/*
for (byte address = 21; address < 29; address++)
{
Wire.beginTransmission(address);
Wire.write(address);
lcd20x4_27.setCursor(0, 0);
lcd20x4_27.print("Master calling");
lcd20x4_27.setCursor(15, 0);
lcd20x4_27.print(address);
Wire.endTransmission();
delay(2000);
}
*/
//Find Devices on I2C Bus
//set find_devices = 1
if (find_devices == 1)
{
// I2C Scanner Code
byte error, address;
int nDevices;
Serial.println("Scanning…");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknown error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(5000); // wait 5 seconds for next scan
// I2C Scanner Code
}
}
I am using two of the Ardiuno devices to power the 5V. I tested it with a multimeter and it is over 4.6V on Arduino side and I connected up 3 more Arduino devices 5V and ground to the power rail. Multimeter shows 4.12-4.36V on LCD side . I was considering getting a bench power supply for my projects. Usually I have all 9 of them powering the 5V rail. I checked the I2C signal on my Siglent scope and it is square waves. I don't see interference. I could get a I2C extender to help but the length is under a meter.
I checked the wires and put in the 10K pull up resistors. I checked and moved the wires for no interference. When I get back from vacation I will get a Siglent SPD3303C - Programmable Linear DC Power Supply (3 Channels, 220W)
@scsiraidguru, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project.
Bi-Directional Logic Level Converter for I2C. This is an inexpensive solution to connect a Raspberry Pi on 3.3V to Arduino devices on 5V and move data between them. Raspberry Pi is the master device. I connected the I2C LCD screens to the Raspberry Pi and displayed the data from the Arduino devices to them. I2C section in the menu shows pictures of the connection. I am staying with yellow and blue I2C wiring for the bus configuration.
I can spot many problems at first glance. How much effort are you willing to put into your project to make it work ? We have to do everything all over, step by step. Both hardware and software.
I think it is not very useful to name every problem, since I prefer to start all over. But I don't want others guessing what I mean. Here is just a first impression:
The I2C bus is a weak bus. It can nog go all over the place. If you have motors, then you need something else.
The Sparkfun I2C Logic Level shifter is for SDA and SCL. It connects a 5V I2C bus to a 3.3V I2C bus. It also makes the I2C bus even more weaker. It must be connected properly or it will disturb the I2C bus. Remove it for now.
One I2C Logic Level shifter + two Mega boards + 4 displays + pullup resistors. I see nine pullup resistors. That could be more than the maximum of 3mA sink current.
You use the LCD library (which uses I2C) and after that call Wire.begin(). That is not okay. The Wire.begin() initializes the I2C bus.
Using Wire.beginTransmission() and Wire.endTransmission() around the library functions is not okay. It is as if you call randomly those functions. Remove them. Keep them in the I2C Scanner.
The displays need a good 5V. Try to give them at least 4.5V.
Have you used arrays ? The display objects can be put in a array. That makes the sketch easier.
Is the Raspberry Pi the Master(Controller) ? But your sketch runs as a Master on a Arduino board on the same I2C bus. How is that possible ?
The LCD library is one level higher than the Wire library. The functions inside the LCD library use the Wire library functions to communicate with the display, so you don't have to use them. The LCD functions close the I2C bus before returning. You can mix all LCD functions to all displays in any which way.
Now that I start to think about your project, do you want the Arduino boards to control the displays while the Raspberry Pi is the Master ? Then you have a multi-Master bus. Avoid a multi-Master bus at all costs.
I appreciate the help. I had the RPi setup as master. Actually, you can name all the issues. It is hard to find great information on having this many devices together.
The next major purchase is the Siglent Bench Power Supply. Each of the Arduino devices has a 9V 1A power supply.
I have been working with Inventr.io on a space ship project. The multiple I2C LCDs where to display various component readings. My Siglent scope has I2C capable settings. The I2C bus seemed to be a good way connect the devices. I have been looking into an I2C extender chip.
I talked with Sparkfun about that component to connect the RPi to the Arduino devices.
I have 1000uF caps on the 5V rail. I have two 10k resistors doing power up on SDA and SCL.
Can you tell who does what ?
It is to explore the I2C bus ? Then this is not the right way.
If you connect the Arduino Mega boards via a USB cable to a USB hub and then to the Raspberry Pi, and use Python with Serial, that will work. Each Arduino Mega board can have its own display via I2C, that would be a good project.
If you want a project with 4 displays and many sensors, then you can do that with a single Arduino board.
There are I2C extender chips. Some convert the I2C bus into a twisted-pair signals, others clean up the signal, and other chips are just vague snake oil. I'm not a fan of those chips, but some wrote on this forum that it helped to finish their project.
Koepel, Thanks for your help and taking your time for the write up.
I2C can handle 120+ devices.
I had the RPi as the master. Arduino devices are addressed from 14 to 1C. LCDs are 24 to 27.
I want code on the RPi master to loop the addresses 14 to 22 (1C). It sends the address across the I2C bus. The slaves read the address, a if (address == slave) matches the device I2C address, it triggers the slave to begin transmission for what is running on it. When done, end transmission. This way only one device is sending data to the I2C LCDs at a time. I was put a delay on the master loop for 7 seconds.
Interesting idea setting up the serial bus to speed up transmission. Can I run both I2C and serial bus at the same time?