'zero'에 해당되는 글 1건

  1. 2021.11.18 Raspberry Pi Pico & RP2040-Zero - 라즈베리 파이 피코
반응형

 

 

Raspberry Pi Pico를 사용해 보자.

 

Pico를 컴퓨터에 연결하면 기타 장치 - RP2 Boot로 인식된다.

 

파일 익스플로러에서도 확인 할 수 있다. (RPI-RP2)

만약 파일 익스플로러에 Pico가 표시되지 않는다면 BOOTSEL 버튼을 누른 상태에서 컴퓨터에 연결한다.

 

MicroPython을 설치하기 위해 아래 링크에 접속해 MicroPython UF2 파일을 다운로드한다.

Raspberry Pi Documentation

 

MicroPython is a full implementation of the Python 3 programming language that runs directly on embedded hardware like Raspberry Pi Pico. You get an interactive prompt (the REPL) to execute commands immediately via USB Serial, and a built-in filesystem. The Pico port of MicroPython includes modules for accessing low-level chip-specific hardware.

 

 

다운로드한 UF2 파일을 Pico(RPI-RP2)에 복사해 넣는다.

 

한 쪽 구석에 디바이스 설정 중이라는 메세지가 나타난다.

 

설정이 끝나면 기타 장치였던 Pico는 USB 직렬 장치(COMX)로 표시된다.

 

Thonny를 다운로드하고 설치한다.

Thonny

 

 

Thonny를 실행한다.

 

Run - Select interpreter...를 클릭한다.

 

MicroPython (Raspberry Pi Pico)와 USB 직렬 장치(COMX)를 선택한다.

 

간단한 소스를 입력하고 Run 버튼(F5)을 클릭한다.

 

 

소스를 어디에 저장할지 물어 보면 Raspberry Pi Pico를 선택한다.

 

적당한 이름을 지정한다.

Run 버튼을 클릭했으므로 소스가 저장되고 나면 바로 실행된다.

Pico에 달려있는 LED(GP25)가 1초 간격으로 깜빡인다.

 

LED(GP25)

 

Pico를 다시 연결하면 아무것도 실행되지 않는다. File - Open...을 클릭한다.

 

 

Raspberry Pi Pico를 선택한다.

 

Pico에 저장되어 있는 소스를 선택하고 실행한다.

 

WAVESHARE의 Pico-like MCU, RP2040-Zero도 같은 방식으로 동작한다.

RP2040-Zero는 Raspberry Pi Pico와 Pinout이 다르고 단색 LED가 아닌 WS2812 RGB LED(GP16)가 사용되었다.

단색 LED가 아니기 때문에 간단한 Blink.py 예제는 동작하지 않는다.

 

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import time
from machine import Pin
import rp2
 
max_lum =100
r=0
g=0
b=0
 
@rp2.asm_pio(sideset_init=rp2.PIO.OUT_LOW, out_shiftdir=rp2.PIO.SHIFT_LEFT, autopull=True, pull_thresh=24)
def ws2812():
    T1 = 2
    T2 = 5
    T3 = 3
    wrap_target()
    label("bitloop")
    out(x, 1)               .side(0)    [T3 - 1]
    jmp(not_x, "do_zero")   .side(1)    [T1 - 1]
    jmp("bitloop")          .side(1)    [T2 - 1]
    label("do_zero")
    nop()                   .side(0)    [T2 - 1]
    wrap()
 
 
# Create the StateMachine with the ws2812 program, outputting on Pin(4).
sm = rp2.StateMachine(0, ws2812, freq=8_000_000, sideset_base=Pin(16))
 
# Start the StateMachine, it will wait for data on its FIFO.
sm.active(1)
 
# Color change
while True:
    for i in range(0,max_lum):
        r=i
        b=max_lum-i
        rgb =(g<<24| (r<<16| (b<<8)
        sm.put(rgb)
        time.sleep_ms(10)
    time.sleep_ms(300)
    for i in range(0,max_lum):
        g=i
        r=max_lum-i
        rgb =(g<<24| (r<<16| (b<<8)
        sm.put(rgb)
        time.sleep_ms(10)
    time.sleep_ms(300)
    for i in range(0,max_lum):
        b=i
        g=max_lum-i
        rgb =(g<<24| (r<<16| (b<<8)
        sm.put(rgb)
        time.sleep_ms(10)
    time.sleep_ms(300)
 

 

조금 복잡한 WS2812 Test Code로 RGB값 변화를 확인할 수 있다.

 

반응형
Posted by J-sean
: