Lessons learned

A project log for KSP Gegi

Kerbal Space Program physical status and control panel

Maciej WitkowiakMaciej Witkowiak 01/29/2016 at 23:230 Comments


It's very hard to do nice woodwork without proper space, table and tools. With space, table and tools available it's just hard to do. That said, I am content with how it looks for a prototype.

IKEA LACK shelf is very easy to work with if you start with cutting through only thin boards on sides and top/bottom. They are just about 3-5mm thin. The reinforced sides (front and back, with hinges) are much thicker and tougher. To avoid them you have to leave about 1cm clearance for the front and at least 3cm on the back side of the shelf.

I made a mistake of trying to use Dremel fiberglass disc to cut through the bottom board. I thought it would be more precise. I almost started a fire of the paper honeycomb shelf insides without having access there. An oscillating tool with proper wood blade was much better choice.

Drilling in this material is very easy. Just use low speed on your drill. I made the smallest holes for screws with no effort using IKEA FIXA electric screwdriver with keyless drill jack with hex shank. Even then I had to be careful to actually drill the hole, not to punch through by just the weight of the tool.


I have tested each component separately on the breadboard so I knew what to expect: how to drive it and how to read its status.

The final software that connected these parts already worked as expected on the first run. It was coded before hardware existed in one piece.

During the course of this project I learned about latest C++11 features through Embedding C++ articles on hackaday. This was the main motivation for me to finally upgrade to latest Arduino IDE.

I was skeptical. After spending so much time on low-level 6502 assembly for C64/C128 (just check out list of my GitHub repositories) it was hard for me to believe that there is no huge cost with using C++ (instead of plain C) for AVR programming.

I restuctured my code by designing new classes to handle switches and LEDs, analog input and output (PWM). I have also replaced fixed arrays of data structures with collections of classes.

C++ classes have constructors. Instead of managing the state variables initialization myself I got it "for free" just by specyfing how constructor arguments are mapped to member variables:

digitalPin::digitalPin(const uint8_t id, const uint8_t pinSwitch) : m_id(id), m_pinSwitch(pinSwitch)

So now I could remove housekeeping code. It made the program logic much clearer to see.

But the greatest thing was replacing clumsy loops over structures:

for (int i=0; i<sizeof(digitalPins)/sizeof(digitalPin[0]); i++)

or equally awful:

for (int i=0; i<NUMBER_OF_DIGITAL_PINS; i++)
with clean for-each iterator:
for (auto &p : digitalPins) {
  // do something with p
Not only it is much easier on the eyes and cleaner. Not only the code is easier to maintain. I actually saved 60 bytes of flash after making these C++11 changes.

Imagine my surprise. Now I don't fear, I love C++11 for AVR.


My largest dilemma was to decide if I should drop some features and try to fit everything in Arduino Mini Pro (ATmega168) or Arduino Micro Pro (ATmega32U4) or combine them both. Or maybe I should use ATmega8 instead of Mini Pro?

Next time for the same device I would use Micro Pro again, for USB connectivity, and ATmega8 as a slave device for additional I/O pins and PWM.

Soldering the circuit was quite time-consuming because all these wires that had to be cut, stripped covered with flux, solder and finally soldered.

This circuit has only three chips and soldering the connections between them on a perforated board was very easy. The difficult part was to connect all the external components: LEDs, potentiometers, PWM output (analog voltage meters), switches and I2C bus.

My largest mistake was that I soldered and twisted all the wires that went to each component before actually mounting the components. Next time I would solder only signal wires - those that go to I/O on the board. Then I would mount the components. Only after that I would cut to the proper length and solder all the unconnected GND and VCC pins into two buses.

Oh, and I will use some kind of connectors on board. Any kind of connectors.