Jump to content

Recommended Posts

Posted

Trying to get the MCP23017 working with DCS-Bios.

 

I'm starting to understand some of the concepts but still a lot to learn!

 

I tried this but no luck. Compiles fine but....nothing works

 

 

 

/*

Tell DCS-BIOS to use a serial connection and use the default Arduino Serial

library. This will work on the vast majority of Arduino-compatible boards,

but you can get corrupted data if you have too many or too slow outputs

(e.g. when you have multiple character displays), because the receive

buffer can fill up if the sketch spends too much time updating them.

 

If you can, use the IRQ Serial connection instead.

*/

#define DCSBIOS_DEFAULT_SERIAL

#include "DcsBios.h"

#include "Wire.h" // Use the Wire Library for I2C

byte a=0; // Variable to store the Byte in

 

/* paste code snippets from the reference documentation here */

 

DcsBios::Switch2Pos cmspArw1("CMSP_ARW1", byte(1));

 

void setup() {

DcsBios::setup();

Wire.begin(); // wake up I2C bus

Wire.beginTransmission(0x20); // Connect to chip

Wire.write((byte)0x01); // Select Bank B

Wire.write((byte)0x00); // Set all of bank B to outputs

Wire.endTransmission(); // Close connection

}

void loop() {

DcsBios::loop();

// Read the inputs of bank A

Wire.beginTransmission(0x20); // Connect to chip

Wire.write(0x12); // Set Memory Pointer to Bank A

Wire.endTransmission(); // Close connection

Wire.requestFrom(0x20, 1); // Request one Byte

a=Wire.read(); // Put the Byte into variable 'a'

 

// Write the Byte to Bank B

//Wire.beginTransmission(0x20); // Connect to chip

//Wire.write(0x13); // Set Memory Pointer to Bank B

//Wire.write(a); // Write the Byte

//Wire.endTransmission(); // Close connection

 

delay(50); // Small delay to debounce switch

}

 

 

The "byte a=0" has me confused.

 

I did expect to see some output but got nothing! Hmm...

 

I also messed around with the Adafruit MCP23017 library but could not make sense of using it for inputs.

 

Thanks

 

Clay

Posted

Hi Clay

Haven't seen much you. Must be hard at work on the pit.:P

 

I'm not 100% sure but I do not thick DCS BIOS wil work with a port expander without some major code writing. I see the rational for wanting to use one but there are other options that are extremely cost effective and do not require special code. I'm using Pro Minis and Nano's throughout with RS487 IC's to get them all talking. The code is already part of DCS BIOS and the cost of additional Arduno's is approx. $1.40. The circuit for adding the RS487 IC is also very simple and you can create a breakout board or integrate the IC onto your PCB.

 

Anyways, it something to think about.

 

Anymore pics of the pit?

Regards

John W

aka WarHog.

 

My Cockpit Build Pictures...



John Wall

 

My Arduino Sketches ... https://drive.google.com/drive/folders/1-Dc0Wd9C5l3uY-cPj1iQD3iAEHY6EuHg?usp=sharing

 

 

WIN 10 Pro, i8-8700k @ 5.0ghz, ASUS Maximus x Code, 16GB Corsair Dominator Platinum Ram,



AIO Water Cooler, M.2 512GB NVMe,

500gb SSD, EVGA GTX 1080 ti (11gb), Sony 65” 4K Display

VPC MongoosT-50, TM Warthog Throttle, TRK IR 5.0, Slaw Viper Pedals

Posted

Greetings John!

 

Hope your feeling better!

 

Pit progress seems to be getting slower and slower as the level of difficulty is getting higher. It has taken me 2 weeks to build the landing gear indicators and I'm still not thrilled with them. They stick out of the panel too far in my opinion so back to the drawing board(again). Also the back lighting for the panels is slowing me down a lot. On top of all that I spent a couple weeks trying out some ideas for correct sized MFCDs. The size of the thrustmasters has always bothered me. Especially that giant radius they have on the inside of the frames. I put those on hold until I see what Lynx comes up with.

 

Reasoning behind the MCP23017s is that I already have these built. I used them with helios and eos bus from gadroc. I used Uno R3s and the proto shields. On each shield I have one MCP23017 and one max485 (they are on sockets so i can change to max487 easily). Also I can change out the 23017 to a max7219 if need to. I was just trying to use up some of my existing gear. They are really easy to build with no custom pcb and give you lots of I/O.

 

But i have to agree with you. I have couple of pro minis I haven't used yet. I guess its time to give them a shot. My goal right now is to get the cmsp fully functional and use the max 487.

 

No more pics yet. I hacked up my MIP to fit a new 27" monitor so I need to do some repairs first!

 

So your idea is for me to make custom PCB to mount two prominis and two max487 thus allowing me to use the simple DCS-Bios code? Have you found you can just use a standard board for most panels and using two if required? or is there too many variables to make that work. I have my UHF panel on a mega right now due to so many pins required for the encoders. I havent even started VHFs yet.

 

So much left to do.......

 

Thanks

 

Clay

Posted
Greetings John!

 

Hope your feeling better!

Thanks Clay. Haven't had anymore heart attacks since Feb.

Pit progress seems to be getting slower and slower as the level of difficulty is getting higher. It has taken me 2 weeks to build the landing gear indicators and I'm still not thrilled with them.

I can sure sympathise. I've been at this steady with virtually no breaks using every spare minute I have and its been just over two years since I began the cockpit. The panels were actually the easy part. The electronics and programming is much more time consuming and intense...and theres that damned learning curve that keeps popping up and getting in the way of progress.

 

 

 

I spent a couple weeks trying out some ideas for correct sized MFCDs. The size of the thrustmasters has always bothered me. Especially that giant radius they have on the inside of the frames. I put those on hold until I see what Lynx comes up with.

 

I've too have been playing with the design off and on for a couple of months now. I didn't want to get too serious until I found a display that was close to the correct size. I have one on order and when it arrives I let you know if its worth while. The TM frames are great for everyone else but they suck for us as far as size goes. They are way to small and that inside radius, as you quite correctly pointed out, is very annoying.

 

So your idea is for me to make custom PCB to mount two prominis and two max487 thus allowing me to use the simple DCS-Bios code? Have you found you can just use a standard board for most panels and using two if required?

 

Yes to the board No to the one standard board. It seems I'm always needing JUST ONE MORE UKING PIN. Talk about frustrating... it happens every time. SO now I just assume I will always use 2 Pro Minis or 2 Nano's for a panel. I really don't care because these little boards cost nothing comparatively speaking. BTW, I quite like the Nanos. I'm glad Ian pointed out the excellent price for them. I was always so focused on the Pro Mini's. I really didn't pay attention to anything else until Ian made me look.... (read: target fixation):smilewink:

 

Another thing I started to do was combine panels. As I build a console I find that several panels needed only a couple of IO pins but the panel beside it needs more than a single board can provide so I decided to share IO pins. The Oxy panel only needs a couple of pins because much of it is not functional in the sim. The left over pins get used by the next closest panel. These panels are just inches apart so its not problem. In fact I am combining the three radios and treating them as ONE big radio. All the displays will be driven by one Arduino board and all of the rotary encoders by one or two or three Arduino boards. With the boards all in close proximity to each other its just makes sense. The RS485 IC's will be virtually side by side as well. Very efficient use of boards and space.

 

...and thats my storey and I'm stickin to it:thumbup:

 

 

So much left to do.......
No Shit!! :thumbup: I sometimes wonder if I will ever get it finished. I'm also building a new stick and Pedals from scratch. I am not happy with the TM Warthog gimbal and the Saitek Combat pedals I'm using are rather substandard from my perspective. Once you see what really good pedals look like... well, there's really no going back. Kind of like a Warthog quality stick but for pedals. Unfortunately they are rather expensive. However, I'm sure I can make them with the same quality for very little cost. It just takes more time:music_whistling: .

Regards

John W

aka WarHog.

 

My Cockpit Build Pictures...



John Wall

 

My Arduino Sketches ... https://drive.google.com/drive/folders/1-Dc0Wd9C5l3uY-cPj1iQD3iAEHY6EuHg?usp=sharing

 

 

WIN 10 Pro, i8-8700k @ 5.0ghz, ASUS Maximus x Code, 16GB Corsair Dominator Platinum Ram,



AIO Water Cooler, M.2 512GB NVMe,

500gb SSD, EVGA GTX 1080 ti (11gb), Sony 65” 4K Display

VPC MongoosT-50, TM Warthog Throttle, TRK IR 5.0, Slaw Viper Pedals

Posted

Hi ClayM,

 

It may not be of much assistance but in the experiemental version of DCS-BIOS I actually managed to get the MCP23017 to work use the sketch found here;

http://docs.macetech.com/doku.php/centipede_shield

 

Now granted that Ian did say that I could make it work the 'old' in later versions my programming skill level or lack of same did manage to get it working.

 

I think this was my original code fr NMSP which include connections via Ethernet shield to the Uno;

 

#include <DcsBios.h>
#include <Servo.h>
#include <SPI.h>         // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <Wire.h>
#include <Centipede.h>

/****
Change these values to the IP address to assign to your Arduino
and the IP address of your DCS computer.

Make sure that the IP address you assign to your Arduino is on
the same network as your DCS host. If you make sure that the first
three numbers are the same, you should be fine.

You will also edit BIOSConfig.lua to send a copy of the export data
to the IP address of your Arduino.
****/
IPAddress arduinoIpAddress(192, 168, 87, 120);
IPAddress dcsHost(192, 168, 87, 104);

// Enter a MAC address for your controller below.
byte mac[] = {  
 0xDE, 0xAD, 0xBE, 0xEF, 0xDC, 0xB0 };

/**** Make your changes after this line ****/
Centipede CS; // create Centipede object



/**** In most cases, you do not have to change anything below this line ****/

/* Instantiate a ProtocolParser object to parse the DCS-BIOS export stream */
DcsBios::ProtocolParser parser;

/* Create an instance of the Udp class */
EthernetUDP Udp;

void setup() {
 Ethernet.begin(mac, arduinoIpAddress);
 Udp.begin(7777);
 Wire.begin(); // start I2C
 CS.initialize(); // set all registers to default
 CS.portMode(0, 0b0000000000000000); // set all pins on chip 0 to output
 //TWBR = 12; // uncomment for 400KHz I2C (on 16MHz Arduinos)
 
 // Test of all lamps
 for (int i = 0; i < 15; i++) {
   CS.digitalWrite(i, HIGH);
   delay(500);
 }
  for (int i = 0; i < 15; i++) {
   CS.digitalWrite(i, LOW);
   delay(500);
 } 
 CS.digitalWrite(1, HIGH);
 delay(2000);
 CS.digitalWrite(1, LOW);
}

/*
Your main loop needs to pass data from the DCS-BIOS export
stream to the parser object you instantiated above.

It also needs to call DcsBios::PollingInput::pollInputs()
to detect changes in the state of connected controls and
pass them on to DCS.
*/
void loop() {
 // if there's data available, read a packet
 int packetSize = Udp.parsePacket();
 if(packetSize)
 {   
   for (int i=0; i<packetSize; i++) {
     parser.processChar(Udp.read());
   }
 }
 
 // poll inputs
 DcsBios::PollingInput::pollInputs();
}
void onDcsBiosMessage(char* msg, char* arg) {

}
/*
You need to define
void sendDcsBiosMessage(const char* msg, const char* arg)
so that the string msg, followed by a space, the string arg
and a newline gets sent to the DCS-BIOS import stream.

In this example we send it to the DCS computer in a UDP packet.
*/
void sendDcsBiosMessage(const char* msg, const char* arg) {
 Udp.beginPacket(dcsHost, 7778);
 Udp.write(msg);
 Udp.write(' ');
 Udp.write(arg);
 Udp.write('\n');
 Udp.endPacket();
}

/*
This subroutine gets called every time new data is received
from the export stream (you need to define it even if it
does nothing).

Use this to handle integer outputs which are not covered by the
DcsBios Arduino library.
*/
//void onDcsBiosWrite(unsigned int address, unsigned int value) {
void onDcsBiosWrite(unsigned int address, unsigned int value) {
if (address, "NMSP_ILS_LED" == 0) {      // NMSP ILS
   if (value == '1') {
     CS.digitalWrite(6, HIGH);
   } else {
     CS.digitalWrite(6, LOW); 
   }
 }
 if (address, "NMSP_TCN_LED" == 0) {      // NMSP TACAN
   if (value == '1') {
     CS.digitalWrite(5, HIGH);
   } else {
     CS.digitalWrite(5, LOW); 
   }
 }
 if (address, "NMSP_ANCHR_LED" == 0) {    // NMSP ANCHOR POINT
   if (value == '1') {
     CS.digitalWrite(4, HIGH);
   } else {
     CS.digitalWrite(4, LOW); 
   }
 }
 if (address, "NMSP_STEERPT_LED" == 0) {    // NMSP STeer PT
   if (value == '1') {
     CS.digitalWrite(3, HIGH);
   } else {
     CS.digitalWrite(3, LOW); 
   }
 }
 if (address, "NMSP_TISL_LED" == 0) {      // NMSP TISL
   if (value == '1') {
     CS.digitalWrite(2, HIGH);
   } else {
     CS.digitalWrite(2, LOW); 
   }
 }
 if (address, "NMSP_EGI_LED" == 0) {          // NMSP EGI
   if (value == '1') {
     CS.digitalWrite(1, HIGH);
   } else {
     CS.digitalWrite(1, LOW); 
   }
 }
 if (address, "NMSP_HARS_LED" == 0) {          // NMSP HARS
   if (value == '1') {
     CS.digitalWrite(0, HIGH);
   } else {
     CS.digitalWrite(0, LOW); 
   }
 } 
}

 

 

Anyway you may very well be able to find the missing link which I never did :-)

 

Cheers

Hans

Posted

Thanks Hans! I didn't think to try the centipede library. I will give it shot! Coming up with new code on my own has not been going well but modifying existing code is getting easier. Thanks for giving me something to start with. I'll report back with results.

 

@ Warhog

 

I get the pin count problem. I also realize it would be "cool" to have self contained panels. For me that sounded way to difficult. That is why (so far) I went with the centralized controller concept. For example my one left console mega handles the AHCP,L/G panel with the servo and indicators,fuel panel,aux ltg,sas and the day/night switchs for mfds. Its my easy way to do it I guess. It just makes for a hell of a lot wire running everywhere! On the right console is another mega that takes care of CMSP i/o(not the display though) canopy,elec pwr,oxy,aap,and some misc like pitot heat and anti-collision lights. So with just 2 mega's using only 2 usb ports I managed to take care of most of the simple panels. The backlighting is all independent using your idea with pwm drivers mounted in the ext/int lighting panel.

 

I'm not saying my way is better. I requires a LOT of wire and plugs but not as many custom pcb's. The problem I have is that as soon as I use a Nano or Promini I have to do RS485 also. So there is the added design and parts and cnc and copper clad board and sockets and.......

 

Wife says I have to cut the grass. Gotta go!:(

 

Thanks Guys!

 

Clay

Posted
I went with the centralized controller concept. For example my one left console mega handles the AHCP,L/G panel with the servo and indicators,fuel panel,aux ltg,sas and the day/night switchs for mfds. Its my easy way to do it I guess. It just makes for a hell of a lot wire running everywhere! On the right console is another mega that takes care of CMSP i/o(not the display though) canopy,elec pwr,oxy,aap,and some misc like pitot heat and anti-collision lights. So with just 2 mega's using only 2 usb ports I managed to take care of most of the simple panels.

 

Clay

 

Thats great Clay. Whatever gets your project up and running. I'm also considering using MMjoy2 as a centralized controller in addition to DCS-BIOS to help with rotary encoders. I have almost 35 rotary encoders on the left console. If I use MMJoy with a matrix on a MEGA I only use 20 pins vs 70 pins any other way. The R.E's are easy to assign in the options menu in DCS. You see, I need MMJoy2 to run my new stick and pedals so I thought I might use some of its other functionality at the same time. But I'm not yet decided on that because using the RS485 bus is really easy. With that in mind and the cost of a few extra boards I'll probably stay 100% DCS-BIOS.

 

I was wondering if you have had any issues with your switches using long runs of wire. Whether you pick up any interference that causes switches to stutter or flip by themselves or not at all.

 

John

Regards

John W

aka WarHog.

 

My Cockpit Build Pictures...



John Wall

 

My Arduino Sketches ... https://drive.google.com/drive/folders/1-Dc0Wd9C5l3uY-cPj1iQD3iAEHY6EuHg?usp=sharing

 

 

WIN 10 Pro, i8-8700k @ 5.0ghz, ASUS Maximus x Code, 16GB Corsair Dominator Platinum Ram,



AIO Water Cooler, M.2 512GB NVMe,

500gb SSD, EVGA GTX 1080 ti (11gb), Sony 65” 4K Display

VPC MongoosT-50, TM Warthog Throttle, TRK IR 5.0, Slaw Viper Pedals

Posted

John

 

I don't think I have any interference issues. I did have issues with switch bounce on my cheap tactile's. They would occasionally give me two presses. I added 100 ms delay (as suggested by Ian) in all my sketches and now things like UFC function perfectly. I guess this could have been some kind of cross talk or interference but its a non issue now.

 

I have seen your new stick gimbal! good luck! I'm excited to see what your insanity comes up with next.

 

Keep it up!

 

Clay

Posted
Coming up with new code on my own has not been going well but modifying existing code is getting easier. Thanks for giving me something to start with. I'll report back with results.

:thumbup: that is exactly how I have done it in the past :-D You are most welcome Clay.

 

@John a small question regarding RS485 if I may. As far as I have understood we can connect up to 32 units to the RS485 bus. Do you have an idea whether that be enought for all the panels or do you anticipate that some of them are combined?

 

Cheers

Hans

Posted

Hi Hans

 

I believe that the RS485 bus can handle 128 units with the MAX RS-487 IC. Ian, isn't that correct?

 

That said, I do not plan to use anywhere near that number. From a construction perspective I am planning on using 3 Megas, each as a Master. One for the left and right consoles and one for the MIP. It kind of makes sense from a construction perspective that I have one complete MIP including the Mega as Master which I can plug into the PC and run it separate from the rest of the pit. Same with the left and right consoles. I'm not sure if loading a single Mega with 120 odd units would tax its capabilities or not. My reasoning is based purely from ease of building that I choose to assign a Mega to each major part of the cockpit.

 

BTW Hans, as to your question on combining panels, yes, I have started to do that now that I am actually assembling the consoles. Some panels only require a couple of pins and others need an extra 2 or 3 pins. As a result I decided to combine some of the Arduino Pro Minis to deal with these situations. It doesn't let me pull out an individual panel to service it but I'm starting to think that all I need to do is pull the entire console. They are not as large as I envisioned them to be when flying the sim.

Regards

John W

aka WarHog.

 

My Cockpit Build Pictures...



John Wall

 

My Arduino Sketches ... https://drive.google.com/drive/folders/1-Dc0Wd9C5l3uY-cPj1iQD3iAEHY6EuHg?usp=sharing

 

 

WIN 10 Pro, i8-8700k @ 5.0ghz, ASUS Maximus x Code, 16GB Corsair Dominator Platinum Ram,



AIO Water Cooler, M.2 512GB NVMe,

500gb SSD, EVGA GTX 1080 ti (11gb), Sony 65” 4K Display

VPC MongoosT-50, TM Warthog Throttle, TRK IR 5.0, Slaw Viper Pedals

Posted

Hi Warhog,

 

Thank you very much. I think it makes very good sense to use 3 Mega for a pit :thumbup:

 

Based upon your good info I think I may actually go for a MiniPro per panel with a Mega for each mayor component. Then I should even get anywere near 32 units per RS485 string.

 

Thanks a lot for sharing your experience. I have only begun to scratch the surface so its really appriated :-)

 

All the very best

Hans

  • 5 years later...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...