Cipad 12: Leçon 11: Arduino, affichage LCD, créer des caractères personnalisés

3 min read 2 days ago
Published on Oct 02, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

This tutorial will guide you through connecting a 16x2 alphanumeric LCD display to an Arduino board using TinkerCad. You'll learn how to create custom characters for the display, enhancing your projects with personalized visuals. This is particularly useful for beginners looking to expand their skills in working with Arduino and LCDs.

Step 1: Setting Up TinkerCad

  1. Create a TinkerCad Account: If you don’t have an account, sign up at TinkerCad.
  2. Access the Project: Use the provided link to access the project template:
  3. Open the Project: Click on the link to open the project and familiarize yourself with the components provided.

Step 2: Connecting the LCD to Arduino

  1. Gather Required Components:
    • Arduino board (e.g., Arduino Uno)
    • 16x2 LCD display
    • Breadboard
    • Jumper wires
    • Potentiometer (for contrast adjustment)
  2. Wiring the LCD:
    • Connect the LCD pins to the Arduino as follows:
      • VSS to GND
      • VDD to 5V
      • V0 to the middle pin of the potentiometer (other two pins to 5V and GND)
      • RS to digital pin 12
      • RW to GND
      • E to digital pin 11
      • D4 to digital pin 5
      • D5 to digital pin 4
      • D6 to digital pin 3
      • D7 to digital pin 2
  3. Verify Connections: Double-check all connections to ensure they are secure and correctly positioned.

Step 3: Programming the Arduino

  1. Open the Arduino IDE: Install and launch the Arduino IDE if you haven't already.
  2. Load the Required Libraries: Include the necessary library for controlling the LCD by adding the following line at the top of your code:
    #include <LiquidCrystal.h>
    
  3. Initialize the Display: In your setup function, initialize the LCD with the pins you connected:
    LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
    void setup() {
        lcd.begin(16, 2); // sets the LCD size
        lcd.print("Hello, World!"); // example message
    }
    
  4. Create Custom Characters:
    • Use the following code snippet to define custom characters:
    byte customChar[8] = {
        0b00000,
        0b01110,
        0b10001,
        0b10001,
        0b01110,
        0b00000,
        0b00000,
        0b00000
    };
    lcd.createChar(0, customChar); // store custom character in memory
    lcd.setCursor(0, 1); // set cursor to second line
    lcd.write(byte(0)); // display the custom character
    
  5. Upload the Code: Connect your Arduino to the computer and upload the code.

Step 4: Testing Your Setup

  1. Power On the Arduino: Once the code is uploaded, power on the Arduino.
  2. Check the Display: Ensure the LCD displays the default message and any custom characters you created.
  3. Adjust Contrast: Use the potentiometer to adjust the display contrast for better visibility.

Conclusion

You have successfully connected a 16x2 LCD display to an Arduino and created custom characters. This project enhances your understanding of Arduino programming and interfacing with displays. For further exploration, consider creating more complex graphics or integrating additional sensors to display dynamic information. Happy tinkering!