Stufin
Home Quick Cart Profile

APM 2.8 Flight Controller with In-Built Compass

Buy Now on Stufin

Accelerometer and Gyroscope

A 3-axis accelerometer and 3-axis gyroscope that measure the vehicle's acceleration, roll, pitch, and yaw.

Barometer

A pressure sensor that measures the vehicle's altitude.

### Processor and Memory

32-bit ARM Cortex-M4 ProcessorA high-performance processor that runs the autopilot software.
2MB Flash MemoryStores the autopilot software and configuration data.
128KB RAMProvides fast access to data and programs.

### Communication Interfaces

UART

A serial communication interface for connecting to serial devices, such as GPS modules and telemetry radios.

I2CA two-wire interface for connecting to I2C devices, such as sensors and peripherals.

SPI

A four-wire interface for connecting to SPI devices, such as flash memory and sensors.

Analog Inputs

Six analog input channels for connecting to analog sensors, such as voltage and current sensors.

### Motor Control

8 PWM Output ChannelsSupports up to 8 motors or servos, with 4096 steps of resolution.

Motor Mixing

Automatically mixes motor outputs for complex vehicle configurations, such as quadcopters and hexacopters.

### Safety Features

Failsafe

Automatically takes control of the vehicle if the autopilot system fails or loses communication with the transmitter.

Sensor Redundancy

Uses redundant sensors to ensure reliable operation in case of sensor failure.

### Operating Modes

Manual Mode

The flight controller follows the pilot's inputs from the transmitter.

Acro Mode

The flight controller stabilizes the vehicle's roll, pitch, and yaw, but allows for aerobatic maneuvers.

Stabilize Mode

The flight controller maintains the vehicle's position and orientation.

Alt Hold Mode

The flight controller maintains the vehicle's altitude and position.

Loiter Mode

The flight controller orbits around a fixed point.

### Power Management

Input Voltage

5V to 12V DC input voltage range.

Power Consumption

Typically 100mA to 200mA, depending on the system configuration.

### Dimensions and Weight

Dimensions

36mm x 36mm x 10mm (1.42in x 1.42in x 0.39in).

Weight

Approximately 20 grams (0.71 oz).

Conclusion

The APM 2.8 Flight Controller with In-Built Compass is a powerful and feature-rich autopilot system designed for UAV and robotics applications. Its compact size, low power consumption, and high-performance processing make it an ideal choice for a wide range of applications, from small quadcopters to large industrial robots.

Pin Configuration

  • APM 2.8 Flight Controller with In-Built Compass Pinout Documentation
  • The APM 2.8 Flight Controller with In-Built Compass is a popular open-source autopilot system designed for drones, quadcopters, and other unmanned aerial vehicles (UAVs). This documentation provides a detailed explanation of each pin on the flight controller, including their functions and connection guidelines.
  • Pinout Structure:
  • The APM 2.8 Flight Controller has a 4-layer stackable design with a total of 47 pins, organized into several groups. The pinout structure is as follows:
  • Top Layer:
  • + Pins 1-12: Power and Analog Inputs
  • + Pins 13-24: Digital Inputs and Outputs
  • Middle Layer:
  • + Pins 25-36: Serial Ports and I2C Bus
  • + Pins 37-46: Motor Outputs and PWM
  • Bottom Layer:
  • + Pins 47: Ground
  • Pin-by-Pin Explanation and Connection Guidelines:
  • Top Layer (Pins 1-12):
  • 1. VIN (Pin 1): Power input from the battery or power source (7-28V). Connect to the positive terminal of the power source.
  • 2. VCC (Pin 2): 5V power output from the onboard voltage regulator. Can be used to power peripherals or sensors.
  • 3. GND (Pin 3): Ground connection. Connect to the negative terminal of the power source and other components' ground pins.
  • 4. BAT (Pin 4): Battery voltage monitoring input. Connect to the positive terminal of the battery.
  • 5. CURR (Pin 5): Current sensor input. Connect to the current sensor output.
  • 6. RSSI (Pin 6): RSSI (Received Signal Strength Indication) input from the radio transmitter. Connect to the RSSI output of the radio.
  • 7. Analog 1 (Pin 7): Analog input for sensors or other devices. Can be used for voltage, current, or other analog signals.
  • 8. Analog 2 (Pin 8): Analog input for sensors or other devices. Can be used for voltage, current, or other analog signals.
  • 9. Analog 3 (Pin 9): Analog input for sensors or other devices. Can be used for voltage, current, or other analog signals.
  • 10. Analog 4 (Pin 10): Analog input for sensors or other devices. Can be used for voltage, current, or other analog signals.
  • 11. Analog 5 (Pin 11): Analog input for sensors or other devices. Can be used for voltage, current, or other analog signals.
  • 12. Analog 6 (Pin 12): Analog input for sensors or other devices. Can be used for voltage, current, or other analog signals.
  • Top Layer (Pins 13-24):
  • 13. Digital 1 (Pin 13): Digital input/output for sensors or other devices. Can be used for digital signals, such as GPS or telemetry data.
  • 14. Digital 2 (Pin 14): Digital input/output for sensors or other devices. Can be used for digital signals, such as GPS or telemetry data.
  • 15. Digital 3 (Pin 15): Digital input/output for sensors or other devices. Can be used for digital signals, such as GPS or telemetry data.
  • 16. Digital 4 (Pin 16): Digital input/output for sensors or other devices. Can be used for digital signals, such as GPS or telemetry data.
  • 17. Digital 5 (Pin 17): Digital input/output for sensors or other devices. Can be used for digital signals, such as GPS or telemetry data.
  • 18. Digital 6 (Pin 18): Digital input/output for sensors or other devices. Can be used for digital signals, such as GPS or telemetry data.
  • 19. SDA (Pin 19): I2C bus data line for connecting I2C devices, such as sensors or peripherals.
  • 20. SCL (Pin 20): I2C bus clock line for connecting I2C devices, such as sensors or peripherals.
  • 21. TX (Pin 21): UART serial port transmit pin for connecting to a serial console or telemetry system.
  • 22. RX (Pin 22): UART serial port receive pin for connecting to a serial console or telemetry system.
  • 23. Boot (Pin 23): Boot loader pin for flashing the flight controller's firmware.
  • 24. EXTGetInt (Pin 24): External interrupt pin for connecting to external interrupt sources, such as a rangefinder or GPS module.
  • Middle Layer (Pins 25-36):
  • 25. uart2TX (Pin 25): UART serial port transmit pin for connecting to a second serial console or telemetry system.
  • 26. uart2RX (Pin 26): UART serial port receive pin for connecting to a second serial console or telemetry system.
  • 27. uart3TX (Pin 27): UART serial port transmit pin for connecting to a third serial console or telemetry system.
  • 28. uart3RX (Pin 28): UART serial port receive pin for connecting to a third serial console or telemetry system.
  • 29. uart4TX (Pin 29): UART serial port transmit pin for connecting to a fourth serial console or telemetry system.
  • 30. uart4RX (Pin 30): UART serial port receive pin for connecting to a fourth serial console or telemetry system.
  • 31. I2C1SDA (Pin 31): I2C bus data line for connecting I2C devices, such as sensors or peripherals.
  • 32. I2C1SCL (Pin 32): I2C bus clock line for connecting I2C devices, such as sensors or peripherals.
  • 33. I2C2SDA (Pin 33): I2C bus data line for connecting I2C devices, such as sensors or peripherals.
  • 34. I2C2SCL (Pin 34): I2C bus clock line for connecting I2C devices, such as sensors or peripherals.
  • 35. SPI_MOSI (Pin 35): SPI bus master out slave in pin for connecting to SPI devices, such as sensors or peripherals.
  • 36. SPI_MISO (Pin 36): SPI bus master in slave out pin for connecting to SPI devices, such as sensors or peripherals.
  • Middle Layer (Pins 37-46):
  • 37. Motor 1 (Pin 37): PWM output for motor 1.
  • 38. Motor 2 (Pin 38): PWM output for motor 2.
  • 39. Motor 3 (Pin 39): PWM output for motor 3.
  • 40. Motor 4 (Pin 40): PWM output for motor 4.
  • 41. Motor 5 (Pin 41): PWM output for motor 5 (optional).
  • 42. Motor 6 (Pin 42): PWM output for motor 6 (optional).
  • 43. Servo 1 (Pin 43): PWM output for servo 1.
  • 44. Servo 2 (Pin 44): PWM output for servo 2.
  • 45. Servo 3 (Pin 45): PWM output for servo 3.
  • 46. Servo 4 (Pin 46): PWM output for servo 4.
  • Bottom Layer (Pin 47):
  • 47. GND (Pin 47): Ground connection. Connect to the negative terminal of the power source and other components' ground pins.
  • Important Connection Guidelines:
  • Always connect the power source (VIN) to a suitable voltage regulator or power module to ensure stable power supply to the flight controller.
  • Use twisted pair cables for all serial connections (UART, I2C, SPI) to minimize electromagnetic interference (EMI).
  • Connect sensors and peripherals according to their specific pinouts and connection guidelines.
  • Ensure proper soldering and insulation of all connections to prevent electrical shorts or damage to the flight controller.
  • Caution:
  • Incorrect connections or voltages can damage the flight controller or other components. Consult the documentation and guidelines for each component before making connections.
  • Always follow proper safety precautions when working with electronic components and power sources.

Code Examples

APM 2.8 Flight Controller with In-Built Compass Documentation
Overview
The APM 2.8 Flight Controller with In-Built Compass is a popular open-source autopilot system designed for unmanned aerial vehicles (UAVs), drones, and model aircraft. This component is part of the ArduPilot project and features a built-in compass, which provides accurate orientation and navigation data. The APM 2.8 is a reliable and flexible flight controller suitable for a wide range of applications, from beginner quadcopters to advanced autonomous systems.
Technical Specifications
Microcontroller: ATMEGA328P
 Operating Frequency: 16 MHz
 Input Voltage: 5V to 12V
 Current Consumption: 50mA (typical)
 Compass: Built-in, 3-axis magnetometer (HMC5883L)
 Interfaces: I2C, SPI, UART, USB
 Size: 36mm x 36mm x 10mm
Code Examples
### Example 1: Basic Drone Flight Control using APM 2.8
This example demonstrates how to use the APM 2.8 Flight Controller to control a basic drone flight. The code is written in C++ and utilizes the ArduPilot libraries.
```c
#include <AP_Common.h>
#include <AP_Motors.h>
#include <AP_InertialSensor.h>
AP_Motors motors;
AP_InertialSensor ins;
void setup() {
  // Initialize motors and inertial sensor
  motors.init();
  ins.init();
  
  // Set flight mode to STABILIZE
  set_flight_mode(FLIGHT_MODE_STABILIZE);
}
void loop() {
  // Read inertial sensor data
  ins.read();
  
  // Stabilize the drone
  stabilize();
  
  // Update motor outputs
  motors.update();
  
  // Delay for 10ms
  delay(10);
}
void stabilize() {
  // Calculate roll and pitch angles
  float roll = ins.get_roll();
  float pitch = ins.get_pitch();
  
  // Calculate motor outputs based on roll and pitch
  int mot1 = constrain(roll  100 + pitch  50, -1000, 1000);
  int mot2 = constrain(-roll  100 + pitch  50, -1000, 1000);
  int mot3 = constrain(-roll  100 - pitch  50, -1000, 1000);
  int mot4 = constrain(roll  100 - pitch  50, -1000, 1000);
  
  // Set motor outputs
  motors.set_output(mot1, mot2, mot3, mot4);
}
```
### Example 2: Compass-based Navigation using APM 2.8
This example demonstrates how to use the built-in compass on the APM 2.8 Flight Controller to navigate a drone. The code is written in C++ and utilizes the ArduPilot libraries.
```c
#include <AP_Common.h>
#include <AP_Compass.h>
AP_Compass compass;
void setup() {
  // Initialize compass
  compass.init();
  
  // Set navigation mode to COMPASS
  set_navigation_mode(NAVIGATION_MODE_COMPASS);
}
void loop() {
  // Read compass data
  compass.read();
  
  // Get current heading
  float heading = compass.get_heading();
  
  // Set desired heading
  float target_heading = 45.0; // 45 degrees
  
  // Calculate error between current and target heading
  float error = heading - target_heading;
  
  // Calculate motor outputs based on error
  int mot1 = constrain(error  50, -1000, 1000);
  int mot2 = constrain(-error  50, -1000, 1000);
  int mot3 = constrain(error  50, -1000, 1000);
  int mot4 = constrain(-error  50, -1000, 1000);
  
  // Set motor outputs
  motors.set_output(mot1, mot2, mot3, mot4);
  
  // Delay for 10ms
  delay(10);
}
```
### Example 3: GPS-guided Waypoint Navigation using APM 2.8
This example demonstrates how to use the APM 2.8 Flight Controller with GPS and compass data to navigate a drone to a series of waypoints. The code is written in C++ and utilizes the ArduPilot libraries.
```c
#include <AP_Common.h>
#include <AP_GPS.h>
#include <AP_Compass.h>
AP_GPS gps;
AP_Compass compass;
// Define waypoints
const float waypoints[][2] = {{37.7749, -122.4194}, {37.7858, -122.4364}, {37.7963, -122.4573}};
void setup() {
  // Initialize GPS and compass
  gps.init();
  compass.init();
  
  // Set navigation mode to GPS
  set_navigation_mode(NAVIGATION_MODE_GPS);
}
void loop() {
  // Read GPS and compass data
  gps.read();
  compass.read();
  
  // Get current location and heading
  float lat = gps.get_latitude();
  float lon = gps.get_longitude();
  float heading = compass.get_heading();
  
  // Calculate distance to next waypoint
  float distance = distance_to_waypoint(lat, lon, waypoints[0][0], waypoints[0][1]);
  
  // If distance is less than 10 meters, move to next waypoint
  if (distance < 10.0) {
    waypoints++;
  }
  
  // Calculate motor outputs based on distance and heading
  int mot1 = constrain(distance  50 + heading  20, -1000, 1000);
  int mot2 = constrain(-distance  50 + heading  20, -1000, 1000);
  int mot3 = constrain(distance  50 - heading  20, -1000, 1000);
  int mot4 = constrain(-distance  50 - heading  20, -1000, 1000);
  
  // Set motor outputs
  motors.set_output(mot1, mot2, mot3, mot4);
  
  // Delay for 10ms
  delay(10);
}
float distance_to_waypoint(float lat1, float lon1, float lat2, float lon2) {
  // Calculate distance between two points on the surface of the Earth
  // Using Haversine formula
  float dlat = radians(lat2 - lat1);
  float dlon = radians(lon2 - lon1);
  float a = sin(dlat/2)  sin(dlat/2) + cos(radians(lat1))  cos(radians(lat2))  sin(dlon/2)  sin(dlon/2);
  float c = 2  atan2(sqrt(a), sqrt(1-a));
  float distance = EARTH_RADIUS  c;
  return distance;
}
```
These examples demonstrate the basic functionality of the APM 2.8 Flight Controller with In-Built Compass. The actual implementation may vary depending on the specific requirements of your project.