Skip to content

Commit

Permalink
add I2C timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
cameron-goddard committed Jan 7, 2025
1 parent 6bfe71d commit a13e8df
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
5 changes: 3 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ framework = arduino
board = atmega328p
build_flags =
-D VERBOSE
-D CHIPSAT_ID=2
-D WIRE_TIMEOUT
-D CHIPSAT_ID=3
upload_protocol = custom
upload_speed = 19200
upload_command = avrdude -C /Users/camerongoddard/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf -P /dev/cu.usbmodem11301 -b 19200 -v -V -p atmega328p -c stk500v1 $UPLOAD_FLAGS -U flash:w:$SOURCE:i
upload_command = avrdude -C /Users/camerongoddard/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf -P /dev/cu.usbmodem211301 -b 19200 -v -V -p atmega328p -c stk500v1 $UPLOAD_FLAGS -U flash:w:$SOURCE:i
16 changes: 8 additions & 8 deletions src/Monitors/IMUMonitor.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "IMUMonitor.hpp"

IMUMonitor::IMUMonitor()
IMUMonitor::IMUMonitor(): imu(Wire)
{
}

Expand All @@ -10,7 +10,7 @@ void IMUMonitor::execute()
#ifdef VERBOSE
Serial.println(F("Turning on IMU"));
#endif
if (!IMU.begin()) {
if (!imu.begin()) {
#ifdef VERBOSE
Serial.println(F("IMU failed"));
#endif
Expand All @@ -26,22 +26,22 @@ void IMUMonitor::execute()
void IMUMonitor::capture_imu_values()
{
// Check if the gyroscope, accelerometer, or magnetometer has new data available
if (IMU.gyroscopeAvailable()) {
IMU.readGyroscope(
if (imu.gyroscopeAvailable()) {
imu.readGyroscope(
sfr::imu::gyro_x,
sfr::imu::gyro_y,
sfr::imu::gyro_z); // Data is in degrees/s
}

if (IMU.accelerationAvailable()) {
IMU.readAcceleration(
if (imu.accelerationAvailable()) {
imu.readAcceleration(
sfr::imu::acc_x,
sfr::imu::acc_y,
sfr::imu::acc_z); // Data is in m/s^2
}

if (IMU.magneticFieldAvailable()) {
IMU.readMagneticField(
if (imu.magneticFieldAvailable()) {
imu.readMagneticField(
sfr::imu::mag_x,
sfr::imu::mag_y,
sfr::imu::mag_z); // Data in uT
Expand Down
2 changes: 2 additions & 0 deletions src/Monitors/IMUMonitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class IMUMonitor
* @brief Reads IMU data
*/
void capture_imu_values();

LSM9DS1Class imu;
};

#endif
2 changes: 0 additions & 2 deletions src/Monitors/TempMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

TempMonitor::TempMonitor()
{
// Init I2C communication as master
Wire.begin();
}

void TempMonitor::execute()
Expand Down
4 changes: 4 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ void setup()
Serial.begin(9600);
#endif

// Set I2C transaction timeout
Wire.begin();
Wire.setWireTimeout(3000);

sfr::gps::boot_time = millis();

// Set ChipSat LED high for debugging
Expand Down

0 comments on commit a13e8df

Please sign in to comment.