Jump to content

What to change Dcs Bios script for slave board


Dadzilla74

Recommended Posts

Hi All,

 

Just thinking of adding a slave Arduino Mega to my Existing Mega.

 

Could someone please let me know how to change the DCS-Bios script to account for this?

 

For example, if I would like to setup the Brightness Control Knob onto pin A3 Slave I could not use;

 

DcsBios::Potentiometer ampcdBrtCtl("AMPCD_BRT_CTL", A3);

 

as this would be the master board.

 

I need to know how I change the script.

 

Thanks

Link to comment
Share on other sites

When speaking of DCS-BIOS master/Slave then it's being run over RS-485 communication using Max487 chips. For setup instructions you can take a look here https://forums.eagle.ru/showthread.php?t=243611

 

Also when using DCS-BIOS in master/Slave configuration over RS-485 then you cannot add any code for toggle switches etc to the master unit. The master unit only handles communication between DCSW and the Slave units.

 

You can add an additional Arduino board in USB configuration similwto how your current Mega is running. You just need to open a second communication i.e. you need two times connect-serial-port program running.

 

Cheers

Hans

Link to comment
Share on other sites

Thanks Hans and Smill,

I will look into these both. I do agree Hans with the two USB ports being used but thought there might be an easier style to piggy back them onto on another and most cockpit makeouts would need load of USB ports to hook it all up.

Link to comment
Share on other sites

I do agree Hans with the two USB ports being used but thought there might be an easier style to piggy back them onto on another and most cockpit makeouts would need load of USB ports to hook it all up.

 

Yeap that's RS485 Master-Slave which is already supplied with DCS-BIOS. But there may of cause be other options that can be made to work.

 

Cheers

Hans

Link to comment
Share on other sites

Hi Hans,

 

I did see one of your threads where you have 3 Arduino Micro's set up to your Arduino Mega. I would just like to know the difference in script. For example if you are setting up the Altitude Switch to pins 8 and 9, the script would look like;

DcsBios::Switch2Pos hudAltSw("HUD_ALT_SW", PIN);

 

What would the script look like if it was on the same pins but on the Micro 1 board and then again on the Micro 2 board?

Link to comment
Share on other sites

Alright so in your example you want to use a 2-position switch with feed back in both positions connected to pin8 and pin 9 which in your current setup with a single Arduino Mega would look like this;

 

const byte hudAltSwPins[2] = {8, 9 };
DcsBios::SwitchMultiPos hudAltSw("HUD_ALT_SW", hudAltSwPins, 2);

 

You now want to see what it looking like in the DCS-BIOS RS-485 Master Slave setup.

 

First of all the Mega can only hold the Master code which is directly used from the examples;

/*
 Tell DCS-BIOS this is a RS-485 Master.
 You will need to flash this to a Mega 2560.
*/
#define DCSBIOS_RS485_MASTER

/*
 Define where the TX_ENABLE signals are connected.
 You can connect up to three half-duplex RS-485 transceivers.
 
 Arduino Pin             RS-485 Transceiver Pin
 TXn ------------------- DI (driver input)
 RXn ------------------- RO (Receiver Output)
 UARTn_TXENABLE_PIN ---- /RE, DE (active low receiver enable, driver enable)
 
 If you have less than three transceivers connected, comment out the corresponding
 #define UARTn_TEXENABLE_PIN lines for receivers that are not present.
*/
#define UART1_TXENABLE_PIN 2
#define UART2_TXENABLE_PIN 3
#define UART3_TXENABLE_PIN 4

#include "DcsBios.h"

void setup() {
 DcsBios::setup();
}

void loop() {
 DcsBios::loop();
}

 

You can chose to comment out UART2 and UART3 if you want. I am still running on just UART1 for my setup.

 

The Slaves would look like this;

/*
 The following #define tells DCS-BIOS that this is a RS-485 slave device.
 It also sets the address of this slave device. The slave address should be
 between 1 and 126 and must be unique among all devices on the same bus.
*/
#define DCSBIOS_RS485_SLAVE 1

/*
 The Arduino pin that is connected to the
 /RE and DE pins on the RS-485 transceiver.
*/
#define TXENABLE_PIN 2

#include "DcsBios.h"

/* paste code snippets from the reference documentation here */
const byte hudAltSwPins[2] = {8, 9};
DcsBios::SwitchMultiPos hudAltSw("HUD_ALT_SW", hudAltSwPins, 2);

void setup() {
 DcsBios::setup();
}

void loop() {
 DcsBios::loop();
}

 

Or if you want the same switch for the second Slave;

 

/*
 The following #define tells DCS-BIOS that this is a RS-485 slave device.
 It also sets the address of this slave device. The slave address should be
 between 1 and 126 and must be unique among all devices on the same bus.
*/
#define DCSBIOS_RS485_SLAVE 2

/*
 The Arduino pin that is connected to the
 /RE and DE pins on the RS-485 transceiver.
*/
#define TXENABLE_PIN 2

#include "DcsBios.h"

/* paste code snippets from the reference documentation here */
const byte hudAltSwPins[2] = {8, 9};
DcsBios::SwitchMultiPos hudAltSw("HUD_ALT_SW", hudAltSwPins, 2);

void setup() {
 DcsBios::setup();
}

void loop() {
 DcsBios::loop();
}

 

Notice that the Slave number is different. It doesn’t have to be Slave 1 and 2. It could have been 4 and 2.

 

Either of the two Slave unit will then send the following over the RS485 bus to the Master;

HUD_ALT_SW 1

When switching from pos 0 to pos 1 and

HUD_ALT_SW 0

when switching back to pos 0

 

In my setup I am currently running 23 Slave units in DCS-BIOS RS485 Master-Slave configuration.

 

You can argue that the Mega Master is a waste of pins since you cannot connect any I/O’s to it. But it comes out of the box.

 

You most definitely interconnect two Arduino’s using different methods. You just have to figure it out yourself as it doesn’t come with DCS-BIOS natively.

 

You may also use and IO expander like MCP23017 . I had those running in the very first experimental version of DCS-BIOS but later took the RS-485 route. I am not sure if ClayM solve the use of MCP23017 both that could also be worth trying; https://forums.eagle.ru/showthread.php?t=169462

 

Cheers

Hans

Link to comment
Share on other sites

  • 1 month later...

Ok Guys,

 

Using 2x Arduino Mega boards.

 

I have connected master SCL with Slave SDA and Master SDA with Slave SCL.

 

There is a Potentiometer at Slave-A7 for the console Dimmer and I am trying to communicate through the master to dcsbios.

 

Master Script

/Master_test
#include <Wire.h>

/*
 Tell DCS-BIOS to use a serial connection and use interrupt-driven
 communication. The main program will be interrupted to prioritize
 processing incoming data.
 
 This should work on any Arduino that has an ATMega328 controller
 (Uno, Pro Mini, many others).
*/
#define DCSBIOS_IRQ_SERIAL

#include "DcsBios.h"

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

void setup() {
  Wire.begin(); // join i2c bus (address optional for master)

 DcsBios::setup();
}

void loop() {


 DcsBios::loop();
}

 

And the Slave Script;

/Slave_Test
#include <Wire.h>



/*
 Tell DCS-BIOS to use a serial connection and use interrupt-driven
 communication. The main program will be interrupted to prioritize
 processing incoming data.
 
 This should work on any Arduino that has an ATMega328 controller
 (Uno, Pro Mini, many others).
*/
#define DCSBIOS_IRQ_SERIAL

#include "DcsBios.h"
DcsBios::Potentiometer consolesDimmer("CONSOLES_DIMMER", A7);
/* paste code snippets from the reference documentation here */

void setup() {
  
Wire.begin(1);

 DcsBios::setup();
}

void loop() {
 DcsBios::loop();
}

 

Could someone help me with the missing pieces?

 

If not, I will look into getting a couple of RS485 chips.


Edited by Mark McCosker
Link to comment
Share on other sites

Hi Hans,

 

I am now working on this.

 

Using 2 mega Boards only (no RS-485 Chip), do you have a wire guide to connect each?

 

I have currently connected pins SDA Master with SCL Slave, and SCL Master with SDA Slave.

 

Is this correct?

 

Hi Mark,

 

I have no idea. I haven't tried to run DCS-BIOS using this method.

 

Cheers

Hans

Link to comment
Share on other sites

Hi Guys,

 

Final chapter on this thread.

 

Firstly a very big Thankyou to Hansolo for all his time and help. I greatly appreciate that.

 

I now have the slave up and running using the RS-485 Chips as Han suggested.

 

The only change I had to make was;

 

Solder following wires on Slave chip;

Pin 2&3 (RE+DE) on IC socket - BLUE - Pin 2 on Nano

Pin 1 (RO) on IC Socket - GREEN - Pin RX0 on Nano

**Pin 4 (DI) on IC socket - YELLOW - Pin TX0 on Nano** Changed fro TX1 to TX0

Pin 5 (GND) on IC socket - GREY - GND on Nano

Pin 8 (Vcc) on IC socket - PINK - 5V on Nano

 

Also, I was able to connect the slave up to the master 5V and GRD to get power to the board instead of using the USB power.

 

I was a little disappointing when I found out that I could not use the master for direct inputs for DCS BIOS which means that I would need two slaves and a master (which would only be connected to the RS-485, waste of space if you ask me).

 

For this reason I think I will just go and connected the two boards through Multi coms port connection unless I can use a Micro or some other smaller board as the master. This project wont have much space for 3 large boards.

 

Thanks Again Hans

Link to comment
Share on other sites

Further Information,

 

I connected my display for the UFC menu on the slave board. As the RS-485 can only send one code at a time, the UFC Menu board needs to send 2 per line. In my case I have one display for all 5 lines which mean any change will send up to 10 codes. As it does this the codes get confused and I think out of sync as the display losses parts of the menus for a moment before correcting. This makes the display look confusing.

 

For this reason I will be connecting the two boards to a usb Hub within the project box then have the hub connect into the computer.

 

If anyone knows a faster way to connect two Arduino boards please let me know.

Link to comment
Share on other sites

As the RS-485 can only send one code at a time, the UFC Menu board needs to send 2 per line. In my case I have one display for all 5 lines which mean any change will send up to 10 codes.

 

 

Can you elaborate on what you mean by this?

Your description confuses me, and I wrote the damn thing (granted, that was four years ago, so I may have forgotten how some of it works...)

 

 

 

Can you post your sketch?

Link to comment
Share on other sites

  • 2 weeks later...

Hi Ian,

 

Sorry as I have deleted the Slave and master script and will use two Arduino via USB Hub.

 

To try and make things clear, I had the master set up using the RS 485 Chip and the Slave set up using another RS 485 Chip in which they communiacted to each other.

 

The display I am using will run all the UFC Menu items and selector icons such as ;

 

void onUfcOptionDisplay1Change(char*newValue) {

   u8g2.setCursor(0,0);
   u8g2.setFont(u8g2_font_crox3cb_tr);
   u8g2.setDrawColor(0);
   u8g2.drawBox(5, 0, 61, 15);
   u8g2.setDrawColor(1);
   u8g2.drawStr(5, 15, newValue);

}

DcsBios::StringBuffer<4> ufcOptionDisplay1Buffer(0x542a, onUfcOptionDisplay1Change);

void onUfcOptionCueing1Change(char* newValue) {
   u8g2.setCursor(0,0);
   u8g2.setFont(u8g2_font_samim_16_t_all);
   u8g2.setDrawColor(0);
   u8g2.drawBox(0, 0, 4, 15);
   u8g2.setDrawColor(1);
   u8g2.drawStr(0, 13, newValue);
}
 DcsBios::StringBuffer<1> ufcOptionCueing1Buffer(0x5420, onUfcOptionCueing1Change);
 
///////////////////////////////////////////////////////////////////////////////////////

void onUfcOptionDisplay2Change(char* newValue) {
   u8g2.setCursor(0,0);
   u8g2.setFont(u8g2_font_crox3cb_tr);
   u8g2.setDrawColor(0);
   u8g2.drawBox(5, 16, 61, 35);
   u8g2.setDrawColor(1);
   u8g2.drawStr(5, 40, newValue);

}
DcsBios::StringBuffer<4> ufcOptionDisplay2Buffer(0x542e, onUfcOptionDisplay2Change);

void onUfcOptionCueing2Change(char* newValue) {
   u8g2.setCursor(0,0);
   u8g2.setFont(u8g2_font_samim_16_t_all);
   u8g2.setDrawColor(0);
   u8g2.drawBox(0, 16, 4, 34);
   u8g2.setDrawColor(1);
   u8g2.drawStr(0, 38, newValue);
}
DcsBios::StringBuffer<1> ufcOptionCueing2Buffer(0x5422, onUfcOptionCueing2Change);

/////////////////////////////////////////////////////////////////////////////////////////////////

void onUfcOptionDisplay3Change(char* newValue) {
   u8g2.setCursor(0,0);
   u8g2.setFont(u8g2_font_crox3cb_tr);
   u8g2.setDrawColor(0);
   u8g2.drawBox(5, 41, 61, 35);
   u8g2.setDrawColor(1);
   u8g2.drawStr(5, 65, newValue);
}
DcsBios::StringBuffer<4> ufcOptionDisplay3Buffer(0x5432, onUfcOptionDisplay3Change);

void onUfcOptionCueing3Change(char* newValue) {
   u8g2.setCursor(0,0);
   u8g2.setFont(u8g2_font_samim_16_t_all);
   u8g2.setDrawColor(0);
   u8g2.drawBox(0, 41, 4, 34);
   u8g2.setDrawColor(1);
   u8g2.drawStr(0, 63, newValue);
}
DcsBios::StringBuffer<1> ufcOptionCueing3Buffer(0x5424, onUfcOptionCueing3Change);

////////////////////////////////////////////////////////////////////////////////////////////////////////

void onUfcOptionDisplay4Change(char* newValue) {
   u8g2.setCursor(0,0);
   u8g2.setFont(u8g2_font_crox3cb_tr);
   u8g2.setDrawColor(0);
   u8g2.drawBox(5, 66, 61, 35);
   u8g2.setDrawColor(1);
   u8g2.drawStr(5, 90, newValue);
}
DcsBios::StringBuffer<4> ufcOptionDisplay4Buffer(0x5436, onUfcOptionDisplay4Change);


void onUfcOptionCueing4Change(char* newValue) {
   u8g2.setCursor(0,0);
   u8g2.setFont(u8g2_font_samim_16_t_all);
   u8g2.setDrawColor(0);
   u8g2.drawBox(0, 66, 4, 34);
   u8g2.setDrawColor(1);
   u8g2.drawStr(0, 88, newValue);
}
DcsBios::StringBuffer<1> ufcOptionCueing4Buffer(0x5426, onUfcOptionCueing4Change);

/////////////////////////////////////////////////////////////////////////////////////////////////////

void onUfcOptionDisplay5Change(char* newValue) {
   u8g2.setCursor(0,0);
   u8g2.setFont(u8g2_font_crox3cb_tr);
   u8g2.setDrawColor(0);
   u8g2.drawBox(5, 91, 61, 35);
   u8g2.setDrawColor(1);
   u8g2.drawStr(5, 115, newValue);
}
DcsBios::StringBuffer<4> ufcOptionDisplay5Buffer(0x543a, onUfcOptionDisplay5Change);


void onUfcOptionCueing5Change(char* newValue) {
   u8g2.setCursor(0,0);
   u8g2.setFont(u8g2_font_samim_16_t_all);
   u8g2.setDrawColor(0);
   u8g2.drawBox(0, 91, 4, 34);
   u8g2.setDrawColor(1);
   u8g2.drawStr(0, 113, newValue);
}
DcsBios::StringBuffer<1> ufcOptionCueing5Buffer(0x5428, onUfcOptionCueing5Change);

 

Although this worked, the display would constantly confuse the display by dropping context out and not replacing correctly as every change need these line to run to update the display.

 

Due to the RS chip only sending one line then fixing that line then sending another line then fixing that line, it appeared the display was confused and seemed to be in a state of catch up.

 

The loop is;

 

    onUfcOptionDisplay1Change;
   onUfcOptionCueing1Change;
   onUfcOptionDisplay2Change;
   onUfcOptionCueing2Change;
   onUfcOptionDisplay3Change;
   onUfcOptionDisplay3Change;
   onUfcOptionDisplay4Change;
   onUfcOptionCueing4Change;
   onUfcOptionDisplay5Change;
   onUfcOptionCueing5Change;// write something to the internal memory
   u8g2.sendBuffer();          // transfer internal memory to the display

 

I hope that helps a little.


Edited by Mark McCosker
Link to comment
Share on other sites

  • Recently Browsing   0 members

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