Bits and Droids logo
Mail icon

Tutorial: Arduino mfs2020 Cessna inspired throttlebox

3/30/2024 | by Bits and Droids

The code I've used in the video uses a new function that is out today. Using the connector, we can program our Arduino to handle the throttle and mixture functionalities in just 11 lines of code.

cpp
#include <BitsAndDroidsFlightConnector.h> BitsAndDroidsFlightConnector connector = BitsAndDroidsFlightConnector(); void setup() { Serial.begin(115200); } void loop() { connector.simpleInputHandling(A2); connector.mixtureInputHandling(A0,A0); connector.propsInputHandling(A1, A1); }

Needed for this project are:

The 3D files are up for grabs on Printables

Picking the Arduino

To use the literal code in the examples, you have to use an Arduino Pro Micro or a Leonardo. With some slight variations, you can also use Uno, Mega, Nano, etc. It's important to note that when you use one of these boards, you must place a capacitor between the reset pin and the ground. I've had success with 4.7 uF and upwards.

If you want to use the joystick library, you must use the Leonardo or pro-micro. The other Arduino boards don't offer HID capabilities.

The schematics

The wiring of the throttle box is rather simple. It will be a great starting point if you've never worked with electronics or Arduino. If you are comfortable soldering,, you can connect the ground line daisy-chaining a ground wire starting at the Arduino -> the first potentiometer -> the second potentiometer -> the third potentiometer. The same can be done for the 5V power line. It's important to look at the markings on your potentiometers to see which pin is the ground pin and which is the 5v pin. They are usually marked with VCC for the power line and GND or GRND for the ground line.

The last pin on our potentiometer will send the analog data to our Arduino. Arduinos can either read digital signals or analog signals. Reading a digital signal will return either a HIGH or LOW state. Reading an analog input returns a value between 0 and 1023. This allows us to read how far the potentiometer has been opened or closed. All analog pins can be used as digital pins, but not all digital pins can be used as analog pins. Therefore, using pins on your Arduino that are prefixed with an A is important. On the pro-micro, these are A0, A1, A2,A3, A4. different boards may have different layouts.

If you want to create a quick prototype or don't have a soldering Iron, you can also use a breadboard. The ground wires can then be joined on the common blue line, and the power line can be joined on the common red line.

For those of you who are completely new to breadboards, this is how they are connected internally.

breadboard internals

The top horizontal row is split into 2 lines. These are usually used to create a common ground line and a common power line. You can plug your other components into these lines to get them powered and complete the circuit via the ground. The yellow and green lines show how the middle part is connected. The vertical holes are connected in the middle part, but the horizontal lines aren't. A gap in the middle part isn't connected, dividing the breadboard into the top and bottom half. Adding a component or piece of wire could bridge any gap or connect horizontal lines.

breadboard components

In the Old version of the connector, this would be the code to use:

cpp
#include <BitsAndDroidsFlightConnector.h> BitsAndDroidsFlightConnector connector = BitsAndDroidsFlightConnector(true); void setup() { Serial.begin(115200); connector.setEMA_a(0.15); } void loop() { connector.advancedInputHandling(A2,A2,A2,A2,A0); connector.propsInputHandling(A1, A1); delay(10); }

Serial

The connector uses Serial communication to transmit inputs to it and vice versa. Serial.begin(115200) starts a Serial connection at a baud rate of 115200. The baud rate is the rate at which data is transmitted over your circuit. Since the connector listens at a rate of 115200, we have to ensure this value gets matched on our Arduino.

Split the engines and mixture

At first, I combined the throttle and mixture inputs into 1 command.

cpp
connector.advancedInputHandling(A2,A2,A2,A2,A0, 1023.0);

Let's dissect this line, shall we? The connector object has a function called advancedInputHandling. This function requires 6 parameters: engine pin 1 to 4, 1 mixture pin, and the max value of your potentiometers. In most cases, this will be 1023.0. The first flaw we're able to spot is that we're only able to bind 1 potentiometer as a mixture input. Since there are numerous prop planes with dual engines, this would limit your possibilities.

The second strange thing is that the mixture usually doesn't change in sync with your engine levers. By splitting the mixture apart from the engine inputs, we decrease the odds of data corruption (during testing, I've noticed that the longer the string travels over our com port, the more likely a part will fall off). This will also create new possibilities where you perhaps only want to use a mixture handle and use your store-bought solution for the engines. The sky is the limit!

In the upcomming update the input functions will be split in three parts.

  • Engine
  • Mixture
  • Propellers
cpp
connector.simpleInputHandling(A2); connector.propsInputHandling(A1, A1); connector.mixtureInputHandling(A0, A0);

There is a parameter added to each function that determines if the input pin has to be reversed. In the Cessna throttle box I've built, the potentiometer is closed when I push the knob in and open when I pull it out. To fix these situations, I could flip the design internals (and print a new case over a 26-hour period... no thanks) or reverse the code. Imagine you might encounter the same issue, and that's why you can now flip it by setting the last parameter to true. You can set the parameter to false if you don't need to reverse the input.

When in doubt, ask yourself if you need to reverse it. If so (so the statement is true), pass true to the function. If not(so the statement is false), pass false to the function.

Joystick library

Later this week, I'll upload another piece of code showing you how to program the throttles using the Joystick library. This code will be larger, but it will make it possible to use this throttle box in, i.e., Xplane or any flight sim where the throttle can be configured to a controller Axis.