festival_finder/festival_finder.ino
Tim Staat 99e0c88e1d Initial commit
Added basic functionality
2025-08-27 18:54:28 +02:00

70 lines
1.8 KiB
C++

#include <U8g2lib.h>
#define SDA_1 15
#define SCL_1 16
#define SDA_2 17
#define SCL_2 18
U8G2_SSD1315_128X64_NONAME_1_HW_I2C(U8G2_R1)
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_HMC5883_U.h>
/* Assign a unique ID to this sensor at the same time */
Adafruit_HMC5883_Unified mag = Adafruit_HMC5883_Unified(12345);
#define GPS_BAUD 9600
#define RXD2 16
#define TXD2 17
// Create an instance of the HardwareSerial class for Serial 2
HardwareSerial gpsSerial(2);
void setup() {
u8g2.begin();
gpsSerial.begin(GPS_BAUD, SERIAL_8N1, RXD2, TXD2);
}
void loop() {
// put your main code here, to run repeatedly:
sensors_event_t event;
mag.getEvent(&event);
while (gpsSerial.available() > 0){
// get the byte data from the GPS
char gpsData = gpsSerial.read();
Serial.print(gpsData);
}
delay(1000);
Serial.println("-------------------------------");
/* Display some basic information on this sensor */
displaySensorDetails();
gpsSerial.begin(GPS_BAUD, SERIAL_8N1, RXD2, TXD2);
float heading = atan2(event.magnetic.y, event.magnetic.x);
// Once you have your heading, you must then add your 'Declination Angle', which is the 'Error' of the magnetic field in your location.
// Find yours here: http://www.magnetic-declination.com/
// Mine is: -13* 2' W, which is ~13 Degrees, or (which we need) 0.22 radians
// If you cannot find your Declination, comment out these two lines, your compass will be slightly off.
float declinationAngle = 0.22;
heading += declinationAngle;
// Correct for when signs are reversed.
if(heading < 0)
heading += 2*PI;
// Check for wrap due to addition of declination.
if(heading > 2*PI)
heading -= 2*PI;
// Convert radians to degrees for readability.
float headingDegrees = heading * 180/M_PI;
}