7.10.22
I am reconnecting the I2C LCD screens to the Raspberry PI 4B.
From Left to Right
Raspberry Pi 4B 8GB with T-Cobbler
Bi directional Logic Level Converter (BD-LLC), little red IC
Arduino 4: Arduino Hero (Arduino master until BD-LLC is configured)
Arduino 5: Arduino Hero
Arduino 6: Arduino Hero
Arduino 7: Arduino Mega 2560
Arduino 8: Arduino Mega Wifi
Arduino 9: Arduino Uno R3
Arduino 10: Arduino Hero
Arduino 11: Arduino Hero
Arduino 12: Arduino Hero
You can see the I2C LCD addresses at 24 and 27.
i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: — — — — — — — —
10: — — — — 14 15 16 17 18 19 1a 1b 1c — — —
20: — — — — 24 — — 27 — — — — — — — —
30: — — — — — — — — — — — — — — — —
40: — — — — — — — — — — — — — — — —
50: — — — — — — — — — — — — — — — —
60: — — — — — — — — — — — — — — — —
70: — — — — — — — —
LCD 0x24 is displaying information from each Arduino to Raspberry PI that has each of the 9 Arduino devices checking in.
INO files for Arduino device
Arduino 5
// Wire Slave Receiver
// by Nicholas Zambetti <http://www.zambetti.com>
// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this
// Created 29 March 2006
// This example code is in the public domain.
// 04-Feb-2018 mcarter adapted
#include <Wire.h>
const int ledPin = 13; // onboard LED
int ValueA3 = 0;
static_assert(LOW == 0, "Expecting LOW to be 0");
int Checking_In = 1;
void setup() {
Serial.begin(9600);
Wire.begin(0x15); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Wire.onRequest(requestEvent); // send date to Pi
Wire.onRequest(ard_checkingIn); // send date to Pi
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW); // turn it off
}
void loop() {
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent() {
while (Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
digitalWrite(ledPin, c);
}
}
void requestEvent()
{
}
void ard_checkingIn()
{
Wire.write(Checking_In);
} Arduino 6
// Wire Slave Receiver
// by Nicholas Zambetti <http://www.zambetti.com>
// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this
// Created 29 March 2006
// This example code is in the public domain.
// 04-Feb-2018 mcarter adapted
#include <Wire.h>
const int ledPin = 13; // onboard LED
int ValueA3 = 0;
static_assert(LOW == 0, "Expecting LOW to be 0");
int Checking_In = 1;
void setup() {
Serial.begin(9600);
Wire.begin(0x16); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Wire.onRequest(requestEvent); // send date to Pi
Wire.onRequest(ard_checkingIn); // send date to Pi
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW); // turn it off
}
void loop() {
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent() {
while (Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
digitalWrite(ledPin, c);
}
}
void requestEvent()
{
}
void ard_checkingIn()
{
Wire.write(Checking_In);
} Arduino Mega 7
// Wire Slave Receiver
// by Nicholas Zambetti <http://www.zambetti.com>
// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this
// Created 29 March 2006
// This example code is in the public domain.
// 04-Feb-2018 mcarter adapted
#include <Wire.h>
const int ledPin = 13; // onboard LED
int ValueA3 = 0;
static_assert(LOW == 0, "Expecting LOW to be 0");
int Checking_In = 1;
void setup() {
Serial.begin(9600);
Wire.begin(0x17); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Wire.onRequest(requestEvent); // send date to Pi
Wire.onRequest(ard_checkingIn); // send date to Pi
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW); // turn it off
}
void loop() {
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent() {
while (Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
digitalWrite(ledPin, c);
}
}
void requestEvent()
{
}
void ard_checkingIn()
{
Wire.write(Checking_In);
} Arduino Mega Wifi 8
// Wire Slave Receiver
// by Nicholas Zambetti <http://www.zambetti.com>
// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this
// Created 29 March 2006
// This example code is in the public domain.
// 04-Feb-2018 mcarter adapted
#include <Wire.h>
const int ledPin = 13; // onboard LED
int ValueA3 = 0;
static_assert(LOW == 0, "Expecting LOW to be 0");
int Checking_In = 1;
void setup() {
Serial.begin(9600);
Wire.begin(0x18); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Wire.onRequest(requestEvent); // send date to Pi
Wire.onRequest(ard_checkingIn); // send date to Pi
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW); // turn it off
}
void loop() {
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent() {
while (Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
digitalWrite(ledPin, c);
}
}
void requestEvent()
{
}
void ard_checkingIn()
{
Wire.write(Checking_In);
} Arduino 9
// Wire Slave Receiver
// by Nicholas Zambetti <http://www.zambetti.com>
// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this
// Created 29 March 2006
// This example code is in the public domain.
// 04-Feb-2018 mcarter adapted
#include <Wire.h>
const int ledPin = 13; // onboard LED
int ValueA3 = 0;
static_assert(LOW == 0, "Expecting LOW to be 0");
int Checking_In = 1;
void setup() {
Serial.begin(9600);
Wire.begin(0x19); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Wire.onRequest(requestEvent); // send date to Pi
Wire.onRequest(ard_checkingIn); // send date to Pi
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW); // turn it off
}
void loop() {
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent() {
while (Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
digitalWrite(ledPin, c);
}
}
void requestEvent()
{
}
void ard_checkingIn()
{
Wire.write(Checking_In);
} Arduino 10
// Wire Slave Receiver
// by Nicholas Zambetti <http://www.zambetti.com>
// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this
// Created 29 March 2006
// This example code is in the public domain.
// 04-Feb-2018 mcarter adapted
#include <Wire.h>
const int ledPin = 13; // onboard LED
int ValueA3 = 0;
static_assert(LOW == 0, "Expecting LOW to be 0");
int Checking_In = 1;
void setup() {
Serial.begin(9600);
Wire.begin(0x1a); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Wire.onRequest(requestEvent); // send date to Pi
Wire.onRequest(ard_checkingIn); // send date to Pi
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW); // turn it off
}
void loop() {
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent() {
while (Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
digitalWrite(ledPin, c);
}
}
void requestEvent()
{
}
void ard_checkingIn()
{
Wire.write(Checking_In);
} Arduino 11
// Wire Slave Receiver
// by Nicholas Zambetti <http://www.zambetti.com>
// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this
// Created 29 March 2006
// This example code is in the public domain.
// 04-Feb-2018 mcarter adapted
#include <Wire.h>
const int ledPin = 13; // onboard LED
int ValueA3 = 0;
static_assert(LOW == 0, "Expecting LOW to be 0");
int Checking_In = 1;
void setup() {
Serial.begin(9600);
Wire.begin(0x1b); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Wire.onRequest(requestEvent); // send date to Pi
Wire.onRequest(ard_checkingIn); // send date to Pi
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW); // turn it off
}
void loop() {
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent() {
while (Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
digitalWrite(ledPin, c);
}
}
void requestEvent()
{
}
void ard_checkingIn()
{
Wire.write(Checking_In);
} Arduino 12
// Wire Slave Receiver
// by Nicholas Zambetti <http://www.zambetti.com>
// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this
// Created 29 March 2006
// This example code is in the public domain.
// 04-Feb-2018 mcarter adapted
#include <Wire.h>
const int ledPin = 13; // onboard LED
int ValueA3 = 0;
static_assert(LOW == 0, "Expecting LOW to be 0");
int Checking_In = 1;
void setup() {
Serial.begin(9600);
Wire.begin(0x1c); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Wire.onRequest(requestEvent); // send date to Pi
Wire.onRequest(ard_checkingIn); // send date to Pi
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW); // turn it off
}
void loop() {
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent() {
while (Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
digitalWrite(ledPin, c);
}
}
void requestEvent()
{
}
void ard_checkingIn()
{
Wire.write(Checking_In);
} Arduino 4 Slave
// Wire Slave Receiver
// by Nicholas Zambetti <http://www.zambetti.com>
// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this
// Created 29 March 2006
// This example code is in the public domain.
// 04-Feb-2018 mcarter adapted
#include <Wire.h>
const int ledPin = 13; // onboard LED
int ValueA3 = 0;
static_assert(LOW == 0, "Expecting LOW to be 0");
int Checking_In = 1;
void setup() {
Serial.begin(9600);
Wire.begin(0x14); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Wire.onRequest(requestEvent); // send date to Pi
Wire.onRequest(ard_checkingIn); // send date to Pi
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW); // turn it off
}
void loop() {
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent() {
while (Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
digitalWrite(ledPin, c);
}
}
void requestEvent()
{
}
void ard_checkingIn()
{
Wire.write(Checking_In);
} Raspberry Pi Python File
#! /usr/bin/env python3
#include <iostream>
#include <wiringPiI2C.h>
import time
from smbus import SMBus
from array import *
import I2C_LCD_driver_24
import I2C_LCD_driver_27
ard_addr = bytearray([0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c])
dev_name = ['14', '15', '16', '17', '18', '19', '1a', '1b', '1c']
number = bytearray([0, 0, 0, 0, 0, 0, 0, 0, 0])
check_in = [0, 0, 0, 0, 0, 0, 0, 0, 0]
lcd_24_screen_format = [ [1,0,1,2,1,3], [2,0,2,2,2,3], [3,0,3,2,3,3], [4,0,4,2,4,3], [1,5,1,7,1,8], [2,5,2,7,2,8],
[3,5,3,7,3,8], [4,5,4,7,4,8], [1,10,1,12,1,13] ]
bus = SMBus(1) # indicates /dev/ic2-1
lcd_24 = I2C_LCD_driver_24.lcd()
lcd_27 = I2C_LCD_driver_27.lcd()
cnt = 0
check_in_answer = ""
while True:
lcd_24.lcd_clear()
while cnt < 9:
check_in[cnt] = bus.read_byte(ard_addr[cnt])
print("Arduino", dev_name[cnt], "reporting in", check_in[cnt])
bus.write_byte(ard_addr[cnt], 0x1) # switch it on
time.sleep(2)
bus.write_byte(ard_addr[cnt], 0x0) # switch it on
str_addr = "{}".format(dev_name[cnt])
str_check_in = "{}".format(check_in[cnt])
lcd_24.lcd_display_string(str_addr, lcd_24_screen_format[cnt][0], lcd_24_screen_format[cnt][1])
lcd_24.lcd_display_string(": ", lcd_24_screen_format[cnt][2], lcd_24_screen_format[cnt][3])
if (str_check_in == "1"):
check_in_answer = "Y"
elif (str_check_in == "0"):
check_in_answer = "N"
lcd_24.lcd_display_string(check_in_answer, lcd_24_screen_format[cnt][4], lcd_24_screen_format[cnt][5])
cnt +=1
time.sleep(3)
cnt = 0
print(" ")