From 4b1455322bd4271a91f9ceac64e6b66615c186a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E4=B8=8A=E6=B8=B8?= <8647356+zengshanyou@user.noreply.gitee.com> Date: Fri, 16 Jul 2021 00:37:29 +0000 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adxl335/code/adxl335.py | 19 ++++++++++++ adxl335/code/main.py | 28 +++++++++++++++++ ...7\264\346\230\216\346\226\207\346\241\243" | 30 +++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 adxl335/code/adxl335.py create mode 100644 adxl335/code/main.py create mode 100644 "adxl335/\350\257\264\346\230\216\346\226\207\346\241\243" diff --git a/adxl335/code/adxl335.py b/adxl335/code/adxl335.py new file mode 100644 index 0000000..67df5c1 --- /dev/null +++ b/adxl335/code/adxl335.py @@ -0,0 +1,19 @@ +from machine import Pin +from machine import ADC +import utime +x=ADC(Pin(5)) +y=ADC(Pin(12)) +z=ADC(Pin(13)) +x.equ(ADC.EQU_MODEL_8) +x.atten(ADC.CUR_BAIS_DEFAULT) +y.equ(ADC.EQU_MODEL_8) +y.atten(ADC.CUR_BAIS_DEFAULT) +z.equ(ADC.EQU_MODEL_8) +z.atten(ADC.CUR_BAIS_DEFAULT) + +def xyzread(x,y,z): + accx=x.read() + accy=y.read() + accz=z.read() + acclist=[accx,accy,accz] + return acclist diff --git a/adxl335/code/main.py b/adxl335/code/main.py new file mode 100644 index 0000000..5a49ded --- /dev/null +++ b/adxl335/code/main.py @@ -0,0 +1,28 @@ +from machine import ADC,Pin +import utime +x=ADC(Pin(5)) +y=ADC(Pin(12)) +z=ADC(Pin(13)) +x.equ(ADC.EQU_MODEL_8) +x.atten(ADC.CUR_BAIS_DEFAULT) +y.equ(ADC.EQU_MODEL_8) +y.atten(ADC.CUR_BAIS_DEFAULT) +z.equ(ADC.EQU_MODEL_8) +z.atten(ADC.CUR_BAIS_DEFAULT) + +def xyzread(x,y,z): + accx=x.read() + accy=y.read() + accz=z.read() + acclist=[accx,accy,accz] + return acclist +steps = 0 + + +while 1: + acclist=xyzread(x,y,z) + acc = acclist[0]*acclist[0]+acclist[1]*acclist[1]+acclist[2]*acclist[2] + if (acc>2500000): + steps=steps+1 + print(steps) + utime.sleep(1.4) \ No newline at end of file diff --git "a/adxl335/\350\257\264\346\230\216\346\226\207\346\241\243" "b/adxl335/\350\257\264\346\230\216\346\226\207\346\241\243" new file mode 100644 index 0000000..5eec97a --- /dev/null +++ "b/adxl335/\350\257\264\346\230\216\346\226\207\346\241\243" @@ -0,0 +1,30 @@ +传感器选择 +   传感器选择如下图所示的型号为adxl335的加速度模组。 + + +传感器接线 +  传感器与Waffle Nano 之间的接线方式如下表所示,且未在下表中显示的引脚均处于悬空不连装态。 + +Waffle Nano 传感器 +3.3 Vcc +IO5 Xout +IO12 Yout +IO13 Zout +GND GND + + + +传感器库使用 +  可以获取adxl335.py,将此库通过Waffle Maker 的文件上传功能将此库上传到Waffle Nano上。 +  我们在可以在主函数中使用以下代码导入此库。 +from adxl335 import adxl335 +   Xyzread()#读取xyz三轴加速度,返回列表 +案例代码复现 + Simple code:打印三轴加速度 +while 1: +    acclist=xyzread(x,y,z) +    print(acclist) +    utime.sleep(0.7) + + +   \ No newline at end of file -- Gitee