728x90

 

 

 

그림1. LCD 1602(16X2) 4(I2C제어) 디스플레이 모듈

 

 

 

  LCD 1602(16x2) 4(I2C제어) 디스플레이 모듈

 

LCD 가장보편적이고초보자, 입문자분들이쉽게활용할있는모델인LCD 1602 입니다. 또한 16핀의제어핀을LCD뒤에부착된I2C변환모듈을통해 4개의핀으로제어가가능하도록쉽게만들어진모델입니다.

 

 

 

그림2. LCD 1602(16X2) 4(I2C제어) 디스플레이 모듈 핀맵

 

 

 

 

 

LCD 1602(16x2) 4(I2C)제어 레이 모듈 보러가기(클릭)

 

 

 

 

 

1. LCD 1602(16x2) 4(I2C)제어 디스플레이 모듈  

 

쉽게사용할있는 4모델로I2C통신을통해제어되는 LCD 디스플레이모듈입니다. 해상도는16x2 케릭터(Character Type)입니다.

 

디스플레이 타입(Display Type)

LCD(Liquid Crystal Display)

동작 전압(Operating Volate)

5V

해상도(Resolution)

16x2

I2C 주소

0x3F or 0x27

통신 인터페이스

I2C 통신 지원

백라이트

파란색(Blue)

색상

흰색(White)

소비전력

0.4W

무게(Weight)

3.2g

크기(Size)

82 x 35 x 18mm

 

 

 

2. 라이브러리 다운로드  설치하기  

 

LCD_I2C사용하기위해서는라이브러리를다운받아야합니다. 다운경로는아래와같습니다.

 

 

 

LCD I2C 라이브러리 다운받기(클릭)

 

 

 

 

 

 

다운받은 ZIP파일안에들어있는폴더를컴퓨터의아두이노 IDE 설치경로로들어가아래그림과같이라이브러리폴더아래에복사해넣어줍니다. 아두이노 IDE껐다실행하면자동으로아래경로의라이브러리가포함되어실행됩니다.

 

 

 

 

 

 

 주의사항

  - 라이브러리 추가시 경로설정을 정확하게 해야합니다.

    아래 그림과 같이 ' C:\Program Files (x86)\Arduino\libraries\LiquidCrystal_I2C-master ' 경로 안에

    example 폴더와 헤더파일을 포함한 파일들이 들어있어야 합니다.

    (경로설정을 잘못하면 아두이노 IDE에서 컴파일 오류가 발생할 수 있습니다.)

 

 

 

 

 

 

 

3. 회로도 구성  

 

아두이노우노와I2C 통신을구성해봅시다. 회로도는아래와같이연결해줍니다.

 

5V – VCC

GND – GND

A4 – SDA

A5 - SCL

 

 

 

 

4. 예제 따라하기1 – Hellow world  

 

 이제디스플레이해봅시다!!

 

 

예제소스는다음과같습니다.

 

#include <Wire.h>                        // i2C 통신을 위한 라이브러리

#include <LiquidCrystal_I2C.h>        // LCD 1602 I2C 라이브러리

LiquidCrystal_I2C lcd(0x3F,16,2);     // 접근주소: 0x3F or 0x27

void setup()

{

  lcd.init();                      // LCD 초기화

  // Print a message to the LCD.

  lcd.backlight();                // 백라이트 켜기

  lcd.setCursor(0,0);             // 1번째, 1라인

  lcd.print("Hello, world!");

  lcd.setCursor(0,1);             // 1번째, 2라인

  lcd.print("Enjoy - Eduino");

}

void loop()

{

}

 

실제동작모습은다음과같습니다.

 

 

 

그림3. LCD 1602 4핀제어 디스플레이 모듈 실행 예제1. Hellow world

'홍익인간 프로젝트 > Arduino C' 카테고리의 다른 글

u8g2setupcpp  (0) 2020.12.25
PCF8574 I2C 확장보드로 CLCD, Text(텍스트) LCD 구동 (아두이노)  (0) 2020.12.25
Software Serial Example  (0) 2020.12.16
Arduino Uno TM1637 Display  (0) 2020.12.16
Arduino Basic  (0) 2020.12.12
728x90

Arduino boards have built in support for serial communication on pins 0 and 1, but what if you need more serial ports? The SoftwareSerial Library has been developed to allow serial communication to take place on the other digital pins of your boards, using software to replicate the functionality of the hardwired RX and TX lines. This can be extremely helpful when the need arises to communicate with two serial enabled devices, or to talk with just one device while leaving the main serial port open for debugging purpose.

In the example below, digital pins 10 and 11 on your Arduino boards are used as virtual RX and TX serial lines. The virtual RX pin is set up to listen for anything coming in on via the main serial line, and to then echo that data out the virtual TX line. Conversely, anything received on the virtual RX is sent out over the hardware TX.

Hardware Required

  • Arduino Board

Circuit

There is no circuit for this example. Make sure that your Arduino board is attached to your computer via USB to enable serial communication through the serial monitor window of the Arduino Software (IDE).

 

Schematics

image developed using Fritzing. For more circuit examples, see the Fritzing project page

Code

/*
  Software serial multple serial test

 Receives from the hardware serial, sends to software serial.
 Receives from software serial, sends to hardware serial.

 The circuit:
 * RX is digital pin 2 (connect to TX of other device)
 * TX is digital pin 3 (connect to RX of other device)

 Note:
 Not all pins on the Mega and Mega 2560 support change interrupts,
 so only the following can be used for RX:
 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69

 Not all pins on the Leonardo support change interrupts,
 so only the following can be used for RX:
 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).

 created back in the mists of time
 modified 25 May 2012
 by Tom Igoe
 based on Mikal Hart's example

 This example code is in the public domain.

 */
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Native USB only
  }


  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(38400);
  mySerial.println("Hello, world?");
}

void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}

www.arduino.cc/en/Tutorial/LibraryExamples/SoftwareSerialExample

728x90

rasino.tistory.com/203

728x90

In this blog post, we will see the C program to convert Hexadecimal to Decimal. In the interview, people ask the below questions,

 

  • How will you convert hexadecimal to decimal value?
  • Write a C program to convert hexadecimal number system value to decimal number system?
  • Implement logic to convert a hexadecimal number to a decimal number system?
  • Get a hexadecimal number from the user and convert it to its decimal equivalent?

Examples:

Input : 67

Output : 103

 

Input : 512

Output : 1298

 

Input: 123

Output: 291

 

We need to know the decimal and hexadecimal numbers before writing the C program to convert hexadecimal to the decimal.

The hexadecimal number system is a base 16 number system. The hexadecimal number is represented by 16 values i.e 0 1 2 3 4 5 6 7 8 9 A B C D E F.

The decimal number system is a base 10 number system. It uses 10 symbols to represent all numbers i.e. 0123456789

 

Logic to convert Hexadecimal to Decimal System:

We know that in hexadecimal number uses 16 symbols {0, 1, 2, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F} to represent all numbers. Here, (A, B, C, D, E, F) represents (10, 11, 12, 13, 14, 15).

We need to run a loop from 0 to  (buffer_length -1). The buffer_length  is the length of the buffer which contains entered hexadecimal number.

To convert hex to decimal, we need to extract the digits of a given hexadecimal number from the buffer. At the time of extracting digits from the hexadecimal number, multiply the digit with the proper base (Power of 16) and add it to the variable “decimal”.

 

After ending the iteration, the variable “decimal” will store the resultant decimal number.

For Example:
If the hexadecimal number is 1A.
decimal = 1*(16^1) + 10*(16^0) = 26

Below diagram explains how to convert hexadecimal number ( 1AB ) to equivalent decimal value:

 

C Program to convert hexadecimal to decimal number system:

 

 

 

#include <stdio.h>
#include <math.h>
#include <string.h>
#define ARRAY_SIZE  20
int main()
{
    char hex[ARRAY_SIZE];
    long long decimal = 0, base = 1;
    int i = 0, value, length;
    /* Get hexadecimal value from user */
    printf("Enter hexadecimal number: ");
    fflush(stdin);
    fgets(hex,ARRAY_SIZE,stdin);
    length = strlen(hex);
    for(i = length--; i >= 0; i--)
    {
        if(hex[i] >= '0' && hex[i] <= '9')
        {
            decimal += (hex[i] - 48) * base;
            base *= 16;
        }
        else if(hex[i] >= 'A' && hex[i] <= 'F')
        {
            decimal += (hex[i] - 55) * base;
            base *= 16;
        }
        else if(hex[i] >= 'a' && hex[i] <= 'f')
        {
            decimal += (hex[i] - 87) * base;
            base *= 16;
        }
    }
    printf("\nHexadecimal number = %s", hex);
    printf("Decimal number = %lld\n", decimal);
    return 0;
}

 

 

 

Enter hexadecimal number: 1A
Hexadecimal number = 1A
Decimal number = 26

+ Recent posts