Hello world!

The normal way:

Arduino->Display

// Arduino code
#include <Wire.h>
#include <LiquidCrystal_PCF8574.h>
LiquidCrystal_PCF8574 lcd(0x27);

void setup() {
  Wire.begin();
  Wire.beginTransmission(0x27);
  lcd.begin(16, 2);
  lcd.setBacklight(255);

  lcd.home();
  lcd.clear();
  lcd.print("Hello world!");
}

void loop() {
  // nothing to do here
}

The overengineered way:

Raspberry Pi with Python script->USB->Arduino->Display

//Python script
import serial
import time

def main():
    ser = serial.Serial("/dev/ttyUSB0", 9600)
    time.sleep(2)
    ser.write(('Hello world!\n').encode())

if __name__ == "__main__":
    main()
// Arduino code, with inspiration from Serial Event example code in Arduino IDE
#include <Wire.h>
#include <LiquidCrystal_PCF8574.h>
LiquidCrystal_PCF8574 lcd(0x27);

String inputString = "";
bool stringComplete = false;

void setup() {
  Wire.begin();
  Wire.beginTransmission(0x27);
  lcd.begin(16, 2);
  lcd.setBacklight(255);

  Serial.begin(9600);
  inputString.reserve(16);

  lcd.home();
  lcd.clear();
}

void loop() {
  if (stringComplete) {
    lcd.home();
    lcd.clear();
    lcd.print(inputString);
    inputString = "";
    stringComplete = false;
  }
}

void serialEvent() {
  while (Serial.available()) {
    char inChar = (char)Serial.read();
    if (inChar == '\n') {
      stringComplete = true;
    }else{
      inputString += inChar;
    }
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *