DIY- Σύνδεση οθόνης 16x2 LCD με arduino #3

Σε αυτό το tutorial θα δούμε πως μπορούμε να συνδέσουμε σχετικά εύκολα μια οθόνη LCD με το Arduino. 

Στην προκειμένη περίπτωση η οθόνη μας έχει ήδη κολλημένο το module επικοινωνίας.

Τα υλικά που θα χρειαστούμε:

1x Character LCD 16x2

1x Arduino Uno R3 (ή όποια έκδοση έχετε)

Jumper Wires

ΣΥΝΔΕΣΗ:

I2C Character LCD
Arduino
GNDGND
VCC5V
SDAA4
SDLA5

Αφού κάνετε τις συνδέσεις, ίσως χρειαστεί να προσαρμόσετε την αντίθεση της οθόνης. Αυτό γίνεται από το ποτενσιόμετρο που έχει το module.


Στην συνέχεια κατεβάζουμε την βιβλιοθήκη που χρειάζεται η οθόνη από ΕΔΩ.


Στην συνέχεια την εγκαθιστούμε χειροκίνητα στο φάκελο του Arduino, όπου βρίσκονται οι βιβλιοθήκες.


Ή το κάνουμε με τον παρακάτω τρόπο, SKETCH-Include Library-Add .ZIP library



Η βιβλιοθήκη περιέχει και κάποια παραδείγματα που ίσως σας φανούν χρήσιμα. Αφου εγκαταστήσουμε την βιβλιοθήκη, θα χρειαστεί να βρούμε την διεύθυνση της οθόνης μας, το οποίο θα μας χρειαστεί στον κώδικα.

Η διεύθυνση συνήθως είναι 0x27.

  1. /*I2C_scanner
  2. This sketch tests standard 7-bit addresses.
  3. Devices with higher bit address might not be seen properly.*/
  4. #include <Wire.h>
  5. void setup() {
  6. Wire.begin();
  7. Serial.begin(9600);
  8. while (!Serial);
  9. Serial.println("\nI2C Scanner");
  10. }
  11. void loop() {
  12. byte error, address;
  13. int nDevices;
  14. Serial.println("Scanning...");
  15. nDevices = 0;
  16. for (address = 1; address < 127; address++ ) {
  17. Wire.beginTransmission(address);
  18. error = Wire.endTransmission();
  19. if (error == 0) {
  20. Serial.print("I2C device found at address 0x");
  21. if (address < 16)
  22. Serial.print("0");
  23. Serial.print(address, HEX);
  24. Serial.println(" !");
  25. nDevices++;
  26. }
  27. else if (error == 4) {
  28. Serial.print("Unknown error at address 0x");
  29. if (address < 16)
  30. Serial.print("0");
  31. Serial.println(address, HEX);
  32. }
  33. }
  34. if (nDevices == 0)
  35. Serial.println("No I2C devices found\n");
  36. else
  37. Serial.println("done\n");
  38. delay(5000);
  39. }

Συην συνέχεια ανοίγουμε το Serial Monitor (Ctrl + Shift + M) και σημειώνουμε την διεύθυνση.

Σημειώνουμε την διεύθυνση και γράφουμε τον κώδικα μας.

ΚΩΔΙΚΑΣ

/* I2C LCD with Arduino example code.

// Συμπεριλάβετε τις βιβλιοθήκες

#include <Wire.h> // βιβλιοθήκη για I2C επικοινωνία

#include <LiquidCrystal_I2C.h> // βιβλιοθήκη για LCD

// Wiring: SDA pin is connected to A4 and SCL pin to A5.

// Connect to LCD via I2C, default address 0x27 (A0-A2 not jumpered)

LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 20, 4); // Change to (0x27,16,2) for 16x2 LCD.

void setup() {

  // Initiate the LCD:

  lcd.init();

  lcd.backlight();

}

void loop() {

  // Print 'Hello World!' on the first line of the LCD:

  lcd.setCursor(0, 0); // Set the cursor on the first column and first row.

  lcd.print("Hello World!"); // Print the string "Hello World!"

  lcd.setCursor(2, 1); //Set the cursor on the third column and the second row (counting starts at 0!).

  lcd.print("LCD tutorial");

}


Αυτό είναι ένα βασικό παράδειγμα για να εμφανίσετε το πρώτο σας μήνυμα στην οθόνη.

Μπορείτε να πειραματιστείτε, να εμφανίσετε ειδικά σύμβολα, να κάνετε το μήνυμα να κινείται και πολλά άλλα.


Στείλτε μας πιθανόν απορίες σας.

Comments: 0
No comments
Leave a Reply

Your email address cannot be published. Required fields are marked*