Arduino Serial connection

Post Reply
FaustoP
Posts: 48
Joined: 02 Mar 2014, 08:17

Arduino Serial connection

Post by FaustoP »

Hi all,

I'm having issues in connecting my Arduino via the Serial connection. I developed a protocol which listens to the serial for LEDs and displays and writes to the serial based on a button matrix. Everything works well when using the Arduino serial monitor.

When I open Prosim I continuously hear switches clicking and all I can see in the main window is that it connects and disconnects to the COM port many times per second. It keeps going from connected to disconnected and this goes forever.
If I do the following steps:
1) close Prosim
2) open Arduino serial monitor and connect it to the Arduino
3) close Arduino serial monitor
4) open prosim again
...then everything works. Prosim successfully connects to the COM port and it sends and receives data.

If for some reasons the Arduino gets disconnected and reconnected I have to do the whole sequence again, therefore no way to manage it in flight.

I'm using standard COM port settings (115200 baud, databit 8, parity None, Stopbit 1).
I'm using customised variable names.

There below the standard code I use for opening the serial connection in Arduino in the setup() function.

Code: Select all

    Serial.begin(115200);
    delay(5000);
    while (!Serial) {
    }
I also tried deleting the condition while(!Serial) or increasing/decreasing the delay but nothing changes.
Any advice on how to solve the issue? Is there a particular timing for opening the serial I should consider for getting a stable connection to Prosim?

Thanks in advance for you support,

Best

Fausto
User avatar
dvincent
Posts: 4647
Joined: 14 Jun 2011, 11:21
Location: Nederland - Vlissingen
Contact:

Re: Arduino Serial connection

Post by dvincent »

Hi,
there is somewhere here on the forum a userproject where a lot of knowledge regarding Arduino can be found. I don't remember the exact topic but you can do a search on the forum.
Arduino is not natively supported by Prosim but it works if you have the knowledge.
Regards,
Dirk

Image
Bernie
Posts: 4948
Joined: 01 Jun 2011, 13:36
Location: Riverland South Australia

Re: Arduino Serial connection

Post by Bernie »

Kind Regards

Bernie.
Bernie
Image
User avatar
dvincent
Posts: 4647
Joined: 14 Jun 2011, 11:21
Location: Nederland - Vlissingen
Contact:

Re: Arduino Serial connection

Post by dvincent »

Ah, thanks Bernie. :D
Regards,
Dirk

Image
FaustoP
Posts: 48
Joined: 02 Mar 2014, 08:17

Re: Arduino Serial connection

Post by FaustoP »

Thanks!

Of course I know it (have been searching quite a lot on the forum in the past months/years) but it works in a different way, especially for inputs, as you can configure a limited number of inputs per device while I'm using a fully customisable button matrix and (in theory) with a faster cpu such as Teensy4 I can manage all the switches of the entire cockpit with only one device.

Changing to the other solution (perhaps I think the user also discontinued it now) would now imply rebuilding my whole cockpit (cabling is 100% finished for all the sections) which is something I would do only in extreme conditions. At the moment I have a problem which might be related only to the initialisation of the serial communication. Apart from that everything works.

Thanks anyway for your advice :) much appreciated!
User avatar
miked
Posts: 254
Joined: 31 Mar 2011, 07:59
Location: Buderim, Queensland, Australia....... Home Airport:- Sunshine Coast YBSU

Re: Arduino Serial connection

Post by miked »

Hi FaustoP
I am using Arduino for my system. I have designed the pcbs and have had them made. Obviously there is a lot more than set out here, but this works and data is received from prosim OK

in setup()

// START THE SERIAL PORT
Serial.begin(Baudrate);
Serial.setTimeout(5);


in loop() // to get data from prosim in the form xxxx = 1 or xxxx = 0 were xxxx is a 4 digit variable say 5460

.
.
// receive data and lamp status
if (Serial.available()) {// IS there any lamp data from ProSim737 on the USB?
RXvariable = Serial.parseInt(); // Lamp number eg 5460
RXvarValue = Serial.parseInt(); // ON or OFF eg 1
if (RXvariable >= varBase && RXvariable <= varBase + 99) { //is it in range for this card ? (varBase would be 5400 )
//
.

If you would like more info. please PM me :D
Regards
Michael

Image
FaustoP
Posts: 48
Joined: 02 Mar 2014, 08:17

Re: Arduino Serial connection

Post by FaustoP »

Hi Michael,

Thanks. I will PM you, maybe we can both improve our code. I also designed my own boards both for LEDs, switches and 7-segment displays (3,4, 5, 6 digits).

The only difference (and I noticed it also with Arduino737 code) is the setTimeout command which I've never been using. Will give it a try and get you posted, maybe that could be helpful also for other people building their own electronics platform.

Also, I made a comparison between sequence of Serial.read() and Serial.parseInt() and it seems that a cycle with parseInt is slower, then I'm using simple serial.read() code and parsing afterwards.

Have a nice day and thanks again!

Fausto
Post Reply

Return to “Cockpit building questions”