极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 13597|回复: 3

地磁传感器

[复制链接]
发表于 2018-3-24 18:25:47 | 显示全部楼层 |阅读模式
现在有了HTMC5883L的库文件了,也能编译成功,地磁是新买的,但是串口输出的数值没有丝毫变化

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

 楼主| 发表于 2018-3-24 18:29:29 | 显示全部楼层
希望有大神解决,关于车位检测,想用这个模块感觉比较好,啊!求解
回复 支持 反对

使用道具 举报

发表于 2018-3-28 08:00:00 | 显示全部楼层
你这发的啥啊,问题也没说明白
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-3-28 15:34:30 | 显示全部楼层
中锐老殷 发表于 2018-3-28 08:00
你这发的啥啊,问题也没说明白

问题就是:现在在弄HMC5883L,刚用不太会,所以传的是别人的代码(代码如下),串口输出的数值就是我上传的图片,没有任何变化是怎么回事?改变位置什么的也没有。
#include <Wire.h>
#include <HMC5883L.h>
HMC5883L compass;
void setup()
{
  Serial.begin(9600);
  Wire.begin();
  compass = HMC5883L();
  compass.SetScale(1.3);
  compass.SetMeasurementMode(Measurement_Continuous);
}
void loop()
{
  MagnetometerRaw raw = compass.ReadRawAxis();
  MagnetometerScaled scaled = compass.ReadScaledAxis();
  float xHeading = atan2(scaled.YAxis, scaled.XAxis);
  float yHeading = atan2(scaled.ZAxis, scaled.XAxis);
  float zHeading = atan2(scaled.ZAxis, scaled.YAxis);
  if(xHeading < 0)    xHeading += 2*PI;
  if(xHeading > 2*PI)    xHeading -= 2*PI;
  if(yHeading < 0)    yHeading += 2*PI;
  if(yHeading > 2*PI)    yHeading -= 2*PI;
  if(zHeading < 0)    zHeading += 2*PI;
  if(zHeading > 2*PI)    zHeading -= 2*PI;
  float xDegrees = xHeading * 180/M_PI;
  float yDegrees = yHeading * 180/M_PI;
  float zDegrees = zHeading * 180/M_PI;
  Serial.print(xDegrees);
  Serial.print(",");
  Serial.print(yDegrees);
  Serial.print(",");
  Serial.print(zDegrees);
  Serial.println(";");
  delay(100);
}
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-24 02:01 , Processed in 0.040997 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表