'2020/03/12'에 해당되는 글 1건

  1. 2020.03.12 rpi clcd / wiringpi deprecated
embeded/raspberry pi2020. 3. 12. 17:51

헐.. wiringpi 프로젝트 종료? 아무튼 그럼 이걸 쓰면 안되려나..?

일단은 소스를 찾아야 하니 mirror 된 git을 발견 해당 저장소의 소스를 사용하고 복사해서 수정한다.

$ git clone https://github.com/WiringPi/WiringPi.git

$ cd WiringPi/example

$ cp lcd.c lcd2.c

$ vi lcd2.c

$ gcc lcd2.c -o lcd2 -lwiringPi -lwiringPiDev

[링크 : http://wiringpi.com/wiringpi-deprecated/]

  [링크 : https://github.com/WiringPi/WiringPi]

 

별로 도움이 안될 배선 사진. jpg

 

넣을 위치가 마땅찮아 대충 끼워넣는 동영상.avi

 

링크 블로그의 내용 그대로 사용한다.

LCD  1번핀(VSS) --- RPI3  6번핀(ground), 가변저항의 왼쪽 다리

LCD  2번핀(VDD) --- RPI3  2번핀(+5V), 가변저항의 오른쪽 다리

LCD  3번핀(VE, VO) --- 가변저항의 가운데 다리

LCD  4번핀(RS) --- RPI3 26번핀(GPIO 7)

LCD  5번핀(RW) --- RPI3 14번핀(ground)

LCD  6번핀(EN,E) --- RPI3 24번핀(GPIO 8)

 

LCD 11번핀(D4) --- RPI3 11번핀(GPIO 17)

LCD 12번핀(D5) --- RPI3 12번핀(GPIO 18)

LCD 13번핀(D6) --- RPI3 13번핀(GPIO 27)

LCD 14번핀(D7) --- RPI3 15번핀(GPIO 22)

LCD 15번핀(LED+) --- RPI3   4번핀(+5V)

LCD 16번핀(LED-)  --- RPI3 34번핀(ground)


약간(!) 수정한 소스는 아래와 같다.

크게 바뀌는 건 별로 없고, 배선상의 문제로 아래의 코드로 4,5,6,7 에서 0,1,2,3 으로 변경해야 한다.

  if (bits == 4)
    lcdHandle = lcdInit (rows, cols, 4, 11,10, 0,1,2,3,0,0,0,0) ;
//  lcdHandle = lcdInit (rows, cols, 4, 11,10, 4,5,6,7,0,0,0,0) ;

 

전체 소소는 아래와 같다.

$ cat lcd2.c
/*
 * lcd.c:
 *      Text-based LCD driver.
 *      This is designed to drive the parallel interface LCD drivers
 *      based in the Hitachi HD44780U controller and compatables.
 *
 *      This test program assumes the following:
 *
 *      8-bit displays:
 *              GPIO 0-7 is connected to display data pins 0-7.
 *              GPIO 11 is the RS pin.
 *              GPIO 10 is the Strobe/E pin.
 *
 *      For 4-bit interface:
 *              GPIO 4-7 is connected to display data pins 4-7.
 *              GPIO 11 is the RS pin.
 *              GPIO 10 is the Strobe/E pin.
 *
 * Copyright (c) 2012-2013 Gordon Henderson.
 ***********************************************************************
 * This file is part of wiringPi:
 *      https://projects.drogon.net/raspberry-pi/wiringpi/
 *
 *    wiringPi is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU Lesser General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    wiringPi is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public License
 *    along with wiringPi.  If not, see <http://www.gnu.org/licenses/>.
 ***********************************************************************
 */

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

#include <unistd.h>
#include <string.h>
#include <time.h>

#include <wiringPi.h>
#include <lcd.h>

#ifndef TRUE
#  define       TRUE    (1==1)
#  define       FALSE   (1==2)
#endif

static unsigned char newChar [8] =
{
  0b11111,
  0b10001,
  0b10001,
  0b10101,
  0b11111,
  0b10001,
  0b10001,
  0b11111,
} ;


// Global lcd handle:

static int lcdHandle ;

/*
 * usage:
 *********************************************************************************
 */

int usage (const char *progName)
{
  fprintf (stderr, "Usage: %s bits cols rows\n", progName) ;
  return EXIT_FAILURE ;
}


/*
 * scrollMessage:
 *********************************************************************************
 */

static const char *message =
  "                    "
  "Wiring Pi by Gordon Henderson. HTTP://WIRINGPI.COM/"
  "                    " ;

void scrollMessage (int line, int width)
{
  char buf [32] ;
  static int position = 0 ;
  static int timer = 0 ;

  if (millis () < timer)
    return ;

  timer = millis () + 200 ;

  strncpy (buf, &message [position], width) ;
  buf [width] = 0 ;
  lcdPosition (lcdHandle, 0, line) ;
  lcdPuts     (lcdHandle, buf) ;

  if (++position == (strlen (message) - width))
    position = 0 ;
}


/*
 * pingPong:
 *      Bounce a character - only on 4-line displays
 *********************************************************************************
 */

static void pingPong (int lcd, int cols)
{
  static int position = 0 ;
  static int dir      = 0 ;

  if (dir == 0)         // Setup
  {
    dir = 1 ;
    lcdPosition (lcdHandle, 0, 3) ;
    lcdPutchar  (lcdHandle, '*') ;
    return ;
  }

  lcdPosition (lcdHandle, position, 3) ;
  lcdPutchar (lcdHandle, ' ') ;
  position += dir ;

  if (position == cols)
  {
    dir = -1 ;
    --position ;
  }

  if (position < 0)
  {
    dir = 1 ;
    ++position ;
  }

  lcdPosition (lcdHandle, position, 3) ;
  lcdPutchar  (lcdHandle, '#') ;
}


/*
 * waitForEnter:
 *********************************************************************************
 */

static void waitForEnter (void)
{
  printf ("Press ENTER to continue: ") ;
  (void)fgetc (stdin) ;
}


/*
 * The works
 *********************************************************************************
 */

int main (int argc, char *argv[])
{
  int i ;
  int lcd ;
  int bits, rows, cols ;

  struct tm *t ;
  time_t tim ;

  char buf [32] ;

  if (argc != 4)
    return usage (argv [0]) ;

  printf ("Raspberry Pi LCD test\n") ;
  printf ("=====================\n") ;

  bits = atoi (argv [1]) ;
  cols = atoi (argv [2]) ;
  rows = atoi (argv [3]) ;

  if (!((rows == 1) || (rows == 2) || (rows == 4)))
  {
    fprintf (stderr, "%s: rows must be 1, 2 or 4\n", argv [0]) ;
    return EXIT_FAILURE ;
  }

  if (!((cols == 16) || (cols == 20)))
  {
    fprintf (stderr, "%s: cols must be 16 or 20\n", argv [0]) ;
    return EXIT_FAILURE ;
  }

  wiringPiSetup () ;

  if (bits == 4)
    lcdHandle = lcdInit (rows, cols, 4, 11,10, 0,1,2,3,0,0,0,0) ;
//  lcdHandle = lcdInit (rows, cols, 4, 11,10, 4,5,6,7,0,0,0,0) ;
  else
    lcdHandle = lcdInit (rows, cols, 8, 11,10, 0,1,2,3,4,5,6,7) ;

  if (lcdHandle < 0)
  {
    fprintf (stderr, "%s: lcdInit failed\n", argv [0]) ;
    return -1 ;
  }

  lcdPosition (lcdHandle, 0, 0) ; lcdPuts (lcdHandle, "Gordon Henderson") ;
  lcdPosition (lcdHandle, 0, 1) ; lcdPuts (lcdHandle, "  wiringpi.com  ") ;

  waitForEnter () ;

  if (rows > 1)
  {
    lcdPosition (lcdHandle, 0, 1) ; lcdPuts (lcdHandle, "  wiringpi.com  ") ;

    if (rows == 4)
    {
      lcdPosition (lcdHandle, 0, 2) ;
      for (i = 0 ; i < ((cols - 1) / 2) ; ++i)
        lcdPuts (lcdHandle, "=-") ;
      lcdPuts (lcdHandle, "=3") ;

      lcdPosition (lcdHandle, 0, 3) ;
      for (i = 0 ; i < ((cols - 1) / 2) ; ++i)
        lcdPuts (lcdHandle, "-=") ;
      lcdPuts (lcdHandle, "-4") ;
    }
  }

  waitForEnter () ;

  lcdCharDef  (lcdHandle, 2, newChar) ;

  lcdClear    (lcdHandle) ;
  lcdPosition (lcdHandle, 0, 0) ;
  lcdPuts     (lcdHandle, "User Char: ") ;
  lcdPutchar  (lcdHandle, 2) ;

  lcdCursor      (lcdHandle, TRUE) ;
  lcdCursorBlink (lcdHandle, TRUE) ;

  waitForEnter () ;

  lcdCursor      (lcdHandle, FALSE) ;
  lcdCursorBlink (lcdHandle, FALSE) ;
  lcdClear       (lcdHandle) ;

  for (;;)
  {
    scrollMessage (0, cols) ;

    if (rows == 1)
      continue ;

    tim = time (NULL) ;
    t = localtime (&tim) ;

    sprintf (buf, "%02d:%02d:%02d", t->tm_hour, t->tm_min, t->tm_sec) ;

    lcdPosition (lcdHandle, (cols - 8) / 2, 1) ;
    lcdPuts     (lcdHandle, buf) ;

    if (rows == 2)
      continue ;

    sprintf (buf, "%02d/%02d/%04d", t->tm_mday, t->tm_mon + 1, t->tm_year+1900) ;

    lcdPosition (lcdHandle, (cols - 10) / 2, 2) ;
    lcdPuts     (lcdHandle, buf) ;

    pingPong (lcd, cols) ;
  }

  return 0 ;
}

[링크 : https://webnautes.tistory.com/1111]

'embeded > raspberry pi' 카테고리의 다른 글

라즈베리 파이 카메라 케이블이 이상해  (0) 2020.03.15
라즈베리 프로젝트?  (0) 2020.03.14
미세먼지(웹 크롤링) 표시용 장치  (0) 2020.03.11
라즈베리 node.js gpio  (0) 2020.03.10
라즈베리 python gpio  (0) 2020.03.10
Posted by 구차니