# 3. Coding

Now that the electronics are sorted, time to build the firmware. You might already have a project where the wiring is set and you're looking to change your firmware to DDC. Then this is where you start.

Here are the things you need:

## Applications

* [Arduino IDE](https://www.arduino.cc/en/software) (Legacy or IDE2)
* Since the Windows USB device interface just shows the first 32 buttons, I suggest using [Fred's joystick tester](https://github.com/fredemmott/Freds-Controller-Tester) for checking that all your buttons work the way you want.&#x20;

## Libraries

* All libraries needed are included in the repository. They will however have to be moved over to your Arduino library folder. Usually found under documents/Arduino/libraries.&#x20;

<figure><img src="/files/SOslVhqUOHi5K2bMQq16" alt=""><figcaption></figcaption></figure>

## The sketch

Download the repository. The folder called `DahlDesignDDC` holds the "sketch". The piece of code that eventually will become your custom firmware. The sketch is organized in many .ino files. The way this works is that Arduino IDE will read these files as a single, big file, starting with the main file `DahlDesignDDC.ino`, and then reading the rest in alphabetical order. Hence the numbering of all the other .ino files. They are simply split into many files to get a better overview.&#x20;

To open the sketch, open the `DahlDesignDDC.ino` file, Arduino IDE will automatically include all the other files. All the files are now available as **tabs** in Arduino IDE.

<figure><img src="/files/4w5HnRQM9nUMurGfn0Fd" alt=""><figcaption><p>Note the tabs at the top</p></figcaption></figure>

&#x20;Only some of these tabs are relevant to building your controller firmware, in fact only 4 of them are needed to get your firmware going, and a few more are optional.&#x20;

## Board cores

Before uploading any code to your controller, the IDE needs to know what board you're using. A board core is a guide for the IDE to talk to the controller. Many cores are already installed in the IDE. You chose your board under tools-->boards.

* For Atmel 32U4 boards, the Arduino Leonardo board core will do fine. Sparkfun Pro Micro is a very popular board, they have their own cores which can be installed. [Guide here](https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide). As mentioned, also these boards work fine with the Arduino Leonardo core.&#x20;
* For SAMD21/51 boards, you actually need to roll back the core to an earlier version in order for it to work as a joystick. Version 1.6.19 or earlier is needed. I'm using 1.6.19. This is done in the boards manager.
*

```
<figure><img src="/files/Z0JDxbVaHCLV9o7MRotE" alt=""><figcaption></figcaption></figure>
```

* For RP2040, the [Earle Philhower board cores](https://github.com/earlephilhower/arduino-pico) are used. Installation guide on that GitHub page. Also set the USB stack to Adafruit TinyUSB.

<figure><img src="/files/M7BmCkczF2OrV65AL4uq" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dahl-design.gitbook.io/ddc/3.-coding.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
