File tree Expand file tree Collapse file tree 5 files changed +102
-0
lines changed
Expand file tree Collapse file tree 5 files changed +102
-0
lines changed Original file line number Diff line number Diff line change 1+ <h1 align =" center " > Develop with Pico Ctrl using MicroPython</h1 >
2+ <p align =" center " >
3+ <img width =" 500 " alt =" Cover " src =" ./cover.png " >
4+ </p >
5+
6+ Brief Set Up guide: https://pico.me365.xyz/steps
7+
8+ ### (Step 1 - same) Set Up Pico Ctrl
9+
10+ ### (Step 2 - different) Code with Pico W
11+
12+ - Use ` dev.uf2 ` file.
13+ - Download IDE to access Pico, e.g. [ Thonny IDE] ( https://thonny.org/ )
14+ - Connect to your Pico W
15+ - Add ` src ` files to your Pico W, this handles each received command
16+ - Make some changes to handle new things e.g. create blink handle in handleCommands:
17+
18+ ` def handleCommands(item, value): `
19+
20+ ``` python
21+ if " blink" == item:
22+ blink_onboard_led(int (value))
23+ ```
24+
25+ `... `
26+
27+ - Rerun `main.py` after changes
28+
29+ # ## (Step 3 - similiar) Test Pico W Control with Pico Ctrl
30+
31+ - Create new Controller for `your new commands` , e.g. use command `blink=5 ` and offCommand `led=0 `
32+ - Update your device by enabling created command
33+ - Click on Control in Devices Control to emit new control command
Original file line number Diff line number Diff line change 1+ import machine
2+ import time
3+
4+ led = machine .Pin ('LED' , machine .Pin .OUT )
5+ pwm = machine .PWM (machine .Pin (15 ))
6+ pwm .freq (50 )
7+
8+
9+ def blink_onboard_led (num_blinks ):
10+ for i in range (num_blinks ):
11+ led .on ()
12+ time .sleep (.2 )
13+ led .off ()
14+ time .sleep (.2 )
15+
16+
17+ def handleGP (item , value ):
18+ pin = machine .Pin (int (item [2 :]), machine .Pin .OUT )
19+ pin .value (int (value ))
20+
21+
22+ def handleLed (value ):
23+ if "1" == value :
24+ led .on ()
25+ if "0" == value :
26+ led .off ()
27+
28+
29+ def handleServo (value ):
30+ try :
31+ valuesFromToSpeed = value .split (',' )
32+
33+ valueFrom = int (valuesFromToSpeed [0 ])
34+ valueTo = int (valuesFromToSpeed [1 ])
35+
36+ if (valueFrom < valueTo ):
37+ for position in range (valueFrom , valueTo , 50 ):
38+ pwm .duty_u16 (position )
39+ time .sleep (.02 )
40+ else :
41+ for position in range (valueFrom , valueTo , - 50 ):
42+ pwm .duty_u16 (position )
43+ time .sleep (.02 )
44+ except :
45+ print ("Something went wrong with servo" )
46+
47+
48+ def handleCommands (item , value ):
49+ try :
50+ if "blink" == item :
51+ blink_onboard_led (int (value ))
52+ if "led" == item :
53+ handleLed (value )
54+ if "servo" == item :
55+ handleServo (value )
56+ else :
57+ handleGP (item , value )
58+ except :
59+ print ("Something went wrong" )
Original file line number Diff line number Diff line change 1+ from wlan import RunWlan
2+ from AP import RunAP
3+ from secrets import secrets
4+
5+ ssid = secrets ['ssid' ]
6+
7+ if ssid == "" :
8+ RunAP ()
9+ else :
10+ RunWlan ()
You can’t perform that action at this time.
0 commit comments