久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 8856|回復(fù): 42
打印 上一主題 下一主題
收起左側(cè)

【Arduino】168種傳感器模塊系列實(shí)驗(yàn)(158)---QMC5883L三軸羅盤

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
37款傳感器與模塊的提法,在網(wǎng)絡(luò)上廣泛流傳,其實(shí)Arduino能夠兼容的傳感器模塊肯定是不止37種的。鑒于本人手頭積累了一些傳感器和執(zhí)行器模塊,依照實(shí)踐出真知(一定要?jiǎng)邮肿觯┑睦砟睿詫W(xué)習(xí)和交流為目的,這里準(zhǔn)備逐一動(dòng)手試試做實(shí)驗(yàn),不管成功與否,都會(huì)記錄下來---小小的進(jìn)步或是搞不定的問題,希望能夠拋磚引玉。

【Arduino】168種傳感器模塊系列實(shí)驗(yàn)(資料代碼+圖形編程+仿真編程)
實(shí)驗(yàn)一百五十八:QMC5883L電子指南針羅盤模塊 三軸磁場(chǎng)傳感器GY-271









分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:513258 發(fā)表于 2021-1-22 21:40 | 只看該作者


QMC5883L
源于Honeywell的HMC5883L,是一款表面貼裝的集成了信號(hào)處理電路的三軸磁性傳感器,應(yīng)用場(chǎng)景主要包括羅盤、導(dǎo)航、無人機(jī)、機(jī)器人和手持設(shè)備等一些高精度的場(chǎng)合。HMC5883是霍尼韋爾公司生產(chǎn)的一款地磁場(chǎng)檢測(cè)芯片,其國(guó)產(chǎn)替代產(chǎn)品為QMC5883。這兩種芯片基本相似,QMC 5883也是號(hào)稱得到了霍尼韋爾公司的授權(quán)。

回復(fù)

使用道具 舉報(bào)

板凳
ID:513258 發(fā)表于 2021-1-23 08:57 | 只看該作者
QMC5883L特征
(1)霍尼韋爾(中國(guó))QMC5883L是一款表面貼裝多芯片模塊,設(shè)計(jì)用于具有數(shù)字接口的低場(chǎng)磁感應(yīng),適用于低成本指南針和磁力計(jì)等應(yīng)用
(2)結(jié)合低噪聲AMR傳感器的12位ADC在±8高斯場(chǎng)中實(shí)現(xiàn)5毫高斯場(chǎng)分辨率
(3)低電壓運(yùn)行,低功耗; 支持內(nèi)置的自檢
(4)內(nèi)置式皮帶驅(qū)動(dòng)電路,I2C數(shù)字接口,寬磁場(chǎng)范圍(+/- 8 oe)
(5)工作電壓:3.3v-5v; PCB尺寸:1.3 x 2.3厘米(QMC5883L尺寸:3.0 x 3.0 x 0.9毫米),帶有16引腳無鉛芯片載體(LCC)




回復(fù)

使用道具 舉報(bào)

地板
ID:513258 發(fā)表于 2021-1-23 09:39 | 只看該作者
QMC5883L內(nèi)部原理圖




回復(fù)

使用道具 舉報(bào)

5#
ID:513258 發(fā)表于 2021-1-23 09:57 | 只看該作者
QMC5883L是一款多芯片三軸磁傳感器。 這個(gè)表面貼裝的小尺寸芯片集成了磁傳感器信號(hào)條件ASIC,面向高精度應(yīng)用,例如無人機(jī),機(jī)器人,移動(dòng)設(shè)備中的指南針,導(dǎo)航和游戲個(gè)人手持設(shè)備。

QMC5883L基于最新的高分辨率,霍尼韋爾AMR技術(shù)授權(quán)的磁阻技術(shù)。結(jié)合定制設(shè)計(jì)的16位ADC ASIC,它具有以下優(yōu)勢(shì):
低噪聲,高精度,低功耗,偏移消除和溫度補(bǔ)償。 QMC5883L啟用1°至2°指南針航向精度。 I2C串行總線可簡(jiǎn)化接口。QMC5883L位于3x3x0.9mm3中表面貼裝16針焊盤柵格陣列(LGA)封裝。

功能
1、3x3x0.9 mm3中的3軸磁阻傳感器陸地柵格陣列封裝(LGA),保證在擴(kuò)展的溫度范圍內(nèi)工作-40°C至+85°C。
2、具有低噪聲AMR傳感器的16位ADC實(shí)現(xiàn)2毫高斯場(chǎng)分辨率。
3、寬磁場(chǎng)范圍(±8高斯)。
4、溫度補(bǔ)償數(shù)據(jù)輸出和溫度輸出。
5、具有標(biāo)準(zhǔn)模式和快速模式的I2C接口。
6、寬范圍工作電壓(2.16V至3.6V)和低功耗(75uA)。
7、無鉛封裝構(gòu)造。
8、提供軟件和算法支持。

優(yōu)點(diǎn)
1、體積小,適用于高度集成的產(chǎn)品。 信號(hào)有已數(shù)字化和校準(zhǔn)。
2、啟用1°至2°度的羅盤航向精度,允許導(dǎo)航和LBS應(yīng)用。
3、最大化傳感器的完整動(dòng)態(tài)范圍和分辨率。
4、在寬廣的范圍內(nèi)自動(dòng)保持傳感器的靈敏度工作溫度范圍。
5、用于快速數(shù)據(jù)通信的高速接口,最大200Hz數(shù)據(jù)輸出速率。
6、兼容電池供電的應(yīng)用。
7、符合RoHS標(biāo)準(zhǔn)。
8、羅盤航向,硬鐵,軟鐵和自動(dòng)可用校準(zhǔn)庫(kù)。




回復(fù)

使用道具 舉報(bào)

6#
ID:513258 發(fā)表于 2021-1-23 10:23 | 只看該作者
QMC5883L封裝3-D視圖
箭頭指示在正常測(cè)量中產(chǎn)生正輸出讀數(shù)的磁場(chǎng)方向組態(tài)。




回復(fù)

使用道具 舉報(bào)

7#
ID:513258 發(fā)表于 2021-1-23 10:51 | 只看該作者

回復(fù)

使用道具 舉報(bào)

8#
ID:513258 發(fā)表于 2021-1-23 10:55 | 只看該作者




回復(fù)

使用道具 舉報(bào)

9#
ID:513258 發(fā)表于 2021-1-23 11:08 | 只看該作者
外部連接
雙電源連接



回復(fù)

使用道具 舉報(bào)

10#
ID:513258 發(fā)表于 2021-1-23 11:10 | 只看該作者

單電源連接



回復(fù)

使用道具 舉報(bào)

11#
ID:513258 發(fā)表于 2021-1-23 11:22 | 只看該作者
QMC5883L性能




回復(fù)

使用道具 舉報(bào)

12#
ID:513258 發(fā)表于 2021-1-23 11:25 | 只看該作者

回復(fù)

使用道具 舉報(bào)

13#
ID:513258 發(fā)表于 2021-1-23 11:27 | 只看該作者

回復(fù)

使用道具 舉報(bào)

14#
ID:513258 發(fā)表于 2021-1-23 11:28 | 只看該作者

回復(fù)

使用道具 舉報(bào)

15#
ID:513258 發(fā)表于 2021-1-23 11:30 | 只看該作者

回復(fù)

使用道具 舉報(bào)

16#
ID:513258 發(fā)表于 2021-1-23 11:32 | 只看該作者



回復(fù)

使用道具 舉報(bào)

17#
ID:513258 發(fā)表于 2021-1-23 11:56 | 只看該作者
GY-271 QMC5883L模塊 電子指南針羅盤模塊 三軸磁場(chǎng)傳感器

采用高品質(zhì)沉金pcb,機(jī)器焊接工藝,保證品質(zhì)
名稱:QMC5883L模塊(三軸磁場(chǎng)模塊)
型號(hào):GY-271使用芯片:QMC5883L
供電電源:3-5v
通信方式:IIC通信協(xié)議
測(cè)量范圍:±1.3-8 高斯



回復(fù)

使用道具 舉報(bào)

18#
ID:513258 發(fā)表于 2021-1-23 12:01 | 只看該作者
該模塊包括一個(gè)最新的高分辨率QMC5883X系列磁阻傳感器,一個(gè)包含放大功能的ASIC,自動(dòng)消磁帶驅(qū)動(dòng)器,失調(diào)消除以及一個(gè)12位ADC,可實(shí)現(xiàn)1°至2°的羅盤 航向精度。 I2C串行總線可簡(jiǎn)化接口。電原理圖如下。





回復(fù)

使用道具 舉報(bào)

19#
ID:513258 發(fā)表于 2021-1-23 12:08 | 只看該作者


引腳功能
VCC + 5V-電源引腳,給它3.3v-5VDC。 對(duì)于Arduino,建議5v
GND-接地引腳
SDA和SCL-這些是I2C數(shù)據(jù)和時(shí)鐘引腳,用于從模塊向微控制器發(fā)送和接收數(shù)據(jù)。 這些引腳上有1萬上拉至3.3v引腳。 您可以將這些引腳連接到5V I2C線路,板上有電平轉(zhuǎn)換器,可將引腳安全降低到3V
DRDY-這是“數(shù)據(jù)就緒”引腳輸出。 如果要高速流傳輸數(shù)據(jù)(每秒超過100次),則可以在準(zhǔn)備好讀取數(shù)據(jù)時(shí)收聽此引腳。 有關(guān)使用DRDY引腳的更多詳細(xì)信息,請(qǐng)參見數(shù)據(jù)表,我們不使用它,因?yàn)槲覀冏x得不快!

Build the circuit
QMC5883L--------------- Uno/Mega2560
VCC------------------- 5V
GND------------------- GND
SCL------------------- A5/ pin21 mega2560
SDA------------------- A4/pin20 mega2560
DRDY------------------ N/C

回復(fù)

使用道具 舉報(bào)

20#
ID:513258 發(fā)表于 2021-1-23 13:37 | 只看該作者

QMC5883L模塊的幾個(gè)定義:

AMR Bridge:三軸磁性傳感器

MUX:多路復(fù)用通道

PGA:可編程控制的傳感器信號(hào)增益放大器

Signal Conditioning:進(jìn)行磁場(chǎng)信號(hào)校正及補(bǔ)償?shù)臄?shù)字模塊

ADC:16位的模數(shù)轉(zhuǎn)換器

I2C:總線形式

NVM:用于校正的非易失性存儲(chǔ)器

SET/RST Driver:用于初始化磁性傳感器的內(nèi)部驅(qū)動(dòng)

Reference:用于內(nèi)部偏移的電壓/電流基準(zhǔn)

Clock Gen.:內(nèi)部振蕩器,用于內(nèi)部操作

POR:上電復(fù)位

Temperature Sensor:用于內(nèi)部精度/偏移的溫度傳感器,也可以用于測(cè)量溫度并輸出

QMC5883L有兩種工作模式:連續(xù)測(cè)量模式和待命模式。




回復(fù)

使用道具 舉報(bào)

21#
ID:513258 發(fā)表于 2021-1-23 13:42 | 只看該作者
QMC5883L模塊實(shí)驗(yàn)接線示意圖




回復(fù)

使用道具 舉報(bào)

22#
ID:513258 發(fā)表于 2021-1-23 14:14 | 只看該作者
安裝QMC5883庫(kù),在網(wǎng)上搜到不少相關(guān)的庫(kù):
keepworking /Mecha_QMC5883L
https://github.com/keepworking/mecha_qmc5883l











回復(fù)

使用道具 舉報(bào)

23#
ID:513258 發(fā)表于 2021-1-24 19:05 | 只看該作者
項(xiàng)目一:簡(jiǎn)易測(cè)量方位角度的實(shí)驗(yàn)開源代碼



  1. /*
  2.   【Arduino】168種傳感器模塊系列實(shí)驗(yàn)(資料代碼+圖形編程+仿真編程)
  3.    實(shí)驗(yàn)一百五十八:QMC5883L電子指南針羅盤模塊 三軸磁場(chǎng)傳感器GY-271
  4.   1、安裝庫(kù):IDE--工具--管理庫(kù)--搜索“QMC5883L”--安裝QMC5883LCompass
  5.   2、項(xiàng)目一:簡(jiǎn)易測(cè)量方位角度
  6.   3、實(shí)驗(yàn)接線:
  7.   QMC5883L-------------- UNO
  8.   VCC------------------- 5V
  9.   GND------------------- GND
  10.   SCL ------------------- A5
  11.   SDA------------------- A4
  12.   DRDY------------------ N/C
  13. */

  14. #include <QMC5883LCompass.h>

  15. QMC5883LCompass compass;

  16. void setup() {
  17.   Serial.begin(9600);
  18.   compass.init();

  19. }

  20. void loop() {
  21.   int a;

  22.   // 讀取羅盤值
  23.   compass.read();

  24.   // 返回方位角讀數(shù)
  25.   a = compass.getAzimuth();

  26.   Serial.print("A: ");
  27.   Serial.print(a);
  28.   Serial.println();

  29.   delay(500);
  30. }
復(fù)制代碼




回復(fù)

使用道具 舉報(bào)

24#
ID:513258 發(fā)表于 2021-1-24 19:12 | 只看該作者
實(shí)驗(yàn)串口返回情況






回復(fù)

使用道具 舉報(bào)

25#
ID:513258 發(fā)表于 2021-1-24 19:25 | 只看該作者
實(shí)驗(yàn)場(chǎng)景圖




回復(fù)

使用道具 舉報(bào)

26#
ID:513258 發(fā)表于 2021-1-24 20:14 | 只看該作者
項(xiàng)目二:簡(jiǎn)易測(cè)量方位角度的實(shí)驗(yàn)開源代碼(數(shù)值在0-11之間,每個(gè)數(shù)值間隔30度)


  1. /*
  2.   【Arduino】168種傳感器模塊系列實(shí)驗(yàn)(資料代碼+圖形編程+仿真編程)
  3.    實(shí)驗(yàn)一百五十八:QMC5883L電子指南針羅盤模塊 三軸磁場(chǎng)傳感器GY-271
  4.   1、安裝庫(kù):IDE--工具--管理庫(kù)--搜索“QMC5883L”--安裝QMC5883LCompass
  5.   2、項(xiàng)目二:簡(jiǎn)易測(cè)量方位角度(數(shù)值在0-11之間,每個(gè)數(shù)值間隔30度)
  6.   3、實(shí)驗(yàn)接線:
  7.   QMC5883L-------------- UNO
  8.   VCC------------------- 5V
  9.   GND------------------- GND
  10.   SCL ------------------- A5
  11.   SDA------------------- A4
  12.   DRDY------------------ N/C
  13. */

  14. #include <QMC5883LCompass.h>

  15. QMC5883LCompass compass;

  16. void setup() {
  17.   Serial.begin(9600);
  18.   compass.init();
  19. }

  20. void loop() {
  21.   compass.read();

  22.   byte a = compass.getAzimuth();
  23.   // 根據(jù)方位/方位角的方向,此處的輸出將是介于0到11之間的值。
  24.   byte b = compass.getBearing(a);
  25.   
  26.   Serial.print("B: ");
  27.   Serial.print(b);
  28.   Serial.println();
  29.   
  30.   delay(250);
  31. }
復(fù)制代碼



回復(fù)

使用道具 舉報(bào)

27#
ID:513258 發(fā)表于 2021-1-24 20:26 | 只看該作者
實(shí)驗(yàn)串口返回情況




回復(fù)

使用道具 舉報(bào)

28#
ID:513258 發(fā)表于 2021-1-24 20:46 | 只看該作者

知識(shí)點(diǎn):方位角

又稱地平經(jīng)度(Azimuth angle,縮寫為Az),是在平面上量度物體之間的角度差的方法之一。是從某點(diǎn)的指北方向線起,依順時(shí)針方向到目標(biāo)方向線之間的水平夾角,用“度”和“密位”表示。常用于判定方位、指示目標(biāo)和保持行進(jìn)方向。


從真子午線起算的為真方位角,通常在精密測(cè)量中使用,從磁子午線起算的方磁方位角,在航空、航海、炮兵射擊、軍隊(duì)行進(jìn)時(shí)廣泛使用,從地形圖的坐標(biāo)縱線起算的為坐標(biāo)方位角,炮兵使用較多。磁方位角與真方位角的關(guān)系式為:磁方位角=真方位角-(±磁偏角)。坐標(biāo)方位角與磁方位角的關(guān)系式為:坐標(biāo)方位角=磁方位角+ (±磁坐偏角)。


從標(biāo)準(zhǔn)方向的北端起,順時(shí)針方向到直線的水平角稱為該直線的方位角。以北點(diǎn)為起算點(diǎn),由北點(diǎn)開始按順時(shí)針方向計(jì)量。方位角的取值范圍為0~360度,北點(diǎn)為0°,東點(diǎn)為90°,南點(diǎn)為180°,西點(diǎn)為270°。





回復(fù)

使用道具 舉報(bào)

29#
ID:513258 發(fā)表于 2021-1-24 21:05 | 只看該作者
QMC5883L Compass是一個(gè)Arduino庫(kù),用于將QMC5583L系列模塊使用指南針(電子羅盤)功能。支持:

1、獲取XYZ軸的值。
2、計(jì)算方位角。
3、獲得16點(diǎn)方位角軸承方向(0-15)。
4、獲取16點(diǎn)方位角軸承名稱(N,NNE,NE,ENE,E,ESE,SE,SSE,S,SSW,SW,WSW,W,WNW,NW,NNW)
5、通過滾動(dòng)平均和最小/最大消除來平滑XYZ讀數(shù)。
6、任選的芯片組模式。


QMC5883LCompass.cpp 庫(kù)文件


  1. /*
  2. ===============================================================================================================
  3. QMC5883LCompass.h
  4. Library for using QMC5583L series chip boards as a compass.
  5. Learn more at [https://github.com/mprograms/QMC5883LCompass]
  6. Supports:
  7. - Getting values of XYZ axis.
  8. - Calculating Azimuth.
  9. - Getting 16 point Azimuth bearing direction (0 - 15).
  10. - Getting 16 point Azimuth bearing Names (N, NNE, NE, ENE, E, ESE, SE, SSE, S, SSW, SW, WSW, W, WNW, NW, NNW)
  11. - Smoothing of XYZ readings via rolling averaging and min / max removal.
  12. - Optional chipset modes (see below)
  13. ===============================================================================================================
  14. v1.0 - June 13, 2019
  15. Written by MRPrograms
  16. Github: [https://github.com/mprograms/]
  17. Release under the GNU General Public License v3
  18. [https://www.gnu.org/licenses/gpl-3.0.en.html]
  19. ===============================================================================================================
  20. FROM QST QMC5883L Datasheet [https://nettigo.pl/attachments/440]
  21. -----------------------------------------------
  22. MODE CONTROL (MODE)
  23.         Standby                        0x00
  24.         Continuous                0x01
  25. OUTPUT DATA RATE (ODR)
  26.         10Hz                0x00
  27.         50Hz                0x04
  28.         100Hz               0x08
  29.         200Hz               0x0C
  30. FULL SCALE (RNG)
  31.         2G                  0x00
  32.         8G                  0x10
  33. OVER SAMPLE RATIO (OSR)
  34.         512                 0x00
  35.         256                 0x40
  36.         128                 0x80
  37.         64                  0xC0
  38.   
  39. */



  40. #include "Arduino.h"
  41. #include "QMC5883LCompass.h"
  42. #include <Wire.h>

  43. QMC5883LCompass::QMC5883LCompass() {
  44. }


  45. /**
  46.         INIT
  47.         Initialize Chip - This needs to be called in the sketch setup() function.
  48.        
  49.         @since v0.1;
  50. **/
  51. void QMC5883LCompass::init(){
  52.         Wire.begin();
  53.         _writeReg(0x0B,0x01);
  54.         setMode(0x01,0x0C,0x10,0X00);
  55. }


  56. /**
  57.         SET ADDRESS
  58.         Set the I2C Address of the chip. This needs to be called in the sketch setup() function.
  59.        
  60.         @since v0.1;
  61. **/
  62. // Set I2C Address if different then default.
  63. void QMC5883LCompass::setADDR(byte b){
  64.         _ADDR = b;
  65. }




  66. /**
  67.         REGISTER
  68.         Write the register to the chip.
  69.        
  70.         @since v0.1;
  71. **/
  72. // Write register values to chip
  73. void QMC5883LCompass::_writeReg(byte r, byte v){
  74.         Wire.beginTransmission(_ADDR);
  75.         Wire.write(r);
  76.         Wire.write(v);
  77.         Wire.endTransmission();
  78. }


  79. /**
  80.         CHIP MODE
  81.         Set the chip mode.
  82.        
  83.         @since v0.1;
  84. **/
  85. // Set chip mode
  86. void QMC5883LCompass::setMode(byte mode, byte odr, byte rng, byte osr){
  87.         _writeReg(0x09,mode|odr|rng|osr);
  88. }


  89. /**
  90.         RESET
  91.         Reset the chip.
  92.        
  93.         @since v0.1;
  94. **/
  95. // Reset the chip
  96. void QMC5883LCompass::setReset(){
  97.         _writeReg(0x0A,0x80);
  98. }

  99. // 1 = Basic 2 = Advanced
  100. void QMC5883LCompass::setSmoothing(byte steps, bool adv){
  101.         _smoothUse = true;
  102.         _smoothSteps = ( steps > 10) ? 10 : steps;
  103.         _smoothAdvanced = (adv == true) ? true : false;
  104. }

  105. /**
  106.     SET CALIBRATION
  107.         Set calibration values for more accurate readings
  108.                
  109.         @author Claus N&auml;veke - TheNitek [https://github.com/TheNitek]
  110.        
  111.         @since v1.1.0
  112. **/
  113. void QMC5883LCompass::setCalibration(int x_min, int x_max, int y_min, int y_max, int z_min, int z_max){
  114.         _calibrationUse = true;

  115.         _vCalibration[0][0] = x_min;
  116.         _vCalibration[0][1] = x_max;
  117.         _vCalibration[1][0] = y_min;
  118.         _vCalibration[1][1] = y_max;
  119.         _vCalibration[2][0] = z_min;
  120.         _vCalibration[2][1] = z_max;
  121. }



  122. /**
  123.         READ
  124.         Read the XYZ axis and save the values in an array.
  125.        
  126.         @since v0.1;
  127. **/
  128. void QMC5883LCompass::read(){
  129.         Wire.beginTransmission(_ADDR);
  130.         Wire.write(0x00);
  131.         int err = Wire.endTransmission();
  132.         if (!err) {
  133.                 Wire.requestFrom(_ADDR, (byte)6);
  134.                 _vRaw[0] = (int)(int16_t)(Wire.read() | Wire.read() << 8);
  135.                 _vRaw[1] = (int)(int16_t)(Wire.read() | Wire.read() << 8);
  136.                 _vRaw[2] = (int)(int16_t)(Wire.read() | Wire.read() << 8);

  137.                 if ( _calibrationUse ) {
  138.                         _applyCalibration();
  139.                 }
  140.                
  141.                 if ( _smoothUse ) {
  142.                         _smoothing();
  143.                 }
  144.                
  145.                 //byte overflow = Wire.read() & 0x02;
  146.                 //return overflow << 2;
  147.         }
  148. }

  149. /**
  150.     APPLY CALIBRATION
  151.         This function uses the calibration data provided via @see setCalibration() to calculate more
  152.         accurate readings
  153.        
  154.         @author Claus N&auml;veke - TheNitek [https://github.com/TheNitek]
  155.        
  156.         Based on this awesome article:
  157.         https://appelsiini.net/2018/calibrate-magnetometer/
  158.        
  159.         @since v1.1.0
  160.        
  161. **/
  162. void QMC5883LCompass::_applyCalibration(){
  163.         int x_offset = (_vCalibration[0][0] + _vCalibration[0][1])/2;
  164.         int y_offset = (_vCalibration[1][0] + _vCalibration[1][1])/2;
  165.         int z_offset = (_vCalibration[2][0] + _vCalibration[2][1])/2;
  166.         int x_avg_delta = (_vCalibration[0][1] - _vCalibration[0][0])/2;
  167.         int y_avg_delta = (_vCalibration[1][1] - _vCalibration[1][0])/2;
  168.         int z_avg_delta = (_vCalibration[2][1] - _vCalibration[2][0])/2;

  169.         int avg_delta = (x_avg_delta + y_avg_delta + z_avg_delta) / 3;

  170.         float x_scale = (float)avg_delta / x_avg_delta;
  171.         float y_scale = (float)avg_delta / y_avg_delta;
  172.         float z_scale = (float)avg_delta / z_avg_delta;

  173.         _vCalibrated[0] = (_vRaw[0] - x_offset) * x_scale;
  174.         _vCalibrated[1] = (_vRaw[1] - y_offset) * y_scale;
  175.         _vCalibrated[2] = (_vRaw[2] - z_offset) * z_scale;
  176. }


  177. /**
  178.         SMOOTH OUTPUT
  179.         This function smooths the output for the XYZ axis. Depending on the options set in
  180.         @see setSmoothing(), we can run multiple methods of smoothing the sensor readings.
  181.        
  182.         First we store (n) samples of sensor readings for each axis and store them in a rolling array.
  183.         As each new sensor reading comes in we replace it with a new reading. Then we average the total
  184.         of all (n) readings.
  185.        
  186.         Advanced Smoothing
  187.         If you turn advanced smoothing on, we will select the min and max values from our array
  188.         of (n) samples. We then subtract both the min and max from the total and average the total of all
  189.         (n - 2) readings.
  190.        
  191.         NOTE: This function does several calculations and can cause your sketch to run slower.
  192.        
  193.         @since v0.3;
  194. **/
  195. void QMC5883LCompass::_smoothing(){
  196.         byte max = 0;
  197.         byte min = 0;
  198.        
  199.         if ( _vScan > _smoothSteps - 1 ) { _vScan = 0; }
  200.        
  201.         for ( int i = 0; i < 3; i++ ) {
  202.                 if ( _vTotals[i] != 0 ) {
  203.                         _vTotals[i] = _vTotals[i] - _vHistory[_vScan][i];
  204.                 }
  205.                 _vHistory[_vScan][i] = ( _calibrationUse ) ? _vCalibrated[i] : _vRaw[i];
  206.                 _vTotals[i] = _vTotals[i] + _vHistory[_vScan][i];
  207.                
  208.                 if ( _smoothAdvanced ) {
  209.                         max = 0;
  210.                         for (int j = 0; j < _smoothSteps - 1; j++) {
  211.                                 max = ( _vHistory[j][i] > _vHistory[max][i] ) ? j : max;
  212.                         }
  213.                        
  214.                         min = 0;
  215.                         for (int k = 0; k < _smoothSteps - 1; k++) {
  216.                                 min = ( _vHistory[k][i] < _vHistory[min][i] ) ? k : min;
  217.                         }
  218.                                        
  219.                         _vSmooth[i] = ( _vTotals[i] - (_vHistory[max][i] + _vHistory[min][i]) ) / (_smoothSteps - 2);
  220.                 } else {
  221.                         _vSmooth[i] = _vTotals[i]  / _smoothSteps;
  222.                 }
  223.         }
  224.        
  225.         _vScan++;
  226. }


  227. /**
  228.         GET X AXIS
  229.         Read the X axis
  230.        
  231.         @since v0.1;
  232.         @return int x axis
  233. **/
  234. int QMC5883LCompass::getX(){
  235.         return _get(0);
  236. }


  237. /**
  238.         GET Y AXIS
  239.         Read the Y axis
  240.        
  241.         @since v0.1;
  242.         @return int y axis
  243. **/
  244. int QMC5883LCompass::getY(){
  245.         return _get(1);
  246. }


  247. /**
  248.         GET Z AXIS
  249.         Read the Z axis
  250.        
  251.         @since v0.1;
  252.         @return int z axis
  253. **/
  254. int QMC5883LCompass::getZ(){
  255.         return _get(2);
  256. }

  257. /**
  258.         GET SENSOR AXIS READING
  259.         Get the smoothed, calibration, or raw data from a given sensor axis
  260.        
  261.         @since v1.1.0
  262.         @return int sensor axis value
  263. **/
  264. int QMC5883LCompass::_get(int i){
  265.         if ( _smoothUse )
  266.                 return _vSmooth[i];
  267.        
  268.         if ( _calibrationUse )
  269.                 return _vCalibrated[i];

  270.         return _vRaw[i];
  271. }



  272. /**
  273.         GET AZIMUTH
  274.         Calculate the azimuth (in degrees);
  275.        
  276.         @since v0.1;
  277.         @return int azimuth
  278. **/
  279. int QMC5883LCompass::getAzimuth(){
  280.         int a = atan2( getY(), getX() ) * 180.0 / PI;
  281.         return a < 0 ? 360 + a : a;
  282. }


  283. /**
  284.         GET BEARING
  285.         Divide the 360 degree circle into 16 equal parts and then return the a value of 0-15
  286.         based on where the azimuth is currently pointing.
  287.        
  288.         @since v1.0.1 - function now requires azimuth parameter.
  289.         @since v0.2.0 - initial creation
  290.        
  291.         @return byte direction of bearing
  292. */
  293. byte QMC5883LCompass::getBearing(int azimuth){
  294.         unsigned long a = azimuth / 22.5;
  295.         unsigned long r = a - (int)a;
  296.         byte sexdec = 0;       
  297.         sexdec = ( r >= .5 ) ? ceil(a) : floor(a);
  298.         return sexdec;
  299. }


  300. /**
  301.         This will take the location of the azimuth as calculated in getBearing() and then
  302.         produce an array of chars as a text representation of the direction.
  303.        
  304.         NOTE: This function does not return anything since it is not possible to return an array.
  305.         Values must be passed by reference back to your sketch.
  306.        
  307.         Example:
  308.        
  309.         ( if direction is in 1 / NNE)
  310.        
  311.         char myArray[3];
  312.         compass.getDirection(myArray, azimuth);
  313.        
  314.         Serial.print(myArray[0]); // N
  315.         Serial.print(myArray[1]); // N
  316.         Serial.print(myArray[2]); // E
  317.        
  318.        
  319.         @see getBearing();
  320.        
  321.         @since v1.0.1 - function now requires azimuth parameter.
  322.         @since v0.2.0 - initial creation
  323. */
  324. void QMC5883LCompass::getDirection(char* myArray, int azimuth){
  325.         int d = getBearing(azimuth);
  326.         myArray[0] = _bearings[d][0];
  327.         myArray[1] = _bearings[d][1];
  328.         myArray[2] = _bearings[d][2];
  329. }
復(fù)制代碼




回復(fù)

使用道具 舉報(bào)

30#
ID:513258 發(fā)表于 2021-1-24 21:07 | 只看該作者
QMC5883LCompass.h 庫(kù)文件

  1. #ifndef QMC5883L_Compass
  2. #define QMC5883L_Compass

  3. #include "Arduino.h"
  4. #include "Wire.h"


  5. class QMC5883LCompass{
  6.        
  7.   public:
  8.     QMC5883LCompass();
  9.         void init();
  10.     void setADDR(byte b);
  11.     void setMode(byte mode, byte odr, byte rng, byte osr);
  12.         void setSmoothing(byte steps, bool adv);
  13.         void setCalibration(int x_min, int x_max, int y_min, int y_max, int z_min, int z_max);
  14.     void setReset();
  15.     void read();
  16.         int getX();
  17.         int getY();
  18.         int getZ();
  19.         int getAzimuth();
  20.         byte getBearing(int azimuth);
  21.         void getDirection(char* myArray, int azimuth);
  22.        
  23.   private:
  24.     void _writeReg(byte reg,byte val);
  25.         int _get(int index);
  26.         bool _smoothUse = false;
  27.         byte _smoothSteps = 5;
  28.         bool _smoothAdvanced = false;
  29.     byte _ADDR = 0x0D;
  30.         int _vRaw[3] = {0,0,0};
  31.         int _vHistory[10][3];
  32.         int _vScan = 0;
  33.         long _vTotals[3] = {0,0,0};
  34.         int _vSmooth[3] = {0,0,0};
  35.         void _smoothing();
  36.         bool _calibrationUse = false;
  37.         int _vCalibration[3][2];
  38.         int _vCalibrated[3];
  39.         void _applyCalibration();
  40.         const char _bearings[16][3] =  {
  41.                 {' ', ' ', 'N'},
  42.                 {'N', 'N', 'E'},
  43.                 {' ', 'N', 'E'},
  44.                 {'E', 'N', 'E'},
  45.                 {' ', ' ', 'E'},
  46.                 {'E', 'S', 'E'},
  47.                 {' ', 'S', 'E'},
  48.                 {'S', 'S', 'E'},
  49.                 {' ', ' ', 'S'},
  50.                 {'S', 'S', 'W'},
  51.                 {' ', 'S', 'W'},
  52.                 {'W', 'S', 'W'},
  53.                 {' ', ' ', 'W'},
  54.                 {'W', 'N', 'W'},
  55.                 {' ', 'N', 'W'},
  56.                 {'N', 'N', 'W'},
  57.         };
  58.        
  59.        
  60.        
  61. };

  62. #endif
復(fù)制代碼




回復(fù)

使用道具 舉報(bào)

31#
ID:513258 發(fā)表于 2021-1-25 10:12 | 只看該作者
實(shí)驗(yàn)開源代碼,
項(xiàng)目三:通過串口實(shí)時(shí)繪制電子羅盤方位角的波形



  1. /*
  2.   【Arduino】168種傳感器模塊系列實(shí)驗(yàn)(資料代碼+圖形編程+仿真編程)
  3.    實(shí)驗(yàn)一百五十八:QMC5883L電子指南針羅盤模塊 三軸磁場(chǎng)傳感器GY-271
  4.   1、安裝庫(kù):IDE--工具--管理庫(kù)--搜索“QMC5883L”--安裝QMC5883LCompass
  5.   2、項(xiàng)目三:通過串口實(shí)時(shí)繪制電子羅盤方位角的波形
  6.   3、實(shí)驗(yàn)接線:
  7.   QMC5883L-------------- UNO
  8.   VCC------------------- 5V
  9.   GND------------------- GND
  10.   SCL ------------------- A5
  11.   SDA------------------- A4
  12.   DRDY------------------ N/C
  13. */

  14. #include <QMC5883LCompass.h>

  15. QMC5883LCompass compass;

  16. void setup() {
  17.   Serial.begin(9600);
  18.   compass.init();

  19. }

  20. void loop() {
  21.   int a;

  22.   // 讀取羅盤值
  23.   compass.read();

  24.   // 返回方位角讀數(shù)
  25.   a = compass.getAzimuth();

  26.   Serial.print("電子羅盤方位角: ");
  27.   Serial.print(a);
  28.   Serial.println();

  29.   delay(800);
  30. }
復(fù)制代碼







回復(fù)

使用道具 舉報(bào)

32#
ID:513258 發(fā)表于 2021-1-25 10:15 | 只看該作者
用手轉(zhuǎn)動(dòng)QMC5883L模塊,串口輸出的實(shí)時(shí)波形,數(shù)值在0--359°之間波動(dòng),簡(jiǎn)單又直觀。






回復(fù)

使用道具 舉報(bào)

33#
ID:513258 發(fā)表于 2021-1-25 10:17 | 只看該作者
串口輸出的實(shí)時(shí)數(shù)值





回復(fù)

使用道具 舉報(bào)

34#
ID:513258 發(fā)表于 2021-1-25 11:07 | 只看該作者
QMC5883L Compass庫(kù)函數(shù)的幾個(gè)使用要點(diǎn)

1、QMC5883L與Arduino Uno / Nano的連接

VCC  O ---- O +5v
GND  O ---- O GND
SCL  O ---- O A5
SDA  O ---- O A4
DRDY O ---- X NOT CONNECTED

2、入門
首先,在程序頂部包括QMC5883L指南針庫(kù)。

#include <QMC5883LCompass.h>
QMC5883LCompass compass;

然后在setup()函數(shù)中添加:

void setup(){
  compass.init();
}

3、獲取X,Y或Z軸的數(shù)值
要獲取X,Y或Z傳感器的讀數(shù),只需調(diào)用所需的功能。

void loop(){
   int x = compass.getX();
   int y = compass.getY();
   int z = compass.getZ();
}

回復(fù)

使用道具 舉報(bào)

35#
ID:513258 發(fā)表于 2021-1-25 11:11 | 只看該作者
4、獲取方位角的數(shù)值
要獲取計(jì)算出的方位角(羅盤度)值,只需調(diào)用getAzimuth();。
void loop(){
   int a = compass.getAzimuth();
}
5、獲取方向/方位
QMC5883L指南針庫(kù)可計(jì)算傳感器指向的方向范圍和方向。您可以調(diào)用兩個(gè)函數(shù)。
要獲取傳感器面向的方向的12點(diǎn)值,可以調(diào)用getBearing(azimuth)。這會(huì)將羅盤的360度范圍劃分為12個(gè)部分,并按順時(shí)針順序返回值0-12。在這種情況下,0 = N,4 = E,8 = S,12 =W。如果您希望滾動(dòng)自己的方向輸出功能而不需要計(jì)算,則此功能很有用。
void loop(){
   azimuth = compass.getAzimuth();
   byte b = compass.getBearing(azimuth);
}
要獲取傳感器指向方向的12點(diǎn)文字表示,可以致電getDirection(azimuth);。這將產(chǎn)生一個(gè)char數(shù)組[3],其中的字母代表每個(gè)方向。由于我們無法返回?cái)?shù)組,因此需要通過引用傳遞值。
void loop(){
   azimuth = compass.getAzimuth();
   char myArray[3];
   getDirection(myArray, azimuth);
}
如果要打印這些值,可以這樣:
void loop(){
   azimuth = compass.getAzimuth();
   char myArray[3];
   
   getDirection(myArray, azimuth);
   
   Serial.print(myArray[0]);
   Serial.print(myArray[1]);
   Serial.print(myArray[2]);
   Serial.println();
}

回復(fù)

使用道具 舉報(bào)

36#
ID:513258 發(fā)表于 2021-1-25 11:35 | 只看該作者
6、更改I2C地址
要在調(diào)用compass.setADDR(BYTE_VALUE);之前更改I2C地址呼叫,compass.init();如下所示:


void setup(){
  compass.setADDR(BYTE);
  compass.init();
}


7、更改模式,數(shù)據(jù)速率,比例,采樣率
您還可以更改QMC5583L芯片的模式,靈敏度,采樣率和輸出率。等等,只需在調(diào)用compass.setMode(MODE, ODR, RNG, OSR);后調(diào)用即可compass.init()。請(qǐng)注意,每個(gè)值必須是一個(gè)字節(jié)。設(shè)置每個(gè)模式的值在預(yù)設(shè)中,并取自QST QMC5583L數(shù)據(jù)表。





回復(fù)

使用道具 舉報(bào)

37#
ID:513258 發(fā)表于 2021-1-25 11:55 | 只看該作者
8、精細(xì)QMC5583L傳感器輸出
在傳感器讀數(shù)似乎反彈的情況下,平滑可以提供幫助。QMC5883L指南針庫(kù)使用滾動(dòng)平均值功能來存儲(chǔ)(N)個(gè)傳感器讀數(shù)并返回每個(gè)軸的平均值。該平均還對(duì)方位角和方向輸出進(jìn)行平滑處理。


如果啟用,該功能的第二部分將采用內(nèi)部滾動(dòng)逐步通過的當(dāng)前替代和替代,將其從總體上中刪除。這可以幫助消除在錯(cuò)誤的讀數(shù)中可能發(fā)生的替代的高點(diǎn)和低點(diǎn)。


應(yīng)該注意的是,內(nèi)置的平滑功能將導(dǎo)致額外的處理時(shí)間。


compass.setSmoothing(STEPS, ADVANCED);




在循環(huán)之前啟用平滑調(diào)用。


步驟:int,使結(jié)果平滑的步驟數(shù)。1到10的有效值。更高的步長(zhǎng)等于更平滑,但處理時(shí)間縮短。


*:?jiǎn)⒂么斯δ軐⑹蛊交Ч,但處理時(shí)間縮短。*


void setup(){
  compass.init();
  compass.setSmoothing(10, true);
}



回復(fù)

使用道具 舉報(bào)

38#
ID:513258 發(fā)表于 2021-1-25 11:59 | 只看該作者
9、校準(zhǔn)QMC5583L傳感器
QMC5883LCompass庫(kù)包含校準(zhǔn)功能和實(shí)用程序大綱,可幫助您校準(zhǔn)QMC5883L芯片。校準(zhǔn)是一個(gè)兩步過程。


步驟1:運(yùn)行校準(zhǔn)程序
a、確保已連接QMC5883L芯片。
b、在示例> QMC5883LCOMPASS>校準(zhǔn)下找到隨附的校準(zhǔn)草圖。
c、將校準(zhǔn)草圖上傳到您的arduino,然后打開串行監(jiān)視器。
d、校準(zhǔn)過程開始時(shí),通過移動(dòng)傳感器來伴隨屏幕上的指示。
c、收集完所有校準(zhǔn)數(shù)據(jù)后,復(fù)制副本的代碼


compass.setCalibration(-1537, 1266, -1961, 958, -1342, 1492);




可能需要保存它以備將來參考。


步驟2:使用校正資料
a、項(xiàng)目的程序,將然后復(fù)制的代碼行直接插入到compass.init()調(diào)用下方。
b、照常使用QMC5883LCompass庫(kù)。

建議您使用提供的校準(zhǔn)草圖來生成傳感器的預(yù)設(shè)和替代,但也可以使用該


compass.setCalibration(X_MIN, X_MAX, Y_MIN, Y_MAX, Z_MIN, Z_MAX);




函數(shù)添加自己的預(yù)設(shè)和替代。


回復(fù)

使用道具 舉報(bào)

39#
ID:513258 發(fā)表于 2021-1-25 13:16 | 只看該作者
實(shí)驗(yàn)開源代碼
項(xiàng)目四:通過串口實(shí)時(shí)繪制電子羅盤方位(12等分)的波形
說明:實(shí)時(shí)數(shù)值 0 = N,3 = E,6 = S,9 =W

  1. /*
  2.   【Arduino】168種傳感器模塊系列實(shí)驗(yàn)(資料代碼+圖形編程+仿真編程)
  3.    實(shí)驗(yàn)一百五十八:QMC5883L電子指南針羅盤模塊 三軸磁場(chǎng)傳感器GY-271
  4.   1、安裝庫(kù):IDE--工具--管理庫(kù)--搜索“QMC5883L”--安裝QMC5883LCompass
  5.   2、項(xiàng)目四:通過串口實(shí)時(shí)繪制電子羅盤方位(12等分)的波形
  6.   3、實(shí)驗(yàn)接線:
  7.   QMC5883L-------------- UNO
  8.   VCC------------------- 5V
  9.   GND------------------- GND
  10.   SCL ------------------- A5
  11.   SDA------------------- A4
  12.   DRDY------------------ N/C
  13.   4、說明:實(shí)時(shí)數(shù)值 0 = N,3 = E,6 = S,9 =W
  14. */

  15. #include <QMC5883LCompass.h>

  16. QMC5883LCompass compass;

  17. void setup() {
  18.   Serial.begin(9600);
  19.   compass.init();
  20. }

  21. void loop() {
  22.   compass.read();

  23.   byte a = compass.getAzimuth();
  24.   // 根據(jù)方位/方位角的方向,此處的輸出將是介于0到11之間的值。
  25.   byte b = compass.getBearing(a);
  26.   
  27.   Serial.print("指南針方位: ");
  28.   Serial.print(b);
  29.   Serial.println();
  30.   
  31.   delay(800);
  32. }
復(fù)制代碼




回復(fù)

使用道具 舉報(bào)

40#
ID:513258 發(fā)表于 2021-1-25 14:08 | 只看該作者
用手轉(zhuǎn)動(dòng)QMC5883L模塊,串口輸出的指南針方位數(shù)值變動(dòng)實(shí)時(shí)波形




回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 日本久久久久久久久 | 久久精品国产亚洲一区二区 | 午夜小视频在线播放 | 99精品观看 | 国产午夜精品久久久久 | av永久免费 | 国产成人免费在线观看 | 中文字幕二区三区 | 一区二区三区欧美 | 天天夜夜操 | 欧美一区二区视频 | 综合激情久久 | 天天天天操 | 懂色tv| 91视频在线 | 亚洲一区二区三区免费在线观看 | 欧美精品99 | aaaa一级毛片| 国产欧美在线播放 | 久久精品91久久久久久再现 | 国产在线视频一区二区 | 久久久青草婷婷精品综合日韩 | 夜夜草导航 | 久久久精品一区 | 免费黄色a级毛片 | 中文字幕在线播放不卡 | 永久精品 | 中文字幕二区 | av在线免费观看网址 | 天天干天天谢 | 可以看黄的视频 | 国产精品18hdxxxⅹ在线 | 国产精品一区一区 | 精品欧美一区二区三区久久久 | 国产一区免费 | 国产精品成人国产乱一区 | 欧美成人精品一区二区男人看 | 精品一二三区 | 亚洲精品一区二区三区在线 | 男女在线免费观看 | 视频1区 |