티스토리 뷰
<LCD 패널에 NAVER 책 API에서 받아온 책 정보를 출력하고 싶다.>
라즈베리파이 1602 I2C 캐릭터 LCD 사용 (Python, 파이썬)
라즈베리파이3 B+아두이노 I2C 1602 LCD 모듈 \[SZH-EK101]브레드보드, 케이블VSCode로 했음.python3 설치I2C Enable 설정3 Interface Options > P5 I2C > Enable 할거냐고 물어보면 YES!smbus 설치i2c
velog.io
위 사이트에서 기본 과정을 모두 동일하게 수행한다.
1. 회로연결
2. 연결 확인
> lsmod | grep i2c
> i2cdetect -y 1
3. 라이브러리 설치
> git clone https://github.com/the-raspberry-pi-guy/lcd.git
> cd lcd
> sudo sh install.sh
설치 완료.
4. 데모실행
python3 demo_lcd.py
(***환경 변수 설정 -> 나는 이게 잘 안 되서 시간이 많이 걸렸다..)
<<BOOK Project : 해야할 것, 한 것>>
1. OpenCV (바코드 인식 -> csv 파일에 isbn 값 저장)
2. Naver Book API (저장된 isbn값 전송하여 책 정보 받아옴)
3. LCD 패널에 책 제목 가격 출력 ****
>>>이전 게시글 참고 : https://ing-min.tistory.com/58
라즈베리파이_네이버 책 검색 api
>>참고 사이트 https://shiinachianti.tistory.com/7 Python :: 네이버 Book API로 책 데이터 가져오기 Edit Python :: 네이버 Book API로 책 데이터 가져오기 프로젝트 파우스트를 만들면서 네이버 북 API를 사용..
ing-min.tistory.com
> csv 파일에서 isbn 값을 받아와 naver api를 통해 책 제목과 가격을 받아오고 이를 LCD 패널에 출력해보자
#barcode_scanner_video.py
import csv
import drivers
# import I2C_LCD_driver
from time import sleep
#naver api
CLIENT_ID = '네이버api아이디'
CLIENT_SECRET = '네이버api비밀번호'
#LCD display
display = drivers.Lcd()
# display = I2C_LCD_driver.lcd()
#request
def search_book(query):
from urllib.request import Request, urlopen
from urllib.parse import urlencode, quote
import json
# request = Request('https://openapi.naver.com/v1/search/book?query='+quote(query))
#isbn
request = Request('https://openapi.naver.com/v1/search/book_adv?d_isbn='+quote(query))
request.add_header('X-Naver-Client-Id', CLIENT_ID)
request.add_header('X-Naver-Client-Secret', CLIENT_SECRET)
response = urlopen(request).read().decode('utf-8')
search_result = json.loads(response)
return search_result
if __name__ == "__main__":
#csv first line only
f = open('barcodes.csv', 'r', encoding='utf-8')
rdr = csv.reader(f)
for line in rdr:
#search
print(line[1])
books = search_book(line[1])['items']
#erro
if(books == None):
print("fail")
exit()
#print
for book in books:
print("title: " + book['title'])
print("price: "+book["price"]+"won")
try:
while True:
# Remember that your sentences can only be 16 characters long!
print("Writing to display")
display.lcd_display_string(book['title'], 1) # Write line of text to first line of display
display.lcd_display_string(book["price"]+"won", 2) # Write line of text to second line of display
sleep(6) # Give time for the message to be read
display.lcd_clear() # Clear the display of any data
sleep(2) # Give time for the message to be read
except KeyboardInterrupt:
# If there is a KeyboardInterrupt (when you press ctrl+c), exit the program and cleanup
print("Cleaning up!")
display.lcd_clear()
f.close()
당연히 한 번에 안 된다..
오류 1
ModuleNotFoundError: No module named 'drivers'
>> 분명히 설치하라는 데로 했는데.. 환경변수 부분을 설정을 제대로 안 해줘서 그런 듯!
https://stackoverflow.com/questions/41695104/importerror-no-module-named-driver-in-pyttsx
:: 하지만 환경변수 설정하는 법 잘 몰라서
git으로 받은 경로로 들어가서 /home/lcd 폴더의 drivers 폴더 자체를 실행파일 경로에 붙여 넣었더니 잘된다.
오류 2
OSError: [Errno 121] Remote I/O error
이거는 LCD를 인식 못해서 그렇다
연결 잘해주면 끝
https://github.com/adafruit/Adafruit_CircuitPython_VEML6075/issues/4
오류3
ModuleNotFoundError: No module named 'smbus’
>>>>smbus2로 바꿔주면 된다. 파이선 3.6에서 smbus 안 된다..
$ pip3 --version
Python 3.6.5 //내 파이선 버전을 확인한다.
//smbus2설치
$ sudo pip3 install smbus2
$ sudo apt-get install python3-smbus2
// 코드수정(smbus를 smbus2로 바꿔준다.)
import smbus2 as smbus
오류3
ModuleNotFoundError: No module named 'RPi’
>> 이미 'RPI' 설치되어있는데 이런 문제가 생긴다면 업그레이드 하면 해결된다..
sudo pip3 install --upgrade RPi.GPIO
[ 다음 문제 ]
문제 ..... 한글 출력이 안 된다!!!!!!!(다른 사람이 한글로 출력한 게 있지만.. 보기에 좋지 않다)
https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=junwha0511&logNo=221529144374
아두이노 16x2 LCD 한글 출력 라이브러리 1편-사용법
안녕하세요! 아두이노 16x2 LCD에서 한글 출력하기 1편입니다. 16x2 LCD 한글 출력 라이브러리는 제...
blog.naver.com
-> LCD 특성상 영어만 출력되므로 NAVER papago를 활용해 번역해주자.
#LCD_naver_papago.py
import csv
import drivers
# import I2C_LCD_driver
from time import sleep
import os
import sys
import urllib.request
import json
#naver api
CLIENT_ID = 'WEEJIGpgCSrz628DTDdw'
CLIENT_SECRET = '89KHsk1_Uy'
#LCD display
display = drivers.Lcd()
# display = I2C_LCD_driver.lcd()
#request
def search_book(query):
from urllib.request import Request, urlopen
from urllib.parse import urlencode, quote
import json
# request = Request('https://openapi.naver.com/v1/search/book?query='+quote(query))
#isbn
request = Request('https://openapi.naver.com/v1/search/book_adv?d_isbn='+quote(query))
request.add_header('X-Naver-Client-Id', CLIENT_ID)
request.add_header('X-Naver-Client-Secret', CLIENT_SECRET)
response = urlopen(request).read().decode('utf-8')
search_result = json.loads(response)
return search_result
def papago(book):
client_id = "aUnwPIcv7XXaJ2FiPZqp" # 개발자센터에서 발급받은 Client ID 값
client_secret = "fTz8WOpetl" # 개발자센터에서 발급받은 Client Secret 값
encText = urllib.parse.quote(book)
data = "source=ko&target=en&text=" + encText
url = "https://openapi.naver.com/v1/papago/n2mt"
request1 = urllib.request.Request(url)
request1.add_header("X-Naver-Client-Id",client_id)
request1.add_header("X-Naver-Client-Secret",client_secret)
response1 = urllib.request.urlopen(request1, data=data.encode("utf-8"))
rescode = response1.getcode()
if(rescode==200):
response_body = response1.read()
#json 형 변환
res = json.loads(response_body.decode('utf-8'))
print(res['message']['result']['translatedText'])
return res['message']['result']['translatedText']
else:
print("Error Code:" + rescode)
if __name__ == "__main__":
#csv first line only
f = open('barcodes.csv', 'r', encoding='utf-8')
rdr = csv.reader(f)
for line in rdr:
#search
print(line[1])
books = search_book(line[1])['items']
#erro
if(books == None):
print("fail")
exit()
#print
for book in books:
print("title: " + book['title'])
print("price: "+book["price"]+"won")
title = book['title']
price = book["price"]+"won"
papares= papago(title)
try:
while True:
# Remember that your sentences can only be 16 characters long!
print("Writing to display")
display.lcd_display_string(papares, 1) # Write line of text to first line of display
display.lcd_display_string(book["price"]+"won", 2) # Write line of text to second line of display
sleep(6) # Give time for the message to be read
display.lcd_clear() # Clear the display of any data
sleep(2) # Give time for the message to be read
except KeyboardInterrupt:
# If there is a KeyboardInterrupt (when you press ctrl+c), exit the program and cleanup
print("Cleaning up!")
display.lcd_clear()
f.close()
[완료]
하지만 ... 또 문제는 제목이 너무 길어서 너무 짧은 시간만에 제목이 지나가버린다 ... .. 언제 끝나지
https://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/
How to Setup an I2C LCD on the Raspberry Pi
How to use I2C to connect an LCD to the Raspberry Pi. Learn how to scroll, position, and clear text, print the date, time, IP address, and sensor data.
www.circuitbasics.com
이거는 다른 git lcd 사용..
https://m.blog.naver.com/elepartsblog/221583231746
라즈베리파이에서 파이썬으로 1602 I2C 캐릭터 LCD 사용하기
이번 포스팅에서는 라즈베리파이에서 1602 IIC LCD를 이용해 문자를 출력해 보는 동작을 하도록 하겠...
blog.naver.com
'Iot > 라즈베리파이' 카테고리의 다른 글
라즈베리파이_비콘연결 (0) | 2022.03.28 |
---|---|
라즈베리파이_[Oled 디스플레이 0.96 SSD1306] 연결하기 (0) | 2022.03.21 |
라즈베리파이_네이버 책 검색 api (0) | 2022.03.10 |
라즈베리파이_ 실시간 바코드 인식 pyzbar + playsound (0) | 2022.03.10 |
라즈베리파이_OpenCV_QR 바코드 인식 (0) | 2022.03.08 |
- Total
- Today
- Yesterday
- docker
- Unity
- Python
- three.js
- emotive eeg
- sequelize
- unity 360
- VR
- oculuspro
- MQTT
- imgtoimg
- Java
- CNC
- motor controll
- Midjourney
- ardity
- Express
- TouchDesigner
- AI
- RNN
- node.js
- opencv
- DeepLeaning
- Arduino
- 유니티플러그인
- 유니티
- 후디니
- 라즈베리파이
- colab
- houdini
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |