Jump to content

Dcs-bios RSS-485, i2c question


Regnad517

Recommended Posts

So I have read about 50 pages of threads here and am left with some questions. Though I don't consider myself an"electrical" person, I have done pretty good so far (with a question here and there and so terrific help from this site and its users).

 

So I've decided I want to basically run each panel from an independent arduino, so tacan will have its own, caution, radios, cdu, etc... And I have figured out how to actually get that running with the multiple cmd script and such. My question is..there has to be a better way to do this than having 20-30 usb cords running to a hub. What happens if I plug a thumb drive in, do the com ports get reassigned, etc... I think my answer has something to do with either an RS-485 bus or an i2c bus. My problem is I really don't know what those are or how to implement them. And will they actually remove the need for 20 usb cords, 20 com assignments, etc...

 

Any insight or pointing in a direction to find out more about this would be very much appreciated. I've dove in head first, CNC machine, engraver, even cncing my own circuit boards from copper so I really want to grasp this idea. Can't wait to start a "Regnads cockpit" thread with some of the things I have in the process.

 

Thanks again. This is a great community. :pilotfly:

Link to comment
Share on other sites

Dear Regnad517

 

I made a post a while back trying to explain how I have been doing it; https://forums.eagle.ru/showpost.php?p=3247704&postcount=171

 

Would it be smarter to make a generic PCB that can take most of the panels. Yes it it would but I haven't ventured down that road yet. Take a look at the post and see if a few of your questions get answered.

 

Cheers

Hans

Link to comment
Share on other sites

That is a huge help. Wish I'd found it earlier. Want to make sure I am understanding properly if you don't mind.

 

1) so you need a 485 for each arduino board.

2) you then just wire up the arduino normally per switch, buttons, etc...

3) can you still utilize i2c components with this such as lcd?

4) your schematic you left was a huge eye opener. If I'm reading that properly, those 4 arduinos will now work over 1 com port?

 

Either way, I'm ordering a 10pack of 485s right now to start playing. Hope I don't become a pest. Lol. I do try to figure it out myself and come here with questions when I am spent.

 

Thanks a bunch Han.

Link to comment
Share on other sites

That is a huge help. Wish I'd found it earlier. Want to make sure I am understanding properly if you don't mind.

 

1) so you need a 485 for each arduino board.

2) you then just wire up the arduino normally per switch, buttons, etc...

3) can you still utilize i2c components with this such as lcd?

4) your schematic you left was a huge eye opener. If I'm reading that properly, those 4 arduinos will now work over 1 com port?

 

Either way, I'm ordering a 10pack of 485s right now to start playing. Hope I don't become a pest. Lol. I do try to figure it out myself and come here with questions when I am spent.

 

Thanks a bunch Han.

 

The chip you want is actually an RS-487. Read his schematic again.

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

Link to comment
Share on other sites

Hi Regnad517, Warhog is correct

 

 

Q1) so you need a 485 for each arduino board. - A: yes need one MAX487 per panel and on per master

Q2) you then just wire up the arduino normally per switch, buttons, etc... A: Yes Rest is same way but don't use pin 0, 1 and 2 which are used for communication.

Q3) can you still utilize i2c components with this such as lcd? A: I haven tried but are pretty sure you can. If I have time over the weekend I can see if I can get my CMSP up and running with I2C LCD. No promisses made though.

Q4) your schematic you left was a huge eye opener. If I'm reading that properly, those 4 arduinos will now work over 1 com port? A: Yes but you can have more. The exact limit I don't remember but have following running on this setup;

 

Left console:

Fuel control panel (real one)

LASTE panel (mockup but with 1x mag switches)

Auxiliary Lighting Control Panel (mockup)

SAS panel (mockup w. 4x mag switches and light)

Emergency flight control panel (mock up with light)

 

MIP:

Armament Hud Control Panel (mockup missing some of the A-lock flat heads)

Landing gear panel (mockup w. 1x mag switch)

Navigation Mode Selection Panel (mockup backplate, real light plate and switches. Lenses are wrong)

MFCD bezels (real F-16)

 

Right console:

Electrical power panel (real)

Aux Avionics Panel (real)

ILS panel (simulator one)

Lighting control panel (real w. 1x mag switch)

 

 

Cheers

Hans

Link to comment
Share on other sites

The chip you want is actually an RS-487. Read his schematic again.

 

Yup, me being anxious. Thanks Warhog

 

So looks like China is only option I can find online but curious, there are low powered and high powered ones (cpa, csa, eepa). I’m assuming since we are looking for only 5v that the low power cpa are adequate?

 

Thanks

Link to comment
Share on other sites

Hi Regnad517, Warhog is correct

 

 

Q1) so you need a 485 for each arduino board. - A: yes need one MAX487 per panel and on per master

Q2) you then just wire up the arduino normally per switch, buttons, etc... A: Yes Rest is same way but don't use pin 0, 1 and 2 which are used for communication.

Q3) can you still utilize i2c components with this such as lcd? A: I haven tried but are pretty sure you can. If I have time over the weekend I can see if I can get my CMSP up and running with I2C LCD. No promisses made though.

Q4) your schematic you left was a huge eye opener. If I'm reading that properly, those 4 arduinos will now work over 1 com port? A: Yes but you can have more. The exact limit I don't remember but have following running on this setup;

 

Left console:

Fuel control panel (real one)

LASTE panel (mockup but with 1x mag switches)

Auxiliary Lighting Control Panel (mockup)

SAS panel (mockup w. 4x mag switches and light)

Emergency flight control panel (mock up with light)

 

MIP:

Armament Hud Control Panel (mockup missing some of the A-lock flat heads)

Landing gear panel (mockup w. 1x mag switch)

Navigation Mode Selection Panel (mockup backplate, real light plate and switches. Lenses are wrong)

MFCD bezels (real F-16)

 

Right console:

Electrical power panel (real)

Aux Avionics Panel (real)

ILS panel (simulator one)

Lighting control panel (real w. 1x mag switch)

 

 

Cheers

Hans

 

Awesome. I’m planning very similar. Separated my cockpit into sections like you did. Currently I’m on 9 touch screens but am completely rebuilding from scratch to do away with the touchscreens.

 

I too don’t see why an i2c lcd wouldn’t work. Only asked to see if you had tried it. Don’t spend too much time on it, I can test that when my chips arrive.

 

Cheers

Link to comment
Share on other sites

It's OK

 

In my Thread https://forums.eagle.ru/showthread.php?t=194670

 

I use arduino pro mini ,every board use a max487 .

The ILS panel use I2C OLED screen. It's OK.

The CMSP panel use SPI interface OLED Screen, It's OK. but,the Pro mini not have enough pins to control so many buttons ,so I use two boards.

Link to comment
Share on other sites

Yup, me being anxious. Thanks Warhog

 

So looks like China is only option I can find online but curious, there are low powered and high powered ones (cpa, csa, eepa). I’m assuming since we are looking for only 5v that the low power cpa are adequate?

 

Thanks

 

The designation cpa, csa, etc represent different environmental conditions that the ICs can operate in. More specifically temperature ranges.

 

Most of the Chinese vendors offer the MAX 487 cpa IC. It seems to be the most common. That’s what I use in all my panels.

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

Link to comment
Share on other sites

Here's how the MAX487 model numbers work. Let's use the MAX487CPA as an example.

 

"MAX487" -- chip identifier

"C" -- first letter: temperature range. "C" is consumer (0°C to 70°C), "E" is extended (-40°C to +85°C).

"PA" -- package. "PA" is 8-pin DIP (breadboard compatible, standard 0.1 inch pin pitch) and "SA" is 8-pin SOIC (0.05 inch pin pitch, surface mount package).

 

In general: you don't care about the first letter (the consumer temp. range is fine), and you want the last two to be either "PA" for the through-hole package or "SA" for the surface mount version depending on how you construct your panel. The chip is available in even smaller packages but those can be annoying to solder, and you are not that space constrained in a home cockpit, so why bother?

 

For the meaning of other letters, refer to the "ordering information" section in the MAX487 datasheet.

 

The maximum number of devices on one bus has no easy answer.

Standard RS-485 has a limit of 32 "unit loads" on the bus. The MAX487 is a 1/4 unit load device, so the maximum is 128 MAX487's on the same bus (assuming all transceivers are 1/4 unit load devices).

 

If you add termination and bias resistors (mandatory if your bus wiring gets longer than about 10 meters), they add a load to the bus and that limit shrinks to about 25.

 

Have a wiring length less than 10 meters? This app note talks about minimum spacing between transceivers. Assuming the worst case of the examples given, you may need 20 cm between each node, so a 10 meter cable would limit you to 50 devices.

 

In practice, I'd plan a cockpit as two or three RS-485 buses with about 10 to 40 MAX487 transceivers each, making sure that each bus length is less than 10 meters and not to add any termination or fail-safe resistors.

 

One Arduino Mega can handle at least two RS-485 buses, possibly three (I don't know if it is fast enough to do that yet, but the software will let you try).

 

Disclaimer: This is all theoretical, as far as I know nobody has tried it in practice at this scale yet.

But if everything is plugged in and it turns out that there are too many devices on a bus for reliable operation, you can always split it in the middle and add another Mega.

 

I expect a typical finished cockpit to use two to five USB ports: one, two or three Arduino Megas as RS-485 bus masters, and the rest for those cases where you use another Arduino-compatible board in DEFAULT_SERIAL mode because the IRQ_SERIAL code is not available (an example would be a board with a fast ARM processor to control a small TFT display for the CDU).

 

I hope this makes some sense, I wasn't very awake while I wrote this :D

Link to comment
Share on other sites

Is there a thread who explain the code we need for the rs485 lan?

 

I see this :

 

#define DCSBIOS_RS485_SLAVE XX

 

For the slave, but I don't find what I must write for the master.

 

Any help?

 

And so, I need 2/3 Mega 2560 Pro for RS485 Master:

https://fr.aliexpress.com/item/Mega-2560-PRO-Embed-CH340G-ATmega2560-16AU-with-male-pinheaders-Compatible-for-Arduino-Mega-2560/32801785024.html?

 

And, X unit of 2560 Pro MINI and Micro for Slave :

https://fr.aliexpress.com/item/Mega-2560-PROMINI-5V-ATmega2560-16AU-with-male-pinheaders-Compatible-for-Arduino-Mega-2560/32802310906.html?

https://fr.aliexpress.com/item/Pro-Micro-ATmega32U4-5V-16MHz-Replace-ATmega328-For-Arduino-Pro-Mini-With-2-Row-Pin-Header/32808519179.html

 

Right?

 

A 12v transformer with 3A, it's enough to power everything (all arduino board)?

Thanks a lot!


Edited by Roger01
Link to comment
Share on other sites

For the master, all you need to do is to upload the RS485Master example sketch to an Arduino Mega (and comment out some of the UARTn_TXENABLE_PIN lines if you connect less than three tansceivers).

 

RS-485 documentation is lacking right now because I never got around to properly testing all of that. I am still not sure if three transceivers on a Mega work reliably (two should be no problem at all).

 

If you know how an RS-485 bus works in general (so you know to connect all the "A" and "B" lines in a bus topology), the comments in the RS485Master and RS485Slave example sketches (which tell you how to connect the MAX487 transceiver chip to the Arduino) along with the MAX487 datasheet (which tells you the MAX487 pinout, where to connect 5V and GND, and that you should add a 100 nF capacitor between the two) is all you need to know.

 

For the master, you have to use an ATMega2560.

Slave devices can be anything with an ATMega328 or ATMega2560 chip.

 

For the power supply, I would recommend an old PC power supply (short the green wire on the motherboard connector to a black one to make it turn on). It is inexpensive or free to acquire and gives you several amps of cleanly regulated power at 12V, 5V and 3.3V.

 

Powering your Arduino boards from 5V (directly to the 5V pin) is better than 12V to the V_in pin, because you are not wasting energy in the linear regulator on the Arduino board and don't have to take its limitations into account.

 

If all you are running is the Arduino board itself (a few milliamps), you can power it from 12V without problems, but a linear regulator that converts 12V to 5V will waste 1.4 times its output power as heat, so if you add additional 5V loads, you can quickly reach its limits and make it go into thermal shutdown.

Link to comment
Share on other sites

Hoo RS485 is already included in dcs bios, perfect! I found the RS485 exemple, thanks!

 

Using a PC power supply is a good idea.

I read for powering Arduino is :

 

5v by USB port

6-20V (7-12v better) by the Vin pin or the jack. (not 5v cause Arduino do a -1v, drop of tension by this way)

 

So, how can I send 5v by the 5v pin? It's not a 5v out?

 

Else, If I powering all arduino with the 5v, so the 12v no use at all?

 

Thanks again!

Link to comment
Share on other sites

The 5V pin on your Arduino is a power supply rail (i.e. that part of the circuit that is always at the supply voltage, +5V for most Arduino boards).

 

A general rule of thumb for power supply rails is this:

Exactly one power supply is connected to it, feeding an arbitrary number of consumers.

 

If you have more than one power supply active in parallel, they need to work together to regulate to the exact same voltage, otherwise the supply that is trying to regulate to the higher voltage will bear all of the load. Multiple parallel power supplies are thus only used for very high loads or if you need redundancy.

 

For your Arduino board, you have three options:

  • Feed 7 to 12 V to the V_in pin. This supplies the linear regulator that is built in to your board, which in turn supplies 5 V to the power supply rail and needs to drop (V_in - 5V) * current_draw as heat to do so.
  • Directly feed 5 V to the +5V pin, ignoring the built-in regulator. This is the best option if you already have a source of regulated 5V available.
  • Keep the Arduino board connected to a PC over USB. It will power itself over USB. This option only works if the total draw from the 5V power supply on the Arduino board does not exceed about 400 to 500 mA, otherwise the polyfuse on the Arduino board will disconnect the board to avoid damage to the computer.

 

A 12V supply can be useful to power things that can work at 12 V, such as some backlight circuits and stepper motors. Those can be controlled from your 5 V Arduino through MOSFETs and stepper motor driver boards.

 

Using 12 V can also be useful if the length of your power supply lines becomes long enough so you have a signficant voltage drop (in this case you'd use it to feed a regulator that converts it to 5 V at the destination, using either the one on your Arduino board through the V_in pin or a separate one -- e.g. an LM7805 -- if you need more power). I don't expect that to be an issue in a typical home cockpit.

Link to comment
Share on other sites

  • 3 weeks later...

So I got the chips in this week and have given it the old college try. I cannot get the slave to communicate with the master and I feel it's one of 2 things. Either I have my RX/TX wrong since I am using an Uno rather than a Nano, I assumed it would still be rx/tx. Or my code is missing something.

 

Master Code

 

#include <Wire.h>

#include "SevenSegmentTM1637.h"

#define TM1637_MAX_LINES 1 // number of display lines

#define TM1637_MAX_COLOM 4 // number of coloms (digits)

 

SevenSegmentTM1637 am(2,3);

 

#define DCSBIOS_DEFAULT_SERIAL

 

#include "DcsBios.h"

#define DCSBIOS_RS485_MASTER

#define UART1_TXENABLE_PIN 7 //Yes I am using Pin 7

 

void onVhfamFreq1Change(char* newValue)

{

am.setCursor(0,0);

am.print(newValue);

}

DcsBios::StringBuffer<2> vhfamFreq1StrBuffer(0x1190, onVhfamFreq1Change);

 

void onVhfamFreq2Change(unsigned int newValue)

{

am.setCursor(0,3);

am.print(newValue);

}

DcsBios::IntegerBuffer vhfamFreq2Buffer(0x118e, 0x00f0, 4, onVhfamFreq2Change);

 

void setup()

{

DcsBios::setup();

am.init();

am.clear();

}

 

void loop()

{

DcsBios::loop();

}

 

Slave Code

 

#define DCSBIOS_IRQ_SERIAL

 

#include "DcsBios.h"

#include <Wire.h>

#include <LCD.h>

#include <LiquidCrystal_I2C.h>

 

#define I2C_ADDR 0x27 // I2c Address

 

#define DCSBIOS_RS485_SLAVE 11

#define TXENABLE_PIN 2

 

LiquidCrystal_I2C lcd(I2C_ADDR,2,1,0,4,5,6,7);

 

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

 

void onTacanChannelChange(char* newValue)

{

lcd.setCursor(0,0);

lcd.print(newValue);

}

DcsBios::StringBuffer<4> tacanChannelBuffer(0x1162, onTacanChannelChange);

 

void setup()

{

// Define LCD

lcd.begin (16,2); // 16x2 LCD

 

// Switch on the backlight

lcd.setBacklightPin(3,POSITIVE);

lcd.setBacklight(HIGH);

 

DcsBios::setup();

}

 

void loop()

{

DcsBios::loop();

}

 

Each board works great independently but cannot get communication with the slave when chained. I'm pretty sure wiring is correct, have gone over it many many times. Everything powers up, just no communication. Thanks

 

I have found that it sinks in better with sample code, if anyone can help I'd be thankful

Link to comment
Share on other sites

Not an expert but looks like you are defining the Mega as both RS485 Master and serial communication at the same time.

 

I believe this is the DCS-BIOS RS485Master sketch

/*
 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();
}

 

But you have also included

#define DCSBIOS_DEFAULT_SERIAL

I am fairly sure you shouldn't use this along with the RS485 master sketch.

 

Cheers

Hans

Link to comment
Share on other sites

So wait, can the Mega not be used as an actual DCS-Bios board while acting as the Master?

 

That is correct.

 

The protocol that I am using over the RS-485 bus has some tight timing requirements. Because of that, I had to simplify the code that looks at the incoming export data. It only determines where an update begins and ends; there is not enough CPU time left to determine whether the master board has any outputs that need to react to a particular piece of information.

 

At this time, I am not even sure if there is enough CPU time to run three RS-485 buses at once reliably.

 

In other words: the 16 MHz CPU on the bus master spends all of its time juggling four different communication channels (one to the PC and three to the RS-485 buses), so it doesn't have time to handle anything else.

Link to comment
Share on other sites

So have redone it all but getting a compile error on the uno

 

/*

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"

#include <Wire.h>

#include "SevenSegmentTM1637.h"

 

SevenSegmentTM1637 am(3,4); // D10 pin first, CLK pin second

 

// DCS-Bios Code

void onVhfamFreq1Change(char* newValue)

{

am.setCursor(0,0);

am.print(newValue);

}

DcsBios::StringBuffer<2> vhfamFreq1StrBuffer(0x1190, onVhfamFreq1Change);

 

void onVhfamFreq2Change(unsigned int newValue)

{

am.setCursor(0,3);

am.print(newValue);

}

DcsBios::IntegerBuffer vhfamFreq2Buffer(0x118e, 0x00f0, 4, onVhfamFreq2Change);

// End DCS-Bios Code

 

void setup() {

DcsBios::setup();

}

 

void loop() {

DcsBios::loop();

}

 

Compile error message

 

HardwareSerial0.cpp.o (symbol from plugin): In function `Serial':

 

(.text+0x0): multiple definition of `__vector_18'

 

sketch\RS485SlaveTest.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

 

HardwareSerial0.cpp.o (symbol from plugin): In function `Serial':

 

(.text+0x0): multiple definition of `__vector_19'

 

sketch\RS485SlaveTest.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

 

collect2.exe: error: ld returned 1 exit status

 

exit status 1

Error compiling for board Arduino/Genuino Uno.

 

As far as my searches go it appears I have a library conflict?

 

Doing some test builds it appears the #include "SevenSegmentTM1637.h" library conflicts with something when being used as a slave

Tried it with i2c LCD library as well and even more errors. I'm missing something I think. And if I comment out the #define DCSBIOS_RS485_SLAVE 1 line it builds fine. Grrrrrr

 

Thanks in advance


Edited by Regnad517
Link to comment
Share on other sites

This problem can happen with Arduino libraries that still have (unused) debugging code left in them that uses the serial port.

 

Open the code files for the SevenSegmentTM1637 library and comment out every line that uses the Arduino's Serial class, such as "Serial.begin" or "Serial.print".

 

In IRQ_SERIAL and RS485 modes, the DCS-BIOS Arduino library supplies its own driver for the UART peripheral which conflicts with the standard Arduino libraries. As soon as any other code references the default Serial class, you get a compile error (because both implementations want to handle the serial RX and TX interrupts), even if that code is never reached.

Link to comment
Share on other sites

So just an update.

 

I still couldnt get it working but I was using Unos rather than Nanos, so I hooked it up with Nanos and it works great. Either I have a PIN mislabeled or a wire wrong with Unos but no matter, was planning on using Nanos anyway so all is good.

 

Gonna start a My Cockpit thread soon with code examples that have helped me get through this, along with all of the "issues" I ran into in case I forget how to fix or for others experiencing the same issues.

 

You guys have been life savers here, thanks for the community.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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