2024-02-09 02:14:45 +01:00
|
|
|
/*
|
|
|
|
* This code utilizes the AVR libraries for I2C and UART communication.
|
|
|
|
* Make sure to connect the SDA and SCL pins of the ATmega328P to the
|
|
|
|
* corresponding pins of your I2C temperature sensor. Additionally, you might
|
|
|
|
* need pull-up resistors for the I2C lines.
|
|
|
|
*/
|
|
|
|
|
2024-03-24 00:00:32 +01:00
|
|
|
#define LED_PIN PB5 // Define the pin connected to the LED
|
|
|
|
|
2024-02-09 02:14:45 +01:00
|
|
|
#include <avr/io.h>
|
2024-03-24 05:08:56 +01:00
|
|
|
#include <avr/sleep.h>
|
2024-02-09 02:14:45 +01:00
|
|
|
#include <math.h>
|
2024-03-24 02:35:30 +01:00
|
|
|
#include <util/delay.h>
|
2024-02-09 02:14:45 +01:00
|
|
|
|
2024-03-23 21:27:59 +01:00
|
|
|
#include "MPU6050.h"
|
|
|
|
#include "i2c.h"
|
|
|
|
#include "uart.h"
|
2024-02-09 02:14:45 +01:00
|
|
|
|
|
|
|
void blink() {
|
|
|
|
// Set the LED pin as output
|
|
|
|
DDRB |= (1 << LED_PIN);
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
// Turn on the LED by setting the pin high
|
|
|
|
PORTB |= (1 << LED_PIN);
|
|
|
|
// Delay for 500 milliseconds
|
|
|
|
_delay_ms(500);
|
|
|
|
|
|
|
|
// Turn off the LED by setting the pin low
|
|
|
|
PORTB &= ~(1 << LED_PIN);
|
|
|
|
// Delay for 500 milliseconds
|
|
|
|
_delay_ms(500);
|
|
|
|
}
|
|
|
|
}
|
2024-03-23 04:28:03 +01:00
|
|
|
|
|
|
|
int main(void) {
|
2024-03-24 04:07:20 +01:00
|
|
|
int16_t accel_data[3]; // Array to store accelerometer data (X, Y, Z)
|
2024-03-24 02:35:30 +01:00
|
|
|
int32_t iteration = 0;
|
|
|
|
|
2024-03-23 04:28:03 +01:00
|
|
|
initUART();
|
2024-03-24 02:35:30 +01:00
|
|
|
UART_println("UART Initialized!");
|
|
|
|
|
|
|
|
DEBUG("DEBUG mode enabled!");
|
|
|
|
|
2024-03-24 04:07:20 +01:00
|
|
|
I2C_init(100000);
|
2024-03-24 01:23:44 +01:00
|
|
|
UART_println("I2C Initialized!");
|
2024-03-24 02:35:30 +01:00
|
|
|
|
2024-03-24 01:23:44 +01:00
|
|
|
MPU6050_Init();
|
2024-03-24 02:35:30 +01:00
|
|
|
UART_println("MPU6050 Initialized!");
|
2024-03-23 04:28:03 +01:00
|
|
|
|
2024-03-24 02:35:30 +01:00
|
|
|
while (1) {
|
|
|
|
UART_println("%d Hello, World!", iteration++);
|
2024-03-24 04:07:20 +01:00
|
|
|
|
2024-03-24 02:35:30 +01:00
|
|
|
// Read accelerometer data
|
2024-03-24 04:07:20 +01:00
|
|
|
UART_println("Reading MPU6050 accelerometer data...");
|
|
|
|
MPU6050_Read_Accel(accel_data);
|
|
|
|
|
|
|
|
UART_println("Accelerometer (mg): X=%d, Y=%d, Z=%d", accel_data[0], accel_data[1], accel_data[2]);
|
2024-03-24 05:08:56 +01:00
|
|
|
sleep_mode();
|
2024-03-23 04:28:03 +01:00
|
|
|
}
|
|
|
|
|
2024-03-24 00:00:32 +01:00
|
|
|
return 0;
|
2024-03-24 04:07:20 +01:00
|
|
|
}
|