0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ESP32: AE-BNO055-BO の地磁気センサーの使い方

Last updated at Posted at 2024-07-30

プログラム

magnetic.ino
// ---------------------------------------------------------------------
//	magnetic.ino
//
//						Aug/01/2024
// ---------------------------------------------------------------------
#include <Adafruit_BNO055.h>

Adafruit_BNO055 bno = Adafruit_BNO055(55, 0x28);
// ---------------------------------------------------------------------
void setup(void) {
	Serial.begin(115200);
	Serial.println("AE-BNO055-BO Test");

	if (!bno.begin()) {
		Serial.println("AE-BNO055-BO not detected. Check your connections or I2C address.");
		while (1);
	}

	delay(1000);
	Serial.println("*** setup end ***");
}

// ---------------------------------------------------------------------
void loop(void) {
	sensors_event_t mevent;
	bno.getEvent(&mevent,Adafruit_BNO055::VECTOR_MAGNETOMETER);
	Serial.print("Magnetic: ");
	Serial.print(mevent.magnetic.x, 4);
	Serial.print(" ");
	Serial.print(mevent.magnetic.y, 4);
	Serial.print(" ");
	Serial.print(mevent.magnetic.z, 4);
	double htt = (180.0 / PI) * atan2(mevent.magnetic.x, mevent.magnetic.y);
	double heading = 360.0 - htt;
	if (360.0 < heading)
		{
		heading -= 360.0;
		}

	if (heading < 0)
		{
		heading += 360.0;
		}

	Serial.print(" ");
	Serial.println(heading, 4);

	delay(2000);
}

// ---------------------------------------------------------------------

Ubuntu 24.04 上の Arduino IDE 2.3.2 を使いました。
ボードは、 ESP32 Dev Module です。

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?