Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Harmony version, examples and pyb #1

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.vscode
.generated_files
dist/
debug/
build/
private/
node_modules/
**/nbproject/Makefile-*
**/nbproject/Package-*
defmplabxtrace*
firmware/pic32mz_w1_curiosity_freertos.X/nbproject/pic32mz_w1_curiosity_freertos.debug
firmware/pic32mz_w1_curiosity_freertos.X/nbproject/pic32mz_w1_curiosity_freertos.production
63 changes: 63 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
21 changes: 21 additions & 0 deletions example_scripts/class_example/led/led_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from umachine import Pin

class LED:
def __init__(self, pin_number, on_time_ms, off_time_ms):
self.led = Pin(pin_number, Pin.OUT)
self.on_time = on_time_ms
self.off_time = off_time_ms
self.led.on() # Start with LED off
self.last_toggle = 0 # Keep track of last toggle time
self.state = False # Initial LED state
self.current_time = 0 # Initial time
def update(self):
self.current_time += 1
if self.state and self.current_time - self.last_toggle >= self.on_time:
self.led.on()
self.state = False
self.last_toggle = self.current_time
elif not self.state and self.current_time - self.last_toggle >= self.off_time:
self.led.off()
self.state = True
self.last_toggle = self.current_time
18 changes: 18 additions & 0 deletions example_scripts/class_example/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from umachine import Timer
from led.led_class import LED

led1 = LED(pin_number=16, on_time_ms=100, off_time_ms=500)
led2 = LED(pin_number=17, on_time_ms=500, off_time_ms=500)
led3 = LED(pin_number=18, on_time_ms=500, off_time_ms=100)

def mycallback(t):
led1.update()
led2.update()
led3.update()

timer=Timer(0)
timer.init(period=1, callback=mycallback)

while True:
pass

4 changes: 4 additions & 0 deletions example_scripts/frozen_module/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import test

test.test1()
test.test2()
27 changes: 0 additions & 27 deletions example_scripts/gpio_interrupt/gpio_interrupt.py

This file was deleted.

20 changes: 20 additions & 0 deletions example_scripts/gpio_interrupt/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This test is used to Pin 44 (Mirko bus AN pin) to trigger Pin 14 (Mirko bus CS pin) at rising edge
# To perfrom tests, connect Pin 44 (Mirko bus AN pin) to Pin 14 (Mirko bus CS pin)


from pyb import LED, delay
from umachine import Pin

led_blue = LED(4)
led_yellow = LED(2)

def callback_test(p):
print("SW IRQ event is triggered ..")
led_yellow.toggle()

switch = Pin(47, mode=Pin.IN)
switch.irq(handler=callback_test, trigger=Pin.IRQ_RISING)

while True:
delay(500)
led_blue.toggle()
27 changes: 5 additions & 22 deletions example_scripts/gpio_on_off_led/main.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
from umachine import Pin
from umachine import Timer
from pyb import LED, delay


cnt = 0

def mycallback(t):
global cnt
cnt = cnt + 1
if (cnt % 2 != 0):
print("yellow led off")
p1.on()
else:
print("yellow led on")
p1.off()


p1 = Pin(16, Pin.OUT)


tim=Timer(0)
tim.init(period=2000, callback=mycallback)
leds = [LED(1), LED(2), LED(3), LED(4)]

while True:
pass
for i in range(4):
leds[i].toggle()
delay(150)
18 changes: 18 additions & 0 deletions example_scripts/gpio_timer_callback/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from umachine import Pin
from umachine import Timer

def mycallback(t):
if p1.value() == 1:
print("yellow led on")
p1.off()
else:
print("yellow led off")
p1.on()


p1 = Pin(16, Pin.OUT)
timer=Timer(0)
timer.init(period=2000, callback=mycallback)

while True:
pass
34 changes: 34 additions & 0 deletions example_scripts/i2c_light_temp_read/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from umachine import I2C

i2c = I2C(1, freq=100000)

# light sensor address = 68
# light sensor registers (16 bit)
# 0 - result
# 1 - configuration
# 2 - low limit
# 3 - high limit
# 126 - manufacturer
# 127 - device id

# read light sensor manufacturer
manufacturer = i2c.readfrom_mem(68, 126, 2)
print("light manufacturer:", manufacturer)

# temperature sensor address = 24
# temp sensor registers (16 bit)
# 0 - reserved
# 1 - configuration
# 2 - alert upper temp
# 3 - alert lower temp
# 4 - critical temp
# 5 - temperature [ >TCRIT >TUP <tLW SIGN T7 T6 T5 T4 T3 T2 T1 T0 . T-1 T-2 T-3 T-4 ]
# 6 - manufacturer ID
# 7 - device ID
# 8 - Resolution register

manufacturer = i2c.readfrom_mem(24, 6, 2)
print("temp manufacturer:", hex(manufacturer[1]))
temp = i2c.readfrom_mem(24, 5, 2)
temp[1]

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import socket

ssid = 'demo_ap'
password = 'password'
password = '12345678'
nic=network.WLAN(network.STA_IF)
nic.active(True)
nic.connect(ssid, password)
Expand All @@ -24,7 +24,7 @@ def http_get(url):
if data:
print(str(data, 'utf8'), end='')
else:
print("conn is close");
print("conn is close")
break
s.close()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
s.connect(addr) # or s.connect(ip, port)

s.send("hello world")
print("data is send")
print("data is sent")
while True:
data = s.recv(500)
if len(data) > 0:
Expand Down
4 changes: 2 additions & 2 deletions example_scripts/spi_read_sst26_id/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

utime.sleep(1)

print("Test is start..")
print("Test start...")
cs_pin.off()
spi.write(b'\x66') # sst26 enable reset command
cs_pin.on()
Expand All @@ -38,7 +38,7 @@
cs_pin.off()
spi.write_readinto(txdata, rxdata)
cs_pin.on()
print("Test is finish..")
print("Test finish...")

print("manufactureID = " + hex(rxdata[1]))
print("deviceID = " + hex(rxdata[2] <<8 | rxdata[3]))
Loading