buildroot: add pinpong library
This commit is contained in:
@ -345,6 +345,8 @@ BR2_PACKAGE_PYTHON_MODBUS_TK=y
|
||||
BR2_PACKAGE_PYTHON_EVDEV=y
|
||||
BR2_PACKAGE_PYTHON_FREETYPE=y
|
||||
|
||||
BR2_PACKAGE_PYTHON_PINPONG=y
|
||||
|
||||
#
|
||||
# Compression and decompression
|
||||
#
|
||||
|
||||
@ -1099,6 +1099,7 @@ menu "External python modules"
|
||||
source "package/python-piexif/Config.in"
|
||||
source "package/python-pigpio/Config.in"
|
||||
source "package/python-pillow/Config.in"
|
||||
source "package/python-pinpong/Config.in"
|
||||
source "package/python-pip/Config.in"
|
||||
source "package/python-pluggy/Config.in"
|
||||
source "package/python-ply/Config.in"
|
||||
|
||||
4
buildroot-2021.05/package/python-pinpong/Config.in
Normal file
4
buildroot-2021.05/package/python-pinpong/Config.in
Normal file
@ -0,0 +1,4 @@
|
||||
config BR2_PACKAGE_PYTHON_PINPONG
|
||||
bool "python-pinpong"
|
||||
help
|
||||
The pinpong library is an open-source Python library.
|
||||
@ -0,0 +1,60 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
import subprocess
|
||||
|
||||
from pinpong.base.programmer import *
|
||||
|
||||
class DfuUtil(Programmer):
|
||||
def __init__(self, port="", baudrate=115200):
|
||||
super().__init__(port, baudrate)
|
||||
|
||||
def setup(self):
|
||||
print("DfuUtil setup")
|
||||
|
||||
def initialize(self):
|
||||
global logger
|
||||
print("initialize")
|
||||
|
||||
def display(self):
|
||||
return True
|
||||
|
||||
def read_sig_bytes(self):
|
||||
pass
|
||||
|
||||
def enable(self):
|
||||
pass
|
||||
|
||||
def program_enable(self):
|
||||
global logger
|
||||
pass
|
||||
|
||||
def burn(self):
|
||||
print(self.filename)
|
||||
print("stm32flash -w %s -v -g 0x08000000 /dev/ttyS3"%(self.filename))
|
||||
if not os.path.exists("/sys/class/gpio/gpio80"):
|
||||
os.system("echo 80 > /sys/class/gpio/export")#RST
|
||||
if not os.path.exists("/sys/class/gpio/gpio69"):
|
||||
os.system("echo 69 > /sys/class/gpio/export")#BOOT0
|
||||
os.system("echo out > /sys/class/gpio/gpio69/direction")
|
||||
os.system("echo out > /sys/class/gpio/gpio80/direction")
|
||||
os.system("echo 0 > /sys/class/gpio/gpio69/value")
|
||||
os.system("echo 1 > /sys/class/gpio/gpio80/value")
|
||||
time.sleep(0.1)
|
||||
os.system("echo 1 > /sys/class/gpio/gpio69/value")#BOOT0=HIGH
|
||||
time.sleep(0.1)
|
||||
os.system("echo 0 > /sys/class/gpio/gpio80/value")#RST=LOW
|
||||
time.sleep(0.1)
|
||||
os.system("echo 1 > /sys/class/gpio/gpio80/value")#RST = HIGH
|
||||
time.sleep(0.1)
|
||||
os.system("echo 0 > /sys/class/gpio/gpio69/value")#BOOT0=LOW
|
||||
time.sleep(1)
|
||||
os.system("stm32flash -w %s -v -g 0x08000000 /dev/ttyS3"%(self.filename))
|
||||
os.system("echo 0 > /sys/class/gpio/gpio80/value")#RST=LOW
|
||||
time.sleep(0.2)
|
||||
os.system("echo 1 > /sys/class/gpio/gpio80/value")#RST = HIGH
|
||||
time.sleep(2)
|
||||
def disable(self):
|
||||
pass
|
||||
2683
buildroot-2021.05/package/python-pinpong/pinpong/base/EspTool.py
Normal file
2683
buildroot-2021.05/package/python-pinpong/pinpong/base/EspTool.py
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
16920
buildroot-2021.05/package/python-pinpong/pinpong/base/avrdude.conf
Normal file
16920
buildroot-2021.05/package/python-pinpong/pinpong/base/avrdude.conf
Normal file
File diff suppressed because it is too large
Load Diff
131
buildroot-2021.05/package/python-pinpong/pinpong/base/avrdude.py
Normal file
131
buildroot-2021.05/package/python-pinpong/pinpong/base/avrdude.py
Normal file
@ -0,0 +1,131 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
import time
|
||||
import serial
|
||||
import logging
|
||||
import sys, getopt
|
||||
from pinpong.base.stk500 import *
|
||||
from pinpong.base.stk500v2 import *
|
||||
from pinpong.base.butterfly import *
|
||||
from pinpong.base.microbit import *
|
||||
from pinpong.base.EspTool import *
|
||||
from pinpong.base.DfuUtil import *
|
||||
|
||||
def parse_op(arg):
|
||||
x={}
|
||||
l=arg.split(":")
|
||||
x["filename"] = l[2]
|
||||
x["op"] = 0
|
||||
x["format"] = 2
|
||||
return x
|
||||
|
||||
def read_config():
|
||||
print(sys_config)
|
||||
|
||||
def parse_args(argv):
|
||||
global baudrate, programmer,verbose,sys_config,partdesc,port,upd
|
||||
opts,args = getopt.getopt(argv,"?b:B:c:C:DeE:Fi:np:OP:qstU:uvVx:yY:")
|
||||
print(opts)
|
||||
for opt,arg in opts:
|
||||
if(opt == "-b"):
|
||||
baudrate = int(arg)
|
||||
logger.info("baudrate=%d"%baudrate)
|
||||
|
||||
if(opt == "-c"):
|
||||
programmer = arg
|
||||
logger.info("programmer=%s"%(programmer))
|
||||
|
||||
if(opt == "-C"):
|
||||
sys_config = arg
|
||||
logger.info("sys_config=%s"%(sys_config))
|
||||
|
||||
if(opt == "-p"):
|
||||
partdesc = arg
|
||||
logger.info("partdesc=%s"%(partdesc))
|
||||
|
||||
if(opt == "-P"):
|
||||
port = arg
|
||||
logger.info("port=%s"%(port))
|
||||
|
||||
if(opt == "-v"):
|
||||
verbose = verbose + 1
|
||||
|
||||
if(opt == "-U"):
|
||||
upd = parse_op(arg)
|
||||
logger.info(upd)
|
||||
|
||||
def producePGM(name,port,baudrate):
|
||||
pgms={
|
||||
"arduino":STK500,
|
||||
"avr109":Butterfly,
|
||||
"wiring":STK500V2,
|
||||
"microbit":Microbit,
|
||||
"handpy":EspTool,
|
||||
"dfu-util":DfuUtil,
|
||||
}
|
||||
return pgms[name](port,baudrate)
|
||||
|
||||
|
||||
def main(argv):
|
||||
global programmer,port,baudrate
|
||||
parse_args(argv)
|
||||
pgm = producePGM(programmer, port, baudrate)
|
||||
if not pgm.display():
|
||||
return False
|
||||
|
||||
pgm.initialize()
|
||||
print(upd)
|
||||
pgm.read_sig_bytes()
|
||||
pgm.enable()
|
||||
pgm.ihex2b(upd["filename"])
|
||||
pgm.burn()
|
||||
pgm.disable()
|
||||
|
||||
def set_logger():
|
||||
global logger
|
||||
#logger.setLevel(logging.INFO)
|
||||
logger.setLevel(logging.FATAL)
|
||||
ph = logging.StreamHandler()
|
||||
formatter = logging.Formatter("%(asctime)s - [%(filename)s %(funcName)s]:%(lineno)d - %(levelname)s: %(message)s")
|
||||
ph.setFormatter(formatter)
|
||||
logger.addHandler(ph)
|
||||
|
||||
if __name__ == "__main__":
|
||||
set_logger()
|
||||
main(sys.argv[1:])
|
||||
|
||||
class Burner:
|
||||
def __init__(self,board,port):
|
||||
global programmer,baudrate
|
||||
set_logger()
|
||||
if board.upper() == 'UNO':
|
||||
programmer="arduino"
|
||||
baudrate = 115200
|
||||
elif board.upper() == 'LEONARDO':
|
||||
programmer="avr109"
|
||||
baudrate = 57600
|
||||
elif board.upper() == 'MEGA2560':
|
||||
programmer = "wiring"
|
||||
baudrate = 115200
|
||||
elif board.upper() == 'MICROBIT':
|
||||
programmer = 'microbit'
|
||||
baudrate = 115200
|
||||
elif board.upper() == 'HANDPY':
|
||||
programmer = 'handpy'
|
||||
baudrate = 921600
|
||||
elif board.upper() == 'UNIHIKER':
|
||||
programmer = 'dfu-util'
|
||||
baudrate = 115200
|
||||
self.pgm = producePGM(programmer, port, baudrate)
|
||||
|
||||
def burn(self,filename):
|
||||
if not self.pgm.display():
|
||||
return False
|
||||
self.pgm.initialize()
|
||||
self.pgm.read_sig_bytes()
|
||||
self.pgm.enable()
|
||||
self.pgm.filename = filename
|
||||
self.pgm.ihex2b(filename)
|
||||
self.pgm.burn()
|
||||
self.pgm.disable()
|
||||
Binary file not shown.
Binary file not shown.
@ -0,0 +1,149 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import serial
|
||||
from pinpong.base.butterfly_param import *
|
||||
from pinpong.base.programmer import *
|
||||
|
||||
class Butterfly(Programmer):
|
||||
def __init__(self, port="/dev/ttyS1", baudrate=115200):
|
||||
super().__init__(port, baudrate)
|
||||
|
||||
def setup(self):
|
||||
print("Butterfly setup %s"%self.port)
|
||||
|
||||
def vfy_cmd_sent(self):
|
||||
res = self.ser.read(1)
|
||||
logger.info(res)
|
||||
return res[0] == 0x0d
|
||||
|
||||
def enter_prog_mode(self):
|
||||
buf = bytearray(8)
|
||||
buf[0] = ord('P')
|
||||
self.ser.write(buf[:1])
|
||||
self.vfy_cmd_sent()
|
||||
|
||||
def initialize(self):
|
||||
global logger
|
||||
print("butter initialize")
|
||||
id = bytearray(1)
|
||||
sw = bytearray(1)
|
||||
hw = bytearray(1)
|
||||
buf = bytearray(8)
|
||||
type=0
|
||||
has_auto_incr_addr=0
|
||||
buffersize=0
|
||||
|
||||
buf[0] = 0x1b
|
||||
self.ser.write(buf[:1])
|
||||
self.drain()
|
||||
|
||||
buf[0] = ord('S')
|
||||
self.ser.write(buf[:1])
|
||||
res = self.ser.read(1)
|
||||
logger.info(res)
|
||||
if(res[0] != '?'):
|
||||
id[0] = res[0]
|
||||
id = id + self.ser.read(6)
|
||||
|
||||
buf[0] = ord('V')
|
||||
self.ser.write(buf[:1])
|
||||
res = self.ser.read(1)
|
||||
logger.info(res)
|
||||
if(res[0] != '?'):
|
||||
sw[0] = res[0]
|
||||
sw = sw + self.ser.read(1)
|
||||
|
||||
buf[0] = ord('v')
|
||||
self.ser.write(buf[:1])
|
||||
res = self.ser.read(1)
|
||||
logger.info(res)
|
||||
if(res[0] != '?'):
|
||||
hw[0] = res[0]
|
||||
hw = hw + self.ser.read(1)
|
||||
|
||||
buf[0] = ord('p')
|
||||
self.ser.write(buf[:1])
|
||||
res = self.ser.read(1)
|
||||
logger.info(res)
|
||||
type = res[0]
|
||||
|
||||
buf[0] = ord('a')
|
||||
self.ser.write(buf[:1])
|
||||
res = self.ser.read(1)
|
||||
has_auto_incr_addr=res[0]
|
||||
logger.info(res)
|
||||
|
||||
buf[0] = ord('b')
|
||||
self.ser.write(buf[:1])
|
||||
res = self.ser.read(1)
|
||||
if res[0] == ord('Y'):
|
||||
res = self.ser.read(2)
|
||||
buffersize = res[0]*256 + res[1]
|
||||
|
||||
devtype_1st = 0
|
||||
buf[0] = ord('t')
|
||||
self.ser.write(buf[:1])
|
||||
while True:
|
||||
res = self.ser.read(1)
|
||||
if devtype_1st == 0:
|
||||
devtype_1st = res[0]
|
||||
if(res[0] == 0 or res==None):
|
||||
break;
|
||||
|
||||
buf[0] = ord('T')
|
||||
buf[1] = devtype_1st
|
||||
self.ser.write(buf[:2])
|
||||
self.vfy_cmd_sent()
|
||||
|
||||
self.enter_prog_mode()
|
||||
self.drain()
|
||||
|
||||
def read_sig_bytes(self):
|
||||
global logger
|
||||
buf = bytearray(1)
|
||||
buf[0] = ord('s')
|
||||
self.ser.write(buf[:1])
|
||||
res = self.ser.read(3)
|
||||
|
||||
def set_addr(self,addr):
|
||||
buf = bytearray(3)
|
||||
buf[0] = ord('A')
|
||||
buf[1] = (addr//2)>>8
|
||||
buf[2] = (addr//2) & 0xff
|
||||
self.ser.write(buf[:3])
|
||||
self.vfy_cmd_sent()
|
||||
|
||||
def burn(self):
|
||||
addr = 0
|
||||
blocksize = 128
|
||||
total_len = len(self.buffer)
|
||||
self.set_addr(addr)
|
||||
|
||||
while True:
|
||||
buf = bytearray(4)
|
||||
buf[0] = ord('B')
|
||||
buf[3] = ord('F')
|
||||
if total_len - addr < blocksize:
|
||||
blocksize = total_len - addr
|
||||
buf[1] = (blocksize)>>8
|
||||
buf[2] = (blocksize)&0xff
|
||||
|
||||
next_addr = addr + blocksize
|
||||
buf = buf+self.buffer[addr:addr+blocksize]
|
||||
self.ser.write(buf)
|
||||
self.vfy_cmd_sent()
|
||||
|
||||
if next_addr - total_len == 0:
|
||||
break
|
||||
else:
|
||||
addr = next_addr
|
||||
|
||||
def disable(self):
|
||||
buf = bytearray(1)
|
||||
buf[0] = ord('L')
|
||||
self.ser.write(buf)
|
||||
self.vfy_cmd_sent()
|
||||
|
||||
buf[0] = ord('E')
|
||||
self.ser.write(buf)
|
||||
self.vfy_cmd_sent()
|
||||
self.ser.close()
|
||||
@ -0,0 +1 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
247
buildroot-2021.05/package/python-pinpong/pinpong/base/comm.py
Normal file
247
buildroot-2021.05/package/python-pinpong/pinpong/base/comm.py
Normal file
@ -0,0 +1,247 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import serial
|
||||
import serial.tools.list_ports
|
||||
import platform
|
||||
|
||||
PINPONG_MAJOR=0
|
||||
PINPONG_MINOR=5
|
||||
PINPONG_DELTA=2
|
||||
|
||||
FIRMATA_MAJOR = 2
|
||||
FIRMATA_MINOR = 7
|
||||
|
||||
|
||||
firmware_version = {
|
||||
"UNO":(2,8),
|
||||
"LEONARDO":(2,7),
|
||||
"MEGA2560":(2,8),
|
||||
"MICROBIT":(2,9),
|
||||
"HANDPY":(2,9),
|
||||
"UNIHIKER":(3,8)
|
||||
}
|
||||
|
||||
def printlogo_big():
|
||||
print("""
|
||||
__________________________________________
|
||||
| ____ _ ____ |
|
||||
| / __ \(_)___ / __ \____ ____ ____ _ |
|
||||
| / /_/ / / __ \/ /_/ / __ \/ __ \/ __ `/ |
|
||||
| / ____/ / / / / ____/ /_/ / / / / /_/ / |
|
||||
|/_/ /_/_/ /_/_/ \____/_/ /_/\__, / |
|
||||
| v%d.%d.%d Designed by DFRobot /____/ |
|
||||
|__________________________________________|
|
||||
"""%(PINPONG_MAJOR,PINPONG_MINOR,PINPONG_DELTA))
|
||||
|
||||
|
||||
def printlogo():
|
||||
print("""
|
||||
___________________________
|
||||
| |
|
||||
| PinPong v%d.%d.%d |
|
||||
| Designed by DFRobot |
|
||||
|___________________________|
|
||||
"""%(PINPONG_MAJOR,PINPONG_MINOR,PINPONG_DELTA))
|
||||
|
||||
class PinInformation:
|
||||
D0 = 0
|
||||
D1 = 1
|
||||
D2 = 2
|
||||
D3 = 3
|
||||
D4 = 4
|
||||
D5 = 5
|
||||
D6 = 6
|
||||
D7 = 7
|
||||
D8 = 8
|
||||
D9 = 9
|
||||
D10 = 10
|
||||
D11 = 11
|
||||
D12 = 12
|
||||
D13 = 13
|
||||
D14 = 14
|
||||
D15 = 15
|
||||
D16 = 16
|
||||
D17 = 17
|
||||
D18 = 18
|
||||
D19 = 19
|
||||
D20 = 20
|
||||
D21 = 21
|
||||
D22 = 22
|
||||
D23 = 23
|
||||
D24 = 24
|
||||
D25 = 25
|
||||
D26 = 26
|
||||
D27 = 27
|
||||
D28 = 28
|
||||
D29 = 29
|
||||
D30 = 30
|
||||
D31 = 31
|
||||
D32 = 32
|
||||
D33 = 33
|
||||
D34 = 34
|
||||
D35 = 35
|
||||
D36 = 36
|
||||
D37 = 37
|
||||
D38 = 38
|
||||
D39 = 39
|
||||
D40 = 40
|
||||
D41 = 41
|
||||
D42 = 42
|
||||
D43 = 43
|
||||
D44 = 44
|
||||
D45 = 45
|
||||
D46 = 46
|
||||
D47 = 47
|
||||
D48 = 48
|
||||
D49 = 49
|
||||
D50 = 50
|
||||
D51 = 51
|
||||
D52 = 52
|
||||
D53 = 53
|
||||
|
||||
A0 = 100
|
||||
A1 = 101
|
||||
A2 = 102
|
||||
A3 = 103
|
||||
A4 = 104
|
||||
A5 = 105
|
||||
A6 = 106
|
||||
A7 = 107
|
||||
A8 = 108
|
||||
A9 = 109
|
||||
A10 = 110
|
||||
A11 = 111
|
||||
A12 = 112
|
||||
A13 = 113
|
||||
A14 = 114
|
||||
A15 = 115
|
||||
A16 = 116
|
||||
A17 = 117
|
||||
A18 = 118
|
||||
A19 = 119
|
||||
A20 = 120
|
||||
A21 = 121
|
||||
A22 = 122
|
||||
A23 = 123
|
||||
|
||||
P0 = 0
|
||||
P1 = 1
|
||||
P2 = 2
|
||||
P3 = 3
|
||||
P4 = 4
|
||||
P5 = 5
|
||||
P6 = 6
|
||||
P7 = 7
|
||||
P8 = 8
|
||||
P9 = 9
|
||||
P10 = 10
|
||||
P11 = 11
|
||||
P12 = 12
|
||||
P13 = 13
|
||||
P14 = 14
|
||||
P15 = 15
|
||||
P16 = 16
|
||||
P17 = 17
|
||||
P18 = 18
|
||||
P19 = 19
|
||||
P20 = 20
|
||||
P21 = 21
|
||||
P22 = 22
|
||||
P23 = 23
|
||||
P24 = 24
|
||||
P25 = 25 #Pythonboard L<><4C>
|
||||
P26 = 26 #Pythonboard <20><><EFBFBD>ط<EFBFBD><D8B7><EFBFBD><EFBFBD><EFBFBD>
|
||||
P27 = 27 #Pythonboard key_a
|
||||
P28 = 28 #Pythonboard key_b
|
||||
P29 = 29
|
||||
P30 = 30
|
||||
P31 = 31
|
||||
P32 = 32
|
||||
|
||||
OUT = 0
|
||||
IN = 1
|
||||
IRQ_FALLING = 2
|
||||
IRQ_RISING = 1
|
||||
IRQ_DRAIN = 7
|
||||
PULL_DOWN = 1
|
||||
PULL_UP = 2
|
||||
PWM = 0x10
|
||||
ANALOG = 0x11
|
||||
|
||||
|
||||
def find_board(board): #<23><><EFBFBD><EFBFBD><EFBFBD>Ż<EFBFBD><C5BB>ռ<EFBFBD>
|
||||
vidpid={
|
||||
"UNO":"3343:0043",
|
||||
"UNO":"2341:0043",
|
||||
"LEONARDO":"3343:8036",
|
||||
"LEONARDO":"2341:8036",
|
||||
"MEGA2560":"2341:0042",
|
||||
"MICROBIT":"0D28:0204",
|
||||
"HANDPY":"10C4:EA60",
|
||||
"HANDPY":"1A86:55D4" #<23><><EFBFBD><EFBFBD><EFBFBD>°<EFBFBD><C2B0>ƿ<EFBFBD>
|
||||
}
|
||||
findboard={
|
||||
"VID:PID=3343:0043":"UNO",
|
||||
"VID:PID=2341:0043":"UNO",
|
||||
"VID:PID=3343:8036":"LEONARDO",
|
||||
"VID:PID=2341:8036":"LEONARDO",
|
||||
"VID:PID=2341:0042":"MEGA2560",
|
||||
"VID:PID=0D28:0204":"MICROBIT",
|
||||
"VID:PID=10C4:EA60":"HANDPY",
|
||||
"VID:PID=1A86:55D4":"HANDPY"
|
||||
}
|
||||
_vidpid = '''
|
||||
VID:PID=3343:0043
|
||||
VID:PID=2341:0043
|
||||
VID:PID=3343:8036
|
||||
VID:PID=2341:8036
|
||||
VID:PID=2341:0042
|
||||
VID:PID=0D28:0204
|
||||
VID:PID=10C4:EA60
|
||||
VID:PID=1A86:55D4
|
||||
'''
|
||||
if platform.node() == "UNIHIKER":
|
||||
board.boardname = "UNIHIKER"
|
||||
if platform.node() == "milkv-duo":
|
||||
board.boardname = "MILKV-DUO"
|
||||
print(platform.node())
|
||||
portlist=[]
|
||||
localportlist=[]
|
||||
|
||||
if board.boardname in ["RPI","NEZHA"]:
|
||||
return
|
||||
elif board.boardname == "UNIHIKER":
|
||||
board.port = "/dev/ttyS3"
|
||||
if board.port == None and board.boardname != "":
|
||||
plist = list(serial.tools.list_ports.comports())
|
||||
for port in plist:
|
||||
msg = list(port)
|
||||
if msg[2].find(vidpid[board.boardname]) >= 0:
|
||||
portlist.insert(0,msg)
|
||||
break
|
||||
elif msg[2].find("USB") >= 0:
|
||||
portlist.insert(0,msg)
|
||||
else:
|
||||
localportlist.append(msg)
|
||||
portlist += localportlist
|
||||
if len(portlist) > 0:
|
||||
board.port = portlist[0][0]
|
||||
elif board.boardname == "" and board.port != None:
|
||||
plist = list(serial.tools.list_ports.comports())
|
||||
for port in plist:
|
||||
msg = list(port)
|
||||
if msg[0] == port:
|
||||
vidpid = msg[2].split(" ")
|
||||
if len(vidpid) > 2 and vidpid[1] in _vidpid:
|
||||
board.boardname = findboard[vidpid[1]]
|
||||
board.port = msg[0]
|
||||
break
|
||||
else:
|
||||
plist = list(serial.tools.list_ports.comports())
|
||||
for port in plist:
|
||||
msg = list(port)
|
||||
vidpid = msg[2].split(" ")
|
||||
if len(vidpid) > 2 and vidpid[1] in _vidpid:
|
||||
board.boardname = findboard[vidpid[1]]
|
||||
board.port = msg[0]
|
||||
|
||||
120
buildroot-2021.05/package/python-pinpong/pinpong/base/config.py
Normal file
120
buildroot-2021.05/package/python-pinpong/pinpong/base/config.py
Normal file
@ -0,0 +1,120 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import fcntl
|
||||
import termios
|
||||
import sys
|
||||
import ctypes
|
||||
import time
|
||||
from ctypes import c_int
|
||||
|
||||
MY_IOCTL_RESET = 25345 # reset gd32V
|
||||
|
||||
STATE_NONE = 0
|
||||
STATE_GPIO = 1
|
||||
STATE_IIC = 2
|
||||
STATE_SPI = 4
|
||||
STATE_UART = 8
|
||||
STATE_PWM = 16
|
||||
STATE_ADC = 32
|
||||
|
||||
pin_default_state = [
|
||||
STATE_GPIO, #> PA0 | | ADC_0 | tim4_0 pwm |
|
||||
STATE_GPIO, #> PA1 | | ADC_1 | tim4_1 pwm |
|
||||
STATE_GPIO, #> PA2 | uart1 | ADC_2 | tim4_2 pwm | 不测
|
||||
STATE_GPIO, #> PA3 | uart1 | ADC_3 | tim1_3 pwm | 不测
|
||||
STATE_GPIO, #> PA4 | | ADC_4 | |
|
||||
STATE_GPIO, #> PA5 | spi0 | ADC_5 | |
|
||||
STATE_GPIO, #> PA6 | spi0 | ADC_6 | tim2_0 pwm |
|
||||
STATE_GPIO, #> PA7 | spi0 | ADC_7 | tim2_1 pwm |
|
||||
STATE_GPIO, #> PA8 | | | tim0_0 pwm |
|
||||
STATE_UART, #> PA9 | uart0 | | | 通信接口不可更改
|
||||
STATE_UART, #> PA10 | uart0 | | | 通信接口不可更改
|
||||
STATE_GPIO, #> PA11 | | | tim0_3 pwm |
|
||||
STATE_GPIO, #> PA12 | | | |
|
||||
STATE_GPIO, #> PA13 | | | |
|
||||
STATE_GPIO, #> PA14 | | | |
|
||||
STATE_GPIO, #> PA15 | | | |
|
||||
STATE_GPIO, #> PB0 | | ADC_8 | tim2_2 pwm |
|
||||
STATE_GPIO, #> PB1 | | ADC_9 | tim2_3 pwm |
|
||||
STATE_GPIO, #> PB2 | | | |
|
||||
STATE_GPIO, #> PB3 | | | tim1_1 pwm |
|
||||
STATE_GPIO, #> PB4 | | | tim2_0 pwm |
|
||||
STATE_GPIO, #> PB5 | | | tim2_1 pwm |
|
||||
STATE_GPIO, #> PB6 | | | tim3_0 pwm |
|
||||
STATE_GPIO, #> PB7 | | | tim3_1 pwm |
|
||||
STATE_GPIO, #> PB8 | | | tim3_2 pwm |
|
||||
STATE_GPIO, #> PB9 | | | tim3_3 pwm |
|
||||
STATE_IIC, #> PB10 | iic1 | | tim1_2 pwm |
|
||||
STATE_IIC, #> PB11 | iic1 | | tim1_3 pwm |
|
||||
STATE_GPIO, #> PB12 | | | |
|
||||
STATE_GPIO, #> PB13 | spi1 | | |
|
||||
STATE_GPIO, #> PB14 | spi1 | | |
|
||||
STATE_GPIO #> PB15 | spi1 | | |
|
||||
]
|
||||
class IoctlParams(ctypes.Structure):
|
||||
_fields_ = [("mode", c_int) ,
|
||||
("num", c_int)] # 根据实际情况定义字段类型和名称
|
||||
|
||||
|
||||
|
||||
def pinConfig():
|
||||
fd = os.open("/dev/pinpong_config", os.O_RDWR)
|
||||
if fd == -1:
|
||||
print("open error")
|
||||
return -1
|
||||
'''
|
||||
params = IoctlParams()
|
||||
params.mode = 0x1F
|
||||
params.num = 1
|
||||
|
||||
ret = fcntl.ioctl(fd, MY_IOCTL_RESET, params)
|
||||
time.sleep(1);
|
||||
if ret == -1:
|
||||
print("reset fail")
|
||||
'''
|
||||
temp = bytearray(200)
|
||||
|
||||
'''
|
||||
# Configuring a single IO port
|
||||
temp[0] = 2
|
||||
temp[1] = STATE_UART
|
||||
temp[2] = STATE_UART
|
||||
ret = os.write(fd, temp[:3])
|
||||
if ret == -1:
|
||||
print("io error")
|
||||
else:
|
||||
print("one io success")
|
||||
'''
|
||||
# Configuring all IO ports
|
||||
temp[0] = 0
|
||||
temp[1:33] = bytearray(pin_default_state)
|
||||
ret = os.write(fd, temp[:33])
|
||||
if ret == -1:
|
||||
print("io error")
|
||||
|
||||
|
||||
'''
|
||||
temp = os.read(fd, 32)
|
||||
if len(temp) == 32:
|
||||
print("read success")
|
||||
for i in range(32):
|
||||
if i % 8 == 0:
|
||||
print()
|
||||
if temp[i] == STATE_NONE:
|
||||
print("none \t", end="")
|
||||
elif temp[i] == STATE_GPIO:
|
||||
print("gpio \t", end="")
|
||||
elif temp[i] == STATE_IIC:
|
||||
print("iic \t", end="")
|
||||
elif temp[i] == STATE_SPI:
|
||||
print("spi \t", end="")
|
||||
elif temp[i] == STATE_UART:
|
||||
print("uart \t", end="")
|
||||
elif temp[i] == STATE_PWM:
|
||||
print("pwm \t", end="")
|
||||
elif temp[i] == STATE_ADC:
|
||||
print("ADC\t", end="")
|
||||
'''
|
||||
os.close(fd)
|
||||
|
||||
|
||||
Binary file not shown.
@ -0,0 +1,56 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import sys, getopt
|
||||
import serial
|
||||
import os
|
||||
import json
|
||||
import platform
|
||||
import serial.tools.list_ports
|
||||
from pinpong.base.comm import *
|
||||
|
||||
def main():
|
||||
argc = len(sys.argv)
|
||||
cwdpath,_ = os.path.split(os.path.realpath(__file__))
|
||||
|
||||
with open(cwdpath+'/../libs/libs.json', 'r', encoding='UTF-8') as f:
|
||||
descs = json.loads(f.read())
|
||||
if argc == 1:
|
||||
argc = 2
|
||||
sys.argv.append("help")
|
||||
cmd = sys.argv[1]
|
||||
if cmd == "help" and argc == 2:
|
||||
printlogo_big()
|
||||
version = sys.version.split(' ')[0]
|
||||
plat = platform.platform()
|
||||
print("[1]Environment information: Python"+version+" "+plat+"\n")
|
||||
print("[2]Document URL: "+"\n")
|
||||
print("Main Station:https://pinpong.readthedocs.io"+"\n")
|
||||
print("Mirror station:https://pinpong.gitee.io"+"\n")
|
||||
print("[3]Commands:")
|
||||
print(" pinpong Help information for pinpong library")
|
||||
print(" pinpong libs list List of pinpong libraries")
|
||||
print(" pinpong libs xxx How to use the xxx library\n")
|
||||
print("[4]Serial ports list:")
|
||||
plist = list(serial.tools.list_ports.comports())
|
||||
for port in plist:
|
||||
print(" ",port)
|
||||
elif cmd == "libs" and argc == 3:
|
||||
arg = sys.argv[2]
|
||||
if arg == "list":
|
||||
print("\n[-] Libs list:")
|
||||
items = descs.items()
|
||||
for key,_ in items:
|
||||
print(str(key).lower())
|
||||
else:
|
||||
if arg.upper() in descs:
|
||||
print("\n[-] How to import?: ")
|
||||
print(descs[arg.upper()]["import"])
|
||||
print("\n[-] API list ")
|
||||
print(descs[arg.upper()]["api"])
|
||||
else:
|
||||
print("[Err] Unknown lib: ",arg)
|
||||
else:
|
||||
print("\n[Err] Unknown command:", sys.argv[1])
|
||||
print("\n[-] Available commands")
|
||||
print(" pinpong Help information for pinpong library")
|
||||
print(" pinpong libs list List of modules currently supported by the pinpong library")
|
||||
print(" pinpong libs xxx How to use the xxx module")
|
||||
105
buildroot-2021.05/package/python-pinpong/pinpong/base/i2c.py
Normal file
105
buildroot-2021.05/package/python-pinpong/pinpong/base/i2c.py
Normal file
@ -0,0 +1,105 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import sys
|
||||
from contextlib import closing
|
||||
try:
|
||||
import posix
|
||||
from fcntl import ioctl
|
||||
except Exception:
|
||||
pass
|
||||
from ctypes import create_string_buffer, sizeof, c_int, byref, pointer, addressof, string_at
|
||||
|
||||
assert sys.version_info.major >= 3, __name__ + " is only supported on Python 3"
|
||||
|
||||
from ctypes import c_int, c_uint16, c_ushort, c_short, c_ubyte, c_char, POINTER, Structure
|
||||
|
||||
|
||||
class i2c_msg(Structure):
|
||||
|
||||
_fields_ = [
|
||||
('addr', c_uint16), #变量名和类型
|
||||
('flags', c_ushort),
|
||||
('len', c_short),
|
||||
('buf', POINTER(c_char))]
|
||||
|
||||
__slots__ = [name for name,type in _fields_]
|
||||
|
||||
# i2c_msg flags
|
||||
I2C_M_TEN = 0x0010 # this is a ten bit chip address
|
||||
I2C_M_RD = 0x0001 # read data, from slave to master
|
||||
I2C_M_NOSTART = 0x4000 # if I2C_FUNC_PROTOCOL_MANGLING
|
||||
I2C_M_REV_DIR_ADDR = 0x2000 # if I2C_FUNC_PROTOCOL_MANGLING
|
||||
I2C_M_IGNORE_NAK = 0x1000 # if I2C_FUNC_PROTOCOL_MANGLING
|
||||
I2C_M_NO_RD_ACK = 0x0800 # if I2C_FUNC_PROTOCOL_MANGLING
|
||||
I2C_M_RECV_LEN = 0x0400 # length will be first received byte
|
||||
|
||||
class i2c_rdwr_data(Structure):
|
||||
|
||||
_fields_ = [
|
||||
('msgs', POINTER(i2c_msg)),
|
||||
('nmsgs', c_int)]
|
||||
|
||||
__slots__ = [name for name,type in _fields_]
|
||||
|
||||
I2C_FUNC_I2C = 0x00000001
|
||||
I2C_FUNC_10BIT_ADDR = 0x00000002
|
||||
I2C_FUNC_PROTOCOL_MANGLING = 0x00000004 # I2C_M_NOSTART etc.
|
||||
|
||||
I2C_SLAVE = 0x0703 # Change slave address
|
||||
# Attn.: Slave address is 7 or 10 bits
|
||||
I2C_SLAVE_FORCE = 0x0706 # Change slave address
|
||||
# Attn.: Slave address is 7 or 10 bits
|
||||
# This changes the address, even if it
|
||||
# is already taken!
|
||||
I2C_TENBIT = 0x0704 # 0 for 7 bit addrs, != 0 for 10 bit
|
||||
I2C_FUNCS = 0x0705 # Get the adapter functionality
|
||||
I2C_RDWR = 0x0707 # Combined R/W transfer (one stop only)
|
||||
|
||||
class I2CTrans(object):
|
||||
|
||||
def __init__(self, n, extra_open_flags=0):
|
||||
self.fd = posix.open("/dev/i2c-%i"%n, posix.O_RDWR|extra_open_flags)
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
self.close()
|
||||
|
||||
def close(self):
|
||||
posix.close(self.fd)
|
||||
|
||||
def read(self, msgs, read_byte):
|
||||
value = self.transfer(msgs)
|
||||
read_buf = []
|
||||
for i in range(read_byte): #返回字节数组列表,进行数据处理
|
||||
read_buf.append(value[0][i])
|
||||
return read_buf
|
||||
|
||||
def read_mem(self, msgs, read_byte):
|
||||
value = self.transfer(*msgs)
|
||||
read_buf = []
|
||||
for i in range(read_byte): #返回字节数组列表,进行数据处理
|
||||
read_buf.append(value[0][i])
|
||||
return read_buf
|
||||
|
||||
def transfer(self, *msgs):
|
||||
msg_count = len(msgs)
|
||||
msg_array = (i2c_msg*msg_count)(*msgs)
|
||||
ioctl_arg = i2c_rdwr_data(msgs=msg_array, nmsgs=msg_count)
|
||||
ioctl(self.fd, I2C_RDWR, ioctl_arg)
|
||||
read_data = [string_at(m.buf, m.len) for m in msgs if (m.flags & I2C_M_RD)]
|
||||
return read_data
|
||||
|
||||
def reading(addr, n_bytes):
|
||||
|
||||
buf = create_string_buffer(n_bytes)
|
||||
return i2c_msg(addr=addr, flags=I2C_M_RD, len=sizeof(buf), buf=buf)
|
||||
|
||||
|
||||
def writing(addr, byte_seq):
|
||||
|
||||
byte_seq = tuple(byte_seq)
|
||||
buf = bytes(byte_seq)
|
||||
buf = create_string_buffer(buf,len(buf))
|
||||
a = i2c_msg(addr=addr, flags=0, len=sizeof(buf), buf=buf)
|
||||
return a
|
||||
@ -0,0 +1,83 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
from pinpong.base.programmer import *
|
||||
|
||||
class Microbit(Programmer):
|
||||
def __init__(self, port="/dev/ttyS1", baudrate=115200):
|
||||
super().__init__(port, baudrate)
|
||||
|
||||
def setup(self):
|
||||
print("Microbit setup %s"%self.port)
|
||||
|
||||
def initialize(self):
|
||||
global logger
|
||||
print("initialize")
|
||||
|
||||
def display(self):
|
||||
if sys.platform == 'win32':
|
||||
try:
|
||||
disks = subprocess.Popen(
|
||||
"wmic logicaldisk get deviceid, description", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.read().decode('utf-8').split("\n")
|
||||
except Exception:
|
||||
disks = subprocess.Popen(
|
||||
"wmic logicaldisk get deviceid, description", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.read().decode('gbk').split("\n")
|
||||
for disk in disks:
|
||||
if 'Removable' in disk or '可移动磁盘' in disk:
|
||||
d=re.search(r'\w:', disk).group()
|
||||
diskname = subprocess.Popen(
|
||||
"wmic logicaldisk where name='%s' get volumename"%(d), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.read().decode('utf-8').split("\n")
|
||||
if "MICROBIT" in diskname[1]:
|
||||
self.mount_point = d+"/"
|
||||
elif sys.platform == 'linux':
|
||||
message=""
|
||||
with open('/proc/mounts', 'r') as f:
|
||||
while True:
|
||||
l = f.readline()
|
||||
if l == "":
|
||||
break
|
||||
elif "MICROBIT" in l:
|
||||
message=l
|
||||
if message != "":
|
||||
self.mount_point = message.split(" ")[1]+"/"
|
||||
elif sys.platform == 'darwin':
|
||||
result = subprocess.Popen(
|
||||
"ls /Volumes", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.read().decode('utf-8').split()
|
||||
if 'MICROBIT' in result:
|
||||
self.mount_point = "/Volumes/MICROBIT/"
|
||||
else:
|
||||
self.mount_point = None
|
||||
return True if self.mount_point else False
|
||||
|
||||
def read_sig_bytes(self):
|
||||
pass
|
||||
|
||||
def enable(self):
|
||||
pass
|
||||
|
||||
def program_enable(self):
|
||||
global logger
|
||||
pass
|
||||
|
||||
def burn(self):
|
||||
if self.mount_point is not None:
|
||||
if sys.platform == "win32":
|
||||
self.filename = self.filename.replace("\\","/")
|
||||
filename = self.filename[self.filename.rfind("/")+1:]
|
||||
path = self.filename[0:self.filename.rfind("/")+1]
|
||||
cmd = "robocopy " + path + " " + self.mount_point + " " + filename + " /NFL /NDL /NJH /NJS /nc /ns /np" #debug 不显示复制信息
|
||||
os.system(cmd)
|
||||
|
||||
else:
|
||||
if 'V2' in self.filename:
|
||||
os.system("cp "+ self.filename +" " + self.mount_point) #debug
|
||||
time.sleep(14)
|
||||
else:
|
||||
os.system("cp "+ self.filename +" " + self.mount_point)
|
||||
time.sleep(9)
|
||||
def disable(self):
|
||||
pass
|
||||
BIN
buildroot-2021.05/package/python-pinpong/pinpong/base/msyh.ttf
Normal file
BIN
buildroot-2021.05/package/python-pinpong/pinpong/base/msyh.ttf
Normal file
Binary file not shown.
@ -0,0 +1,92 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Copyright (c) 2015-2017 Alan Yorinks All rights reserved.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3 as published by the Free Software Foundation; either
|
||||
or (at your option) any later version.
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
"""
|
||||
|
||||
|
||||
class PinData:
|
||||
"""
|
||||
Each analog and digital input pin is described by an instance of
|
||||
this class. It contains both the last data value received and a potential
|
||||
callback reference. It may also contain a callback differential that if met
|
||||
will cause a callback to occur. The differential pertains to non-digital
|
||||
inputs.
|
||||
"""
|
||||
|
||||
def __init__(self, data_lock):
|
||||
self.data_lock = data_lock
|
||||
# current data value
|
||||
self._current_value = 0
|
||||
# time stamp of last change event
|
||||
self._event_time = 0
|
||||
# callback reference
|
||||
self._cb = None
|
||||
# analog differential
|
||||
self._differential = 1
|
||||
# digital pin was set as a pullup pin
|
||||
self._pull_up = False
|
||||
#修饰符学习
|
||||
@property
|
||||
def current_value(self):
|
||||
with self.data_lock:
|
||||
return self._current_value
|
||||
|
||||
@current_value.setter
|
||||
def current_value(self, value):
|
||||
with self.data_lock:
|
||||
self._current_value = value
|
||||
|
||||
@property
|
||||
def event_time(self):
|
||||
with self.data_lock:
|
||||
return self._event_time
|
||||
|
||||
@event_time.setter
|
||||
def event_time(self, value):
|
||||
with self.data_lock:
|
||||
self._event_time = value
|
||||
|
||||
@property
|
||||
def cb(self):
|
||||
with self.data_lock:
|
||||
return self._cb
|
||||
|
||||
@cb.setter
|
||||
def cb(self, value):
|
||||
with self.data_lock:
|
||||
self._cb = value
|
||||
|
||||
@property
|
||||
def differential(self):
|
||||
with self.data_lock:
|
||||
return self._differential
|
||||
|
||||
@differential.setter
|
||||
def differential(self, value):
|
||||
with self.data_lock:
|
||||
self._differential = value
|
||||
|
||||
@property
|
||||
def pull_up(self):
|
||||
with self.data_lock:
|
||||
return self._pull_up
|
||||
|
||||
@pull_up.setter
|
||||
def pull_up(self, value):
|
||||
with self.data_lock:
|
||||
self._pull_up = value
|
||||
|
||||
|
||||
@ -0,0 +1,211 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Copyright (c) 2015-2019 Alan Yorinks All rights reserved.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3 as published by the Free Software Foundation; either
|
||||
or (at your option) any later version.
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
"""
|
||||
|
||||
|
||||
class PrivateConstants:
|
||||
"""
|
||||
This class contains a set of constants for PyMata internal use .
|
||||
"""
|
||||
# the following defines are from FirmataExpress.h
|
||||
# message command bytes (128-255/ 0x80- 0xFF)
|
||||
# from this client to firmata
|
||||
MSG_CMD_MIN = 0x80 # minimum value for a message from firmata
|
||||
REPORT_ANALOG = 0xC0 # enable analog input by pin #
|
||||
REPORT_DIGITAL = 0xD0 # enable digital input by port pair
|
||||
SET_PIN_MODE = 0xF4 # set a pin to INPUT/OUTPUT/PWM/etc
|
||||
SET_DIGITAL_PIN_VALUE = 0xF5 # set a single digital pin value instead of entire port
|
||||
START_SYSEX = 0xF0 # start a MIDI Sysex message
|
||||
END_SYSEX = 0xF7 # end a MIDI Sysex message
|
||||
SYSTEM_RESET = 0xFF # reset from MIDI
|
||||
|
||||
# messages from firmata
|
||||
DIGITAL_MESSAGE = 0x90 # send or receive data for a digital pin
|
||||
ANALOG_MESSAGE = 0xE0 # send or receive data for a PWM configured pin
|
||||
PWM_MESSAGE = 0xE0 # Firmata confusingly conflates analog input with PWM output
|
||||
SERVO_MESSAGE = 0xE0
|
||||
REPORT_VERSION = 0xF9 # report protocol version
|
||||
|
||||
# start of FirmataExpress defined SYSEX commands
|
||||
NEOPIXEL_DATA = 0x30 # NEOPIXEL message
|
||||
NEOPIXEL_CONFIG = 0x31
|
||||
KEEP_ALIVE = 0x50 # keep alive message
|
||||
ARE_YOU_THERE = 0x51 # poll for boards existence
|
||||
I_AM_HERE = 0x52 # response to poll
|
||||
TONE_DATA = 0x5F # play a tone at a specified frequency and duration
|
||||
SONAR_CONFIG = 0x62 # configure pins to control a sonar distance device
|
||||
SONAR_DATA = 0x63 # distance data returned
|
||||
# end of FirmataExpress defined SYSEX commands
|
||||
|
||||
SERVO_CONFIG = 0x70 # set servo pin and max and min angles
|
||||
STRING_DATA = 0x71 # a string message with 14-bits per char
|
||||
STEPPER_DATA = 0x72 # Stepper motor command
|
||||
I2C_REQUEST = 0x76 # send an I2C read/write request
|
||||
I2C_REPLY = 0x77 # a reply to an I2C read request
|
||||
I2C_CONFIG = 0x78 # config I2C settings such as delay times and power pins
|
||||
REPORT_FIRMWARE = 0x79 # report name and version of the firmware
|
||||
SAMPLING_INTERVAL = 0x7A # modify the sampling interval
|
||||
RESERVED_1 = 0x7B
|
||||
|
||||
EXTENDED_PWM = 0x6F # analog write (PWM, Servo, etc) to any pin
|
||||
PIN_STATE_QUERY = 0x6D # ask for a pin's current mode and value
|
||||
PIN_STATE_RESPONSE = 0x6E # reply with pin's current mode and value
|
||||
CAPABILITY_QUERY = 0x6B # ask for supported modes of all pins
|
||||
CAPABILITY_RESPONSE = 0x6C # reply with supported modes and resolution
|
||||
ANALOG_MAPPING_QUERY = 0x69 # ask for mapping of analog to pin numbers
|
||||
ANALOG_MAPPING_RESPONSE = 0x6A # reply with analog mapping data
|
||||
|
||||
# reserved values
|
||||
SYSEX_NON_REALTIME = 0x7E # MIDI Reserved for non-realtime messages
|
||||
SYSEX_REALTIME = 0x7F # MIDI Reserved for realtime messages
|
||||
|
||||
# reserved for PyMata
|
||||
PYMATA_EXPRESS_THREADED_VERSION = "1.4"
|
||||
|
||||
# each byte represents a digital port
|
||||
# and its value contains the current port settings
|
||||
DIGITAL_OUTPUT_PORT_PINS = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
|
||||
|
||||
# These values are the index into the data passed by _arduino and
|
||||
# used to reassemble integer values
|
||||
MSB = 2
|
||||
LSB = 1
|
||||
|
||||
# enable reporting for REPORT_ANALOG or REPORT_DIGITAL message
|
||||
# sent to firmata
|
||||
REPORTING_ENABLE = 1
|
||||
# disable reporting for REPORT_ANALOG or REPORT_DIGITAL message
|
||||
# sent to firmata
|
||||
REPORTING_DISABLE = 0
|
||||
|
||||
# Stepper Motor Sub-commands
|
||||
STEPPER_CONFIGURE = 0 # configure a stepper motor for operation
|
||||
STEPPER_STEP = 1 # command a motor to move at the provided speed
|
||||
STEPPER_LIBRARY_VERSION = 2 # used to get stepper library version number
|
||||
|
||||
# pin modes
|
||||
INPUT = 0x00 # pin set as input
|
||||
OUTPUT = 0x01 # pin set as output
|
||||
ANALOG = 0x02 # analog pin in analogInput mode
|
||||
PWM = 0x03 # digital pin in PWM output mode
|
||||
SERVO = 0x04 # digital pin in Servo output mode
|
||||
I2C = 0x06 # pin included in I2C setup
|
||||
STEPPER = 0x08 # any pin in stepper mode
|
||||
SERIAL = 0x0a
|
||||
PULLUP = 0x0b # Any pin in pullup mode
|
||||
SONAR = 0x0c # Any pin in SONAR mode
|
||||
TONE = 0x0d # Any pin in tone mode
|
||||
PIXY = 0x0e # reserved for pixy camera mode
|
||||
DHT = 0x0f # DHT sensor
|
||||
NEOPIXEL = 0x60 # Any pin in neopixel mode
|
||||
UART = 0x61 # uart mode
|
||||
IGNORE = 0x7f
|
||||
|
||||
# Tone commands
|
||||
TONE_TONE = 0 # play a tone
|
||||
TONE_NO_TONE = 1 # turn off tone
|
||||
|
||||
# DHT command
|
||||
DHT_CONFIG = 0x64 # dht config command
|
||||
DHT_DATA = 0x65 # dht sensor command
|
||||
###
|
||||
|
||||
# I2C command operation modes
|
||||
I2C_WRITE = 0B00000000
|
||||
I2C_READ = 0B00001000
|
||||
I2C_READ_CONTINUOUSLY = 0B00010000
|
||||
I2C_STOP_READING = 0B00011000
|
||||
I2C_READ_WRITE_MODE_MASK = 0B00011000
|
||||
I2C_10BIT_ADDRESS_MODE_MASK = 0B00100000
|
||||
I2C_END_TX_MASK = 0B01000000
|
||||
I2C_STOP_TX = 1
|
||||
I2C_RESTART_TX = 0
|
||||
|
||||
IRQ_FALLING = 2
|
||||
IRQ_RISING = 1
|
||||
|
||||
DFROBOT_MESSAGE = 0x0D
|
||||
SUB_MESSAGE_DFROBOT_ESP32_REPORTS = 0x0A
|
||||
SUB_MESSAGE_DFROBOT_MICROBIT_REPORTS = 0x0B
|
||||
SUB_MESSAGE_DFROBOT_GD32V_REPORTS = 0x0C
|
||||
SUB_MESSAGE_IR = 0x00
|
||||
SUB_MESSAGE_PULSE = 0x03
|
||||
SUB_MESSAGE_MILLIS = 0x04
|
||||
SUB_MESSAGE_I2CSCAN = 0x0E
|
||||
SUB_MESSAGE_DS18B20 = 0x11
|
||||
SUB_MESSAGE_VIBRATION = 0x15
|
||||
SUB_MESSAGE_RESET = 0x7f
|
||||
SUB_MESSAGE_NEOPIXEL = 0x17
|
||||
SUB_MESSAGE_18B20 = 0x19
|
||||
SUB_MESSAGE_GP2Y1010AU0F = 0x58
|
||||
SUB_MESSAGE_AUDIO = 0x21
|
||||
SUB_MESSAGE_HX711 = 0x23
|
||||
SUB_MESSAGE_HEARTRATE = 0x25
|
||||
SUB_MESSAGE_UART_READ = 0x26
|
||||
|
||||
|
||||
SUB_REPORT_FLAG = 0x20
|
||||
SUB_MESSAGE_OLED12864 = 0x16
|
||||
SUB_MESSAGE_WS2812 = 0x14
|
||||
SUB_MESSAGE_SOUND = 0x09
|
||||
SOUND_SETTICKSTEMPO = 0x06
|
||||
SOUND_PLAYNOTE = 0x01
|
||||
|
||||
SUB_MICROBIT_REPORT_FLAG = 0x2A
|
||||
|
||||
SUB_MESSAGE_ssid = 0x40
|
||||
SUB_MESSAGE_password = 0x41
|
||||
SUB_MESSAGE_CONNECT_WIFI = 0x43
|
||||
SUB_MESSAGE_CONNECT_PESPOND = 0x50
|
||||
|
||||
SUB_MESSAGE_MATRIX = 0x05
|
||||
MATRIX_SHOWBITMAP = 0x03
|
||||
MATRIX_SHOWSTRING = 0x04
|
||||
MATRIX_DRAWPIXEL = 0x00
|
||||
MATRIX_CLEAR = 0x02
|
||||
SUB_MESSAGE_SOUND = 0x09
|
||||
SOUND_PLAYSOUND = 0x00
|
||||
SOUND_SETSPEED = 0x03
|
||||
CAL_COMPASS = 0x14
|
||||
SUB_MESSAGE_WIRELESS = 0x10
|
||||
|
||||
HX711_INIT = 0x07
|
||||
HX711_READ = 0x0A
|
||||
AUDIO_VALUE = 0X07
|
||||
AUDIO_INIT = 0x16
|
||||
AUDIO_read = 0x12
|
||||
DS18B20_READ = 0x09
|
||||
SERVO_CONTROL = 0x56
|
||||
UART_CONFIG = 0x0C
|
||||
UART_WRITE = 0x0D
|
||||
UART_READ = 0x0E
|
||||
UART_DEINIT = 0x0F
|
||||
|
||||
SUB_MESSAGE_OLED = 0x30
|
||||
|
||||
MODE_8N1 = 0x00
|
||||
SUB_MESSAGE_SOUND = 0x09
|
||||
SUB_MESSAGE_COMPASS = 0x14
|
||||
|
||||
SUB_MESSAGE_BUZZ = 0x55
|
||||
|
||||
SUB_MESSAGE_SPI_INIT = 0x32
|
||||
SUB_MESSAGE_SPI_SENDTO = 0x33
|
||||
SUB_MESSAGE_SPI_RECVFROM = 0x34
|
||||
SUB_MESSAGE_SPI = 0x35
|
||||
|
||||
@ -0,0 +1,160 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import serial
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger()
|
||||
baudrate=9600
|
||||
programmer = ""
|
||||
verbose=0
|
||||
sys_config=""
|
||||
partdesc="" #part id
|
||||
port=""
|
||||
upd={}
|
||||
|
||||
class Programmer:
|
||||
def __init__(self,port,baudrate):
|
||||
self.port = port
|
||||
self.baudrate = baudrate
|
||||
#print("Programmer init")
|
||||
|
||||
def rdy_led(self):
|
||||
pass
|
||||
|
||||
def err_led(self):
|
||||
pass
|
||||
|
||||
def pgm_led(self):
|
||||
pass
|
||||
|
||||
def vfy_led(self):
|
||||
pass
|
||||
|
||||
def initialize(self):
|
||||
pass
|
||||
|
||||
def drain(self):
|
||||
self.ser.read(self.ser.in_waiting)
|
||||
|
||||
def display(self):
|
||||
print("open port:%s baudrate:%d"%(self.port, self.baudrate))
|
||||
try:
|
||||
self.ser=serial.Serial(self.port, self.baudrate, timeout=0.5)
|
||||
return True;
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return False
|
||||
|
||||
def enable(self):
|
||||
pass
|
||||
|
||||
def disable(self):
|
||||
pass
|
||||
|
||||
def powerup(self):
|
||||
pass
|
||||
|
||||
def powerdown(self):
|
||||
pass
|
||||
|
||||
def program_enable(self):
|
||||
pass
|
||||
|
||||
def chip_erase(self):
|
||||
pass
|
||||
|
||||
def cmd(self):
|
||||
pass
|
||||
|
||||
def cmd_tpi(self):
|
||||
pass
|
||||
|
||||
def open(self):
|
||||
pass
|
||||
|
||||
def close(self):
|
||||
pass
|
||||
|
||||
def paged_write(self):
|
||||
pass
|
||||
|
||||
def paged_load(self):
|
||||
pass
|
||||
|
||||
def write_setup(self):
|
||||
pass
|
||||
|
||||
def write_byte(self):
|
||||
pass
|
||||
|
||||
def read_byte(self):
|
||||
pass
|
||||
|
||||
def read_sig_bytes(self):
|
||||
pass
|
||||
|
||||
def print_parms(self):
|
||||
pass
|
||||
|
||||
def set_vtarget(self):
|
||||
pass
|
||||
|
||||
def set_varef(self):
|
||||
pass
|
||||
|
||||
def set_fosc(self):
|
||||
pass
|
||||
|
||||
def set_sck_period(self):
|
||||
pass
|
||||
|
||||
def setpin(self):
|
||||
pass
|
||||
|
||||
def getpin(self):
|
||||
pass
|
||||
|
||||
def highpulsepin(self):
|
||||
pass
|
||||
|
||||
def parseexitspecs(self):
|
||||
pass
|
||||
|
||||
def perform_osccal(self):
|
||||
pass
|
||||
|
||||
def parseextparams(self):
|
||||
pass
|
||||
|
||||
def setup(self):
|
||||
print("Programmer setup at %s"%self.port)
|
||||
|
||||
def teardown(self):
|
||||
pass
|
||||
|
||||
def ihex2b(self,filename):
|
||||
global logger
|
||||
ihex={}
|
||||
chksum = 0
|
||||
logger.info(filename)
|
||||
file = open(filename, 'rb')
|
||||
logger.info(file)
|
||||
self.buffer=bytearray()
|
||||
while True:
|
||||
line = file.readline()
|
||||
if(line):
|
||||
if(line[0] != 58):
|
||||
continue
|
||||
else:
|
||||
line=line[1:-2]
|
||||
sline=line.decode()
|
||||
b = bytearray.fromhex(sline)
|
||||
ihex["reclen"]=b[0]
|
||||
ihex["loadofs"]=b[1]*255+b[2]
|
||||
ihex["rectyp"]=b[3]
|
||||
ihex["data"] = b[4:-1]
|
||||
ihex["cksum"] = b[-1]
|
||||
chksum = (-sum(bytes(b[:-1])))&0x0ff
|
||||
self.buffer = self.buffer + ihex["data"]
|
||||
else:
|
||||
break
|
||||
|
||||
3204
buildroot-2021.05/package/python-pinpong/pinpong/base/pymata4.py
Normal file
3204
buildroot-2021.05/package/python-pinpong/pinpong/base/pymata4.py
Normal file
File diff suppressed because it is too large
Load Diff
230
buildroot-2021.05/package/python-pinpong/pinpong/base/stk500.py
Normal file
230
buildroot-2021.05/package/python-pinpong/pinpong/base/stk500.py
Normal file
@ -0,0 +1,230 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import serial
|
||||
from pinpong.base.stk500_param import *
|
||||
from pinpong.base.programmer import *
|
||||
|
||||
class STK500(Programmer):
|
||||
def __init__(self, port="/dev/ttyS1", baudrate=115200):
|
||||
super().__init__(port, baudrate)
|
||||
|
||||
def setup(self):
|
||||
print("STK500 setup %s"%self.port)
|
||||
|
||||
def initialize(self):
|
||||
global logger
|
||||
print("initialize")
|
||||
stk500_devcode = 0x86
|
||||
sw_major = self.stk500_getparm(Parm_STK_SW_MAJOR) # 0x41 0x81 0x20 return 0x14 0x04 0x10
|
||||
sw_minor = self.stk500_getparm(Parm_STK_SW_MINOR) # 0x41 0x82 0x20 return 0x14 0x04 0x10
|
||||
buf = bytearray(32)
|
||||
#Cmnd_STK_SET_DEVICE # 42 86 00 00 01 01 01 01 03 ff ff ff ff 00 80 04 00 00 00 80 00 20
|
||||
buf[0] = Cmnd_STK_SET_DEVICE
|
||||
buf[1] = stk500_devcode
|
||||
buf[2] = 0
|
||||
buf[3] = 0
|
||||
|
||||
buf[4] = 1
|
||||
buf[5] = 1
|
||||
buf[6] = 1
|
||||
buf[7] = 1
|
||||
|
||||
buf[8] = 0x03 #fuse size
|
||||
buf[9] = 0xFF #
|
||||
buf[10] = 0xFF #
|
||||
buf[11] = 0xFF #
|
||||
|
||||
buf[12] = 0xFF #
|
||||
buf[13] = 0x00 #
|
||||
buf[14] = 0x80 #
|
||||
buf[15] = 0x04 #
|
||||
|
||||
buf[16] = 0x00 #
|
||||
buf[17] = 0x00 #
|
||||
buf[18] = 0x00 #
|
||||
buf[19] = 0x80 #
|
||||
buf[20] = 0x00 #
|
||||
buf[21] = Sync_CRC_EOP;
|
||||
self.ser.write(buf[:22])
|
||||
res = self.ser.read(1)
|
||||
logger.info(res)
|
||||
res = self.ser.read(1)
|
||||
logger.info(res)
|
||||
|
||||
buf[0] = Cmnd_STK_SET_DEVICE_EXT #45 05 04 d7 c2 00 20
|
||||
buf[1] = 0x05 #n_extparms+1
|
||||
buf[2] = 0x04 #page_size;
|
||||
buf[3] = 0xD7 #pagel;
|
||||
|
||||
buf[4] = 0xC2 #bs2;
|
||||
buf[5] = 0x00 #reset_disposition == RESET_DEDICATED
|
||||
buf[6] = Sync_CRC_EOP
|
||||
self.ser.write(buf[:7])
|
||||
res = self.ser.read(1)
|
||||
logger.info(res)
|
||||
res = self.ser.read(1)
|
||||
logger.info(res)
|
||||
self.program_enable()
|
||||
|
||||
def stk500_cmd(self,cmd):
|
||||
global logger
|
||||
buf = bytearray(16)
|
||||
buf[0] = Cmnd_STK_UNIVERSAL
|
||||
buf[1] = cmd[0]
|
||||
buf[2] = cmd[1]
|
||||
buf[3] = cmd[2]
|
||||
buf[4] = cmd[3]
|
||||
buf[5] = Sync_CRC_EOP
|
||||
self.ser.write(buf[:6])
|
||||
res = self.ser.read(1)
|
||||
logger.info(res)
|
||||
res = self.ser.read(1)
|
||||
logger.info(res)
|
||||
res = self.ser.read(1)
|
||||
logger.info(res)
|
||||
|
||||
def stk500_getparm(self,param):
|
||||
global logger
|
||||
buf = bytearray(16)
|
||||
buf[0] = Cmnd_STK_GET_PARAMETER;
|
||||
buf[1] = param;
|
||||
buf[2] = Sync_CRC_EOP;
|
||||
self.ser.write(buf[:3])
|
||||
res = self.ser.read(1)
|
||||
logger.info(res)
|
||||
ret = self.ser.read(1)
|
||||
logger.info(ret)
|
||||
res = self.ser.read(1)
|
||||
logger.info(res)
|
||||
return ret
|
||||
|
||||
def display(self):
|
||||
global logger,baudrate
|
||||
self.ser=serial.Serial(self.port, self.baudrate, timeout=0.5)
|
||||
retry = 5
|
||||
|
||||
while retry != 0:
|
||||
retry = retry - 1
|
||||
self.ser.read(self.ser.in_waiting)
|
||||
b = bytearray()
|
||||
b.append(Cmnd_STK_GET_SYNC)
|
||||
b.append(Sync_CRC_EOP)
|
||||
self.ser.write(bytes(b))
|
||||
res = self.ser.read(1)
|
||||
|
||||
if(len(res) == 0):
|
||||
continue
|
||||
|
||||
logger.info(res)
|
||||
if(res[0] != Resp_STK_INSYNC):
|
||||
continue
|
||||
res = self.ser.read(1)
|
||||
if(res[0] != Resp_STK_OK):
|
||||
continue
|
||||
logger.info(res)
|
||||
break
|
||||
logger.info("retry=%d"%retry)
|
||||
|
||||
if retry == 0:
|
||||
return False
|
||||
|
||||
hwv = self.stk500_getparm(Parm_STK_HW_VER)
|
||||
sw_major = self.stk500_getparm(Parm_STK_SW_MAJOR)
|
||||
sw_minor = self.stk500_getparm(Parm_STK_SW_MINOR)
|
||||
topcard = self.stk500_getparm(Param_STK500_TOPCARD_DETECT)
|
||||
vtarget = self.stk500_getparm(Parm_STK_VTARGET)
|
||||
vadjust = self.stk500_getparm(Parm_STK_VADJUST)
|
||||
pscale = self.stk500_getparm(Parm_STK_OSC_PSCALE)
|
||||
cmatch = self.stk500_getparm(Parm_STK_OSC_CMATCH)
|
||||
duration = self.stk500_getparm(Parm_STK_SCK_DURATION)
|
||||
|
||||
logger.info(hwv)
|
||||
logger.info(sw_major)
|
||||
logger.info(sw_minor)
|
||||
logger.info(topcard)
|
||||
|
||||
return True
|
||||
|
||||
def read_sig_bytes(self):
|
||||
global logger
|
||||
buf = bytearray(16)
|
||||
buf[0] = Cmnd_STK_READ_SIGN
|
||||
buf[1] = Sync_CRC_EOP
|
||||
|
||||
self.ser.write(buf[:2])
|
||||
|
||||
res = self.ser.read(1)
|
||||
logger.info(res)
|
||||
res = self.ser.read(1)
|
||||
logger.info(res)
|
||||
res = self.ser.read(1)
|
||||
logger.info(res)
|
||||
res = self.ser.read(1)
|
||||
logger.info(res)
|
||||
res = self.ser.read(1)
|
||||
logger.info(res)
|
||||
|
||||
def enable(self):
|
||||
self.stk500_cmd([0x58, 0x08, 0x00, 0x00])
|
||||
self.stk500_cmd([0x50, 0x08, 0x00, 0x00])
|
||||
self.stk500_cmd([0xa0, 0x03, 0xfc, 0x00])
|
||||
self.stk500_cmd([0xa0, 0x03, 0xfd, 0x00])
|
||||
self.stk500_cmd([0xa0, 0x03, 0xfe, 0x00])
|
||||
self.stk500_cmd([0xa0, 0x03, 0xff, 0x00])
|
||||
|
||||
def program_enable(self):
|
||||
global logger
|
||||
buf = bytearray(16)
|
||||
buf[0] = Cmnd_STK_ENTER_PROGMODE
|
||||
buf[1] = Sync_CRC_EOP
|
||||
|
||||
self.ser.write(buf[:2])
|
||||
res = self.ser.read(1)
|
||||
logger.info(res)
|
||||
res = self.ser.read(1)
|
||||
logger.info(res)
|
||||
|
||||
def burn(self):
|
||||
global logger
|
||||
page_size = 128
|
||||
addr = 0
|
||||
total_len = len(self.buffer)
|
||||
logger.info("total_len=%d"%(total_len))
|
||||
while(addr < total_len):
|
||||
block_size = page_size if addr+page_size <= total_len else total_len%page_size
|
||||
b=bytearray()
|
||||
b.append(Cmnd_STK_PROG_PAGE)
|
||||
b.append((block_size>>8) & 0xff)
|
||||
b.append((block_size) & 0xff)
|
||||
b.append(0x46) ######TODO
|
||||
b = b + self.buffer[addr:addr+block_size]
|
||||
b.append(Sync_CRC_EOP)
|
||||
|
||||
buf = bytearray(4)
|
||||
buf[0] = Cmnd_STK_LOAD_ADDRESS
|
||||
buf[1] = (addr>>1) & 0xff
|
||||
buf[2] = ((addr>>1) >> 8) & 0xff
|
||||
buf[3] = Sync_CRC_EOP
|
||||
self.ser.write(buf)
|
||||
res = self.ser.read(1)
|
||||
logger.info(res)
|
||||
res = self.ser.read(1)
|
||||
logger.info(res)
|
||||
|
||||
self.ser.write(bytes(b))
|
||||
res = self.ser.read(1)
|
||||
logger.info(res)
|
||||
res = self.ser.read(1)
|
||||
logger.info(res)
|
||||
|
||||
addr = addr + block_size
|
||||
|
||||
def disable(self):
|
||||
buf = bytearray(2)
|
||||
buf[0] = Cmnd_STK_LEAVE_PROGMODE;
|
||||
buf[1] = Sync_CRC_EOP;
|
||||
self.ser.write(buf)
|
||||
res = self.ser.read(1)
|
||||
logger.info(res)
|
||||
res = self.ser.read(1)
|
||||
logger.info(res)
|
||||
self.ser.close()
|
||||
@ -0,0 +1,79 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
STK_SIGN_ON_MESSAGE ="AVR STK" #// Sign on string for Cmnd_STK_GET_SIGN_ON
|
||||
|
||||
|
||||
Resp_STK_OK = 0x10 # ' '
|
||||
Resp_STK_FAILED = 0x11 # ' '
|
||||
Resp_STK_UNKNOWN = 0x12 # ' '
|
||||
Resp_STK_NODEVICE = 0x13 # ' '
|
||||
Resp_STK_INSYNC = 0x14 # ' '
|
||||
Resp_STK_NOSYNC = 0x15 # ' '
|
||||
|
||||
Resp_ADC_CHANNEL_ERROR = 0x16 # ' '
|
||||
Resp_ADC_MEASURE_OK = 0x17 # ' '
|
||||
Resp_PWM_CHANNEL_ERROR = 0x18 # ' '
|
||||
Resp_PWM_ADJUST_OK = 0x19 # ' '
|
||||
|
||||
Sync_CRC_EOP = 0x20 # 'SPACE'
|
||||
|
||||
Cmnd_STK_GET_SYNC = 0x30 # ' '
|
||||
Cmnd_STK_GET_SIGN_ON = 0x31 # ' '
|
||||
|
||||
Cmnd_STK_SET_PARAMETER = 0x40 # ' '
|
||||
Cmnd_STK_GET_PARAMETER = 0x41 # ' '
|
||||
Cmnd_STK_SET_DEVICE = 0x42 # ' '
|
||||
Cmnd_STK_SET_DEVICE_EXT = 0x45 # ' '
|
||||
|
||||
Cmnd_STK_ENTER_PROGMODE = 0x50 # ' '
|
||||
Cmnd_STK_LEAVE_PROGMODE = 0x51 # ' '
|
||||
Cmnd_STK_CHIP_ERASE = 0x52 # ' '
|
||||
Cmnd_STK_CHECK_AUTOINC = 0x53 # ' '
|
||||
Cmnd_STK_LOAD_ADDRESS = 0x55 # ' '
|
||||
Cmnd_STK_UNIVERSAL = 0x56 # ' '
|
||||
Cmnd_STK_UNIVERSAL_MULTI = 0x57 # ' '
|
||||
|
||||
Cmnd_STK_PROG_FLASH = 0x60 # ' '
|
||||
Cmnd_STK_PROG_DATA = 0x61 # ' '
|
||||
Cmnd_STK_PROG_FUSE = 0x62 # ' '
|
||||
Cmnd_STK_PROG_LOCK = 0x63 # ' '
|
||||
Cmnd_STK_PROG_PAGE = 0x64 # ' '
|
||||
Cmnd_STK_PROG_FUSE_EXT = 0x65 # ' '
|
||||
|
||||
Cmnd_STK_READ_FLASH = 0x70 # ' '
|
||||
Cmnd_STK_READ_DATA = 0x71 # ' '
|
||||
Cmnd_STK_READ_FUSE = 0x72 # ' '
|
||||
Cmnd_STK_READ_LOCK = 0x73 # ' '
|
||||
Cmnd_STK_READ_PAGE = 0x74 # ' '
|
||||
Cmnd_STK_READ_SIGN = 0x75 # ' '
|
||||
Cmnd_STK_READ_OSCCAL = 0x76 # ' '
|
||||
Cmnd_STK_READ_FUSE_EXT = 0x77 # ' '
|
||||
Cmnd_STK_READ_OSCCAL_EXT = 0x78 # ' '
|
||||
|
||||
Parm_STK_HW_VER = 0x80 # ' ' - R
|
||||
Parm_STK_SW_MAJOR = 0x81 # ' ' - R
|
||||
Parm_STK_SW_MINOR = 0x82 # ' ' - R
|
||||
Parm_STK_LEDS = 0x83 # ' ' - R/W
|
||||
Parm_STK_VTARGET = 0x84 # ' ' - R/W
|
||||
Parm_STK_VADJUST = 0x85 # ' ' - R/W
|
||||
Parm_STK_OSC_PSCALE = 0x86 # ' ' - R/W
|
||||
Parm_STK_OSC_CMATCH = 0x87 # ' ' - R/W
|
||||
Parm_STK_RESET_DURATION = 0x88 # ' ' - R/W
|
||||
Parm_STK_SCK_DURATION = 0x89 # ' ' - R/W
|
||||
|
||||
Parm_STK_BUFSIZEL = 0x90 # ' ' - R/W, Range {0..255}
|
||||
Parm_STK_BUFSIZEH = 0x91 # ' ' - R/W, Range {0..255}
|
||||
Parm_STK_DEVICE = 0x92 # ' ' - R/W, Range {0..255}
|
||||
Parm_STK_PROGMODE = 0x93 # ' ' - 'P' or 'S'
|
||||
Parm_STK_PARAMODE = 0x94 # ' ' - TRUE or FALSE
|
||||
Parm_STK_POLLING = 0x95 # ' ' - TRUE or FALSE
|
||||
Parm_STK_SELFTIMED = 0x96 # ' ' - TRUE or FALSE
|
||||
Param_STK500_TOPCARD_DETECT= 0x98 #/ ' ' - Detect top-card attached
|
||||
|
||||
Stat_STK_INSYNC = 0x01 # INSYNC status bit, '1' - INSYNC
|
||||
Stat_STK_PROGMODE = 0x02 # Programming mode, '1' - PROGMODE
|
||||
Stat_STK_STANDALONE = 0x04 # Standalone mode, '1' - SM mode
|
||||
Stat_STK_RESET = 0x08 # RESET button, '1' - Pushed
|
||||
Stat_STK_PROGRAM = 0x10 # Program button, ' 1' - Pushed
|
||||
Stat_STK_LEDG = 0x20 # Green LED status, '1' - Lit
|
||||
Stat_STK_LEDR = 0x40 # Red LED status, '1' - Lit
|
||||
Stat_STK_LEDBLINK = 0x80 # LED blink ON/OFF, '1' - Blink
|
||||
@ -0,0 +1,245 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import time
|
||||
import serial
|
||||
from pinpong.base.stk500v2_param import *
|
||||
from pinpong.base.programmer import *
|
||||
|
||||
class STK500V2(Programmer):
|
||||
def __init__(self, port="/dev/ttyS1", baudrate=115200):
|
||||
super().__init__(port, baudrate)
|
||||
|
||||
def setup(self):
|
||||
#print("STK500V2 setup %s"%self.port)
|
||||
self.command_sequence = 1
|
||||
|
||||
def stk500v2_send(self,_buf,length):
|
||||
buf = bytearray(275+6)
|
||||
buf[0] = MESSAGE_START
|
||||
buf[1] = self.command_sequence
|
||||
buf[2] = int(length/256)
|
||||
buf[3] = length%256
|
||||
buf[4] = TOKEN
|
||||
for i in range(length):
|
||||
buf[5+i] = _buf[i]
|
||||
buf[5+length] = 0
|
||||
for i in range(5+length):
|
||||
buf[5+length] ^= buf[i]
|
||||
self.ser.write(buf[:6+length])
|
||||
|
||||
def stk500v2_recv(self,maxsize):
|
||||
sSTART = 0
|
||||
sSEQNUM = 1
|
||||
sSIZE1 = 2
|
||||
sSIZE2 = 3
|
||||
sTOKEN = 4
|
||||
sDATA = 5
|
||||
sCSUM = 6
|
||||
sDONE = 7
|
||||
state =sSTART
|
||||
checksum = 0
|
||||
msglen = 0
|
||||
curlen = 0
|
||||
msg = bytearray(0)
|
||||
timeout = False
|
||||
tstart = int(time.time())
|
||||
while state is not sDONE and not timeout:
|
||||
res = self.ser.read(1)
|
||||
if len(res):
|
||||
checksum ^= res[0]
|
||||
if state == sSTART:
|
||||
if res[0] == MESSAGE_START:
|
||||
checksum = MESSAGE_START
|
||||
state = sSEQNUM
|
||||
elif state == sSEQNUM:
|
||||
if res[0] == self.command_sequence:
|
||||
state = sSIZE1
|
||||
else:
|
||||
state = sSTART
|
||||
elif state == sSIZE1:
|
||||
msglen = res[0]*256
|
||||
state = sSIZE2
|
||||
elif state == sSIZE2:
|
||||
msglen += res[0]
|
||||
state = sTOKEN
|
||||
elif state == sTOKEN:
|
||||
if res[0] == TOKEN:
|
||||
state = sDATA
|
||||
else:
|
||||
state = sSTART
|
||||
elif state == sDATA:
|
||||
msg.append(res[0])
|
||||
curlen += 1
|
||||
if curlen == msglen:
|
||||
state = sCSUM
|
||||
elif state == sCSUM:
|
||||
if checksum == 0:
|
||||
state = sDONE
|
||||
else:
|
||||
state = sSTART
|
||||
else:
|
||||
state = sSTART
|
||||
else:
|
||||
timeout = True
|
||||
tnow = int(time.time())
|
||||
if tnow - tstart > 2:
|
||||
timeout = True
|
||||
self.command_sequence = self.command_sequence+1
|
||||
return msg
|
||||
|
||||
def stk500v2_command(self,buf,len):
|
||||
self.stk500v2_send(buf,len)
|
||||
resp = self.stk500v2_recv(32)
|
||||
return resp
|
||||
|
||||
def stk500v2_getsync(self):
|
||||
retry = 5
|
||||
buf = bytearray(1)
|
||||
buf[0] = CMD_SIGN_ON
|
||||
|
||||
while retry:
|
||||
self.setup()
|
||||
retry = retry -1
|
||||
self.stk500v2_send(buf,1)
|
||||
resp = self.stk500v2_recv(32)
|
||||
if(len(resp) > 0):
|
||||
break
|
||||
|
||||
def initialize(self):
|
||||
global logger
|
||||
#print("initialize")
|
||||
#stk500_devcode = 0x86
|
||||
#sw_major = self.stk500_getparm(Parm_STK_SW_MAJOR) # 0x41 0x81 0x20 return 0x14 0x04 0x10
|
||||
#sw_minor = self.stk500_getparm(Parm_STK_SW_MINOR) # 0x41 0x82 0x20 return 0x14 0x04 0x10
|
||||
#buf = bytearray(32)
|
||||
#Cmnd_STK_SET_DEVICE # 42 86 00 00 01 01 01 01 03 ff ff ff ff 00 80 04 00 00 00 80 00 20
|
||||
|
||||
self.program_enable()
|
||||
|
||||
def stk500v2_cmd(self,cmd):
|
||||
global logger
|
||||
buf = bytearray(16)
|
||||
buf[0] = CMD_SPI_MULTI
|
||||
buf[1] = 4
|
||||
buf[2] = 4
|
||||
buf[3] = 0
|
||||
buf[4] = cmd[0]
|
||||
buf[5] = cmd[1]
|
||||
buf[6] = cmd[2]
|
||||
buf[7] = cmd[3]
|
||||
|
||||
res = self.stk500v2_command(buf, 8)
|
||||
logger.info(res)
|
||||
|
||||
def stk500v2_getparm(self,param):
|
||||
global logger
|
||||
buf = bytearray(2)
|
||||
buf[0] = CMD_GET_PARAMETER
|
||||
buf[1] = param
|
||||
ret = self.stk500v2_command(buf, 2)
|
||||
return ret[2]
|
||||
|
||||
def display(self):
|
||||
global logger,baudrate
|
||||
self.ser=serial.Serial(self.port, self.baudrate, timeout=0.5)
|
||||
self.stk500v2_getsync()
|
||||
hwv = self.stk500v2_getparm(PARAM_HW_VER)
|
||||
sw_major = self.stk500v2_getparm(PARAM_SW_MAJOR)
|
||||
sw_minor = self.stk500v2_getparm(PARAM_SW_MINOR)
|
||||
|
||||
#topcard = self.stk500v2_getparm(Param_STK500_TOPCARD_DETECT)
|
||||
vtarget = self.stk500v2_getparm(PARAM_VTARGET);
|
||||
#vadjust = self.stk500v2_getparm(Parm_STK_VADJUST);
|
||||
#pscale = self.stk500v2_getparm(Parm_STK_OSC_PSCALE);
|
||||
#cmatch = self.stk500v2_getparm(Parm_STK_OSC_CMATCH);
|
||||
#duration = self.stk500v2_getparm(Parm_STK_SCK_DURATION);
|
||||
logger.info(hwv)
|
||||
logger.info(sw_major)
|
||||
logger.info(sw_minor)
|
||||
logger.info(vtarget)
|
||||
#logger.info(topcard)
|
||||
return True
|
||||
|
||||
def read_sig_bytes(self):
|
||||
pass
|
||||
#global logger
|
||||
#buf = bytearray(16)
|
||||
#buf[0] = CMD_SPI_MULTI;
|
||||
#buf[1] = Sync_CRC_EOP;
|
||||
#stk500_cmd();
|
||||
#logger.info(res)
|
||||
|
||||
def enable(self):
|
||||
self.stk500v2_cmd([0x30, 0x00, 0x00, 0x00])
|
||||
self.stk500v2_cmd([0x30, 0x00, 0x01, 0x00])
|
||||
self.stk500v2_cmd([0x30, 0x00, 0x02, 0x00])
|
||||
|
||||
self.stk500v2_cmd([0x50, 0x00, 0x00, 0x00])
|
||||
self.stk500v2_cmd([0x50, 0x00, 0x00, 0x00])
|
||||
self.stk500v2_cmd([0x50, 0x00, 0x00, 0x00])
|
||||
|
||||
self.stk500v2_cmd([0x58, 0x08, 0x00, 0x00])
|
||||
self.stk500v2_cmd([0x58, 0x08, 0x00, 0x00])
|
||||
self.stk500v2_cmd([0x58, 0x08, 0x00, 0x00])
|
||||
|
||||
self.stk500v2_cmd([0x50, 0x08, 0x00, 0x00])
|
||||
self.stk500v2_cmd([0x50, 0x08, 0x00, 0x00])
|
||||
self.stk500v2_cmd([0x50, 0x08, 0x00, 0x00])
|
||||
|
||||
self.stk500v2_cmd([0xA0, 0x0F, 0xFC, 0x00])
|
||||
self.stk500v2_cmd([0xA0, 0x0F, 0xFD, 0x00])
|
||||
self.stk500v2_cmd([0xA0, 0x0F, 0xFE, 0x00])
|
||||
self.stk500v2_cmd([0xA0, 0x0F, 0xFF, 0x00])
|
||||
|
||||
def program_enable(self):
|
||||
global logger
|
||||
buf = bytearray(16)
|
||||
buf[0] = CMD_ENTER_PROGMODE_ISP
|
||||
buf[1] = 0xc8
|
||||
buf[2] = 0x64
|
||||
buf[3] = 0x19
|
||||
buf[4] = 0x20
|
||||
buf[5] = 0x00
|
||||
buf[6] = 0x53
|
||||
buf[7] = 0x03
|
||||
buf[8] = 0xac
|
||||
buf[9] = 0x53
|
||||
buf[10] = 0x00
|
||||
buf[11] = 0x00
|
||||
ret = self.stk500v2_command(buf,12)
|
||||
#print(ret)
|
||||
|
||||
def burn(self):
|
||||
global logger
|
||||
page_size = 256
|
||||
load_addr = 0x80000000
|
||||
total_len = len(self.buffer)
|
||||
logger.info("total_len=%d"%(total_len))
|
||||
left = total_len
|
||||
addr = 0
|
||||
if(total_len % page_size):
|
||||
for i in range(page_size- (total_len % page_size)):
|
||||
self.buffer.append(0xff)
|
||||
while(addr < total_len):
|
||||
b=bytearray()
|
||||
b.append(CMD_LOAD_ADDRESS)
|
||||
b.append((load_addr>>24) & 0xff)
|
||||
b.append((load_addr>>16) & 0xff)
|
||||
b.append((load_addr>>8) & 0xff)
|
||||
b.append((load_addr) & 0xff)
|
||||
self.stk500v2_command(b,5)
|
||||
|
||||
b=bytearray()
|
||||
b.append(CMD_PROGRAM_FLASH_ISP)
|
||||
b = b + bytearray([0x01,0x00, 0xc1,0x0a,0x40,0x4c, 0x20,0x00,0x00])
|
||||
b = b + self.buffer[addr:addr+page_size]
|
||||
self.stk500v2_command(b, page_size+10)
|
||||
load_addr += 0x80
|
||||
addr = addr + page_size
|
||||
|
||||
def disable(self):
|
||||
buf = bytearray(3)
|
||||
buf[0] = CMD_LEAVE_PROGMODE_ISP
|
||||
buf[1] = 0x01
|
||||
buf[2] = 0x01
|
||||
self.stk500v2_command(buf, 3)
|
||||
self.ser.close()
|
||||
@ -0,0 +1,279 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#**** ATMEL AVR - A P P L I C A T I O N N O T E ************************
|
||||
#*
|
||||
#* Title: AVR068 - STK500 Communication Protocol
|
||||
#* Filename: command.h
|
||||
#* Version: 1.0
|
||||
#* Last updated: 10.01.2005
|
||||
#*
|
||||
#* Support E-mail: avr@atmel.com
|
||||
#*
|
||||
#**************************************************************************
|
||||
#
|
||||
# *****************[ STK message constants ]***************************
|
||||
|
||||
MESSAGE_START = 0x1B
|
||||
TOKEN = 0x0E
|
||||
|
||||
# *****************[ STK general command constants ]**************************
|
||||
|
||||
CMD_SIGN_ON = 0x01
|
||||
CMD_SET_PARAMETER = 0x02
|
||||
CMD_GET_PARAMETER = 0x03
|
||||
CMD_SET_DEVICE_PARAMETERS = 0x04
|
||||
CMD_OSCCAL = 0x05
|
||||
CMD_LOAD_ADDRESS = 0x06
|
||||
CMD_FIRMWARE_UPGRADE = 0x07
|
||||
CMD_CHECK_TARGET_CONNECTION = 0x0D
|
||||
CMD_LOAD_RC_ID_TABLE = 0x0E
|
||||
CMD_LOAD_EC_ID_TABLE = 0x0F
|
||||
|
||||
|
||||
# *****************[ STK ISP command constants ]******************************
|
||||
|
||||
CMD_ENTER_PROGMODE_ISP = 0x10
|
||||
CMD_LEAVE_PROGMODE_ISP = 0x11
|
||||
CMD_CHIP_ERASE_ISP = 0x12
|
||||
CMD_PROGRAM_FLASH_ISP = 0x13
|
||||
CMD_READ_FLASH_ISP = 0x14
|
||||
CMD_PROGRAM_EEPROM_ISP = 0x15
|
||||
CMD_READ_EEPROM_ISP = 0x16
|
||||
CMD_PROGRAM_FUSE_ISP = 0x17
|
||||
CMD_READ_FUSE_ISP = 0x18
|
||||
CMD_PROGRAM_LOCK_ISP = 0x19
|
||||
CMD_READ_LOCK_ISP = 0x1A
|
||||
CMD_READ_SIGNATURE_ISP = 0x1B
|
||||
CMD_READ_OSCCAL_ISP = 0x1C
|
||||
CMD_SPI_MULTI = 0x1D
|
||||
|
||||
# *****************[ STK PP command constants ]*******************************
|
||||
|
||||
CMD_ENTER_PROGMODE_PP = 0x20
|
||||
CMD_LEAVE_PROGMODE_PP = 0x21
|
||||
CMD_CHIP_ERASE_PP = 0x22
|
||||
CMD_PROGRAM_FLASH_PP = 0x23
|
||||
CMD_READ_FLASH_PP = 0x24
|
||||
CMD_PROGRAM_EEPROM_PP = 0x25
|
||||
CMD_READ_EEPROM_PP = 0x26
|
||||
CMD_PROGRAM_FUSE_PP = 0x27
|
||||
CMD_READ_FUSE_PP = 0x28
|
||||
CMD_PROGRAM_LOCK_PP = 0x29
|
||||
CMD_READ_LOCK_PP = 0x2A
|
||||
CMD_READ_SIGNATURE_PP = 0x2B
|
||||
CMD_READ_OSCCAL_PP = 0x2C
|
||||
CMD_SET_CONTROL_STACK = 0x2D
|
||||
|
||||
# *****************[ STK HVSP command constants ]*****************************
|
||||
|
||||
CMD_ENTER_PROGMODE_HVSP = 0x30
|
||||
CMD_LEAVE_PROGMODE_HVSP = 0x31
|
||||
CMD_CHIP_ERASE_HVSP = 0x32
|
||||
CMD_PROGRAM_FLASH_HVSP = 0x33
|
||||
CMD_READ_FLASH_HVSP = 0x34
|
||||
CMD_PROGRAM_EEPROM_HVSP = 0x35
|
||||
CMD_READ_EEPROM_HVSP = 0x36
|
||||
CMD_PROGRAM_FUSE_HVSP = 0x37
|
||||
CMD_READ_FUSE_HVSP = 0x38
|
||||
CMD_PROGRAM_LOCK_HVSP = 0x39
|
||||
CMD_READ_LOCK_HVSP = 0x3A
|
||||
CMD_READ_SIGNATURE_HVSP = 0x3B
|
||||
CMD_READ_OSCCAL_HVSP = 0x3C
|
||||
# These two are redefined since 0x30/0x31 collide
|
||||
# with the STK600 bootloader.
|
||||
CMD_ENTER_PROGMODE_HVSP_STK600 = 0x3D
|
||||
CMD_LEAVE_PROGMODE_HVSP_STK600 = 0x3E
|
||||
|
||||
# *** XPROG command constants ***
|
||||
|
||||
CMD_XPROG = 0x50
|
||||
CMD_XPROG_SETMODE = 0x51
|
||||
|
||||
|
||||
# *** AVR32 JTAG Programming command ***
|
||||
|
||||
CMD_JTAG_AVR32 = 0x80
|
||||
CMD_ENTER_PROGMODE_JTAG_AVR32 = 0x81
|
||||
CMD_LEAVE_PROGMODE_JTAG_AVR32 = 0x82
|
||||
|
||||
|
||||
# *** AVR JTAG Programming command ***
|
||||
|
||||
#define CMD_JTAG_AVR 0x90
|
||||
|
||||
# *****************[ STK test command constants ]***************************
|
||||
|
||||
CMD_ENTER_TESTMODE = 0x60
|
||||
CMD_LEAVE_TESTMODE = 0x61
|
||||
CMD_CHIP_WRITE = 0x62
|
||||
CMD_PROGRAM_FLASH_PARTIAL = 0x63
|
||||
CMD_PROGRAM_EEPROM_PARTIAL = 0x64
|
||||
CMD_PROGRAM_SIGNATURE_ROW = 0x65
|
||||
CMD_READ_FLASH_MARGIN = 0x66
|
||||
CMD_READ_EEPROM_MARGIN = 0x67
|
||||
CMD_READ_SIGNATURE_ROW_MARGIN = 0x68
|
||||
CMD_PROGRAM_TEST_FUSE = 0x69
|
||||
CMD_READ_TEST_FUSE = 0x6A
|
||||
CMD_PROGRAM_HIDDEN_FUSE_LOW = 0x6B
|
||||
CMD_READ_HIDDEN_FUSE_LOW = 0x6C
|
||||
CMD_PROGRAM_HIDDEN_FUSE_HIGH = 0x6D
|
||||
CMD_READ_HIDDEN_FUSE_HIGH = 0x6E
|
||||
CMD_PROGRAM_HIDDEN_FUSE_EXT = 0x6F
|
||||
CMD_READ_HIDDEN_FUSE_EXT = 0x70
|
||||
|
||||
# *****************[ STK status constants ]***************************
|
||||
|
||||
# Success
|
||||
STATUS_CMD_OK = 0x00
|
||||
|
||||
# Warnings
|
||||
STATUS_CMD_TOUT = 0x80
|
||||
STATUS_RDY_BSY_TOUT = 0x81
|
||||
STATUS_SET_PARAM_MISSING = 0x82
|
||||
|
||||
# Errors
|
||||
STATUS_CMD_FAILED = 0xC0
|
||||
STATUS_CKSUM_ERROR = 0xC1
|
||||
STATUS_CMD_UNKNOWN = 0xC9
|
||||
STATUS_CMD_ILLEGAL_PARAMETER = 0xCA
|
||||
|
||||
# Status
|
||||
STATUS_CONN_FAIL_MOSI = 0x01
|
||||
STATUS_CONN_FAIL_RST = 0x02
|
||||
STATUS_CONN_FAIL_SCK = 0x04
|
||||
STATUS_TGT_NOT_DETECTED = 0x00
|
||||
STATUS_ISP_READY = 0x10
|
||||
STATUS_TGT_REVERSE_INSERTED = 0x20
|
||||
|
||||
# hw_status
|
||||
# Bits in status variable
|
||||
# Bit 0-3: Slave MCU
|
||||
# Bit 4-7: Master MCU
|
||||
|
||||
STATUS_AREF_ERROR = 0
|
||||
# Set to '1' if AREF is short circuited
|
||||
|
||||
STATUS_VTG_ERROR = 4
|
||||
# Set to '1' if VTG is short circuited
|
||||
|
||||
STATUS_RC_CARD_ERROR = 5
|
||||
# Set to '1' if board id changes when board is powered
|
||||
|
||||
STATUS_PROGMODE = 6
|
||||
# Set to '1' if board is in programming mode
|
||||
|
||||
STATUS_POWER_SURGE = 7
|
||||
# Set to '1' if board draws excessive current
|
||||
|
||||
# *****************[ STK parameter constants ]***************************
|
||||
PARAM_BUILD_NUMBER_LOW = 0x80
|
||||
PARAM_BUILD_NUMBER_HIGH = 0x81
|
||||
PARAM_HW_VER = 0x90
|
||||
PARAM_SW_MAJOR = 0x91
|
||||
PARAM_SW_MINOR = 0x92
|
||||
PARAM_VTARGET = 0x94
|
||||
PARAM_VADJUST = 0x95
|
||||
PARAM_OSC_PSCALE = 0x96
|
||||
PARAM_OSC_CMATCH = 0x97
|
||||
PARAM_SCK_DURATION = 0x98
|
||||
PARAM_TOPCARD_DETECT = 0x9A
|
||||
PARAM_STATUS = 0x9C
|
||||
PARAM_DATA = 0x9D
|
||||
PARAM_RESET_POLARITY = 0x9E
|
||||
PARAM_CONTROLLER_INIT = 0x9F
|
||||
|
||||
# STK600 parameters
|
||||
PARAM_STATUS_TGT_CONN = 0xA1
|
||||
PARAM_DISCHARGEDELAY = 0xA4
|
||||
PARAM_SOCKETCARD_ID = 0xA5
|
||||
PARAM_ROUTINGCARD_ID = 0xA6
|
||||
PARAM_EXPCARD_ID = 0xA7
|
||||
PARAM_SW_MAJOR_SLAVE1 = 0xA8
|
||||
PARAM_SW_MINOR_SLAVE1 = 0xA9
|
||||
PARAM_SW_MAJOR_SLAVE2 = 0xAA
|
||||
PARAM_SW_MINOR_SLAVE2 = 0xAB
|
||||
PARAM_BOARD_ID_STATUS = 0xAD
|
||||
PARAM_RESET = 0xB4
|
||||
|
||||
PARAM_JTAG_ALLOW_FULL_PAGE_STREAM = 0x50
|
||||
PARAM_JTAG_EEPROM_PAGE_SIZE = 0x52
|
||||
PARAM_JTAG_DAISY_BITS_BEFORE = 0x53
|
||||
PARAM_JTAG_DAISY_BITS_AFTER = 0x54
|
||||
PARAM_JTAG_DAISY_UNITS_BEFORE = 0x55
|
||||
PARAM_JTAG_DAISY_UNITS_AFTER = 0x56
|
||||
|
||||
# *** Parameter constants for 2 byte values ***
|
||||
PARAM2_SCK_DURATION = 0xC0
|
||||
PARAM2_CLOCK_CONF = 0xC1
|
||||
PARAM2_AREF0 = 0xC2
|
||||
PARAM2_AREF1 = 0xC3
|
||||
|
||||
PARAM2_JTAG_FLASH_SIZE_H = 0xC5
|
||||
PARAM2_JTAG_FLASH_SIZE_L = 0xC6
|
||||
PARAM2_JTAG_FLASH_PAGE_SIZE = 0xC7
|
||||
PARAM2_RC_ID_TABLE_REV = 0xC8
|
||||
PARAM2_EC_ID_TABLE_REV = 0xC9
|
||||
|
||||
# STK600 XPROG section
|
||||
# XPROG modes
|
||||
XPRG_MODE_PDI = 0
|
||||
XPRG_MODE_JTAG = 1
|
||||
XPRG_MODE_TPI = 2
|
||||
|
||||
# XPROG commands
|
||||
XPRG_CMD_ENTER_PROGMODE = 0x01
|
||||
XPRG_CMD_LEAVE_PROGMODE = 0x02
|
||||
XPRG_CMD_ERASE = 0x03
|
||||
XPRG_CMD_WRITE_MEM = 0x04
|
||||
XPRG_CMD_READ_MEM = 0x05
|
||||
XPRG_CMD_CRC = 0x06
|
||||
XPRG_CMD_SET_PARAM = 0x07
|
||||
|
||||
# Memory types
|
||||
XPRG_MEM_TYPE_APPL = 1
|
||||
XPRG_MEM_TYPE_BOOT = 2
|
||||
XPRG_MEM_TYPE_EEPROM = 3
|
||||
XPRG_MEM_TYPE_FUSE = 4
|
||||
XPRG_MEM_TYPE_LOCKBITS = 5
|
||||
XPRG_MEM_TYPE_USERSIG = 6
|
||||
XPRG_MEM_TYPE_FACTORY_CALIBRATION = 7
|
||||
|
||||
# Erase types
|
||||
XPRG_ERASE_CHIP = 1
|
||||
XPRG_ERASE_APP = 2
|
||||
XPRG_ERASE_BOOT = 3
|
||||
XPRG_ERASE_EEPROM = 4
|
||||
XPRG_ERASE_APP_PAGE = 5
|
||||
XPRG_ERASE_BOOT_PAGE = 6
|
||||
XPRG_ERASE_EEPROM_PAGE = 7
|
||||
XPRG_ERASE_USERSIG = 8
|
||||
XPRG_ERASE_CONFIG = 9 # TPI only, prepare fuse write
|
||||
|
||||
# Write mode flags
|
||||
XPRG_MEM_WRITE_ERASE = 0
|
||||
XPRG_MEM_WRITE_WRITE = 1
|
||||
|
||||
# CRC types
|
||||
XPRG_CRC_APP = 1
|
||||
XPRG_CRC_BOOT = 2
|
||||
XPRG_CRC_FLASH = 3
|
||||
|
||||
# Error codes
|
||||
XPRG_ERR_OK = 0
|
||||
XPRG_ERR_FAILED = 1
|
||||
XPRG_ERR_COLLISION = 2
|
||||
XPRG_ERR_TIMEOUT = 3
|
||||
|
||||
# XPROG parameters of different sizes
|
||||
# 4-byte address
|
||||
XPRG_PARAM_NVMBASE = 0x01
|
||||
# 2-byte page size
|
||||
XPRG_PARAM_EEPPAGESIZE = 0x02
|
||||
# 1-byte, undocumented TPI param
|
||||
XPRG_PARAM_TPI_3 = 0x03
|
||||
# 1-byte, undocumented TPI param
|
||||
XPRG_PARAM_TPI_4 = 0x04
|
||||
|
||||
# *****************[ STK answer constants ]***************************
|
||||
|
||||
ANSWER_CKSUM_ERROR = 0xB0
|
||||
|
||||
1574
buildroot-2021.05/package/python-pinpong/pinpong/board.py
Normal file
1574
buildroot-2021.05/package/python-pinpong/pinpong/board.py
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,23 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:控制arduino UNO板载LED灯一秒闪烁一次
|
||||
#接线:使用windows或linux电脑连接一块arduino主控板
|
||||
|
||||
import time
|
||||
from pinpong.board import Board,Pin
|
||||
|
||||
Board().begin()#初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
led = Pin(Pin.D13, Pin.OUT) #引脚初始化为电平输出
|
||||
|
||||
while True:
|
||||
led.value(1) #输出高电平
|
||||
print("1") #终端打印信息
|
||||
time.sleep(1) #等待1秒 保持状态
|
||||
|
||||
led.value(0) #输出低电平
|
||||
print("0") #终端打印信息
|
||||
time.sleep(1) #等待1秒 保持状态
|
||||
@ -0,0 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:使用按钮控制arduino UNO板载亮灭
|
||||
#接线:使用windows或linux电脑连接一块arduino主控板,主控板D8接一个按钮模块
|
||||
import time
|
||||
from pinpong.board import Board,Pin
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
btn = Pin(Pin.D8, Pin.IN) #引脚初始化为电平输入
|
||||
led = Pin(Pin.D5, Pin.OUT)
|
||||
|
||||
while True:
|
||||
v = btn.value() #读取引脚电平
|
||||
print(v) #终端打印读取的电平状态
|
||||
led.value(v) #将按钮状态设置给led灯引脚
|
||||
time.sleep(0.1)
|
||||
@ -0,0 +1,37 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:打印UNO板A0口模拟值
|
||||
#接线:使用windows或linux电脑连接一块arduino主控板,主控板A0接一个模拟传感器
|
||||
import time
|
||||
from pinpong.board import Board,Pin,ADC #导入ADC类实现模拟输入
|
||||
|
||||
Board("UNIHIKER").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
adc0 = ADC(Pin(Pin.A22)) #将Pin传入ADC中实现模拟输入
|
||||
#adc1 = ADC(Pin(Pin.A1))
|
||||
#adc2 = ADC(Pin(Pin.A2))
|
||||
#adc3 = ADC(Pin(Pin.A3))
|
||||
#adc4 = ADC(Pin(Pin.A4))
|
||||
#adc10 = ADC(Pin(Pin.A10))
|
||||
while True:
|
||||
v0 = adc0.read() #读取A0口模拟信号数值
|
||||
'''
|
||||
v1 = adc1.read() #读取A1口模拟信号数值
|
||||
v2 = adc2.read() #读取A2口模拟信号数值
|
||||
v3 = adc3.read() #读取A3口模拟信号数值
|
||||
v4 = adc4.read() #读取A4口模拟信号数值
|
||||
v10 = adc10.read() #读取A10口模拟信号数值
|
||||
'''
|
||||
|
||||
print("A0=", v0)
|
||||
'''
|
||||
print("A1=", v1)
|
||||
print("A2=", v2)
|
||||
print("A3=", v3)
|
||||
print("A4=", v4)
|
||||
print("A10=", v10)
|
||||
'''
|
||||
time.sleep(0.5)
|
||||
@ -0,0 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:使用按钮控制LED呼吸灯
|
||||
#接线:使用windows或linux电脑连接一块arduino主控板,主控板D6接一个LED灯模块
|
||||
import time
|
||||
from pinpong.board import Board,Pin,PWM #导入PWM类实现模拟输出
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
pwm0 = PWM(Pin(Pin.D21)) #将Pin传入PWM中实现模拟输出
|
||||
#PWM支持0-255范围
|
||||
|
||||
while True:
|
||||
for i in range(255): #从0到255循环
|
||||
pwm0.duty(i) #设置模拟输出值
|
||||
print(i)
|
||||
time.sleep(0.05)
|
||||
@ -0,0 +1,32 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:引脚模拟中断功能测试
|
||||
#接线:使用windows或linux电脑连接一块arduino主控板,主控板D8接一个按钮模块
|
||||
import time
|
||||
from pinpong.board import Board,Pin
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
btn = Pin(Pin.D1, Pin.IN)
|
||||
|
||||
def btn_rasing_handler(pin):#中断事件回调函数
|
||||
print("\n--rising---")
|
||||
print("pin = ", pin)
|
||||
|
||||
def btn_falling_handler(pin):#中断事件回调函数
|
||||
print("\n--falling---")
|
||||
print("pin = ", pin)
|
||||
|
||||
def btn_both_handler(pin):#中断事件回调函数
|
||||
print("\n--both---")
|
||||
print("pin = ", pin)
|
||||
|
||||
btn.irq(trigger=Pin.IRQ_FALLING, handler=btn_falling_handler) #设置中断模式为下降沿触发
|
||||
#btn.irq(trigger=Pin.IRQ_RISING, handler=btn_rasing_handler) #设置中断模式为上升沿触发,及回调函数
|
||||
#btn.irq(trigger=Pin.IRQ_RISING+Pin.IRQ_FALLING, handler=btn_both_handler) #设置中断模式为电平变化时触发
|
||||
|
||||
while True:
|
||||
time.sleep(1)
|
||||
@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import time
|
||||
from pinpong.board import Board,Pin
|
||||
from pinpong.libs.dfrobot_ens160 import Ens160
|
||||
|
||||
Board("uno").begin()#初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
ens160 = Ens160()
|
||||
|
||||
# ENS160_SLEEP_MODE: DEEP SLEEP mode (low power standby)
|
||||
# ENS160_IDLE_MODE: IDLE mode (low-power)
|
||||
# ENS160_STANDARD_MODE: STANDARD Gas Sensing Modes
|
||||
ens160.set_pwr_mode(ens160.ENS160_STANDARD_MODE)
|
||||
|
||||
ens160.set_temp_hum(25.0, 50.0) # temperature & humidity
|
||||
|
||||
while True:
|
||||
print("-------------------------")
|
||||
print("Sensor operating status : %d" %ens160.get_status())
|
||||
print("Air quality index : %d" %ens160.get_aqi())
|
||||
print("Concentration of total volatile organic compounds : %d ppb" %ens160.get_tvoc())
|
||||
print("Carbon dioxide equivalent concentration : %d ppm" %ens160.get_eco2())
|
||||
time.sleep(1)
|
||||
@ -0,0 +1,25 @@
|
||||
# -*- coding:utf-8 -*-
|
||||
#IIC转串口模块(DFR0627)
|
||||
|
||||
import time
|
||||
from pinpong.board import Board
|
||||
from pinpong.libs.dfrobot_uarttoi2c import DFRobot_IIC_Serial
|
||||
|
||||
Board("uno").begin()
|
||||
|
||||
iic_uart2 = DFRobot_IIC_Serial(DFRobot_IIC_Serial.SUBUART_CHANNEL_2, IA1 = 1, IA0 = 1)
|
||||
iic_uart1 = DFRobot_IIC_Serial(DFRobot_IIC_Serial.SUBUART_CHANNEL_1, IA1 = 1, IA0 = 1)
|
||||
|
||||
iic_uart2.begin(baud = 115200, format = iic_uart2.IIC_Serial_8N1)
|
||||
iic_uart1.begin(baud = 9600, format = iic_uart1.IIC_Serial_8N1)
|
||||
|
||||
data = [0x01, 0x02, 0x03]
|
||||
|
||||
while True:
|
||||
while iic_uart1.available():
|
||||
c = iic_uart1.read()
|
||||
time.sleep(0.002)
|
||||
time.sleep(1)
|
||||
iic_uart1.write(data)
|
||||
iic_uart2.write("hello")
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#SEN0483:风速测量,需搭配RS485转UART模块(DFR0845)、IIC转串口模块(DFR0627)使用
|
||||
|
||||
import time
|
||||
from pinpong.board import Board
|
||||
from pinpong.libs.rs485windspeed_rs485touart_uarttoi2c import IICSerialWindSpeed
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
|
||||
ws = IICSerialWindSpeed(IICSerialWindSpeed.SUBUART_CHANNEL_1, IA1 = 1, IA0 = 1)
|
||||
|
||||
ws.modify_address(0, 2)
|
||||
while True:
|
||||
print(ws.read_wind_speed())
|
||||
time.sleep(0.3)
|
||||
@ -0,0 +1,17 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#SEN0482:风向测量,需搭配RS485转UART模块(DFR0845)、IIC转串口模块(DFR0627)使用
|
||||
|
||||
import time
|
||||
from pinpong.board import Board
|
||||
from pinpong.libs.rs485winddirection_rs485touart_uarttoi2c import IICSerialWindDirection
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
|
||||
wx = IICSerialWindDirection(IICSerialWindDirection.SUBUART_CHANNEL_1, IA1 = 1, IA0 = 1)
|
||||
|
||||
wx.modify_address(0, 2)
|
||||
|
||||
while True:
|
||||
print(wx.read_wind_direction())
|
||||
print(wx.get_wind_angle()) #V2才有读取角度
|
||||
time.sleep(0.3)
|
||||
@ -0,0 +1,33 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#SEN0377:MEMS 气体传感器(CO, Alcohol, NO2 & NH3)
|
||||
import time
|
||||
from pinpong.board import Board,Pin #导入ADC类实现模拟输入
|
||||
from pinpong.libs.dfrobot_mics import DFRobot_MICS_I2C
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
|
||||
CALIBRATION_TIME = 0x01 # calibration time
|
||||
|
||||
mics = DFRobot_MICS_I2C(bus_num=4)
|
||||
|
||||
mics.warm_up_time(CALIBRATION_TIME)
|
||||
|
||||
while True:
|
||||
'''
|
||||
Type of detection gas
|
||||
CO = 0x01 (Carbon Monoxide)
|
||||
CH4 = 0x02 (Methane)
|
||||
C2H5OH = 0x03 (Ethanol)
|
||||
H2 = 0x06 (Hydrogen)
|
||||
NH3 = 0x08 (Ammonia)
|
||||
NO2 = 0x0A (Nitrogen Dioxide)
|
||||
'''
|
||||
gas_concentration = mics.get_gas_ppm(0x06)
|
||||
print("gas concentration is %.1f"%gas_concentration)
|
||||
time.sleep(1)
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#SEN0377:MEMS 气体传感器(CO, Alcohol, NO2 & NH3)
|
||||
import time
|
||||
from pinpong.board import Board,Pin #导入ADC类实现模拟输入
|
||||
from pinpong.libs.dfrobot_mics import DFRobot_MICS_I2C
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
|
||||
CALIBRATION_TIME = 0x03 # calibration time
|
||||
|
||||
mics = DFRobot_MICS_I2C(bus_num=4)
|
||||
|
||||
mics.warm_up_time(CALIBRATION_TIME)
|
||||
|
||||
while True:
|
||||
'''
|
||||
Type of detection gas
|
||||
CO = 0x01 (Carbon Monoxide)
|
||||
CH4 = 0x02 (Methane)
|
||||
C2H5OH = 0x03 (Ethanol)
|
||||
H2 = 0x06 (Hydrogen)
|
||||
NH3 = 0x08 (Ammonia)
|
||||
NO2 = 0x0A (Nitrogen Dioxide)
|
||||
'''
|
||||
if mics.get_gas_exist(mics.C2H5OH) == mics.ERROR:
|
||||
print ("This gas does not exist!")
|
||||
else:
|
||||
print ("This gas exists!")
|
||||
@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#SEN0377:MEMS 气体传感器(CO, Alcohol, NO2 & NH3)
|
||||
import time
|
||||
from pinpong.board import Board,Pin #导入ADC类实现模拟输入
|
||||
from pinpong.libs.dfrobot_mics import DFRobot_MICS_I2C
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
|
||||
CALIBRATION_TIME = 0x03 # calibration time
|
||||
|
||||
mics = DFRobot_MICS_I2C()
|
||||
|
||||
mics.warm_up_time(CALIBRATION_TIME)
|
||||
|
||||
while True:
|
||||
ox_data = mics.get_adc_data(mics.OX_MODE)
|
||||
#red_data = mics.get_adc_data(mics.RED_MODE);
|
||||
print ("ox adc is %d"%ox_data)
|
||||
#print ("red adc is %d"%red_data)
|
||||
time.sleep(1)
|
||||
#mics.sleep_mode()
|
||||
@ -0,0 +1,31 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#SEN0377:MEMS 气体传感器(CO, Alcohol, NO2 & NH3)
|
||||
import time
|
||||
from pinpong.board import Board,Pin #导入ADC类实现模拟输入
|
||||
from pinpong.libs.dfrobot_mics import DFRobot_MICS_I2C
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
CALIBRATION_TIME = 0x03 # calibration time
|
||||
|
||||
mics = DFRobot_MICS_I2C(bus_num=4)
|
||||
|
||||
mics.warm_up_time(CALIBRATION_TIME)
|
||||
|
||||
while True:
|
||||
'''
|
||||
Gets the power mode of the sensor
|
||||
The sensor is in sleep mode when power is on,so it needs to wake up the sensor.
|
||||
The data obtained in sleep mode is wrong
|
||||
'''
|
||||
if mics.get_power_mode() == mics.SLEEP_MODE:
|
||||
mics.wakeup_mode()
|
||||
print("sleep mode, wake up sensor success!")
|
||||
else:
|
||||
mics.sleep_mode()
|
||||
print("wake up mode, sleep sensor success!")
|
||||
time.sleep(3)
|
||||
@ -0,0 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import time
|
||||
from pinpong.board import Board,Pin
|
||||
from pinpong.libs.dfrobot_ph import PH
|
||||
|
||||
Board().begin()
|
||||
|
||||
ph2 = PH(Pin(Pin.A0)) #需供电5V
|
||||
|
||||
while True:
|
||||
print(ph2.read_ph())
|
||||
time.sleep(1)
|
||||
@ -0,0 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import time
|
||||
from pinpong.board import Board,Pin
|
||||
from pinpong.libs.dfrobot_ph import PH2
|
||||
|
||||
Board().begin()
|
||||
|
||||
ph2 = PH2(Pin(Pin.A2))
|
||||
|
||||
while True:
|
||||
print(ph2.read_ph())
|
||||
time.sleep(1)
|
||||
@ -0,0 +1,19 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import time
|
||||
from pinpong.board import Board
|
||||
from pinpong.libs.dfrobot_max30102 import DFRobot_BloodOxygen_S
|
||||
|
||||
Board().begin()
|
||||
|
||||
max30102 = DFRobot_BloodOxygen_S(bus_num=4)
|
||||
|
||||
while (False == max30102.begin()):
|
||||
print("init fail!")
|
||||
time.sleep(1)
|
||||
print("start measuring...")
|
||||
max30102.sensor_start_collect()
|
||||
|
||||
while True:
|
||||
print("SPO2 is : "+str(max30102.get_spo2())+"%")
|
||||
print("heart rate is : "+str(max30102.get_heartbeat())+"Times/min")
|
||||
time.sleep(1)
|
||||
@ -0,0 +1,24 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import time
|
||||
from pinpong.board import Board
|
||||
from pinpong.libs.dfrobot_speech_synthesis import *
|
||||
|
||||
Board().begin()
|
||||
|
||||
sstts = DFRobot_SpeechSynthesis_I2C()
|
||||
|
||||
sstts.begin(sstts.V1) #supports V1 and V2
|
||||
|
||||
# sstts.set_voice(5) #Set volume(0-9)
|
||||
# sstts.set_speed(5) #Set playback speed (0-9)
|
||||
# sstts.set_tone(5) #Set tone(0-9)
|
||||
# sstts.set_sound_type(sstts.FEMALE) #Set voice type/FEMALE/MALE/DONALDDUCK(only V1)
|
||||
# sstts.set_english_pron(sstts.WORD) #Set word synthesis mode /WORD/ALPHABET
|
||||
# sstts.set_digital_pron(sstts.NUMBER) #Set set read number NUMBER/NUMERIC/AUTOJUDGED
|
||||
|
||||
while True:
|
||||
sstts.speak("520")
|
||||
sstts.speak("i have one and three books") #Too long sentences are not supported
|
||||
sstts.speak("Hello world")
|
||||
sstts.speak("我叫小明,高二三班的学生")
|
||||
time.sleep(2)
|
||||
@ -0,0 +1,38 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import time
|
||||
from pinpong.board import Board
|
||||
from pinpong.libs.dfrobot_gravity_pm25 import DFRobot_GravityPM25
|
||||
|
||||
Board().begin()
|
||||
|
||||
pm = DFRobot_GravityPM25(bus_num=4)
|
||||
|
||||
version = pm.gain_version()
|
||||
print("version is : " + str(version))
|
||||
|
||||
# pm.set_lowpower() # Control the sensor to enter low-power mode
|
||||
# pm.awake() # Wake up sensor
|
||||
|
||||
while True:
|
||||
'''
|
||||
@brief Get PM concentration in the air: parameters available
|
||||
@n PARTICLE_PM1_0_STANDARD
|
||||
@n PARTICLE_PM2_5_STANDARD
|
||||
@n PARTICLE_PM10_STANDARD
|
||||
@n PARTICLE_PM1_0_ATMOSPHERE
|
||||
@n PARTICLE_PM2_5_ATMOSPHERE
|
||||
@n PARTICLE_PM10_ATMOSPHERE
|
||||
'''
|
||||
concentration = pm.gain_particle_concentration_ugm3(pm.PARTICLE_PM1_0_STANDARD)
|
||||
print("PM1.0 concentration:" + str(concentration) + " mg/m3")
|
||||
'''
|
||||
@n PARTICLENUM_0_3_UM_EVERY0_1L_AIR
|
||||
@n PARTICLENUM_0_5_UM_EVERY0_1L_AIR
|
||||
@n PARTICLENUM_1_0_UM_EVERY0_1L_AIR
|
||||
@n PARTICLENUM_2_5_UM_EVERY0_1L_AIR
|
||||
@n PARTICLENUM_5_0_UM_EVERY0_1L_AIR
|
||||
@n PARTICLENUM_10_UM_EVERY0_1L_AIR
|
||||
'''
|
||||
num = pm.gain_particlenum_every0_1l(pm.PARTICLENUM_0_3_UM_EVERY0_1L_AIR)
|
||||
print("The number of particles with a diameter of 0.3um per 0.1 in lift-off is:" + str(num))
|
||||
time.sleep(1)
|
||||
@ -0,0 +1,23 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import time
|
||||
from pinpong.board import Board
|
||||
from pinpong.libs.dfrobot_asr import DFRobot_ASR
|
||||
|
||||
Board().begin()
|
||||
|
||||
asr = DFRobot_ASR()
|
||||
|
||||
# 选择模式 LOOP(循环模式)/PASSWORD(指令模式)/BUTTON(按钮模式), 选择MIC(默认麦克风)/MONO(外部音频)
|
||||
asr.begin(asr.LOOP, asr.MIC)
|
||||
# 添加词条
|
||||
asr.add_command("kai deng", 1) # 开灯
|
||||
asr.add_command("guan deng", 2) # 关灯
|
||||
asr.add_command("bei jing", 3) # 北京
|
||||
asr.add_command("shang hai", 4) # 上海
|
||||
asr.add_command("xiang gang", 5) # 香港
|
||||
# 添加词条完毕,开始识别
|
||||
asr.start()
|
||||
while True:
|
||||
result = asr.read() # 识别一次,获取编号
|
||||
print(result)
|
||||
time.sleep(1)
|
||||
@ -0,0 +1,29 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:控制蜂鸣器发声
|
||||
#接线:使用windows或linux电脑连接一块arduino主控板,主控板D12接一个蜂鸣器模块
|
||||
import time
|
||||
from pinpong.board import Board,Pin,Tone
|
||||
|
||||
Board("unihiker").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
tone = Tone(Pin(Pin.D2)) #将Pin传入Tone中实现模拟输出
|
||||
|
||||
tone.freq(200) #按照设置的频率播放
|
||||
|
||||
while True:
|
||||
print("freq=",tone.freq()) #读取频率并打印
|
||||
tone.on() #打开蜂鸣器
|
||||
time.sleep(1)
|
||||
tone.off() #关闭蜂鸣器
|
||||
time.sleep(1)
|
||||
tone.freq(tone.freq()+100) #按照设置的频率播放
|
||||
|
||||
'''
|
||||
while True:
|
||||
tone.tone(200,500) #按照设置的频率和时间播放直到完成
|
||||
time.sleep(1)
|
||||
'''
|
||||
@ -0,0 +1,31 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:舵机控制
|
||||
#接线:使用windows或linux电脑连接一块arduino主控板,D4连接一个舵机
|
||||
import time
|
||||
from pinpong.board import Board,Pin,Servo
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
s2 = Servo(Pin(Pin.D4)) #将Pin传入Servo中初始化舵机引脚
|
||||
s1 = Servo(Pin(Pin.D5)) #将Pin传入Servo中初始化舵机引脚
|
||||
|
||||
while True:
|
||||
s1.angle(0) #控制舵机转到0度位置
|
||||
print("S1 0")
|
||||
time.sleep(1)
|
||||
|
||||
s2.angle(0) #控制舵机转到90度位置
|
||||
print("S2 0")
|
||||
time.sleep(1)
|
||||
|
||||
s1.angle(180) #控制舵机转到180度位置
|
||||
print("S1 180")
|
||||
time.sleep(1)
|
||||
|
||||
s2.angle(180) #控制舵机转到90度位置
|
||||
print("S2 180")
|
||||
time.sleep(1)
|
||||
@ -0,0 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:读取超声波
|
||||
#接线:使用windows或linux电脑连接一块arduino主控板,使用SR04或URM10超声波,Trig接D7,Echo接D8
|
||||
import time
|
||||
from pinpong.board import Board,Pin,SR04_URM10
|
||||
|
||||
TRIGER_PIN = Pin.D7
|
||||
ECHO_PIN = Pin.D8
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
sonar = SR04_URM10(Pin(TRIGER_PIN), Pin(ECHO_PIN))
|
||||
|
||||
while True:
|
||||
dis = sonar.distance_cm() #获取距离,单位厘米(cm)
|
||||
print("distance = %d cm"%dis)
|
||||
time.sleep(0.1)
|
||||
@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:读取dht温湿度传感器
|
||||
#接线:使用windows或linux电脑连接一块arduino主控板,dht11连接D6,dht22连接D7
|
||||
import time
|
||||
from pinpong.board import Board,Pin,DHT11,DHT22
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
dht11 = DHT11(Pin(Pin.D6))
|
||||
dht22 = DHT22(Pin(Pin.D7))
|
||||
|
||||
while True:
|
||||
temp = dht11.temp_c() #读取摄氏温度
|
||||
humi = dht11.humidity() #读取湿度
|
||||
print("dht11 temperature=",temp," humidity=",humi)
|
||||
|
||||
temp = dht22.temp_c() #读取摄氏温度
|
||||
humi = dht22.humidity() #读取湿度
|
||||
print("dht22 temperature=",temp," humidity=",humi)
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:I2C LCD1602控制
|
||||
#接线:使用windows或linux电脑连接一块arduino主控板,LCD1602显示屏接到I2C口SCL及SDA
|
||||
import time
|
||||
from pinpong.board import Board
|
||||
from pinpong.libs.lcd1602 import LCD1602_I2C #从libs中导入lcd1602_i2c库
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
lcd = LCD1602_I2C(i2c_addr=0x20, bus_num=4) #初始化LCD的I2C地址
|
||||
|
||||
print("I2C LCD1602 TEST...")
|
||||
lcd.backlight(True) #打开背光
|
||||
lcd.clear() #清屏
|
||||
lcd.set_cursor(0,0) #设置光标位置
|
||||
lcd.print("Hello World") #显示 "Hello World",1602屏像素点少,不能显示汉字
|
||||
|
||||
lcd.set_cursor(1,1) #设置光标位置
|
||||
lcd.print(1234) #显示数字1234
|
||||
|
||||
while True:
|
||||
time.sleep(1)
|
||||
lcd.scroll_left() #滚动显示
|
||||
@ -0,0 +1,33 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:I2C OLED2864屏控制
|
||||
#接线:使用windows或linux电脑连接一块arduino主控板,OLED2864显示屏接到I2C口SCL及SDA
|
||||
import time
|
||||
from pinpong.board import Board
|
||||
from pinpong.libs.dfrobot_ssd1306 import SSD1306_I2C #导入ssd1306库
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
oled=SSD1306_I2C(width=128, height=64) #初始化屏幕,传入屏幕像素点数
|
||||
|
||||
# oled.set_font(font="default", width = 15, height = 15)
|
||||
|
||||
while True:
|
||||
oled.fill(1) #全部填充显示
|
||||
oled.show() #显示生效
|
||||
print("1")
|
||||
time.sleep(1)
|
||||
|
||||
oled.fill(0) #全部填充熄灭,清屏
|
||||
oled.show() #显示生效
|
||||
print("0")
|
||||
time.sleep(1)
|
||||
|
||||
oled.text(0) #显示数字
|
||||
oled.text("Hello PinPong",8,8) #指定位置显示文字
|
||||
oled.show() #显示生效
|
||||
time.sleep(2)
|
||||
|
||||
@ -0,0 +1,53 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:控制WS2812单线RGB LED灯
|
||||
#接线:使用windows或linux电脑连接一块arduino主控板,ws2812灯接到D9口
|
||||
import time
|
||||
from pinpong.board import Board,Pin,NeoPixel
|
||||
|
||||
NEOPIXEL_PIN = Pin.D7
|
||||
PIXELS_NUM = 4 #灯数
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
np = NeoPixel(Pin(NEOPIXEL_PIN), PIXELS_NUM)
|
||||
|
||||
while True:
|
||||
np[0] = (0, 255 ,0) #设置第一个灯RGB亮度
|
||||
np[1] = (255, 0, 0) #设置第二个灯RGB亮度
|
||||
np[2] = (0, 0, 255) #设置第三个灯RGB亮度
|
||||
np[3] = (255, 0, 255) #设置第四个灯RGB亮度
|
||||
time.sleep(1)
|
||||
|
||||
np[1] = (0, 255, 0)
|
||||
np[2] = (255, 0, 0)
|
||||
np[3] = (255, 255, 0)
|
||||
np[0] = (0, 0, 255)
|
||||
time.sleep(1)
|
||||
|
||||
np.rainbow(0,7,0,0x0022FF)
|
||||
time.sleep(1)
|
||||
for i in range(3):
|
||||
np.rotate(1)
|
||||
time.sleep(1)
|
||||
|
||||
for i in range(3):
|
||||
np.shift(1)
|
||||
time.sleep(1)
|
||||
|
||||
np.clear()
|
||||
time.sleep(1)
|
||||
|
||||
np.range_color(0,4,0xFF0000)
|
||||
time.sleep(1)
|
||||
np.range_color(0,4,0x00FF00)
|
||||
time.sleep(1)
|
||||
np.range_color(0,4,0x0000FF)
|
||||
time.sleep(1)
|
||||
|
||||
np.clear()
|
||||
time.sleep(1)
|
||||
|
||||
@ -0,0 +1,39 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:读取I2C TCS34725颜色传感器数值
|
||||
#接线:使用windows或linux电脑连接一块arduino主控板,TCS34725颜色传感器接到I2C口SCL SDA
|
||||
import time
|
||||
from pinpong.board import Board
|
||||
from pinpong.libs.dfrobot_tcs34725 import TCS34725 #从libs导入tcs34725库
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
tcs = TCS34725() #传感器初始化
|
||||
|
||||
print("Color View Test!")
|
||||
while True:
|
||||
if tcs.begin(): #查找传感器,读取到则返回True
|
||||
print("Found sensor")
|
||||
break #找到 跳出循环
|
||||
else:
|
||||
print("No TCS34725 found ... check your connections")
|
||||
time.sleep(1)
|
||||
|
||||
while True:
|
||||
r,g,b,c = tcs.get_rgbc() #获取rgbc数据
|
||||
print(r,g,b,c)
|
||||
print("C=%d\tR=%d\tG=%d\tB=%d\t"%(c,r,g,b))
|
||||
#数据转换
|
||||
if c:
|
||||
r /= c
|
||||
g /= c
|
||||
b /= c
|
||||
r *= 256
|
||||
g *= 256
|
||||
b *= 256
|
||||
print("------C=%d\tR=%d\tG=%d\tB=%d\t"%(c,r,g,b))
|
||||
|
||||
time.sleep(1)
|
||||
@ -0,0 +1,23 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#实验效果:读取I2C urm09超声波测距
|
||||
#接线:使用windows或linux电脑连接一块arduino主控板,urm09超声波测距传感器接到I2C口SCL SDA
|
||||
import time
|
||||
from pinpong.board import Board
|
||||
from pinpong.libs.dfrobot_urm09 import URM09 #从libs中导入URM09库
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
urm = URM09(i2c_addr=0x11) #初始化传感器,设置I2C地址
|
||||
|
||||
urm.set_mode_range(urm._MEASURE_MODE_AUTOMATIC ,urm._MEASURE_RANG_500) #设置URM09模式为自动检测,最大测量距离500cm
|
||||
|
||||
while True:
|
||||
dist = urm.distance_cm() #读取距离数据,单位厘米(cm)
|
||||
temp = urm.temp_c() #读取传感器温度,单位摄氏度(℃)
|
||||
|
||||
print("Distance is %d cm "%dist)
|
||||
print("Temperature is %.2f .c "%temp)
|
||||
time.sleep(0.5)
|
||||
@ -0,0 +1,28 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:控制I2C RGB彩色LCD1602液晶屏幕
|
||||
#接线:使用windows或linux电脑连接一块arduino主控板,RGBLCD1602接到I2C口SCL SDA
|
||||
import sys
|
||||
import time
|
||||
from pinpong.board import Board
|
||||
from pinpong.libs.dfrobot_rgb1602 import RGB1602 #从libs导入rgb1602库
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
lcd = RGB1602(bus_num=4)
|
||||
|
||||
print("I2C RGB1602 TEST...")
|
||||
|
||||
lcd.set_rgb(0,50,0); #设置RGB值
|
||||
|
||||
lcd.print("PinPong") #显示 "PinPong"
|
||||
|
||||
lcd.set_cursor(1,1) #设置光标位置
|
||||
lcd.print(1234) #显示数字
|
||||
|
||||
while True:
|
||||
time.sleep(1)
|
||||
lcd.scroll_left() #滚动显示
|
||||
@ -0,0 +1,22 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:读取I2C MLX90614远红外测温传感器
|
||||
#接线:使用windows或linux电脑连接一块arduino主控板,红外测温传感器接到I2C口SCL SDA
|
||||
import time
|
||||
from pinpong.board import Board
|
||||
from pinpong.libs.dfrobot_mlx90614 import MLX90614 #从libs导入mlx90614库
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
irt=MLX90614()
|
||||
|
||||
while True:
|
||||
print("Object %s *C"% irt.obj_temp_c()) #读取物体温度 摄氏度(℃)
|
||||
print("Object %s *F"% irt.obj_temp_f()) #读取物体温度 华氏度(℉)
|
||||
print("Ambient %s *C"% irt.env_temp_c()) #读取环境温度 摄氏度(℃)
|
||||
print("Ambient %s *F"% irt.env_temp_f()) #读取环境温度 华氏度(℉)
|
||||
print() #空行
|
||||
time.sleep(1)
|
||||
@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:控制I2C 通信协议展示
|
||||
#接线:连接一个i2c从机设备到arduino,假设i2c地址为0x33
|
||||
import sys
|
||||
import time
|
||||
from pinpong.board import Board,I2C
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
i2c = I2C(bus_num=4)
|
||||
#i2c = I2C(bus_num=0)#bus_num 默认值为0,由于arduino uno只有一个编号为0的i2c口
|
||||
|
||||
l=i2c.scan()#[0x33]
|
||||
print("i2c list:",l)
|
||||
#i2c.writeto(0x33,[1,2,3,4,5]) #将[1,2,3,4,5]写入i2c设备
|
||||
#i2c.readfrom(0x33,6)#从i2c设备读取6个数据
|
||||
#i2c.readfrom_mem(0x33,2,6)#从i2c设备的寄存器2 读取6个数据
|
||||
#i2c.writeto_mem(0x33,2,[1,2,3,4,5])#向i2c设备的寄存器2 写入[1,2,3,4,5]
|
||||
while(1):
|
||||
time.sleep(1)
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#实验效果:展示红外接收功能
|
||||
#接线:uno支持
|
||||
import sys
|
||||
import time
|
||||
from pinpong.board import Board,IRRecv,Pin
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
|
||||
def ir_recv3(data):
|
||||
print("------Pin3--------")
|
||||
print(hex(data))
|
||||
|
||||
#ir2 = IRRecv(Pin(2))
|
||||
ir3 = IRRecv(Pin(3),ir_recv3)
|
||||
|
||||
while(1):
|
||||
# v = ir2.read()
|
||||
# if v:
|
||||
# print("------Pin2--------")
|
||||
# print(v)
|
||||
time.sleep(0.1)
|
||||
@ -0,0 +1,16 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#实验效果:红外发射模块
|
||||
import sys
|
||||
import time
|
||||
from pinpong.board import Board,IRRemote,Pin
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
ir = IRRemote(Pin(Pin.D4))
|
||||
|
||||
while True:
|
||||
ir.send(0xD3) #一次只能8位数据
|
||||
time.sleep(0.5)
|
||||
@ -0,0 +1,42 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:读取I2C DS1307实时时钟
|
||||
#接线:使用windows或linux电脑连接一块arduino主控板,实时时钟接到I2C口SCL SDA
|
||||
import time
|
||||
from pinpong.board import Board
|
||||
from pinpong.libs.dfrobot_ds1307 import DS1307
|
||||
|
||||
Board("uno").begin()#初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
rtc = DS1307(bus_num = 4)
|
||||
|
||||
TIME_YR = 20 #TIME_YR表示年,默认+2000
|
||||
TIME_MTH = 9 #TIME_MTH表示月
|
||||
TIME_DATE = 1 #TIME_DATE表示日
|
||||
TIME_DOW = 2 #TIME_DOW表示星期几
|
||||
TIME_HR = 13 #TIME_HR表示时
|
||||
TIME_MIN = 56 #TIME_MIN表示分
|
||||
TIME_SEC = 10 #TIME_SEC表示秒
|
||||
|
||||
def update():
|
||||
data = [TIME_SEC,TIME_MIN,TIME_HR,TIME_DOW,TIME_DATE,TIME_MTH,TIME_YR]
|
||||
rtc.stop()
|
||||
rtc.set_time(data)
|
||||
rtc.start()
|
||||
|
||||
def set_square_signal():
|
||||
rtc.set_output(rtc.HIGH)
|
||||
|
||||
update() #更新时间函数
|
||||
#set_square_signal() #SQW/OUT引脚设置高电平、低电平、方波输出功能
|
||||
|
||||
while True:
|
||||
now = rtc.get_time()
|
||||
print("%s-%s-%s,%s:%s:%s"%(now.year,now.month,now.day,now.hours,now.minute,now.second))
|
||||
print(now.week)
|
||||
print("*****************")
|
||||
time.sleep(1)
|
||||
|
||||
@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:读取I2C PAJ7620U2手势传感器
|
||||
#接线:使用windows或linux电脑连接一块arduino主控板,手势传感器接到I2C口SCL SDA
|
||||
import time
|
||||
from pinpong.board import Board
|
||||
from pinpong.libs.dfrobot_paj7620u2 import PAJ7620U2,Gesture
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
paj = PAJ7620U2()
|
||||
|
||||
paj.set_gesture_high_rate() #设置高速模式
|
||||
#paj.set_gesture_low_rate() #设置低速模式
|
||||
|
||||
Gesture.print_all()
|
||||
|
||||
while True:
|
||||
description,gesture = paj.get_gesture()
|
||||
if gesture != Gesture.none:
|
||||
print("gesture code =%s"%gesture)
|
||||
print("gesture description =%s"%description)
|
||||
@ -0,0 +1,63 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:读取I2C 10DOF绝对定向传感器
|
||||
#接线:使用windows或linux电脑连接一块arduino主控板,绝对定向传感器接到I2C口SCL SDA
|
||||
import time
|
||||
from pinpong.board import Board
|
||||
from pinpong.libs.dfrobot_bno055 import BNO055
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
bno = BNO055()
|
||||
|
||||
while not bno.begin():#等待传感器初始化完成
|
||||
print("bno begin faild")
|
||||
time.sleep(2)
|
||||
print("bno begin success")
|
||||
|
||||
while True:
|
||||
acc_analog = bno.get_axis_acc()
|
||||
mag_analog = bno.get_axis_mag()
|
||||
gyr_analog = bno.get_axis_gyr()
|
||||
lia_analog = bno.get_axis_lia()
|
||||
grv_analog = bno.get_axis_grv()
|
||||
eul_analog = bno.get_eul()
|
||||
qua_analog = bno.get_qua()
|
||||
print("==================== analog data print start ====================")
|
||||
print("acc analog: (unit mg) x:%.2f y:%.2f z:%.2f\t"%(acc_analog.x,acc_analog.y,acc_analog.z))
|
||||
print("mag analog: (unit ut) x:%.2f y:%.2f z:%.2f\t"%(mag_analog.x,mag_analog.y,mag_analog.z))
|
||||
print("gyr analog: (unit dps) x:%.2f y:%.2f z:%.2f\t"%(gyr_analog.x,gyr_analog.y,gyr_analog.z))
|
||||
print("lia analog: (unit mg) x:%.2f y:%.2f z:%.2f\t"%(lia_analog.x,lia_analog.y,lia_analog.z))
|
||||
print("grv analog: (unit mg) x:%.2f y:%.2f z:%.2f\t"%(grv_analog.x,grv_analog.y,grv_analog.z))
|
||||
print("eul analog: (unit degree) head:%.2f roll:%.2f pitch:%.2f"%(eul_analog.head,eul_analog.roll,eul_analog.pitch))
|
||||
print("qua analog: (no unit) w:%0.2f x:%.2f y:%.2f z:%.2f"%(qua_analog.w,qua_analog.x,qua_analog.y,qua_analog.z))
|
||||
print("==================== analog data print end ====================");
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,73 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:读取I2C BMP280气压传感器
|
||||
#接线:使用windows或linux电脑连接一块arduino主控板,气压传感器接到I2C口SCL SDA
|
||||
import time
|
||||
from pinpong.board import Board
|
||||
from pinpong.libs.dfrobot_bmp280 import BMP280
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
bmp = BMP280()
|
||||
|
||||
while not bmp.begin():
|
||||
print("bmp begin faild")
|
||||
time.sleep(2)
|
||||
|
||||
while True:
|
||||
temp = bmp.temp_c()
|
||||
press = bmp.pressure_p()
|
||||
alti = bmp.altitude_m(press)
|
||||
print("=========== start print ===========")
|
||||
print("temperature: %.2f Celsius" % temp)
|
||||
print("pressure: %d pa" % press)
|
||||
print("altitude: %.2f meter" % alti)
|
||||
print("=========== end print ===========")
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,36 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:NFC近场通讯模块 IIC读取卡片信息
|
||||
#接线:使用windows或linux电脑连接一块arduino主控板,NFC近场通讯模块接到I2C口SCL SDA
|
||||
import time
|
||||
from pinpong.board import Board
|
||||
from pinpong.libs.dfrobot_pn532 import PN532_I2C
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
nfc = PN532_I2C()
|
||||
|
||||
while not nfc.begin():
|
||||
print("initial failure")
|
||||
time.sleep(1)
|
||||
print("Please place the info card/tag on module..... ")
|
||||
|
||||
while True:
|
||||
if nfc.scan():
|
||||
info = nfc.get_information()
|
||||
if info != None:
|
||||
print("----------------NFC card/tag information-------------------")
|
||||
print("UID Lenght: %d"%info.length)
|
||||
print("UID: %x %x %x %x"%(info.uid[0],info.uid[1],info.uid[2],info.uid[3] ))
|
||||
print("AQTA: %x %x"%(info.AQTA[0], info.AQTA[0]))
|
||||
print("SAK: 0x%x"%(info.sak))
|
||||
print("Type: %s"%(info.types))
|
||||
print("Manu facturer: %s"%(info.manu))
|
||||
print("RF Technology: %s"%(info.RF))
|
||||
print("Memory Size: %d bytes(total)/%d bytes(available)"%(info.size_total, info.size_available))
|
||||
print("Block/Page Size: %d bytes"%(info.block))
|
||||
print("Number of Blocks/pages: %d"%(info.num_block))
|
||||
time.sleep(1)
|
||||
@ -0,0 +1,49 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:NFC近场通讯模块 IIC读取卡片内信息
|
||||
#接线:使用windows或linux电脑连接一块arduino主控板,NFC近场通讯模块接到I2C口SCL SDA
|
||||
import time
|
||||
from pinpong.board import Board
|
||||
from pinpong.libs.dfrobot_pn532 import PN532_I2C
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
nfc = PN532_I2C()
|
||||
|
||||
def print_data(block):
|
||||
value = nfc.read_data(block)
|
||||
if value != None:
|
||||
print(value)
|
||||
else:
|
||||
print_data(block)
|
||||
|
||||
while not nfc.begin():
|
||||
print("initial failure")
|
||||
time.sleep(1)
|
||||
print("Waiting for a card......")
|
||||
|
||||
while True:
|
||||
if nfc.scan():
|
||||
card = nfc.get_information()
|
||||
if card != None:
|
||||
if card.length == 0x02 or card.length == 0x04:
|
||||
print("----------------Here is the card information to read-------------------")
|
||||
for i in range(card.num_block):
|
||||
if i == 0:
|
||||
print("Block %d:UID0-UID3/MANUFACTURER--------->"%(i), end="")
|
||||
print_data(i)
|
||||
elif (i+1)%4==0 and i < 128:
|
||||
print("Block %d:KEYA/ACCESS/KEYB--------------->"%(i), end="")
|
||||
print_data(i)
|
||||
elif (i+1)%16==0 and i > 127:
|
||||
print("Block %d:KEYA/ACCESS/KEYB--------------->"%(i), end="")
|
||||
print_data(i)
|
||||
else:
|
||||
print("Block %d:DATA ------------------------>"%(i), end="")
|
||||
print_data(i)
|
||||
else:
|
||||
print("The card type is not mifareclassic...")
|
||||
time.sleep(3)
|
||||
@ -0,0 +1,50 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:NFC近场通讯模块 IIC读写卡片信息
|
||||
#接线:使用windows或linux电脑连接一块arduino主控板,NFC近场通讯模块接到I2C口SCL SDA
|
||||
import time
|
||||
from pinpong.board import Board
|
||||
from pinpong.libs.dfrobot_pn532 import PN532_I2C
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
nfc = PN532_I2C()
|
||||
|
||||
write_data = "DFRobot NFC"
|
||||
#write_data = [1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
#write_data = (10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
|
||||
|
||||
block_num = 2
|
||||
|
||||
while not nfc.begin():
|
||||
print("initial failure")
|
||||
time.sleep(1)
|
||||
print("Waiting for a card......")
|
||||
|
||||
def parse_data(read_data):
|
||||
if read_data != None:
|
||||
print("read success! data is ", end=" ")
|
||||
print(read_data)
|
||||
else:
|
||||
print("read failure!")
|
||||
|
||||
while True:
|
||||
if nfc.scan():
|
||||
info = nfc.get_information()
|
||||
if info != None:
|
||||
if info.length == 0x02 or info.length == 0x04:
|
||||
if not nfc.write_data(block_num, write_data):
|
||||
print("write failure!")
|
||||
else:
|
||||
print("write success! data is", end=" ")
|
||||
print(write_data)
|
||||
read_data= nfc.read_data(block_num)
|
||||
parse_data(read_data)
|
||||
else:
|
||||
print("The card type is not mifareclassic...")
|
||||
time.sleep(2)
|
||||
|
||||
|
||||
@ -0,0 +1,32 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:读取DS18B20防水温度传感器
|
||||
#接线:使用windows或linux电脑连接一块arduino主控板
|
||||
import time
|
||||
from pinpong.board import Board,Pin,DS18B20
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
ds18b20 = DS18B20(Pin(Pin.D12))
|
||||
|
||||
while True:
|
||||
temp = ds18b20.temp_c()
|
||||
print("temperature = ",temp)
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,66 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:读取音频分析
|
||||
import time
|
||||
from pinpong.board import Board,Pin,AudioAnalyzer
|
||||
|
||||
strobe_Pin = Pin.A0
|
||||
rst_Pin = Pin.D5
|
||||
analog_Pin = Pin.A5
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
|
||||
audio = AudioAnalyzer(strobe_Pin, rst_Pin, analog_Pin)
|
||||
|
||||
while True:
|
||||
freq_val = audio.read_freq() #Frequency(Hz):63 160 400 1K 2.5K 6.25K 16K
|
||||
for i in range(7): #FreqVal[]: 0 1 2 3 4 5 6
|
||||
if i < 6:
|
||||
print(freq_val[i], end = ", ")
|
||||
else:
|
||||
print(freq_val[i])
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:读取重量传感器
|
||||
import time
|
||||
from pinpong.board import Board,Pin,HX711
|
||||
|
||||
dout_pin = Pin.D4
|
||||
sck_pin = Pin.D5
|
||||
scale = 2121 #校验值
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
hx = HX711(dout_pin, sck_pin, scale)
|
||||
|
||||
while True:
|
||||
value = hx.read_weight()
|
||||
print("weight = %.2f g" %value)
|
||||
time.sleep(0.2)
|
||||
@ -0,0 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#实验效果:水质传感器读取水质
|
||||
import time
|
||||
from pinpong.board import Board,Pin
|
||||
from pinpong.libs.dfrobot_tds import TDS
|
||||
|
||||
Board("uno").begin()#初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
tds = TDS(Pin(Pin.A2))
|
||||
|
||||
while True:
|
||||
tds_value = tds.get_value()
|
||||
print("TDS Value: %d ppm" % tds_value)
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,41 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:心率传感器读取心率
|
||||
import time
|
||||
from pinpong.board import Board,Pin#,HEARTRATE
|
||||
from pinpong.libs.dfrobot_heartrate import HEARTRATE
|
||||
|
||||
Board("uno").begin()#初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
DIGITAL_MODE = 1
|
||||
ANALOG_MODE = 0
|
||||
heart_rate = HEARTRATE(ANALOG_MODE, Pin.A1) # ANALOG_MODE or DIGITAL_MODE 方式
|
||||
# heart_rate = HEARTRATE(DIGITAL_MODE, Pin.A1) # ANALOG_MODE or DIGITAL_MODE 方式
|
||||
|
||||
while True:
|
||||
heart_rate.get_value()
|
||||
rate_value = heart_rate.get_rate()
|
||||
if rate_value:
|
||||
print(rate_value)
|
||||
time.sleep(0.02)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import time
|
||||
from pinpong.board import Board
|
||||
from pinpong.libs.dfrobot_bme280 import BME280
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
bme = BME280()
|
||||
|
||||
while True:
|
||||
temp = bme.temp_c()
|
||||
press = bme.press_pa()
|
||||
alti = bme.cal_altitudu()
|
||||
humi = bme.humidity()
|
||||
print("temperature: %.2f C" % temp)
|
||||
print("preass: %d pa"% press)
|
||||
print("altitudu: %.2f m"% alti)
|
||||
print("humitity: %.2f"% humi)
|
||||
time.sleep(1)
|
||||
@ -0,0 +1,16 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import time
|
||||
from pinpong.board import Board
|
||||
from pinpong.libs.dfrobot_vl53l0 import VL53L0
|
||||
|
||||
Board("uno").begin()#初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
vl = VL53L0(bus_num=4)
|
||||
|
||||
while True:
|
||||
distance = vl.get_distance_mm()
|
||||
print("distance: %.2f mm"%(distance))
|
||||
time.sleep(0.5)
|
||||
@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import time
|
||||
from pinpong.board import Board
|
||||
from pinpong.libs.dfrobot_lis2dh import LIS2DH
|
||||
|
||||
Board("uno").begin()#初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
lis = LIS2DH()
|
||||
|
||||
# Set measurement range
|
||||
# Ga: LIS2DH12_RANGE_2GA
|
||||
# Ga: LIS2DH12_RANGE_4GA
|
||||
# Ga: LIS2DH12_RANGE_8GA
|
||||
# Ga: LIS2DH12_RANGE_16GA
|
||||
while not lis.init(lis.LIS2DH12_RANGE_8GA):
|
||||
print("No I2C devices found")
|
||||
time.sleep(1)
|
||||
|
||||
while True:
|
||||
lis.read_XYZ()
|
||||
print("x = %.0f mg, y = %.0f mg,z =%.0f mg"%(lis.x, lis.y, lis.z))
|
||||
time.sleep(0.1)
|
||||
@ -0,0 +1,23 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import time
|
||||
from pinpong.board import Board
|
||||
from pinpong.libs.dfrobot_bmp388 import BMP388
|
||||
|
||||
Board("uno").begin()#初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
bmp = BMP388()
|
||||
|
||||
while True:
|
||||
altitude = bmp.cal_altitude_m()
|
||||
pressure = bmp.pressure_pa()
|
||||
temp = bmp.temp_C()
|
||||
print("-----------------------------")
|
||||
print("altitude = %.2f m"% altitude)
|
||||
print("pressure = %.2f pa"% pressure)
|
||||
print("read_temperature = %.2f C"% temp)
|
||||
print("-----------------------------")
|
||||
time.sleep(0.5)
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import time
|
||||
from pinpong.board import Board
|
||||
from pinpong.libs.dfrobot_ina219 import INA219 #从libs中导入INA291库
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
ina = INA219(i2c_addr=0x45, bus_num=4) #初始化传感器,设置I2C地址
|
||||
|
||||
ina.begin()
|
||||
#ina.linear_calibrate(1000)
|
||||
|
||||
while True:
|
||||
vol = ina.get_bus_voltage_mv()
|
||||
print("vol==%.2f mV"%vol)
|
||||
time.sleep(0.5)
|
||||
|
||||
vol = ina.get_current_ma()
|
||||
print("vol==%.2f mA"%vol)
|
||||
time.sleep(0.5)
|
||||
|
||||
vol = ina.get_power_mw()
|
||||
print("vol==%.2f mW"%vol)
|
||||
time.sleep(0.5)
|
||||
|
||||
vol = ina.get_shunt_voltage_mv()
|
||||
print("vol==%.2f mV"%vol)
|
||||
time.sleep(0.5)
|
||||
|
||||
print("-------------------")
|
||||
@ -0,0 +1,24 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:读取I2C CCS811空气质量传感器
|
||||
#接线:使用windows或linux电脑连接一块arduino主控板,空气质量传感器接到I2C口SCL SDA
|
||||
import time
|
||||
from pinpong.board import Board
|
||||
from pinpong.libs.dfrobot_ccs811 import CCS811, CCS811_Ecycle, CCS811_Emode
|
||||
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
ccs811 = CCS811()
|
||||
|
||||
#ccs811.write_base_line(baseline) #获取到的基线填入
|
||||
while True:
|
||||
if(ccs811.check_data_ready()):
|
||||
print("CO2:"+str(ccs811.co2_ppm())+" ppm")
|
||||
print("TVOC:"+str(ccs811.tvoc_ppb())+" ppb")
|
||||
else:
|
||||
print("data is not ready!")
|
||||
time.sleep(1)
|
||||
@ -0,0 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#实验效果:读取I2C CCS811空气质量传感器
|
||||
#接线:使用windows或linux电脑连接一块arduino主控板,空气质量传感器接到I2C口SCL SDA
|
||||
import time
|
||||
from pinpong.board import Board
|
||||
from pinpong.libs.dfrobot_ccs811 import CCS811, CCS811_Ecycle, CCS811_Emode
|
||||
|
||||
|
||||
Board("uno").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
|
||||
#Board("uno","COM36").begin() #windows下指定端口初始化
|
||||
#Board("uno","/dev/ttyACM0").begin() #linux下指定端口初始化
|
||||
#Board("uno","/dev/cu.usbmodem14101").begin() #mac下指定端口初始化
|
||||
|
||||
ccs811 = CCS811()
|
||||
|
||||
while True:
|
||||
if(ccs811.check_data_ready()):
|
||||
print("baseline:",ccs811.read_baseline())
|
||||
else:
|
||||
print("data is not ready!")
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user