MobiFlight Community Support

Welcome to the forum for MobiFlight! Feel free to reach out to the community in case you have questions, issues or just want to share great ideas or details about your latest home cockpit project.

You like MobiFlight? Donate via PayPal and support the MobiFlight development. Thanks! 

05/03/2024 - This forum is read-only

The community support for MobiFlight has moved exclusively over to our Discord server. Register for free and enjoy more interactive functions like image and video upload, voice chat. More than 7,000 registered users around the world make it a great experience!

See you on our MobiFlight Community Discord server.

A HUGE Thank You to everyone who participated in the forum, especially obviously to Pizman and Stephan who did an outstanding job over so many years providing an incredible service to the MobiFlight community.

The forum is still providing a lot of good content, hence we keep this information accessible.

icon
Avatar
juanfortus
From: Torre del Mar / Malaga / Andalucia, Spain
Posts: 24
Hello everyone, I am new to this world of programming, I might know how to use it with Mobiflight and arduino mega2560 to use the spoiler lever, either with a potentiometer or with micro swich:confused: I have already configured with mobiflight and arduino, the landing gear lever and the led and everything is perfect, but I can not manage to assign the spoilers nor with what element I can do it either with a potensiometer or with a micro swich
If someone could help me solve my problem I would appreciate it
I have tried to configure with Arduino mega 2560, as it says a tutorial of mobiflight assigning as joystick in arduino but I get an error when wanting to validate the code that fasilitan in the tutorial, the code is this:

//Create Joystick
Joystick_ Joystick;

Be sure to download the Joystick library from https://github.com/MHeironimus/ArduinoJoystickLibrary

Here is the full code to copy and paste.

#include <Joystick.h>

// Create Joystick
Joystick_ Joystick;

unsigned int xAxis = 0;
unsigned int yAxis = 0;
unsigned int zAxis = 0;

// Set "initAutoSendState" to true for "Auto Send" mode or false for "Manual Send" mode.
const bool initAutoSendState = true;

void setup() {
Joystick.begin();
}

void loop() {
xAxis = analogRead(A0)/4;
xAxis = map(xAxis,0,255,-127,127);
yAxis = analogRead(A1)/4;
yAxis = map(yAxis,0,255,-127,127);
zAxis = analogRead(A2)/4;
zAxis = map(zAxis,0,255,-127,127);

Joystick.setXAxis(xAxis);
Joystick.setYAxis(yAxis);
Joystick.setZAxis(zAxis);

//Joystick.setState(); //this updates the "Joystick" library
//and therefore your computer of all the current
//joystick and button states determined above
//all at once. YOU ONLY NEED TO USE THIS LINE
//IF const bool initAutoSendMode = FALSE (the
//code for the initAutoSendState is a few
//lines above the "setup" section of code.
}

but wanting to load it I get this error:

Arduino:1.8.7 (Windows 7), Tarjeta:"Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

In file included from E:\Mis documentos\Arduino\sketch_nov12a\sketch_nov12a.ino:18:0:

E:\Mis documentos\Arduino\libraries\Joystick\src/Joystick.h:32:2: error: #error The Joystick library can only be used with a USB MCU (e.g. Arduino Leonardo, Arduino Micro, etc.).

#error The Joystick library can only be used with a USB MCU (e.g. Arduino Leonardo, Arduino Micro, etc.).

^

Se encontraron múltiples librerías para "Joystick.h"
Usado: E:\Mis documentos\Arduino\libraries\Joystick
No usado: C:\Program Files (x86)\Arduino\libraries\Joystick
exit status 1
Error compilando para la tarjeta Arduino/Genuino Mega or Mega 2560.

Este reporte podría tener más información con
"Mostrar salida detallada durante la compilación"
opción habilitada en Archivo -> Preferencias.
I'm a big fan of flight simulation, and I like to learn as well as spread my knowledge with whoever needs them.
2018-12-03 23:14
Avatar
pizman82
Moderator
From: ETSI, Germany
Posts: 6010
Supporter
Hi... Welcome to Mobiflight !

You mix up different things !

Mobiflight basicly NOT support potentiometers ! ( At the moment.... Maby in future but this is not a feature that is high priority for us... maby it comes maby not)
So if you like to work via Mobiflight you need to do this with Microswitches.... BUT Spoilers basicly work steppless ... so a Potentiometer is more relistic.
With a Microswitch logic you can build maby just something like OFF-ARM-FULL ... That work But again thats not like real !
(Microswitches are good for Flaps Leaver but not work for Throttle or a realistic Spoiler leaver ! )


About Pottis.

As i said.... With Mobiflight ( And with a Mega that is used as Mobiflight Board .... So after flashing MF Firmware) there is no possibility to use potentiometers!

The Script you quote ( By MHeironimus ) is just for Arduino Micro and Leonardo. It will not work for with MEGA or UNO .... Simply cause it need a Microcontroller that is shown as a HID Controller for Windows . For Mega and Uno this is not possible... Just by rework the Main Mega Code ( By Bootloader) . But again then the Memory size is a Problem i think.
As i know it is NOT possible to use this code on a Mega finaly... Only a older version that not iclude so much Pins !

Whatever.... If you use THIS code then you can not use the same Board via Mobiflight same time !!! ( This script overwrite the MF Firmware ! )

*****
Solution :

For Potentiometers at the moment the only way is to use a Joystick Controller !
1. A Real one like a LeoBodnar BBI32 (Expensiv)
2. A reworked Arduino with Heronimus Script (Note you need a Micro or Leonardo for this)

Finaly i recommend here to work with a Registred Version of FSUIPC ( If you work on FSX/P3D) .

Then the Potentiometer is controlled by the Joystick Controller Board.... And is show as a real Axis like "Joystick Nr 5 Axis X".
Finaly you can set this axis in FSUIPC ( Or in your AddOn Settings) to a function like "Speedbrakes" .
Good Luck !
2018-12-04 02:22
Avatar
juanfortus
From: Torre del Mar / Malaga / Andalucia, Spain
Posts: 24
Thank you very much for your response and expansion of the information, I already feared it! , I get more complicated work, without having much programming knowledge, well, I will try in another way to see what I resolve, and thank you very much for your time
a greeting:blush: :(
I'm a big fan of flight simulation, and I like to learn as well as spread my knowledge with whoever needs them.
2018-12-04 15:12
icon