Categories
Uri_ba's pit

DED Adventures – Part 4 – And there be light

OK, So we got the DED and FuelFlow sorted out. we got a way to get the data over and drive the screen. Before we go on, let’s talk a bit about Arduino boards.

Arduino Boards are ATMEGA based development board, putting the I/O pins available for quick connections. Basic Arduinos traditionally have 13 available digital I/O pins and 6 ADC 10bit “analog” Inputs.

the “classic” arduino board is the Arduino Uno.
Based on the ATMEGA328P, a 16MHZ, 2K RAM chip that uses an on-board RS232 chip to handle serial communication via 2 of the 13 IO pins. I’ve done my initial prototyping work on this board and it works with comms of up to 96000 baud reliably. you might start catching some errors but YMMV.

on the other side of the scale there is the Arduino Due.
the Duo is ARM based 84MHz chip with 96k RAM, it has 54 IO pins, 12 ADC pins and so on. it’s bigger then the Uno.

in the middle this is the Leonardo, it’s about the same size as the Uno, but uses a different Chip, the ATMEGA32u4. However, it’s his little brother the Arduino Micro, is the one I’ll focus about. the 32u4  is pretty much identical to the 328P with a few exceptions, it has 2.5K of RAM, a bit more I/O pins, but the most important feature on the chip is that it has native USB capability, which means it can do serial communication much faster then the Uno. the added bonus is it’s size, the Micro is TINY, it’s slightly less the 5cm long, and has male headers in two rows, which makes it breadboard compatible, and allows an easier mounting . So I chose it and everything I wrote was Micro Optimized. However I do indend to try and make the code in an Uno version (but with diminished capability) and in  Due version (as Acef already has on – so why not).

And back to the design..
I’m using SPI protocol for communication, as it only takes 3 common pins (SCK, MOSI, A0) and another select pit for each screen.
which means we have a bunch of empty pins as on the Arduino Micro MOSI, MISO and SCK are dedicated pins and are not taken out of the 13 classic Arduino Pins. (unlike in the Arduino Uno). the F-16 have “some” bulbs around the pit. because this whole thing revolves around the DED and the fuel flow (which is right next to it) I wanted to put the whole thing inside the DED box to save space (another reason I went with the micro). what lights sit right next to the DED? The answer stare you in the face while you fly, the indexers. we’re talking about 6 lights total.

“Pegasus” (Martin) – makes some awesome projects for sale, checkout Viperpits. but his products are slightly out of my price range (and that is why I’ve started this project in the first place – I cannot afford to pay 300+ Euro for every element in the pit). however he was kind enough to publish a lot of materiel that makes research much easier. the site: http://www.xflight.de.  and the Indexer page.

now, to get 6 leds to work will traditionally requiree 6 I/O pins, but that is just a waste for pins. using a shift register will allow me to light up to 8 LEDs with just three pins. more on that, shift registers can be daisy chained for more output on the same 3 pins. ahh.. the possibilities. but that will wait. I’ve got some shift registers to play with and used this Arduino shiftout tutorial as reference.

let’s look back to the “flightData.h”
Falcon is using three “Lightbit” arrays, which are in fact represented as integers (in c# “int” type are 4 byte long, in arduino however, the 4 byte variable is “long”), where every bit has been assigned a “lamp” with either 0 or 1 in value. the indexers are part of the first Lightbit array:

        // AOA Indexers
        AOAAbove  = 0x1000,
        AOAOn     = 0x2000,
        AOABelow  = 0x4000,

        // Refuel/NWS
        RefuelRDY = 0x8000,
        RefuelAR  = 0x10000,
        RefuelDSC = 0x20000,

where the Hex value represent the bit number (i.e 0x1 is the 0 bit). 0x1000 is the 13th bit – which makes it the 12th. confusing? not really. in C and C derivative languages (C, C#, C++, etc.) arrays are always starting at the “0” position. so, the index for the 13th bit is 12.

so the code i came up with looks like this:

private byte[] MakeAoaLight()
        {
         //Create and populate Bitarray
            BitArray mapping = new BitArray(8, false);
            mapping[0] = lightBits[12]; //AOAAbove
            mapping[1] = lightBits[13]; //AOAOn
            mapping[2] = lightBits[14]; // AOABelow
            mapping[3] = false; // blank
            mapping[4] = false; // blank
            mapping[5] = lightBits[15]; //RefuelRDY
            mapping[6] = lightBits[16]; //RefuelAR
            mapping[7] = lightBits[17]; // //RefuelDSC
         // convert bitarray to byte and return
            byte[] result = new byte[1];
            mapping.CopyTo(result, 0);
            return result;
        }

The Arduino side is very simple:

void readAOA() {
  Serial.print('A');
  Serial.flush();
  Serial.readBytes(AoaIndexer, 1);
}

void lightAOA() {
  digitalWrite(AoaLatchPin, LOW); // pull slave select low to select chip
  shiftOut(LightDataPin, LightClockPin, MSBFIRST, AoaIndexer[0]);
  digitalWrite(AoaLatchPin, HIGH); // light 'em up
}

and that is pretty much it as far as indexers go.

Leave a Reply