第一部分:用跳繩測試儀解決運(yùn)動(dòng)不足問題!
大家好,我是吉田!
在第一部分中,我們簡要介紹了本項(xiàng)目以及所需的準(zhǔn)備工作,從第二部分開始,我們將著手制作這款旨在解決運(yùn)動(dòng)不足問題的跳繩設(shè)備。首先,讓我們嘗試在跳繩上附加SensorMedal,并檢測跳躍次數(shù)吧。在四位顯示器上以數(shù)字形式顯示次數(shù),可以方便您隨時(shí)查看跳躍次數(shù)。
本部分所需部件
跳繩
ROHM SensorMedal(SensorMedal-EVK-002)
Raspberry Pi zero(Raspberry Pi Zero W)
本部分的流程
用SensorMedal進(jìn)行跳繩計(jì)數(shù)
在四位顯示器上顯示
跳繩并顯示次數(shù)
總結(jié)
1. 用SensorMedal進(jìn)行跳繩計(jì)數(shù)
在制作跳繩設(shè)備時(shí),需要準(zhǔn)備一根跳繩。對跳繩沒有格外要求,如果可能的話,最好使用手柄較粗較長的,這樣更容易操作。
然后,考慮計(jì)算跳躍次數(shù)的方法。最直接的辦法就是對跳繩旋轉(zhuǎn)部分每轉(zhuǎn)一圈計(jì)一次這樣進(jìn)行計(jì)數(shù)。這個(gè)可以通過將磁鐵等連接到跳繩的旋轉(zhuǎn)端并用霍爾傳感器對其進(jìn)行檢測來實(shí)現(xiàn)。然而,在旋轉(zhuǎn)部分安裝霍爾傳感器并安裝用來獲取檢測結(jié)果的電路,還涉及到空間問題,難度較高。
這次我們使用SensorMedal的加速度傳感器來檢測跳繩手柄部分的加速度,并作為跳躍次數(shù)來計(jì)數(shù)。這樣的話,還可以捕捉雙飛和雙臂交叉跳等的動(dòng)作,也許還可以檢測出跳法。
現(xiàn)在,我們先將紐扣電池CR2450裝入SensorMedal中并打開電源。用扎帶等將已經(jīng)接通電源的SensorMedal連接到跳繩的手柄上。SensorMedal很輕,而且尺寸不大,所以我認(rèn)為裝上它并不會妨礙跳繩。
接下來,準(zhǔn)備用Raspberry Pi Zero來接收這個(gè)SensorMedal的傳感器值。另外,安裝一個(gè)名為“bluepy”的庫,以便用藍(lán)牙將Raspberry Pi和SensorMedal連接起來。
然后,使用Github(http://github.com/bokunimowakaru/SensorMedal2)上的便利程序來顯示從SensorMedal接收到的數(shù)值。使用“git clone”下載程序。
運(yùn)行示例程序ble_logger_SensorMedal2.py。
pi@raspizero:~ $ sudo pip3 install bluepy Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple Collecting bluepy Installing collected packages: bluepy Successfully installed bluepy-1.3.0 pi@raspizero:~ $ sudo git clone http://github.com/bokunimowakaru/SensorMedal2 Cloning into 'SensorMedal2'... Unpacking objects: 100% (78/78), done. pi@raspizero:~ $ cd SensorMedal2/ pi@raspizero:~/SensorMedal2 $ sudo python3 ble_logger_SensorMedal2.py Device c5:xx:yy:zz::d0 (random), RSSI=-65 dB Short Local Name = ROHMMedal2_0107_01.00 Flags = 06 Incomplete 16b Services = 0000180a-0000 Manufacturer = 0100c86abcdef ID = 0x1 SEQ = 188 Temperature = 27.99 ℃ Humidity = 71.52 % Pressure = 998.578 hPa Illuminance = 93.3 lx Accelerometer = 1.453 g ( 0.062 0.844 1.181 g) Geomagnetic = 92.6 uT ( -15.8 -58.0 -70.4 uT) Magnetic = 0x3 Steps = 8 歩 Battery Level = 90 % RSSI = -65 dB
作為加速度,SensorMedal輸出Accelerometer上的x、y 、z軸的加速度,以及合成的重力加速度(g)。在前面的圖中,跳繩時(shí)的重力加速度為2?4g,SensorMedal以相似的形式,檢測到一定的重力加速度,并輸出Steps的值。這次我們將使用這個(gè)數(shù)值作為跳繩時(shí)的跳躍次數(shù)。
另外,還需要計(jì)算一下跳繩時(shí)消耗的卡路里。在第一部分的文章中,提到過通過卡路里計(jì)算,可知每分鐘跳100次左右、跳30分鐘消耗的卡路里是270大卡,所以我們直接使用這個(gè)數(shù)值。
(每跳一次消耗的卡路里=270大卡/30*100次≒0.1大卡/次)
使用了該數(shù)值的Python程序ble_jump.py如下:
pi@raspizero:~/SensorMedal2 $ sudo cp ble_logger_SensorMedal2.py ../Programs/ble_jump.py --- 下面的第5?7、第12、第16?18、第42?55行是更改或添加部分 --- interval = 1 #動(dòng)作間隔 start_seq = 0 jump_cnt = 0 --- # 每個(gè)BLE設(shè)備的接收數(shù)據(jù)處理 for dev in devices: # print("nDevice %s (%s), RSSI=%d dB" % (dev.addr, dev.addrType, dev.rssi)) isRohmMedal = False sensors = dict() for (adtype, desc, val) in dev.getScanData(): # print(" %s = %s" % (desc, val)) if desc == 'Short Local Name' and val[0:18] == 'ROHMMedal2_xxxx_xx': # 在xxxx_xx中輸入您使用的SensorMedal編號 print(“JUMP!”) isRohmMedal = True if isRohmMedal and desc == 'Manufacturer': --- # 在顯示器上顯示 print(' ID =',sensors['ID']) print(' SEQ =',sensors['SEQ']) “”” print(' Temperature =',round(sensors['Temperature'],2),'℃') print(' Humidity =',round(sensors['Humidity'],2),'%') print(' Pressure =',round(sensors['Pressure'],3),'hPa') print(' Illuminance =',round(sensors['Illuminance'],1),'lx') print(' Accelerometer =',round(sensors['Accelerometer'],3),'g (', round(sensors['Accelerometer X'],3), round(sensors['Accelerometer Y'],3), round(sensors['Accelerometer Z'],3),'g)') print(' Geomagnetic =',round(sensors['Geomagnetic'],1),'uT (', round(sensors['Geomagnetic X'],1), round(sensors['Geomagnetic Y'],1), round(sensors['Geomagnetic Z'],1),'uT)') print(' Magnetic =',sensors['Magnetic']) print(' Steps =',sensors['Steps'],'歩') print(' Battery Level =',sensors['Battery Level'],'%') print(' RSSI =',sensors['RSSI'],'dB') ””” SEQ = sensors['SEQ'] jump_cnt = sensors['Steps'] if SEQ in [0,1] and jump_cnt == 0: start_seq+= 1 print(“START!") else: last_cnt = jump_cnt if start_seq >= 1: cur_cnt = jump_cnt cur_cal = round(cur_cnt*0.1,1) jump_text= str(cur_cnt)+" Jump "+str(cur_cal)+" Cal" print(jump_text) ''' for key, value in sorted(sensors.items(), key=lambda x:x[0]): print(' ',key,'=',value) '''
像sudo python3 ble_jump.py一樣運(yùn)行這個(gè)程序后,按一下SensorMedal上的開關(guān)?,F(xiàn)在,可以跳繩了!您看到如下顯示的跳躍次數(shù)和燃燒的卡路里了嗎?
2. 在四位顯示器上顯示
獲得跳躍次數(shù)后,我們嘗試在手邊顯示該數(shù)值吧。這次我們使用可與Raspberry Pi Zero完美兼容的Pimoroni的四位顯示器。這個(gè)顯示器由每個(gè)字符的顯示器和電路板組成,所以需要把它們焊接起來。
下面的照片是焊接好的狀態(tài)(焊得有點(diǎn)粗糙)。
焊接完成后,將Pimoroni提供的庫安裝到Raspberry Pi上。請?jiān)L問下面的Github:
[ Pimoroni 四位顯示器的 Github https://github.com/pimoroni/fourletter-phat ]
或者只需使用Raspberry Pi運(yùn)行以下命令進(jìn)行安裝:
$ curl https://get.pimoroni.com/fourletterphat | bash
安裝完成后,將會在名為“Pimoroni”的目錄下找到一個(gè)名為“fourletter-phat”的顯示示例程序。在這個(gè)示例程序中,讓我們運(yùn)行一下程序 (clock.py),顯示當(dāng)前時(shí)間作為時(shí)鐘。
$ python ~/Pimoroni/fourletter-phat/examples/clock.py
當(dāng)前時(shí)間顯示如下:
3. 跳繩并顯示次數(shù)
我們已經(jīng)實(shí)現(xiàn)了四位數(shù)字的顯示,現(xiàn)在我們嘗試顯示跳繩時(shí)的跳躍次數(shù)。只需復(fù)制ble_jump.py并添加下面的淺藍(lán)色部分即可創(chuàng)建為ble_jump_4d.jpy。
pi@raspizero:~/Programs $ sudo cp ble_jump.py ble_jump_4d.py --- 下面的第4、11、12行為更改或添加部分 --- import fourletterphat --- if start_seq >= 1: cur_cnt = jump_cnt cur_cal = round(cur_cnt*0.1,1) jump_text= str(cur_cnt)+" Jump "+str(cur_cal)+" Cal" print(jump_text) fourletterphat.print_number_str(cur_cnt) fourletterphat.show() ''' for key, value in sorted(sensors.items(), key=lambda x:x[0]): print(' ',key,'=',value) '''
最后,讓我們更細(xì)致地安裝SensorMedal和Raspberry Pi。首先,我決定將它們安裝到跳繩手柄上方相對平坦的位置。使用較大刀具等在上部開一個(gè)孔,以便Raspberry Pi Zero的引腳正好嵌入進(jìn)去。在開孔位置的背面安裝Raspberry Pi,正面安裝四位顯示器。
注意不要讓它們干涉繩索部分,將Raspberry Pi和四位顯示器固定在開孔的兩面安裝好之后,跳繩設(shè)備就制作完成啦!
現(xiàn)在讓我們運(yùn)行ble_jump_4d.py并開始跳繩吧!
4. 總結(jié)
至此,我們成功地使用Raspberry Pi和SensorMedal實(shí)現(xiàn)了跳繩的數(shù)字化,并關(guān)聯(lián)物聯(lián)網(wǎng)。當(dāng)初的計(jì)劃是制作一款通過輕松的跳繩運(yùn)動(dòng)來助力解決運(yùn)動(dòng)不足問題的設(shè)備。
我們已經(jīng)實(shí)現(xiàn)了基本的功能:跳躍次數(shù)計(jì)量和顯示次數(shù)。您可以試用一下這款跳繩,看看它是否能夠正確計(jì)數(shù)。
在下一部分中,我們會將創(chuàng)建激發(fā)動(dòng)力的機(jī)制,將跳繩連接到互聯(lián)網(wǎng),以保存和顯示以往的次數(shù)和消耗的卡路里。
敬請期待!
本系列連載一覽
第一部分:用跳繩測試儀解決運(yùn)動(dòng)不足問題!
第二部分:用SensorMedal檢測跳躍次數(shù)并在顯示器上顯示(本章)
第三部分:連接Google Drive,保存并查看跳繩結(jié)果
第四部分:在設(shè)備上安裝顯示器以增加動(dòng)力!
審核編輯黃宇
-
測試儀
+關(guān)注
關(guān)注
6文章
3785瀏覽量
55109 -
Raspberry Pi
+關(guān)注
關(guān)注
2文章
559瀏覽量
22342
發(fā)布評論請先 登錄
相關(guān)推薦
評論