Help with basic Arduino set up?

I just got my Arduino Mega2560 as a present. I think many people in the home cockpit section of the forum are familiar with the hardware? :slight_smile:
To start I want to create a basic button board for my flightsim, so I put HoodLoader2 on it. I believe this install is successful.

I made a simple board with a single switch and a led.

Am I doing something wrong with the wiring? The led lights up when the button is pressed, but the board doesn’t register the button press.

the code:

#include <HID-Project.h>

#include <HID-Settings.h>

int input = 0;

void setup() {

pinMode(input, INPUT);

Gamepad.begin();

}

void loop() { if(digitalRead(input) == HIGH){

Gamepad.press(1);

} if(digitalRead(input) == LOW){

Gamepad.release(1); }

Gamepad.write();

}

I tried it with both position 0 and 2. But the button never lights up in this window:

Any help is much appreciated! :slight_smile:

edit:

perhaps I should add that ever since I installed Hoodloader2, the ‘L’ led on the Arduino is flashing 4 times short and 1 time long on repeat. I can’t find anything about what it could mean.

Somebody tested my wiring and script and it worked fine on a Leonardo board. I’ll buy that one. :slight_smile:

I’m gonna have a couple of Arduino Megas to play with in hopefully two months, but I will be using Air Manager to work with them.

1 Like

I will have to check that out, thanks :slight_smile:

1 Like

The Leonardo board is easy to use, because there are joystick libs that turns your Leonardo into a generic joystick in Windows. This means you can bind funcionality to its buttons directly in the sim. Less fun is the fact that it has only 20 pins (in/outputs). while a joystick in Windows can handle 32 buttons. This can be circumvented with some programming and some extra circuitry (for example you can use shift registers to read, say 16 buttons, and communicate the result to the Leonardo through 3 pins, Ive done this in one of my panels), but this is somewhat advanced. Another negative thing about using a Leonardo this way is the fact that you wont be able to read data from the sim to you Leonardo, i.e. your generic joystick. So you will not be able to build a radio unit with 7-seg leds showing the frequency.

The Mega board on the other hand has alot more pins (63 I think). But you will have to program this board for serial communication with some software in the computer, which then talks to the sim. Either you write your own computer software, or you make use of some already invented. SPAD.neXt is one example of software that can be used (Ive experimented with this myself). This way you will have the possibility to read data from the sim to your Mega. Though, this requires some programming skills.

There is a really easy way though, to make use of the Mega board and all its benefits without having to code a single line. It´s called MobiFlight. With this software you can build a panel in no time, both with buttons, rotary encoders, leds and 7-seg leds. I really would recommend MobiFlight if you want quick and easy results.

Of course there are other ways to build your cockpit. This though, is some ways I have experimented with myself. Feel free to go other paths.

1 Like

You’ve got my attention :smiley: thanks for the heads up!

Right now I’m just not sure if my mega is still working or not. :confused: Wiring directly from the 5V to one of the digital inputs reads 0V on my meter, and it does not register the input.

With mobiflight, do I need HoodLoader? Is there an easy way to reset it, or can I leave it on my Arduino?

No, with MobiFlight you dont need HoodLoader (actually I havent heard of HoodLoader before). The MobiFlight software configures your Mega with just a few button clicks. It will overwrite whatever you have uploaded to it. It´s extremly simple. Check out their web page. There you have some easy tutorials on how to wire your Mega too:

The chip on the mega that holds the com can be reflashed with an ISP so the mega will be seen as a HID. But you need to reflash it every time you want to change the code to the mega, and it is a pain. Micro and leonardo are easy to interface. To make it easy you might want to have the mega connected via i2c / serial to a micro an then go from the micro to the pc a standard HID.

Then the micro/leonardo still will be your bottleneck regaring how many buttons you can connect. I think one of the main benefits using a Mega (serial comm or MobiFlight) is the possibility to use more than 32 buttons. And of course the ability to read data from the sim.

Does anyone of you have a tutorial on how to flash it back to standard (non hoodloader)?
I found one tutorial, but I believe it required another mega 2560 (to copy from?).

By looking at the code you will send at each iteration the status of the button on the usb port: so the led on the arduino should flash all the time since you are transmitting. Did you tried if feasible to insert a serial write debug message and check into the debug console?

I think you can just upload a new scetch from the Arduino software, or flash it from the MobiFlight software. Have you tried it?

Mobiflight doesn’t recognize my arduino for some reason. (I assume HL2)
What sketch should I upload? Just sending an empty sketch gives me an error.

Maybe I ‘bricked’ it?

Did you set the correct board, processor and port in the tools menu in the Arduino software?

I tried these boards:

Arduino Mega 2560 (which I think is the one you want me to select)
Hoodloader2 16u2 (the only one I can upload to without errors)
Hoodloader2 Mega 2560

edit:
in the MobiFlight settings, patch to Arduino IDE is just the folder where the Arduino .exe is located right? Because the Arduino Module doesn’t show up in the list above that.

Yeah, thats correct. It didnt show up for me either when I first installed it.

I the Arduino software, under the Tools menu:
Board: Arduino Mega or Mega 2560
Processor: ATMega 2560 (Mega 2560)
Port: The com port you are connected to
Get Board info: Click this one and you should receive board info. Verifies that you are connected.

I get this when I click the get board info:

BN: HoodLoader2 16u2
VID: 2341
PID: 484C
SN: Upload any sketch to obtain it

So I am connected.

If I upload for an Arduino Mega 2560 board, I get this error:

Sketch uses 662 bytes (0%) of program storage space. Maximum is 253952 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 8183 bytes for local variables. Maximum is 8192 bytes.
An error occurred while uploading the sketch

Incorrect, because you can use 2 buttons to drive a function in the sim. Say ou have 3 buttons. 1+1 gives one function, 1+2 an other one 1+3, 2+1, 2+2, 2+3… So even if you are limited with 32 buttons you can achieve more than 32 assignment. And this is made easy with the scan command for binding controls

Ok, had to dig a little. You need to write the Arduino bootloader back to your Mega. I guess the hoodloader has overwritten it. In order to do so you will nead a special device (I use an AVRISP mkII for this stuff), or I think you can use a second Arduino board for this.

Here is an article about it. This article assumes you have programmed the microcontroller with Atmel Studio, thus overwritten the Arduino bootloader. You are in a similiar situation, but for you the hoodloader did the overwriting.

Im not sure I understand. Could you please elaborate?