diff --git "a/ATG336H/GPS\346\250\241\345\235\227.md" "b/ATG336H/GPS\346\250\241\345\235\227.md" new file mode 100644 index 0000000000000000000000000000000000000000..e419a23cc4bc700184973b613aa6d98109be1a1e --- /dev/null +++ "b/ATG336H/GPS\346\250\241\345\235\227.md" @@ -0,0 +1,55 @@ +# GPS模块 + +## 案例展示 + +!![](../ATG336H/img/connect.jpg)[] + +## 物理连接 + +### 传感器选择 + +![](../ATG336H/img/ATG336H.jpg) + +   传感器选择如上图所示的型号为ATG336H的GPS模块。 + +### 传感器接线 + +  传感器与Waffle Nano 之间的接线方式如下表所示,且未在下表中显示的引脚均处于悬空不连装态。 + +| Waffle Nano | | +| ----------- | ---- | +| 3.3 | vcc | +| IO0 | RX | +| IO1 | TX | +| GND | GND | + +## 传感器库使用 + + 可以获取[max30102.py](https://gitee.com/blackwalnutlabs/waffle-nano-v1-sensor-lib/blob/master/ATG336H/code/ATGM336H_5N.py),将此库通过[Waffle Maker](https://wafflenano.blackwalnut.tech/ide/index.html#/editor) 的文件上传功能将此库上传到`Waffle Nano`上。 + +  我们在可以在主函数中使用以下代码导入此库。 + +``` +import ATGM336H_5N() +``` + +  在对象构造函数中,我们需要传入一个已经构造好的`UART对象。 + +``` +# 此处省略UART对象的构造过程 +ag = ATGM336H_5N(uart) #构造ATGM336H对象 +``` + +​ 我们使用函数将数据转换成经纬度。 + +``` +ag.analysis() #将GPS中所读的数据转换成经纬度 +``` + +  关于此库相关细节说明详见代码注释 + +## 案例代码复现 + +  可以获取[main.py](https://gitee.com/blackwalnutlabs/waffle-nano-v1-sensor-lib/blob/master/ATG336H/code/main.py)函数,将其内容复制到[Waffle Maker](https://wafflenano.blackwalnut.tech/ide/index.html#/editor) 编辑器上传输给`Waffle Nano`,以复现此案例。 + +  案例相关细节说明详见代码注释 \ No newline at end of file diff --git a/ATG336H/code/ATGM336H_5N.py b/ATG336H/code/ATGM336H_5N.py new file mode 100644 index 0000000000000000000000000000000000000000..98bd1a85ad8105a893392f9b44c24fc839fd32db --- /dev/null +++ b/ATG336H/code/ATGM336H_5N.py @@ -0,0 +1,68 @@ +from machine import UART,Pin +uart = UART(1, baudrate=9600,parity=0,rx=Pin(1),tx=Pin(0),timeout=10) +import utime + +class ATGM336H_5N(): + def __init__(self,uart): + self.msg="" + self.sign=0 + self.sign2=0 + self.final="" + self.longitude="" + self.latitude="" + self.latitude_direction="" + self.longitude_direction="" + self.uart = uart + self.n=0 + self.e=0 + + def analysis(self): + while(True): + while (not self.uart.bufempty()): + try: + temp=str(self.uart.read(1),'utf-8') + except UnicodeError as e: + time.sleep_us(1) + self.msg=self.msg+temp + if(temp=="\n"): + if(self.msg[0]=="$"): + self.sign=1 + break + else: + self.msg="" + if(self.sign==1): + self.sign=0 + if(self.msg[0:6]=="$GNRMC"): + count=0 + self.sign2=1 + while(self.msg.find(',')!=-1): + index=self.msg.find(',') + if(count==3): + self.latitude=self.msg[0:index] + if(count==4): + self.latitude_direction=self.msg[0:index] + if(count==5): + self.longitude=self.msg[0:index] + if(count==6): + self.longitude_direction=self.msg[0:index] + self.msg=self.msg[index+1:] + count=count+1 + if(self.sign2==1): + self.n = float(self.latitude) + self.n = int(self.n/100) + (self.n - int(self.n/100)*100)/60 + print("latitude:"+str(self.n)) + print("latitude_direction:"+self.latitude_direction) + N=0 + if(self.latitude_direction=="N"): + N=1 + self.e = float(self.longitude) + self.e = int(self.e/100) + (self.e - int(self.e/100)*100)/60 + print("longitude:"+str(self.e)) + print("longitude_direction:"+self.longitude_direction) + E=0 + if(self.longitude_direction=="E"): + E=1 + final="["+str(self.n)+","+"N"+","+str(self.e)+","+"E"+"]" + print(final) + self.sign2=0 + self.msg="" \ No newline at end of file diff --git a/ATG336H/code/main.py b/ATG336H/code/main.py new file mode 100644 index 0000000000000000000000000000000000000000..18da876ca3ac88ae2d836626dea83435582992b0 --- /dev/null +++ b/ATG336H/code/main.py @@ -0,0 +1,10 @@ +from machine import UART,Pin +import utime +from ATGM336H_5N import ATGM336H_5N + +uart = UART(1) +uart.init(baudrate=9600, parity=0, rx=Pin(1), tx=Pin(0)) +ag = ATGM336H_5N(uart) + +while True: + ag.analysis() \ No newline at end of file diff --git a/ATG336H/img/ATG336H.jpg b/ATG336H/img/ATG336H.jpg new file mode 100644 index 0000000000000000000000000000000000000000..21d28601ad6e5f14dcfefe803d46f6cc9aca62e6 Binary files /dev/null and b/ATG336H/img/ATG336H.jpg differ diff --git a/ATG336H/img/connect.jpg b/ATG336H/img/connect.jpg new file mode 100644 index 0000000000000000000000000000000000000000..6d6963ad3a7fed2fad53ed4e45687c884849a795 Binary files /dev/null and b/ATG336H/img/connect.jpg differ diff --git a/ATG336H/img/wallfe nano ATG.png b/ATG336H/img/wallfe nano ATG.png new file mode 100644 index 0000000000000000000000000000000000000000..7da5954253dc01ec6f2c3e72708d84bb7cd684ad Binary files /dev/null and b/ATG336H/img/wallfe nano ATG.png differ diff --git a/MAX_30102/code/main.py b/MAX_30102/code/main.py new file mode 100644 index 0000000000000000000000000000000000000000..3b625dde2298483dfafcf7c1c8c7a30159293716 --- /dev/null +++ b/MAX_30102/code/main.py @@ -0,0 +1,22 @@ +from machine import I2C, Pin +import max30102 +from utime import sleep +from machine import SPI, Pin + + +m = max30102.Max30102(0,1,100) + +hr = 70 +while True: + red,ir = m.read_fifo() + R = red/ir + if red < 20000: + print("please put your finger") + else: + hr = str(int(30/30000*(red-230000)+60)) + spo2 =str(int(-45.060*R*R+30.354 *R + 94.845+22)) + print(red,ir,spo2,hr) + + display.draw_string(10, 10,"hr = %s " %hr,size=3,color=st7789.color565(0, 0, 0)) + display.draw_string(10, 50,"spo2 = %s " %spo2,size=3,color=st7789.color565(0, 0, 0)) + # display.ST7789.fill_rect(10, 10, 200, 200,st7789.color565(255, 255, 255)) \ No newline at end of file diff --git a/MAX_30102/code/max30102.py b/MAX_30102/code/max30102.py new file mode 100644 index 0000000000000000000000000000000000000000..4ad20dfd82f670f02d37b64f8a84cb4164b7b043 --- /dev/null +++ b/MAX_30102/code/max30102.py @@ -0,0 +1,130 @@ +from machine import I2C, Pin +# i2c = I2C(1, sda=Pin(0), scl=Pin(1),freq=400000) +from utime import sleep +I2C_WRITE_ADDR = 0xAE +I2C_READ_ADDR = 0xAF + +# register address-es +REG_INTR_STATUS_1 = 0x00 +REG_INTR_STATUS_2 = 0x01 + +REG_INTR_ENABLE_1 = 0x02 +REG_INTR_ENABLE_2 = 0x03 + +REG_FIFO_WR_PTR = 0x04 +REG_OVF_COUNTER = 0x05 +REG_FIFO_RD_PTR = 0x06 +REG_FIFO_DATA = 0x07 +REG_FIFO_CONFIG = 0x08 + +REG_MODE_CONFIG = 0x09 +REG_SPO2_CONFIG = 0x0A +REG_LED1_PA = 0x0C + +REG_LED2_PA = 0x0D +REG_PILOT_PA = 0x10 +REG_MULTI_LED_CTRL1 = 0x11 +REG_MULTI_LED_CTRL2 = 0x12 + +REG_TEMP_INTR = 0x1F +REG_TEMP_FRAC = 0x20 +REG_TEMP_CONFIG = 0x21 +REG_PROX_INT_THRESH = 0x30 +REG_REV_ID = 0xFE +REG_PART_ID = 0xFF + +class Max30102(): + def __init__(self,sda_pin,scl_pin,fre): + # print("Channel: {0}, address: {1}".format(channel, address)) + self.i2c = I2C(1, sda=Pin(sda_pin), scl=Pin(scl_pin),freq=fre) + self.address = 87 + + self.reset() + + sleep(1) # wait 1 sec + + # read & clear interrupt register (read 1 byte) + reg_data = self.i2c.readfrom_mem(self.address, REG_INTR_STATUS_1, 1) + # print("[SETUP] reset complete with interrupt register0: {0}".format(reg_data)) + self.setup() + + def shutdown(self): + """ + Shutdown the device. + """ + self.i2c.write(87, b'\x09\x80') + + def reset(self): + """ + Reset the device, this will clear all settings, + so after running this, run setup() again. + """ + self.i2c.write(87, b'\x09\x40') + + + def setup(self): + """ + This will setup the device with the values written in sample Arduino code. + """ + # INTR setting + # 0xc0 : A_FULL_EN and PPG_RDY_EN = Interrupt will be triggered when + # fifo almost full & new fifo data ready + self.i2c.write(87, b' \x02\xc0') + self.i2c.write(87, b'\x03\xc0') + + # FIFO_WR_PTR[4:0] + self.i2c.write(87, b'\x04\xc0') + # OVF_COUNTER[4:0] + self.i2c.write(87, b'\x05\xc0') + # FIFO_RD_PTR[4:0] + self.i2c.write(87, b'\x06\xc0') + + # 0b 0100 1111 + # sample avg = 4, fifo rollover = false, fifo almost full = 17 + self.i2c.write(87, b'\x08\x4f') + + # 0x02 for read-only, 0x03 for SpO2 mode, 0x07 multimode LED + self.i2c.write(87, b'\x09\x03') + # 0b 0010 0111 + # SPO2_ADC range = 4096nA, SPO2 sample rate = 100Hz, LED pulse-width = 411uS + self.i2c.write(87, b'\x0A\x27') + + # choose value for ~7mA for LED1 + self.i2c.write(87, b'\x0C\x40') + # choose value for ~7mA for LED2 + self.i2c.write(87, b'\x0D\x40') + # choose value fro ~25mA for Pilot LED + self.i2c.write(87, b'\x10\x7f') + + def read_fifo(self): + """ + This function will read the data register. + """ + red_led = None + ir_led = None + + # read 1 byte from registers (values are discarded) + reg_INTR1 = self.i2c.readfrom_mem(87, REG_INTR_STATUS_1, 1) + reg_INTR2 = self.i2c.readfrom_mem(87, REG_INTR_STATUS_2, 1) + + # read 6-byte data from the device + d = self.i2c.readfrom_mem(87, REG_FIFO_DATA, 6) + # mask MSB [23:18] + red_led = (d[0] << 16 | d[1] << 8 | d[2]) & 0x03FFFF + ir_led = (d[3] << 16 | d[4] << 8 | d[5]) & 0x03FFFF + + return red_led, ir_led + + def read_sequential(self): + """ + This function will read the red-led and ir-led `amount` times. + This works as blocking function. + """ + red_buf = [] + ir_buf = [] + for i in range(100): + red, ir = self.read_fifo() + red_buf.append(red) + ir_buf.append(ir) + + return red_buf, ir_buf diff --git a/MAX_30102/img/max30102.jpg b/MAX_30102/img/max30102.jpg new file mode 100644 index 0000000000000000000000000000000000000000..30e554c40007ded350f51a28463d82a21b00f775 Binary files /dev/null and b/MAX_30102/img/max30102.jpg differ diff --git a/MAX_30102/img/waffle_nano_max30102.jpg b/MAX_30102/img/waffle_nano_max30102.jpg new file mode 100644 index 0000000000000000000000000000000000000000..3819c4042159fb0d91285c0e8769417d60335860 Binary files /dev/null and b/MAX_30102/img/waffle_nano_max30102.jpg differ diff --git "a/MAX_30102/\345\277\203\347\216\207\350\241\200\346\260\247\344\274\240\346\204\237\345\231\250\346\250\241\345\235\227.md" "b/MAX_30102/\345\277\203\347\216\207\350\241\200\346\260\247\344\274\240\346\204\237\345\231\250\346\250\241\345\235\227.md" new file mode 100644 index 0000000000000000000000000000000000000000..567df619250573d11ca3621185117b179bdf72ad --- /dev/null +++ "b/MAX_30102/\345\277\203\347\216\207\350\241\200\346\260\247\344\274\240\346\204\237\345\231\250\346\250\241\345\235\227.md" @@ -0,0 +1,55 @@ +# 心率血氧传感器模块 + +## 案例展示 + +![](img/max30102.jpg) + +## 物理连接 + +### 传感器选择 + +![](img/waffle_nano_max30102.jpg) + +   传感器选择如上图所示的型号为MAX30102的心率血氧传感器模块。 + +### 传感器接线 + +  传感器与Waffle Nano 之间的接线方式如下表所示,且未在下表中显示的引脚均处于悬空不连装态。 + +| Waffle Nano | | +| ----------- | ---- | +| 3.3 | UIN | +| IO0 | SDA | +| IO1 | SCL | +| GND | GND | + +## 传感器库使用 + + 可以获取[max30102.py](https://gitee.com/blackwalnutlabs/waffle-nano-v1-sensor-lib/blob/master/MAX_30102/code/max30102.py),将此库通过[Waffle Maker](https://wafflenano.blackwalnut.tech/ide/index.html#/editor) 的文件上传功能将此库上传到`Waffle Nano`上。 + +  我们在可以在主函数中使用以下代码导入此库。 + +``` +import max30102 +``` + +  在对象构造函数中,我们需要传入一个已经构造好的`IIC`对象,并要给出sda,scl,采样频率的数值。 + +``` +# 此处省略IIC对象的构造过程 +m = max30102.Max30102(0,1,100) #构造max30102对象 +``` + +​ 我们使用实时时钟对象的read_fifo()方法读取出red和ir的数值。 + +``` +red,ir = m.read_fifo() #从血氧芯片中获取数据 +``` + +  关于此库相关细节说明详见代码注释 + +## 案例代码复现 + +  可以获取[main.py](https://gitee.com/blackwalnutlabs/waffle-nano-v1-sensor-lib/blob/master/MAX_30102/code/main.py)函数,将其内容复制到[Waffle Maker](https://wafflenano.blackwalnut.tech/ide/index.html#/editor) 编辑器上传输给`Waffle Nano`,以复现此案例。 + +  案例相关细节说明详见代码注释 \ No newline at end of file