-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c09a747
Showing
5 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<h1 align="center"> Develop with Pico Ctrl using MicroPython</h1> | ||
<p align="center"> | ||
<img width="500" alt="Cover" src="./cover.png"> | ||
</p> | ||
|
||
Brief Set Up guide: https://pico.me365.xyz/steps | ||
|
||
### (Step 1 - same) Set Up Pico Ctrl | ||
|
||
### (Step 2 - different) Code with Pico W | ||
|
||
- Use `dev.uf2` file. | ||
- Download IDE to access Pico, e.g. [Thonny IDE](https://thonny.org/) | ||
- Connect to your Pico W | ||
- Add `src` files to your Pico W, this handles each received command | ||
- Make some changes to handle new things e.g. create blink handle in handleCommands: | ||
|
||
`def handleCommands(item, value):` | ||
|
||
```python | ||
if "blink" == item: | ||
blink_onboard_led(int(value)) | ||
``` | ||
|
||
`...` | ||
|
||
- Rerun `main.py` after changes | ||
|
||
### (Step 3 - similiar) Test Pico W Control with Pico Ctrl | ||
|
||
- Create new Controller for `your new commands`, e.g. use command `blink=5` and offCommand `led=0` | ||
- Update your device by enabling created command | ||
- Click on Control in Devices Control to emit new control command |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import machine | ||
import time | ||
|
||
led = machine.Pin('LED', machine.Pin.OUT) | ||
pwm = machine.PWM(machine.Pin(15)) | ||
pwm.freq(50) | ||
|
||
|
||
def blink_onboard_led(num_blinks): | ||
for i in range(num_blinks): | ||
led.on() | ||
time.sleep(.2) | ||
led.off() | ||
time.sleep(.2) | ||
|
||
|
||
def handleGP(item, value): | ||
pin = machine.Pin(int(item[2:]), machine.Pin.OUT) | ||
pin.value(int(value)) | ||
|
||
|
||
def handleLed(value): | ||
if "1" == value: | ||
led.on() | ||
if "0" == value: | ||
led.off() | ||
|
||
|
||
def handleServo(value): | ||
try: | ||
valuesFromToSpeed = value.split(',') | ||
|
||
valueFrom = int(valuesFromToSpeed[0]) | ||
valueTo = int(valuesFromToSpeed[1]) | ||
|
||
if (valueFrom < valueTo): | ||
for position in range(valueFrom, valueTo, 50): | ||
pwm.duty_u16(position) | ||
time.sleep(.02) | ||
else: | ||
for position in range(valueFrom, valueTo, -50): | ||
pwm.duty_u16(position) | ||
time.sleep(.02) | ||
except: | ||
print("Something went wrong with servo") | ||
|
||
|
||
def handleCommands(item, value): | ||
try: | ||
if "blink" == item: | ||
blink_onboard_led(int(value)) | ||
if "led" == item: | ||
handleLed(value) | ||
if "servo" == item: | ||
handleServo(value) | ||
else: | ||
handleGP(item, value) | ||
except: | ||
print("Something went wrong") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from wlan import RunWlan | ||
from AP import RunAP | ||
from secrets import secrets | ||
|
||
ssid = secrets['ssid'] | ||
|
||
if ssid == "": | ||
RunAP() | ||
else: | ||
RunWlan() |