Skip to content

Commit b67a45b

Browse files
init commit
0 parents  commit b67a45b

File tree

1,411 files changed

+1072782
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,411 files changed

+1072782
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import network
2+
import socket
3+
import gc
4+
5+
softap_ssid = 'MicroPython_Demo_AP'
6+
softap_pw = '12345678'
7+
8+
nic=network.WLAN(network.AP_IF)
9+
nic.active(True)
10+
nic.config(essid=softap_ssid, password=softap_pw, channel=1)
11+
12+
def web_page():
13+
html = """<html><head><meta name="viewport" content="width=device-width, initial-scale=1"></head>
14+
<body><h1>Hello, World!</h1></body></html>"""
15+
return html
16+
17+
18+
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
19+
sock.bind(('0.0.0.0',80))
20+
sock.listen(3)
21+
22+
while True:
23+
conn, addr = sock.accept()
24+
print('Got a connection from %s' % str(addr))
25+
request = conn.recv(1024)
26+
print('Content = %s' % str(request))
27+
response = web_page()
28+
conn.send(response)
29+
conn.close()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from test_pkg import post
2+
from test_pkg import about
3+
4+
print("main.py test start...")
5+
6+
p = post.Post()
7+
p.add_post("Python Programming")
8+
author = about.get_author()
9+
email = about.get_email()
10+
11+
12+
print(p.titles)
13+
print(author)
14+
print(email)
15+
16+
print("main.py test end...")

example_scripts/general_test/test_pkg/__init__.py

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
def get_author():
3+
return "David"
4+
5+
def get_email():
6+
return "demo123@microchip.com"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Post:
2+
3+
def __init__(self):
4+
self.titles = []
5+
6+
def add_post(self, title):
7+
self.titles.append(title)
8+
9+
def delete_post(self, title):
10+
self.titles.remove(title)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This test is used to Pin 44 (Mirko bus AN pin) to trigger Pin 14 (Mirko bus CS pin) at rising edge
2+
# To perfrom tests, connect Pin 44 (Mirko bus AN pin) to Pin 14 (Mirko bus CS pin)
3+
4+
from umachine import Pin
5+
import utime
6+
7+
def callback_test(p):
8+
print("IRQ event is triggered ..")
9+
10+
p14 = Pin(14, mode=Pin.IN)
11+
p14.irq(handler=callback_test, trigger=Pin.IRQ_RISING)
12+
13+
p44 = Pin(44, Pin.OUT)
14+
15+
i = 0
16+
j = 0
17+
while True:
18+
#utime.sleep(1)
19+
i = i+1
20+
if i%100000 == 0:
21+
j = j+1;
22+
if j % 2 == 0:
23+
print('low')
24+
p44.off()
25+
else:
26+
print('high')
27+
p44.on()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from umachine import Pin
2+
from umachine import Timer
3+
4+
5+
cnt = 0
6+
7+
def mycallback(t):
8+
global cnt
9+
cnt = cnt + 1
10+
if (cnt % 2 != 0):
11+
print("yellow led on")
12+
p1.on()
13+
else:
14+
print("yellow led off")
15+
p1.off()
16+
17+
18+
p1 = Pin(16, Pin.OUT)
19+
20+
21+
tim=Timer(0)
22+
tim.init(period=2000, callback=mycallback)
23+
24+
while True:
25+
pass

example_scripts/http_get/main.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import network
2+
import socket
3+
4+
nic=network.WLAN(network.STA_IF)
5+
nic.active(True)
6+
nic.connect('mchp_demo', 'mchp5678')
7+
while not nic.isconnected():
8+
pass
9+
print("wifi connection is done")
10+
11+
12+
def http_get(url):
13+
import socket
14+
_, _, host, path = url.split('/', 3)
15+
addr = socket.getaddrinfo(host, 80)[0][-1]
16+
s = socket.socket()
17+
s.connect(addr)
18+
s.send(bytes('GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n' % (path, host), 'utf8'))
19+
print("HTTP GET command is send");
20+
while True:
21+
data = s.recv(100)
22+
if data:
23+
print(str(data, 'utf8'), end='')
24+
else:
25+
print("conn is close");
26+
break
27+
s.close()
28+
29+
http_get('http://micropython.org/ks/test.html')
30+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import umachine
2+
pins = [umachine.Pin(i, umachine.Pin.IN) for i in (16, 41, 47)]
3+
4+
html = """<!DOCTYPE html>
5+
<html>
6+
<head> <title>PIC32MZW1 Pins State</title> </head>
7+
<body> <h1>PIC32MZW1 Pins State</h1>
8+
<table border="1"> <tr><th>Pin</th><th>Value</th></tr> %s </table>
9+
</body>
10+
</html>
11+
"""
12+
13+
import network
14+
nic=network.WLAN(network.STA_IF)
15+
nic.active(True)
16+
nic.connect('mchp_demo', 'mchp5678')
17+
while not nic.isconnected():
18+
pass
19+
print("wifi connection is done")
20+
21+
import socket
22+
addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
23+
24+
s = socket.socket()
25+
s.bind(addr)
26+
s.listen(1)
27+
28+
print('listening on', addr)
29+
30+
while True:
31+
cl, addr = s.accept()
32+
print('client connected from', addr)
33+
cl_file = cl.makefile('rwb', 0)
34+
while True:
35+
line = cl_file.readline()
36+
if not line or line == b'\r\n':
37+
break
38+
rows = ['<tr><td>%s</td><td>%d</td></tr>' % (str(p), p.value()) for p in pins]
39+
response = html % '\n'.join(rows)
40+
cl.send('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n')
41+
cl.send(response)
42+
cl.close()
43+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from umachine import SPI
2+
from umachine import Pin
3+
import utime
4+
5+
print("SPI Test - Read SST26 manufacture ID and device ID")
6+
7+
spi=SPI(2)
8+
rst_pin = Pin(12, mode=Pin.OUT) # reset pin
9+
cs_pin = Pin(14, mode=Pin.OUT) # cs pin
10+
11+
rst_pin.on()
12+
utime.sleep(1)
13+
cs_pin.on()
14+
15+
utime.sleep(1)
16+
17+
print("Test is start..")
18+
cs_pin.off()
19+
spi.write(b'\x66') # sst26 enable reset command
20+
cs_pin.on()
21+
22+
cs_pin.off()
23+
spi.write(b'\x99') # sst26 memory reset command
24+
cs_pin.on()
25+
26+
27+
cs_pin.off()
28+
spi.write(b'\x06') # sst26 enable write command
29+
cs_pin.on()
30+
31+
cs_pin.off()
32+
spi.write(b'\x98') # sst26 global block protection unlock command
33+
cs_pin.on()
34+
35+
txdata = b"\x9f\xAA\xAA\xAA" # sst26 jedec id read command
36+
rxdata = bytearray(4)
37+
38+
cs_pin.off()
39+
spi.write_readinto(txdata, rxdata)
40+
cs_pin.on()
41+
print("Test is finish..")
42+
43+
print("manufactureID = " + hex(rxdata[1]))
44+
print("deviceID = " + hex(rxdata[2] <<8 | rxdata[3]))

0 commit comments

Comments
 (0)