Board index FlightGear Support Interfacing

SOLUTION : Arduino code button *and* switch matrix diodes  Topic is solved

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

Re: SOLUTION : Arduino code button *and* switch matrix diode

Postby Volador » Wed Oct 05, 2022 1:40 pm

Isaak wrote in Wed Oct 05, 2022 8:59 am:Very nice work, Volador. As of FG 2020.4.0 bidirectional serial traffic has been repaired FG-side, so you should be able to run everything on one Arduino, if you have enough pins.

I'm planning on building a 777 MCP and Efis control panel for my setup this fall, and will definitely revisit your code to get some pointers. The Led and Switch matrix on my overhead panel do their job nicely, but I didn't find the courage yet to rewrite the code for biderectional serial traffic.


Isaak, does bi-directional work for Windows now? I was aware it works on linux.
User avatar
Volador
 
Posts: 1140
Joined: Tue Sep 01, 2020 4:58 pm
Callsign: Volador, G-VLDR
Version: 2020.4
OS: Windows 10, 64 bit

Re: SOLUTION : Arduino code button *and* switch matrix diode

Postby MariuszXC » Wed Oct 05, 2022 1:51 pm

Volador wrote in Tue Oct 04, 2022 8:11 pm:Nice tip Mariusz


You are welcome :)

For those wondering where to acquire such tinted polycarbonate, a good source is cheap beach sunglasses. Some of them have flat lenses and are very inexpensive.
INOP
MariuszXC
 
Posts: 1061
Joined: Tue May 18, 2021 5:38 pm
Location: Europe
Callsign: SP-MRM
Version: 2020.4
OS: Ubuntu 16.04

Re: SOLUTION : Arduino code button *and* switch matrix diode

Postby polly » Wed Oct 05, 2022 2:04 pm

User avatar
polly
 
Posts: 956
Joined: Thu Nov 04, 2010 3:45 pm

Re: SOLUTION : Arduino code button *and* switch matrix diode

Postby Isaak » Wed Oct 05, 2022 7:05 pm

Volador wrote in Wed Oct 05, 2022 1:40 pm:Isaak, does bi-directional work for Windows now? I was aware it works on linux.


I've tested it on next some time ago with some dummy code and it worked on Win10. FG 2020.3.x sadly doesn't have this fix and probably will not receive it.
Want to support medical research with your pc? Start Folding at Home and join team FlightGear!
Isaak
 
Posts: 768
Joined: Sat Jun 04, 2011 3:52 pm
Location: Hamme, Belgium
Pronouns: he, him
Callsign: OO-ISA
Version: next
OS: Windows 10

Re: SOLUTION : Arduino code button *and* switch matrix diode

Postby MariuszXC » Wed Oct 05, 2022 7:07 pm



Nice piece, guitars and all.
I am more of an (early) Pink Floyd fan. Many similarilities, if one listens carefully, though.

How about that? https://www.youtube.com/watch?v=_9aLiv5M6AQ
(to stay more in the spirit of this thread :) )
INOP
MariuszXC
 
Posts: 1061
Joined: Tue May 18, 2021 5:38 pm
Location: Europe
Callsign: SP-MRM
Version: 2020.4
OS: Ubuntu 16.04

Re: SOLUTION : Arduino code button *and* switch matrix diode

Postby polly » Wed Oct 05, 2022 10:16 pm

Well, E, A, B7 !
( Dusty Hill rolls in his grave )
User avatar
polly
 
Posts: 956
Joined: Thu Nov 04, 2010 3:45 pm

Re: SOLUTION : Arduino code button *and* switch matrix diode

Postby MariuszXC » Thu Oct 06, 2022 12:12 pm

OK, so I take more chords and a shifting metrum would be more interesting to you? How about
https://www.youtube.com/watch?v=ZiRuj2_czzw ( analysis here: https://www.youtube.com/watch?v=4P-yUOlOC5M )

With something lighter for dessert https://www.youtube.com/watch?v=g_QtO0Rhp0w (here both audio and video are superb).

(apologies to OP for, hmm, slight thread drift?) :)
INOP
MariuszXC
 
Posts: 1061
Joined: Tue May 18, 2021 5:38 pm
Location: Europe
Callsign: SP-MRM
Version: 2020.4
OS: Ubuntu 16.04

Re: SOLUTION : Arduino code button *and* switch matrix diode

Postby Isaak » Thu Oct 06, 2022 1:00 pm

MariuszXC wrote in Thu Oct 06, 2022 12:12 pm:(apologies to OP for, hmm, slight thread drift?) :)


I accept your appologies, but can you please continue this conversation in 'Hangar Talk'? ;)
Want to support medical research with your pc? Start Folding at Home and join team FlightGear!
Isaak
 
Posts: 768
Joined: Sat Jun 04, 2011 3:52 pm
Location: Hamme, Belgium
Pronouns: he, him
Callsign: OO-ISA
Version: next
OS: Windows 10

Re: SOLUTION : Arduino code button *and* switch matrix diode

Postby polly » Thu Oct 06, 2022 5:05 pm

That's on me, grovel grovel.
To make up:
When you all first posted I went searching for the biggest mpexer I could find:
https://www.sparkfun.com/products/299
The 16 way A/D switch needs 4 selectors so for sixteen sensors you'd need five GPIO pins. For more sensors I didn't see a chip select on the COM 00029 so I'd go for PCF8574 IIC b bit port, would control the four bit selection lines for two mpexers: four Arduiino GPIO's for 32 sensors.
Generally I've moved everything not needing 5v drive to the ESP32, it's as easy as an Arduino to program, wifi and bluetooth on board. If there's any interest in code to run one as a tilt-accelerometer joystick for roll, pitch and yaw I can post.
One more thing, tm, a few-euro logic analyser that is supported with open source protocol plugins ( IIC, SPI, +++ ) :
https://www.sparkfun.com/products/18627
User avatar
polly
 
Posts: 956
Joined: Thu Nov 04, 2010 3:45 pm

Re: SOLUTION : Arduino code button *and* switch matrix diode

Postby rooman » Mon Oct 17, 2022 4:00 pm

@volador Excellent, really kind, thank you.

I'm getting to the end of fitting switches and buttons and the serious coding will start.
Grew up with Dr Who then discovered Monty Python and Middle Earth. The world was never the same.
rooman
 
Posts: 169
Joined: Sun Apr 12, 2015 7:26 pm
Location: Lausanne, Switzerland
Callsign: HB-ROO
Version: Next + LTS
OS: Ubuntu latest stable

Re: SOLUTION : Arduino code button *and* switch matrix diode

Postby Isaak » Mon Oct 17, 2022 4:23 pm

Some hints from my experience with multiplexing a +100 inputs overhead panel:
    - Map out your multiplexer rows and columns in e.g. Excel and note down every change you make immediately so you can immediately spot any double bindings or missing links.
    - Don't hesitate to redo your row/column mapping a few times to reduce the amount of cables until you come up with an as logical and economical layout as possible.
    - Be consistent on where you put your diodes (column input vs row output; same terminal on each switch...)
    - Connect row by row and column by column and check every cable you solder before and after you've soldered it.
No idea if these are helpful, but I've found out the hard way that not doing any of these results in difficult to spot mistakes :)
Want to support medical research with your pc? Start Folding at Home and join team FlightGear!
Isaak
 
Posts: 768
Joined: Sat Jun 04, 2011 3:52 pm
Location: Hamme, Belgium
Pronouns: he, him
Callsign: OO-ISA
Version: next
OS: Windows 10

Re: SOLUTION : Arduino code button *and* switch matrix diode

Postby rooman » Tue Oct 18, 2022 8:52 am

@volador
quick Arduino C code question please. (I'm an old dog learning new tricks)
The function SendData() is called in every if{ } check when a property changes, won't it be executed every time in every check?
Shouldn't it be called only once in void loop{ } ?
Grew up with Dr Who then discovered Monty Python and Middle Earth. The world was never the same.
rooman
 
Posts: 169
Joined: Sun Apr 12, 2015 7:26 pm
Location: Lausanne, Switzerland
Callsign: HB-ROO
Version: Next + LTS
OS: Ubuntu latest stable

Re: SOLUTION : Arduino code button *and* switch matrix diode

Postby Volador » Tue Oct 18, 2022 5:01 pm

Hi Rooman, If I've understood your question the thinking was only to jump to SendData() IF an input or change event was detected rather than flooding FG continuously from the loop{} - If the If condition is not met then SendData() does not get called but we still need to check/read all buttons and switches and encoders all the time on the Arduino input side.

SendData() transmits the whole set of values for all switches and buttons (listed in the xml file) each time it is called. You'll notice sometimes it's called twice for a switch or button (usually a push button), once sending a 0 and then sending a 1 - this is for the rising edge that some of the listeners need to execute stuff on the FG side (it need to be set to 0 then set to 1 for a momentary type behaviour rather than a toggle switch eg gear which is latched at 1 or 0 and not momentary) - I didn't get my head fully around it at the time so there could well be a much more elegant solution which would definitely cut down on the Tx traffic. There is another non-xml protocol method where you can use an ethernet board on the Arduino and just write to one property at a time as a change is detected - I guess that would be far more efficient.

I notice even now that even though I'm only transmitting to FG on an input or change, FG does have a momentary little hiccup of a few 100 ms while it processes the serial data (or some buffer does its thing, I don't know). If I remember rightly without this method of only Tx on change, FG ground to a halt. I tried different baud rates and serial transmission rates (and settled with about 7Hz from Arduino to FG and about 10 Hz from FG to Arduino all at 56000 Baud rate).
User avatar
Volador
 
Posts: 1140
Joined: Tue Sep 01, 2020 4:58 pm
Callsign: Volador, G-VLDR
Version: 2020.4
OS: Windows 10, 64 bit

Re: SOLUTION : Arduino code button *and* switch matrix diode

Postby rooman » Wed Oct 19, 2022 7:08 pm

Volador, I'm going to inspire myself from some of your code because it works and I'm just a nit-picking curious autodidact who's learning C and FG interfacing simultaneously. I've even dismantled working code and even worse working objects just to see how they work and have sometimes/frequently failed to put together again!
Thanks for suggestions.
Grew up with Dr Who then discovered Monty Python and Middle Earth. The world was never the same.
rooman
 
Posts: 169
Joined: Sun Apr 12, 2015 7:26 pm
Location: Lausanne, Switzerland
Callsign: HB-ROO
Version: Next + LTS
OS: Ubuntu latest stable

Re: SOLUTION : Arduino code button *and* switch matrix diode

Postby Volador » Sat Oct 22, 2022 6:15 pm

I took a look back through my code for the switches and using 'Terminal' noticed a lot of serial traffic which is not required but is being generated by all the if statements that call sendData() - Ideally, within the void that checks the switches we should jump back out once a condition has been identified and a sendData() call has been made, is it bad practice to use the Return function in Arduino code to effectively exit that void without going on the check any of the other if conditions? or should the whole void be reconstructed as a set of: else if switch1....;, else if switch2....; else if switch3.....; - to stop calling SendData() more than once
User avatar
Volador
 
Posts: 1140
Joined: Tue Sep 01, 2020 4:58 pm
Callsign: Volador, G-VLDR
Version: 2020.4
OS: Windows 10, 64 bit

PreviousNext

Return to Interfacing

Who is online

Users browsing this forum: No registered users and 4 guests