728x90
반응형

MicroPython base64 패키지 설치 후 

import base64 에서 'NoneType' object has no attribute 'func' 에러 발생

 

Traceback (most recent call last):
  File "<stdin>", line 7, in <module>
  File "/lib/base64.py", line 9, in <module>
  File "/lib/re.py", line 11, in <module>
AttributeError: 'NoneType' object has no attribute 'func'

 

/lib 폴더에 같이 설치된 re.py, ffilib.py 파일삭제 후 에러 해결

보이지는 않지만 microPython에 re.py, ffilib.py가 있어서 내장된 패키지 사용해야함

 

https://github.com/micropython/micropython-lib/issues/395

 

AttributeError: 'NoneType' object has no attribute 'func' · Issue #395 · micropython/micropython-lib

When I import multiprocessing, there is an error saying that: File "main.py", line 5, in File "multiprocessing.py", line 3, in File "select.py", line 14, in AttributeError: 'NoneType' object has no...

github.com

 

728x90
반응형

'Hardware > ESP32' 카테고리의 다른 글

LILYGO T5 - ESP32 MicroPython - REST API CALL  (1) 2023.10.10
LILYGO T5 - ESP32 MicroPython 설치  (0) 2023.10.10
LILYGO T5-4.7 Inch S3 E-Paper  (0) 2023.10.10
728x90
반응형

이전 포스팅에서 LILYGO T5 - ESP32 MicroPython을 설치 후 샘플을 구동해 보았다.

 

이제 MicroPython으로 REST API를 호출해보자

 

#테스트용 rest api 발급

https://api.openweathermap.org

 

Weather API - OpenWeatherMap

Please, sign up to use our fast and easy-to-work weather APIs. As a start to use OpenWeather products, we recommend our One Call API 3.0. For more functionality, please consider our products, which are included in professional collections.

openweathermap.org

 

#REST API 호출 코드

LILYGO MicroPytho에는 urequests라이브러리가 없으므로 설치

import network
import urequests

def connect_to_wifi(wlan, ssid, password):
    if not wlan.isconnected():
        print("Connecting to network...")
        wlan.connect(ssid, password)
        while not wlan.isconnected():
            pass

connect_to_wifi(wlan, "WIFI-SSID", "WIFI-PASS")

#urequests 라이브러리 패키지 설치
import upip
upip.install('urequests')

#REST API 호출 후 JSON 화면에 출력

import network
import urequests
import epd
from time import sleep

def connect_to_wifi(wlan, ssid, password):
    if not wlan.isconnected():
        print("Connecting to network...")
        wlan.connect(ssid, password)
        while not wlan.isconnected():
            pass

wlan = network.WLAN(network.STA_IF)
wlan.active(True)
connect_to_wifi(wlan, "WIFI-SSID", "WIFI-PASS")

response = urequests.get('https://api.openweathermap.org/data/2.5/weather?q=Minneapolis&units=imperial&appid=APP_ID')



print(response.text)
weather_data = response.json()

epd47 = epd.EPD47()

epd47.power(True)
epd47.clear()

epd47.text(response.text, 100, 100, font_size=9)

REST API로 Response JSON 결과 값이 화면에 출력이 되는것을 확인할 수 있다.

728x90
반응형

'Hardware > ESP32' 카테고리의 다른 글

MicroPython - 'NoneType' object has no attribute 'func'  (0) 2023.10.10
LILYGO T5 - ESP32 MicroPython 설치  (0) 2023.10.10
LILYGO T5-4.7 Inch S3 E-Paper  (0) 2023.10.10
728x90
반응형

ESP32칩은 아두이노 IDE를 사용해서 코딩하거나

MicroPython을 ESP에 설치 후 python언어로 코딩이 가능하다.

 

아두이노 IDE를 통해 샘플을 돌려보니 인코딩 후 소스 업로드도 느리고 내가 자중 사용하는

언어가 JAVA이다 보니 python으로 코딩해서 사용하는게 더쉬울것 같은 판단으로 

ESP32에 MicroPython을 설치 해보기로 했다.

 

# LilyGo MicroPython 공식이미지

https://github.com/Xinyuan-LilyGO/lilygo-micropython

 

GitHub - Xinyuan-LilyGO/lilygo-micropython: Micropython for LILYGO boards

Micropython for LILYGO boards. Contribute to Xinyuan-LilyGO/lilygo-micropython development by creating an account on GitHub.

github.com

내가 가지고 있는 제품의 이미지는 T5-4.7 Plus

해당 설치 설명은 리눅스 기준으로 되어있다.

그래서 나는 윈도우 Ubuntu (WSL2)에서 해당 MicroPython파일을 컴파일 후 윈도우에서 설치할 것이다.

 

#Ubuntu 업데이트 및 업그레이드

sudo apt-get update
sudo apt-get upgrade -y

 

#기트허브에 나와있는 필요 패키지 설치

sudo apt-get install git make python3 python3-pip cmake quilt

#기트허브 소스 clone

git clone https://github.com/Xinyuan-LilyGO/lilygo-micropython.git

#T5-4.7 Plus - LilyGo MicroPython

$ cd lilygo-micropython
$ cp config_T5-4.7-Plus config
$ make

컴파일이 모두 끝나면 설치 명령어가 마지막에 나온다. 해당 설치 명령어는 실제 리눅스 USB에 물려서 사용해야하므로

윈도우에 컴파일된 파일을 복사 후 설치 해보겠다.

애래는 마지막에 나오는 설치 명령어이다.

Project build complete. To flash, run this command:
/home/ksm/.espressif/python_env/idf4.4_py3.10_env/bin/python ../../../esp-idf/components/esptool_py/esptool/esptool.py -p (PORT) -b 460800 --before default_reset --after hard_reset --chip esp32  write_flas>
or run 'idf.py -p (PORT) flash'

 

#만들어진 이미지 윈도우로 복사

현재 윈도우에 가상 Ubuntu라서 해당 컴파일된 이미지를 윈도우로 복사한뒤에 윈도우에서 ESP32에 LilyGo MicroPython이미지를 설치할 예정이다.

cp -rf lilygo-micropython /mnt/c/temp

/mnt/c => 윈도우 C:\ 경로이다.

#윈도우에 Python 설치 

https://www.python.org/downloads/

 

Download Python

The official home of the Python Programming Language

www.python.org

설치시에 Add Python 3.8to PATH를 체크해주자 (이미 설치해서 스샷은 없습니다.)

 

#윈도우에 esptool 설치

pip install esptool

#esptool을 사용해서 ESP32에 LilyGo MicroPython 설치

C:\temp>esptool -p COM11 -b 460800 --before default_reset --after no_reset --chip esp32s3 write_flash --flash_mode dio --flash_size detect --flash_freq 80m 0x0 build-LILYGO_T5-4.7-PLUS/bootloader/bootloader.bin 0x8000 build-LILYGO_T5-4.7-PLUS/partition_table/partition-table.bin 0x10000 build-LILYGO_T5-4.7-PLUS/micropython.bin
esptool.py v4.6.2
Serial port COM11
Connecting...
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 34:85:18:97:1c:0c
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Auto-detected Flash size: 16MB
Flash will be erased from 0x00000000 to 0x00004fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x00010000 to 0x0017cfff...
Compressed 18784 bytes to 12004...
Wrote 18784 bytes (12004 compressed) at 0x00000000 in 0.2 seconds (effective 761.3 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 117...
Wrote 3072 bytes (117 compressed) at 0x00008000 in 0.0 seconds (effective 888.1 kbit/s)...
Hash of data verified.
Compressed 1493136 bytes to 1026918...
Wrote 1493136 bytes (1026918 compressed) at 0x00010000 in 9.8 seconds (effective 1215.2 kbit/s)...
Hash of data verified.
Leaving...
Staying in bootloader.

COM11은 장치관리자에서 확인가능하다.

 

#Thonny 툴설치

해당툴은 GUI기반으로 ESP32에 Python을 코딩할 수 있게 제공된다.

https://thonny.org/blog/2018/06/05/thonny_and_micropython.html

 

Thonny blog: Thonny and MicroPython

Thonny, Python IDE for beginners

thonny.org

#Thonny ESP32 연결

도구 > 옵션

인터프리터 > MicroPython (ESP32) / Espressif CDC Device @ CO12

보기 > 파일

연결된 화면 MicroPython 장치가 ESP32에 들어있는 파일이다.

처음에는 비어있는데 나는 테스트 한다고 여러게를 넣은 상태입니다.

 

#데모테스트

from epd import EPD47

e = EPD47()
e.power(True)
e.clear()
e.text("hello world", 100, 100, font_size=9)
e.text("hello world", 100, 120, font_size=12)
e.text("hello world", 100, 150, font_size=18)
e.text("hello world", 100, 190, font_size=24)
e.text("hello world", 100, 210, font_size=25)
e.text("hello world", 100, 250, font_size=24)
e.text("hello world", 100, 290, font_size=24)
e.text("hello world", 100, 330, font_size=24)
e.text("hello world", 100, 370, font_size=24)
e.text("hello world", 100, 410, font_size=24)

del e

작성 후 저장

MicroPython 장치 선택

#현재 스크립트 실행(F5)

출력이되는것을 확인할 수 있다.

 

#이미지 출력 샘플

from epd import EPD47
from random import randint
from time import sleep

e = EPD47()

e.power(True)
e.clear()

#x = randint(0, 960-200)
x = randint(0, 0)
y = randint(0, 0)
e.jpeg("/test2.jpg", x, y)
sleep(1)
#e.jpeg("/cat.jpg", 0, 0)
#sleep(1)a

이미지 파일을 MicroPython 루트(/)에 넣고 하면 출력이 가능하다.

 

# LilyGo T5 MicroPython bin 파일 첨부

LILYGO_T5-4.7-PLUS_bin.zip
0.99MB

728x90
반응형
728x90
반응형

ESP32라는 마이크로컨트롤러제품을 알아보는 중 아래 제품이 디스플레이도 있고 테스트 해보기 좋을것 같아서 

구매해보았다.

 

기본적으로 ESP32는 WIFI이 및 블루투스가 하나의 칩에 포함되어 있다.

 

https://www.lilygo.cc/products/t5-4-7-inch-e-paper-v2-3?_pos=3&_sid=8600f481c&_ss=r 

 

T5 4.7 Inch E-paper V2.3

LILYGO® T5 4.7 Inch E-paper V2.3 ESP32-S3 Development Driver Board Display Module Support TF Arduino Compatible Raspberry Pi Due to the problem of the characteristics of the ink screen, it cannot be partially refreshed for a long time, otherwise, it will

www.lilygo.cc

 

Specifications

MCU ESP32-S3-WROOM-1-N16R8
Wireless Connectivity Wi-fi Bluetooth V5.0
Programming Environment Arduino-ide VS Code
Onboard Functions  
Flash 16MB
PSRAM 8MB
Support PCF8563 RTC Battery capacity detection
 4 . 7-inch Ultra-low Power E-paper
Driver IC  EDO47TC1
Size 4.7 inch
Gray levels 16
Resolution 540 x 960 pixels
Ultra Wide viewing angle low power consumption

 

디스플레이, 블루투스, WIFI가 포함되어있는 칩이여서 나의 장난감을 만들기에는 스펙이 충분해 보인다.

다음편에서는 디스플레이에 화면을 띄우기위한 여정을 기록할 예정이다.

728x90
반응형

+ Recent posts