реклама:

Connecting an LCD display. Part 7.

Slight pause...

You have connected the Arduino and he performed your first program. Now, if you have not already done, you must order all the necessary details, which have been described above.

Then, step by step, we will hard work - we will connect to Arduino more and more modules until it turned into controller. After the addition of each new device will be given an example sketch. You need to copy it and upload into Arduino board. Executing this example will help you to understand whether you have made the right connection. If no - then the error will be covered in tangled wires and contacts on the card or device. Other errors simply can not be. If the sketch was successfully executed, according to the description, then you can proceed to connect the next device.

Connecting an LCD display

Let's start with the most difficult part - this is LCD display. It does not matter what LCD size you currently have: 1602 or 2004 - they are equally connected and the controller supports both of them. To connect, we need 12 wires.

If you will overcome connecting of these 12 wires - you will be very happy! All other rest of connections will be a mere trifle! Be extremely careful.

If look at the display "normal" then its findings will be on top, numbering from left to right from 1 to 16.

LCD display Arduino 1602

Here is a table of pins of LCD display and board arduino:

LCD pins Arduino pins
1GND ()
25V
3GND
439
5GND
641
7not in use
8not in use
9not in use
10not in use
1143
1245
1347
1449
153, brightness
16GND

Here is a diagram to connect the display:

Connecting an LCD display 1602

Another problem is that display's board contains "holes" instead of the usual pins, which makes it impossible to connect it with standard cables Arduino. What to do if you do not know how to solder? My advice: buy low-power 30W soldering iron on and try. It will be very useful for you! There are plenty of YouTube videos, believe me, it's not so hard. Or ask someone to solder 12 wires to the display. The best way to solder such row of pins(sold in the same stores with the arduino).

Arduino soldering pins

Just in case, here's a photo of my LCD connections. I specifically, in details describe the first connection of the LCD display, since it is the most difficult, and most importantly do not stop on this first step. All other connections are made similarly, and will require less number wires.

Connecting an LCD display Connecting an LCD display

Click to zoom image...

Now to validate all wiring I propose upload this example. If everything is connected correctly, you will see House4u sol.proj text and brightness will be changed from zero to 100%

Run the Arduino IDE and you will see the blank window.This example must be completely copied into this window. After that click the upload button.

First program

Copy this sketch into an empty Arduino's window and click upload button:

// include the library code:
#include <LiquidCrystal.h>

// LCD bright pin
#define PWM_LED_PIN 3 
// LCD other pins
#define PIN_LCD_RS 39
#define PIN_LCD_EN 41
#define PIN_LCD_D4 43
#define PIN_LCD_D5 45
#define PIN_LCD_D6 47
#define PIN_LCD_D7 49
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd( PIN_LCD_RS, PIN_LCD_EN, PIN_LCD_D4, PIN_LCD_D5, PIN_LCD_D6, PIN_LCD_D7 );

void setup() {   
  lcd.begin(16, 2); //display size - 16x02
  lcd.print("House4u sol.proj");  
}

int i = 0;
void loop() 
{  
  lcd.setCursor(0, 1);  
  analogWrite( PWM_LED_PIN, i );
  lcd.print("Bright: ");  
  float Br = ( i / 255.0 ) * 100;
  lcd.print( Br, 0);
  lcd.print("%   ");
  
  i = (i + 15) % 256;
 
  delay( 1000 ); 
}

If you did everything right, then you should see this:

LCD Arduino result

UPDATE 05.04.2015:

If you are satisfied with the display - it is possible not to bother and just read down the page, in the view of acquaintance. If your image is not too good, then read carefully...

After a while it turned out that it is necessary to improve connection of the display! We have connected the third pin of display directly to GND, this means that the display will operate with maximum contrast! For some displays it's normal, and some show so sharp image that almost nothing can be seen. I connected first two displays with the highest contrast and everything was fine. But in the assembly of finished controllers under the order, it turned out that the new displays are not working well with such level of contrast.

In this regard, it was necessary to add a function of adjusting the contrast into the firmware. For this I used the 4th pin of Arduino. But if you directly connect the third contact of display with the 4th pin of arduino, and download a new sketch, you will see that the image flickers too much. To solve the problem, we need 1K resistor and a capacitor 100uF (100 microfarad). Improved connection looks like this:

Using PWM to control LCD contrast

What have we done? We have soldered capacitor 100uF 16V or 25V between the first and third pins of display . All the same, you (or someone) will solder the pins to the display, so you can solder and a capacitor. Take into account the polarity! Pin 1 of the display - it is GND of the capacitor, and the third contact of the display will be "+" And you must cut the wire that will go from the third contact of the display to the 4th pin of Arduino, and solder in a resistor 1K into it. After that we will be able to adjust the display contrast using our controller.

To verify the connection, run the following example:


// include the library code:
#include <LiquidCrystal.h>

// LCD bright
#define PWM_LED_PIN 3 
// LCD contrast
#define PWM_LED_CONTRAST 4 
// LCD other pins
#define PIN_LCD_RS 39
#define PIN_LCD_EN 41
#define PIN_LCD_D4 43
#define PIN_LCD_D5 45
#define PIN_LCD_D6 47
#define PIN_LCD_D7 49
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd( PIN_LCD_RS, PIN_LCD_EN, PIN_LCD_D4, PIN_LCD_D5, PIN_LCD_D6, PIN_LCD_D7 );

void setup() {   
  lcd.begin(16, 2); 
  lcd.print("House4u sol.proj"); 
  analogWrite( PWM_LED_PIN, 255 );  
}

int i = 0;
void loop() 
{  
  lcd.setCursor(0, 1); 
  analogWrite( PWM_LED_CONTRAST, i );
  lcd.print("Contrast: ");  
  float Br = ( i / 100.0 ) * 100;
  lcd.print( Br, 0);
  lcd.print("%   ");
  
  i = (i + 2) % 100;
 
  delay( 500 ); //delay 500 ms
}


<< BackNext >>


Share with friends:

Donate