Programming the APM2.8

First I thought that my APM2.8 was malfunctioning but then I made following code to test out my module that I have bought on ebay:

/*
ANALOG OUTPUT FOR THE APM2.8
11.12.2016
BY ENGINEER PAVLE DUKANOVIC
www.dukelanovic.com

*/

// These constants won’t change. They’re used to give names
// to the pins used:
const int analogInPin1 = A0; // Analog input pin NEXT TO Telemetry port (PF0) marked with S
const int analogInPin2 = A1; //PF1
const int analogInPin3 = A2; //PF2
const int analogInPin4 = A3; //PF3
const int analogInPin5 = A4; //PF4
const int analogInPin6 = A5; //PF5
const int analogInPin7 = A6; //PF6
const int analogInPin8 = A7; //PF7
const int analogInPin9 = A8; //PK0

const int analogOutPin1 = 12; // ESC1
const int analogOutPin2 = 11; // ESC2
const int analogOutPin3 = 8; // ESC3
const int analogOutPin4 = 7; // ESC4
const int analogOutPin5 = 6; // ESC5
const int analogOutPin6 = 3; // ESC6
const int analogOutPin7 = 2; // ESC7
const int analogOutPin8 = 5; // ESC8

int sensorValue1 = 0; // analog value read
int sensorValue2 = 0; // analog value read
int sensorValue3 = 0; // analog value read
int sensorValue4 = 0; // analog value read
int sensorValue5 = 0; // analog value read
int sensorValue6 = 0; // analog value read
int sensorValue7 = 0; // analog value read
int sensorValue8 = 0; // analog value read
int sensorValue9 = 0; // analog value read

int outputValue = 0; // value output to the PWM (analog out)

void setup() {

// initialize serial communications at 9600 bps:
Serial.begin(9600);
}

void loop() {
// read the analog in value:
sensorValue1 = analogRead(analogInPin1);
sensorValue2 = analogRead(analogInPin2);
sensorValue3 = analogRead(analogInPin3);
sensorValue4 = analogRead(analogInPin4);
sensorValue5 = analogRead(analogInPin5);
sensorValue6 = analogRead(analogInPin6);
sensorValue7 = analogRead(analogInPin7);
sensorValue8 = analogRead(analogInPin8);
sensorValue9 = analogRead(analogInPin9);

// map it to the range of the analog out:

outputValue = map(1023, 0, 1023, 0, 255);
analogWrite(analogOutPin1, outputValue);
analogWrite(analogOutPin2, outputValue);
analogWrite(analogOutPin3, outputValue);
analogWrite(analogOutPin4, outputValue);
analogWrite(analogOutPin5, outputValue);
analogWrite(analogOutPin6, outputValue);
analogWrite(analogOutPin7, outputValue);
analogWrite(analogOutPin8, outputValue);

delay(1000);

outputValue = map(0, 0, 1023, 0, 255);
analogWrite(analogOutPin1, outputValue);
analogWrite(analogOutPin2, outputValue);
analogWrite(analogOutPin3, outputValue);
analogWrite(analogOutPin4, outputValue);
analogWrite(analogOutPin5, outputValue);
analogWrite(analogOutPin6, outputValue);
analogWrite(analogOutPin7, outputValue);
analogWrite(analogOutPin8, outputValue);

delay(1000);

// change the analog out value:

// print the results to the serial monitor:
Serial.print("sensor1 = ");
Serial.print(sensorValue1);
Serial.print("sensor2 = ");
Serial.print(sensorValue2);
Serial.print("sensor3 = ");
Serial.print(sensorValue3);
Serial.print("sensor4 = ");
Serial.print(sensorValue4);
Serial.print("sensor5 = ");
Serial.print(sensorValue5);
Serial.print("sensor6 = ");
Serial.print(sensorValue6);
Serial.print("sensor7 = ");
Serial.print(sensorValue7);
Serial.print("sensor8 = ");
Serial.print(sensorValue8);
Serial.print("sensor9 = ");
Serial.print(sensorValue9);

//Serial.print("\t output = ");
// Serial.println(outputValue);

// wait 2 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(2);
}

I found out that my hardware was functioning well and there was no malfunction with my software.
I want to keep the things simple and my plan is to program a simple code onto that complex hardware. I would be very happy if someone could help me with that. I discovered that any Arduino environment can program the APM2.8.

Further Thanks to Randy McCain and to the ingenious team about the flightcontroller project. I am a little handicapped and I need to know the basics about programming APM.

For now I found an easy code for programming on the website of Joop Brokking :

http://www.brokking.net/ymfc-al_main.html and my plan is to impement the simple code to the APM2.8 and to build up the flight controller step by step. I need to know how the whole story does function.

It is great that the APM board is still being made and developed. It is also good to know that it can work with Arduino. Best of luck with this project

Hey - hello,

I have been trying to program the MPU6000 accellerometer and somehow I couldn’t find an easy code for that. Do you have experience with that sensor?

Where can I find some good code that will describe the IMU of AMM2.8 ?

You could try the master-AVR branch of ArduPilot

https://github.com/ArduPilot/ardupilot/blob/master-AVR/libraries/AP_InertialSensor/AP_InertialSensor_MPU6000.cpp

Thank you skyscraper, my APM2.8 functioned well with the Arduino IDE. Nowadays I do have the problem on how to use those programming examples on Pixhawk in combination to the Eclipse IDE. Do you have experience with Eclipse ??

I tried Eclipse once but didnt like it. I think then I had a slow PC and as Eclipse is written in Java I got tired waiting for things to happen. (Especially startup was very slow I remember) These days I use Code::Blocks and am too lazy to try other IDE’s.

Most IDE’s work pretty much the same way. They will either generate or call some sort of Makefile. I would expect that Eclipse is very flexible in that way.

My usual approach is to code in the IDE and then write my build script (Makefile) by hand and just call the build script from the IDE build button. I would think that Eclipse can do similar.

Anyway to build the Ardupilot examples by hand. In the master-AVR branch, navigate at a command line to the directory where the example is and invoke

$ make apm2

You can also just invoke make with no arguments to see other options such as upload.

If you can build manually then it should be possible then to get Eclipse to invoke the same way