Board index FlightGear Support Interfacing

dh6 Parking-brake on/off to Arduino led  Topic is solved

Connecting two computers, using generic protocol, connecting with Matlab?

dh6 Parking-brake on/off to Arduino led

Postby rooman » Mon Mar 13, 2023 9:27 pm

I do bi-directionnal interfacing for my simple simpit with an Arduino Mega and a Uno.
Now I wish to add another output; Parking-brake on/off info to a led (on/off).
But I can not find a way that works.
I have created separate simple Arduino and protocol file for debugging this problem.

The two possible properties that activate the parking-brake via the debug property window are;
<node>/controls/gear/parkingbrake-lever</node>, <type>bool</type>

<node>/controls/gear/parkingbrake-lever-pos</node>, <type>double</type>

I have tried these two in an output protocol xml file but to no avail.

Simple Arduino sketch for debugging
Code: Select all
 int incomingByte ;
// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(38400);
  }

void loop() {
    // see if there's incoming serial data:
   while (Serial.available() > 0) {
   incomingByte = Serial.read();
   if (incomingByte == '1') {
       digitalWrite(LED_BUILTIN, 1);  // turn the LED on (HIGH is the voltage level)
    } else {
       digitalWrite(LED_BUILTIN, 0);  // turn the LED off (LOW is the voltage level)
    }   
  }
}

The output protocol with either parkingbrake-lever or parkingbrake-lever-pos
Code: Select all
<?xml version="1.0"?>
<PropertyList>
<generic>
      <output>
        <binary_mode>false</binary_mode>
        <line_separator>newline</line_separator>
        <var_separator>,</var_separator>

   <chunk>
      <name>park</name>
      <node>/controls/gear/parkingbrake-lever</node>
      <type>int</type>
   </chunk>

    </output>
</generic>
</PropertyList>

I have certainly a data format problem but my brain is unable to work this one out...and yes I've been googling and reading
rooman
 
Posts: 74
Joined: Sun Apr 12, 2015 6:26 pm
Location: Lausanne, Switzerland
OS: Ubuntu 22.x

Re: dh6 Parking-brake on/off to Arduino led

Postby SurferTim » Mon Mar 13, 2023 10:38 pm

If you are sending a text character (not binary), you should use a format parameter in your chunk.
Code: Select all
   <chunk>
      <name>park</name>
      <node>/controls/gear/parkingbrake-lever</node>
      <type>int</type>
      <format>%d</format>
   </chunk>

I haven't checked your Arduino code yet.
Fly low. Fly slow. Land on a dime. Twin Otter. https://github.com/SurferTim/dhc6p
My other aircraft is a Citation-X https://github.com/SurferTim/CitationX
PirateAir videos at https://www.youtube.com/user/SurferTim850
User avatar
SurferTim
 
Posts: 1539
Joined: Sun Dec 09, 2018 5:49 pm
Location: Miramar Beach, FL
Callsign: Pirate
Version: 2020.4.0
OS: Ubuntu 18.04

Re: dh6 Parking-brake on/off to Arduino led

Postby rooman » Fri Mar 17, 2023 8:29 pm

Thanks, I've added that line in the protocol file but still no go.
I have also tried testing the FG output in a file with;
Code: Select all
--generic=file,out,1,/home/andrew/data.txt,fg_out_parking_led

but no file is found at all!
I'm feeling rather stupid now.
rooman
 
Posts: 74
Joined: Sun Apr 12, 2015 6:26 pm
Location: Lausanne, Switzerland
OS: Ubuntu 22.x

Re: dh6 Parking-brake on/off to Arduino led

Postby MariuszXC » Fri Mar 17, 2023 9:19 pm

Just making sure, you did place your protocol definition file in a location expected by FG?
MariuszXC
 
Posts: 742
Joined: Tue May 18, 2021 4:38 pm
Location: Europe
Callsign: SP-MRM
Version: 2020.4
OS: Ubuntu 16.04

Re: dh6 Parking-brake on/off to Arduino led  

Postby SurferTim » Fri Mar 17, 2023 9:26 pm

This xml file worked for me. I named it pbrake.xml
Code: Select all
<?xml version="1.0"?>
   <PropertyList>
      <generic>
         <output>
            <line_separator>newline</line_separator> <!-- used at the end of sprintf statements-->
            <var_separator>,</var_separator>
            <!--binary_mode>false</binary_mode-->

            <chunk>
               <name>parking brake</name>
               <node>/controls/gear/parkingbrake-lever</node>
               <format>%d</format>
            </chunk>

         </output>
      </generic>
   </PropertyList>

This in settings
Code: Select all
--generic=serial,out,1,/dev/ttyACM0,38400,pbrake

Here is my Arduino code I use a Mega2560
Code: Select all
void setup() {
  Serial.begin(38400);
  pinMode(13,OUTPUT);
}

void loop() {
  if(Serial.available())
  {
    char ch = Serial.read();
    if(ch == '1') digitalWrite(13,HIGH);
    else if(ch == '0') digitalWrite(13,LOW);
  }
}


Edit: Ensure your Arduino is ttyACM0. I unplugged and plugged in my Arduino, and it became ttyACM1.
Fly low. Fly slow. Land on a dime. Twin Otter. https://github.com/SurferTim/dhc6p
My other aircraft is a Citation-X https://github.com/SurferTim/CitationX
PirateAir videos at https://www.youtube.com/user/SurferTim850
User avatar
SurferTim
 
Posts: 1539
Joined: Sun Dec 09, 2018 5:49 pm
Location: Miramar Beach, FL
Callsign: Pirate
Version: 2020.4.0
OS: Ubuntu 18.04

Re: dh6 Parking-brake on/off to Arduino led

Postby rooman » Sat Mar 18, 2023 5:05 pm

Thanks a lot for supporting me.
I copied the FG parameter, protocol and Arduino code into FG, a new file and a new sketch so no typographic errors.
I have checked xml file location "/usr/share/games/flightgear/Protocol/pbrake.xml"
I checked the Arduino is /dev/ttyACM0.
I started FG.
I put the parking brake on and off with SHIFT+b, cockpit animation is ok and a pop-up confirms "Parking brake on or off" etc.
On the Arduino, nothing.
I have checked serial.read by sending 0 or 1 by keyboard/serial monitor with other simple sketch and led pin13 is ok.

Does this parameter look ok to check if FG sends anything?
Code: Select all
--generic=file,out,1,/home/andrew/data.txt,fg_out_parking_led

I have tried but find no file created, tried creating an empty file but still nothing in it after retrying FG.

What can prevent FG from sending this data?
rooman
 
Posts: 74
Joined: Sun Apr 12, 2015 6:26 pm
Location: Lausanne, Switzerland
OS: Ubuntu 22.x

Re: dh6 Parking-brake on/off to Arduino led

Postby rooman » Sat Mar 18, 2023 6:41 pm

I have reloaded everything and retried, it works now!
But I have no idea why now and not before as i saw nothing different.
I found no errors in the latest log.
Anyway it's working now so I'll be incorporating this code bit by bit (no pun intended) into my main simpit files.

@SurferTim Thanks a lot for your time and patience.
rooman
 
Posts: 74
Joined: Sun Apr 12, 2015 6:26 pm
Location: Lausanne, Switzerland
OS: Ubuntu 22.x


Return to Interfacing

Who is online

Users browsing this forum: No registered users and 3 guests