Skip to content

Commit

Permalink
Initial ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
aarnas committed Feb 2, 2023
0 parents commit c09a747
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.md
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 added cover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dev.uf2
Binary file not shown.
59 changes: 59 additions & 0 deletions src/handleCommands.py
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")
10 changes: 10 additions & 0 deletions src/main.py
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()

0 comments on commit c09a747

Please sign in to comment.