I have a 2x16 I2C character LCD (Newhaven NHD-0216K3Z-FL-GBW-V3) I can write individual characters to using the Wire.write() command. I’d like to write entire strings to it, though, and the Reference suggests Wire.write() should be able to do this without me having to explicitly send a single character at a time, but I’m not having any success. Wire.write(“string”) and Wire.write(x) (where x = “string”) both result in one character, an @, which isn’t one of the ones I sent. What’s the secret? Thanks.
I posted over in Programming but it was suggested that this is a more appropriate forum. Code below:
#include <Wire.h>
char red[] = "RED";
char green[] = "GREEN";
char blue[] = "BLUE";
char yellow[] = "YELLOW";
char orange[] = "ORANGE";
char brown[] = "BROWN";
char unknown[] = "UNKNOWN";
void setup() {
Wire.begin();
Serial.begin(9600);
}
void loop() {
char x;
char* y = green;
Serial.print("First character: ");
Serial.println(y[0]); // This prints "G" to the monitor, as it should
Wire.beginTransmission(0x28);
Wire.write(0xFE); // Clear display
Wire.write(0x51);
Wire.endTransmission();
Wire.beginTransmission(0x28);
Wire.write(y); // Just prints "@" followed by the alphabet, as
// does Wire.write("green") and Wire.write(green)
Wire.endTransmission();
for (x = 0; x < 33; x++) { // Print the alphabet
Wire.beginTransmission(0x28);
if (x == 17) {
Wire.write(0xFE); // Move cursor to 2nd line
Wire.write(0x45);
Wire.write(0x40);
}
Wire.write(64 + x);
Wire.endTransmission();
delay(500);
}
}