RPi GPIO use

Support for connecting hardware to the Raspberry Pi GPIO

Moderators: russ, Ralph

Post Reply
Message
Author
art
Posts: 18
Joined: Mon Oct 30, 2017 12:05 am

RPi GPIO use

#1 Post by art »

Hi!

I'm using RPi3 to display panels for my XP11 but would like to do simple thing: connect potentiometer to GPIO and send dataref to my simulator. Any step by step instructions available?

Regards
art

User avatar
Corjan
Posts: 2936
Joined: Thu Nov 19, 2015 9:04 am

Re: RPi GPIO use

#2 Post by Corjan »

Hi,


The raspberry Pi has no analog (ADC) pins, you need that to read potentiometers.

What you could do is buy an Arduino and connect that to your Raspberry Pi or computer running Air Manager or Air Player.
We support the Arduino Nano, Uno and MEGA 2560. All three have ADC pins, see list below:
https://siminnovations.com/wiki/index.p ... re_id_list

You could do something like that by creating an instrument with the following code:

Code: Select all

-- Callback function which is called when the ADC input value changes
function adc_input_change(value)
  -- value ranges from 0.0 (rotated far left) to 1.0 (rotated far right)
  
  -- transform the ADC value into something sensible for X-plane
  some_value = value * 100
  
  -- Write the dataref in X-plane
  xpl_dataref_write("<XPLANE_DATAREF>", "<TYPE>", some_value)
end

-- Read pin A0 (first analog pin) on the Arduino Uno
id = hw_adc_input_add("ARDUINO_UNO_A_A0", adc_input_change)

Hope this makes sense,

Corjan

art
Posts: 18
Joined: Mon Oct 30, 2017 12:05 am

Re: RPi GPIO use

#3 Post by art »

Cool, just 3 more questions:
1. I see... so how to physically connect Arduino 2560 with the Raspberry Pi 3 (I assume I don't need to buy any additional license if I connect 2560 to RPi3?)?
2. Does is slow down the panel framerate if I use Rpi also to send/recieve the datarefs?
3. Where to put the code?

regards
art

User avatar
Ralph
Posts: 7880
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: RPi GPIO use

#4 Post by Ralph »

First configure the Arduino on the desktop, with our Arduino tool on our wiki (there's also a YouTube video). Then connect it to the Pi through USB, just as on the desktop. It won't slow down the Pi, or at least not very much. You send the code to the Pi as an invisible instrument, or add the hardware code to an existing instrument.

art
Posts: 18
Joined: Mon Oct 30, 2017 12:05 am

Re: RPi GPIO use

#5 Post by art »

How to make an invisible instrument, or add the hardware code to an existing instrument?

a.

User avatar
Corjan
Posts: 2936
Joined: Thu Nov 19, 2015 9:04 am

Re: RPi GPIO use

#6 Post by Corjan »

Hi,


Air Manager has a feature where you can create your own instruments, or edit instruments others have made.

Each instrument has a piece of logic code (written in lua) that describes how the instrument should behave. Here is described where images should be, text elements, what data needs to be fetched from the flight simulator etc. etc.
This logic code can also contain code to interact with hardware.

See a complete list of stuff you can add to an instrument here:
https://siminnovations.com/wiki/index.p ... _Logic_API


Corjan

User avatar
Ralph
Posts: 7880
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: RPi GPIO use

#7 Post by Ralph »

And if you don't add any graphical elements to an instrument, you have an 'invisible' instrument.

Post Reply