Current SPAD.neXt Release: 0.9.12.123

This forum has closed. Please join our Discord Community.

SPAD.neXt online services are no longer available for SPAD.neXt Versions < 0.9.11.5

Arduino controller - Building a GPS

Discussion about special hardware
User avatar
OldAirmail
Donator
Posts: 172
Joined: 10 Mar 2015, 22:00
Status: Offline

Arduino controller - Building a GPS

Post by OldAirmail » 31 Oct 2016, 03:01

In Arduino controller I talked about how versatile some of the Arduino process controller boards can be, and asked if it were possible to include the Arduino boards in SPAD.neXt.

As SPAD.neXt "sees" a properly configured Arduino board as an HID game controller, I don't know if it's all that important now.


Long story short, I've been trying different Arduino programs (called "sketches"), different Arduino boards, and different rotary encoders (used for GPS, and radio frequencies, among a great many other things).

The Arduino boards that can act as game controllers are so very easy to set up that it's incredible. But they can also be programmed to control 7 segment numerical displays, regular LEDs. The difficult part is in controlling the dual concentric encoders used on radios and GPS.

Not a problem. :D

I've used one of the cheaper Arduinos, the Pro Micro, that can cost less that $10. Cheaper on eBay. Also, the dual concentric encoder with a pushbutton function is only $10. Read the original post for more detail


So this is the Pro Micro blown up.
Image

It works in FSX too, but here is how Prepar3d "sees" it. There's no reason that any program can't use it.
Image

[And again, in SPAD.neXt
Image

This is the encoder that I spent so much time with today.
Image



The software is not mine. Check it out here - DIY Arduino Buttonbox

It's set up to control all this, but can easily be expanded.
Image



All I have to do now is to put it all together. :D
Image


I'm rushing this, sorry about any mistakes.
1 Saitek Switch Panel, 1 Radio Panel, 1 Multi Panel, 1 BIP, 1 FIP,
1 Saitek Rudder Pedal,
1 Saitek Throttle, 1 Saitek TPM, 1 Desktop Aviator GPS, 1 CH Yoke


Registered

Image

Rubix101
Flight Attendant
Posts: 36
Joined: 06 Feb 2016, 20:42
Status: Offline

Re: Arduino controller - Building a GPS

Post by Rubix101 » 31 Oct 2016, 19:00

This is brilliant, many thanks for this idea and other posts on how to integrate hardware with Arduino and SPAD.neXt!

Now I just need to figure out what to integrate into my PMDG 777/737 setups. While I will check out the Buttonbox software, can that Arduino board drive LED's as well or do I need something else to illuminate LED's or switches?

User avatar
OldAirmail
Donator
Posts: 172
Joined: 10 Mar 2015, 22:00
Status: Offline

Re: Arduino controller - Building a GPS

Post by OldAirmail » 31 Oct 2016, 23:31

It varies from Arduino named board to board. For the most part you decide whether the pins will be input or output.

If output, the pins can control just about anything. Motors of various kinds, annunciator lights, single LEDs, or 7 segment LED displays such as this -

YouTube doesn't work well on this site, so this link will take you off this page and send you to the YouTube video.
Image

This was a test at an analog flaps gauge using a servo motor.
Image Image

Click on this link - fsx arduino flight sim for general ideas.


Me, I'm not very good at programming. I haven't tried it since the '90s. But the sky really is the limit if you're any good at it.

On the other hand, there's a lot that you can do very simply with the Arduino controller boards.

As far as the PMDG 777/737 planes, I think that SPAD.neXt would be crucial to getting good results.

But as you can see, SPAD.neXt, does recognize the HID implementation of some Arduino boards. So programming switch panels should be a no brainer. LEDs reacting to the aircraft might take a bit more work for some things.

But just lipping a switch and having a light come on at the same time? No problem.

That's not to say that you don't have to learn how to use the Arduinos and the basic programming. But there's a lot of code out there. You can use it direct, as I did, or learn just enough to alter pre-existing code to suit your needs.


I don't know anything about the Leo Bodnar equipment. Nothing at all. It could be easier to use than the Arduino boards. Again, I don't know.

But what I do know is that you should be able to build an entire cockpit more cheaply using Arduino boards than you could using the Leo Bodnar boards.
1 Saitek Switch Panel, 1 Radio Panel, 1 Multi Panel, 1 BIP, 1 FIP,
1 Saitek Rudder Pedal,
1 Saitek Throttle, 1 Saitek TPM, 1 Desktop Aviator GPS, 1 CH Yoke


Registered

Image

User avatar
OldAirmail
Donator
Posts: 172
Joined: 10 Mar 2015, 22:00
Status: Offline

Re: Arduino controller - Building a GPS

Post by OldAirmail » 01 Nov 2016, 00:15

The following is the Arduino code in it's entirety.

This lets you control 4 rotary encoders, for thinks such as setting radio frequencies, and 25 buttons/ switches.

With a little knowledge it can be easily expanded.

THIS IS ONLY THE TIP OF THE ICEBURG AS TO WHAT YOU CAN DO.

--------------------------------------------------------------------------------------------------------------------------------

//Simple buttonbox sketch
//Supports up to 25 buttons and up to 4 encoders
//version 0.1 by TOPMO3
//
//
//Arduino IDE 1.6.6 (or above) !
//
//Joystick library from Matthew Heironimus, https://github.com/MHeironimus/ArduinoJoystickLibrary
//
//Encoders code from Ben Buxton
//More info: http://www.buxtronix.net/2011/10/rotary ... perly.html
//
//Thank you guys! :)
//

#include <Keypad.h>
#include <Joystick.h>
#include <Keyboard.h>


#define ENABLE_PULLUPS
#define NUMROTARIES 4
#define NUMBUTTONS 25
#define NUMROWS 5
#define NUMCOLS 5


//define the symbols on the buttons of the keypads
byte buttons[NUMROWS][NUMCOLS] = {
{1,2,3,4,5},
{6,7,8,9,10},
{11,12,13,14,15},
{16,17,18,19,20},
{21,22,23,24,25},
};



struct rotariesdef {
byte pin1;
byte pin2;
int ccwchar;
int cwchar;
volatile unsigned char state;
};

rotariesdef rotaries[NUMROTARIES] {
{0,1,26,27,0},
{2,3,28,29,0},
{4,5,30,31,0},
{6,7,32,33,0},
};



#define DIR_CCW 0x10
#define DIR_CW 0x20

#define R_START 0x0
#define R_CW_FINAL 0x1
#define R_CW_BEGIN 0x2
#define R_CW_NEXT 0x3
#define R_CCW_BEGIN 0x4
#define R_CCW_FINAL 0x5
#define R_CCW_NEXT 0x6

const unsigned char ttable[7][4] = {
// R_START
{R_START, R_CW_BEGIN, R_CCW_BEGIN, R_START},
// R_CW_FINAL
{R_CW_NEXT, R_START, R_CW_FINAL, R_START | DIR_CW},
// R_CW_BEGIN
{R_CW_NEXT, R_CW_BEGIN, R_START, R_START},
// R_CW_NEXT
{R_CW_NEXT, R_CW_BEGIN, R_CW_FINAL, R_START},
// R_CCW_BEGIN
{R_CCW_NEXT, R_START, R_CCW_BEGIN, R_START},
// R_CCW_FINAL
{R_CCW_NEXT, R_CCW_FINAL, R_START, R_START | DIR_CCW},
// R_CCW_NEXT
{R_CCW_NEXT, R_CCW_FINAL, R_CCW_BEGIN, R_START},
};


byte rowPins[NUMROWS] = {21,20,19,18,15}; //connect to the row pinouts of the keypad
byte colPins[NUMCOLS] = {14,16,10,9,8}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad buttbx = Keypad( makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS);



void setup() {
Joystick.begin();
rotary_init();
Keyboard.begin();
}



void loop() {

CheckAllEncoders();

CheckAllButtons();

}


void CheckAllButtons(void) {
char key = buttbx.getKey();
if (key != NO_KEY) {
Joystick.setButton(key, 1); delay(50); Joystick.setButton(key, 0);
}
}


/* Call this once in setup(). */
void rotary_init() {
for (int i=0;i<NUMROTARIES;i++) {
pinMode(rotaries.pin1, INPUT);
pinMode(rotaries.pin2, INPUT);
#ifdef ENABLE_PULLUPS
digitalWrite(rotaries.pin1, HIGH);
digitalWrite(rotaries.pin2, HIGH);
#endif
}
}


/* Read input pins and process for events. Call this either from a
* loop or an interrupt (eg pin change or timer).
*
* Returns 0 on no event, otherwise 0x80 or 0x40 depending on the direction.
*/
unsigned char rotary_process(int _i) {
unsigned char pinstate = (digitalRead(rotaries[_i].pin2) << 1) | digitalRead(rotaries[_i].pin1);
rotaries[_i].state = ttable[rotaries[_i].state & 0xf][pinstate];
return (rotaries[_i].state & 0x30);
}

void CheckAllEncoders(void) {
for (int i=0;i<NUMROTARIES;i++) {
unsigned char result = rotary_process(i);
if (result == DIR_CCW) {
Joystick.setButton(rotaries.ccwchar, 1); delay(50); Joystick.setButton(rotaries.ccwchar, 0);
};
if (result == DIR_CW) {
Joystick.setButton(rotaries.cwchar, 1); delay(50); Joystick.setButton(rotaries.cwchar, 0);
};
}
}

--------------------------------------------------------------------------------------------------------------------------------

The neat part of this is that the encoder action shows up as brief button presses, which make programing them extremely easy. :D

A concentric dual rotary encoder as used in the GPS will take up 2 encoder positions and 1 button position.



A very simple display of how an encoder knows which way you turn it.
(A click on the picture will send you to the YouTube video link.)

Image

In the software, instead of the light coming on, the flight sim will see a button press. YOU tell the simulator what to do when the button is pressed. EXACTLY like programming the buttons on a joystick. Simple. :D
1 Saitek Switch Panel, 1 Radio Panel, 1 Multi Panel, 1 BIP, 1 FIP,
1 Saitek Rudder Pedal,
1 Saitek Throttle, 1 Saitek TPM, 1 Desktop Aviator GPS, 1 CH Yoke


Registered

Image

Rubix101
Flight Attendant
Posts: 36
Joined: 06 Feb 2016, 20:42
Status: Offline

Re: Arduino controller - Building a GPS

Post by Rubix101 » 01 Nov 2016, 00:58

Many thanks again for all this info and links, looks like I need to do some research and get my hands on a Arduino to play around with the components and SPAD.next to see how to incorporate them all.

User avatar
OldAirmail
Donator
Posts: 172
Joined: 10 Mar 2015, 22:00
Status: Offline

Re: Arduino controller - Building a GPS

Post by OldAirmail » 01 Nov 2016, 02:34

If, like me, and you're new to Arduinos, the best bet is to start off with the Arduino UNO. Most of the books and instructions are for that one.

The software above is specifically for the Pro Micro though.

So you might want to get one of both.

Now if you go only for the Pro Micro, all you need to do is to learn how to load it using the IDE. Well.... you'll also have to learn how to "include" the appropriate "headers".

So now you're back to the need to learn at least a little about Arduinos. :lol:

So get them both. Better yet get an Arduino kit that includes enough parts to learn with. Make sure that one kit includes an Arduino UNO.


Depending on how much money you want to spend, here are some low end price kits to consider.

$25 - New keyestudio Sensor Kit with UNO R3 for ARDUINO

$26 - Osoyoo 2016 New UNO R3 Board Projects Super Starter Kit For Arduino

$32 - Elegoo UNO Project Super Starter Kit with Tutorial, 5V Relay, UNO R3

$17 - Elegoo Upgraded Electronics Fun Kit w/ Power Supply Module, Jumper Wire, Precision Potentiometer, 830 tie-points Breadboard. Basically, lots of extra, small, parts.

If they don't interest you, find one or two kits that do interest you.



If you're not interested in learning, and just want to "get started", let me warn you -
As you practice building small projects you WILL learn about making mistakes. Learning how to track down and fix your mistakes will be EXTREMELY useful when you actually want to make something.
1 Saitek Switch Panel, 1 Radio Panel, 1 Multi Panel, 1 BIP, 1 FIP,
1 Saitek Rudder Pedal,
1 Saitek Throttle, 1 Saitek TPM, 1 Desktop Aviator GPS, 1 CH Yoke


Registered

Image

User avatar
OldAirmail
Donator
Posts: 172
Joined: 10 Mar 2015, 22:00
Status: Offline

Re: Arduino controller - Building a GPS

Post by OldAirmail » 02 Nov 2016, 04:53

I've delayed a bit too much, so I'll make this short.

If you build a GPS, you want it to look great, don't you?



This is not a new programs, but very few people seem to know about it.
Enhanced Garmin 500W GPS Unit (500WX)


Short version - aside from many improvements over the "standard" FSX/P3d GPS, it has a borderless mode that can be detached to another monitor!


Standard GPS in FSX/P3d
Image

The same location (3W5) with the 500WX
Image

And the new borderless GPS screen
Image

Just drag the new GPS, with borders, to another monitor, click on the right spot, and it'll fill the monitor.

NO NEED to try and adjust the old GPS with the on-screen buttons and knobs to fit. :D



This is a shot of the "new" GPS software in use back in June 2013. (Location - Hawaii)
Image

Enjoy. :D
1 Saitek Switch Panel, 1 Radio Panel, 1 Multi Panel, 1 BIP, 1 FIP,
1 Saitek Rudder Pedal,
1 Saitek Throttle, 1 Saitek TPM, 1 Desktop Aviator GPS, 1 CH Yoke


Registered

Image

User avatar
OldAirmail
Donator
Posts: 172
Joined: 10 Mar 2015, 22:00
Status: Offline

Re: Arduino controller - Building a GPS

Post by OldAirmail » 06 Nov 2016, 02:42

Back to building the Arduino based GPS



Back to basics - Reread the beginning if you need to. If you haven't read that, what follows isn't going to make much sense.

One side note - the camera that I have isn't very good color wise, and the close-up pictures come out as if it had a fisheye lens. Trust me, things look better in real life.



So you have all the parts. Maybe you've spent $60 or $70 on the parts. You may have even spent less if you were careful.

Whatever you have, you now need to start putting holes in something.

I started by laying the monitor ON TOP of the aluminum plate and marking it out. You could cut a window for the monitor to sit behind the plate, but why cause problems?

This also helped to determine how much room there was for the buttons, and where to put them.

Image



Next, I drilled a series of connecting holes for the monitor ribbon to pass through. After filing the rough edges smooth, I "painted" the edges with liquid electrical tape. I bought it cheaper at the local hardware store.

Image

Image

I also used the liquid electrical tape to paint the bare metal around the edges of the monitor. Big mistake, it looks ugly. Just use regular paint.



The project box that I'm using gives me the option of having it lay horizontal, or stand upright. I prefer the flat, horizontal, position.

At least with the monitor that I have, it looks better at that angle. And as there are no overhead lights, there is no reflection problems. This position also gives greater stability when pushing the buttons.

Two things about this picture. 1) the screen in real life looks MUCH better. 2) In Prepar3d, if you have the main, flight sim, screen in "full screen mode" (hold the ALT key down & hit the Return key), the aircrafts GPS will have no "Windows" border around it. The GPS in this picture doesn't fill the screen because the cable that I had been using suddenly went bad and I had to disconnect the main monitor to use it's cable. If I had had a good cable the GPS in this picture would have filled the screen top to bottom, and side to side.

Horizontal
Image

Dialing in KSEA from 3W5, Concrete, WA
Image


Standing upright
Image



There are many things that we can do with the help of a cheap Arduino board and a bit of work. Start thinking, and start building.



End notes
Labels - Later I'll printout an overlay with the button identifiers on paper. After printing the overlay, I'll laminate it. If you want to keep it simple, use a label maker.

This is an example of what I want to do.
Image

I'll probably steal the idea of buttons/switches/knobs on the top edge too. :D

Dual concentric knobs - I have a black set, and a gray set of knobs from Propwash Simulations. For the pictures I thought that I'd have one of each for contrast in the pictures. I like it. :D I'll keep it that way.

Attaching the monitor -This isn't gong to get tossed around much, so I attached the monitor with double sided tape. Simple. :D

Monitor resolution - 800 X 640 worked best for this monitor.
1 Saitek Switch Panel, 1 Radio Panel, 1 Multi Panel, 1 BIP, 1 FIP,
1 Saitek Rudder Pedal,
1 Saitek Throttle, 1 Saitek TPM, 1 Desktop Aviator GPS, 1 CH Yoke


Registered

Image

User avatar
OldAirmail
Donator
Posts: 172
Joined: 10 Mar 2015, 22:00
Status: Offline

Re: Arduino controller - Building a GPS

Post by OldAirmail » 06 Nov 2016, 17:04

VERY INTERESTING - VERY IMPORTANT.

I kept hearing the connect/disconnect sound that Windows plays every time that you plug/unplug a USB device.

Furthermore, checking the "Device and Printers" section in the control panel, I'd see that there was a USB device that was unrecognizable.

The Arduino Pro Micro (correctly identified as an Arduino Leonardo, which it imitates) was still shown in the "Device and Printers" section, and still worked without any problem.



Slow child in the neighborhood that I am, it took a while to recall that Windows 10 in particular, has a tendency of using the power saving settings to turn off most USB hubs/devices.

So, guess what? THAT is the problem.

Go here and uncheck the box where it says "Allow the computer to turn off this device to save power". DO IT FOR EVERY USB HUB/CONTROLLER LISTED!

Image

If you need a little help read this - Fix issue: USB Ports not Working in Windows 10

The only thing left to say is that I had to restart the computer to do a 100% fix.

What a difference! :D
1 Saitek Switch Panel, 1 Radio Panel, 1 Multi Panel, 1 BIP, 1 FIP,
1 Saitek Rudder Pedal,
1 Saitek Throttle, 1 Saitek TPM, 1 Desktop Aviator GPS, 1 CH Yoke


Registered

Image

User avatar
OldAirmail
Donator
Posts: 172
Joined: 10 Mar 2015, 22:00
Status: Offline

Re: Arduino controller - Building a GPS

Post by OldAirmail » 09 Nov 2016, 04:31

Just a short post before I go to bed.


Thought that I'd do a very quick run through of the GPS text.

This first one wasn't too far off. The lines will be removed. Maybe. Maybe not.

Text shifted a bit.

And then I'll have to decide what type of paper to print it on. Lots of choices out there, every thing from metallic to textured stock. Maybe even a solid color.

The screws will be covered, as here.


Anyway, here's the first mock-up, on plain white paper, of what I want to print.

Image
1 Saitek Switch Panel, 1 Radio Panel, 1 Multi Panel, 1 BIP, 1 FIP,
1 Saitek Rudder Pedal,
1 Saitek Throttle, 1 Saitek TPM, 1 Desktop Aviator GPS, 1 CH Yoke


Registered

Image

Locked