Вы находитесь на странице: 1из 17

In the previous Tutorial, I showed you on how to connect the impressive PoKeys card to xPlane. http://forums.x-plane.org/index.php app!downloads"showfile!

#$%&%"st 'ut that interface is a one way connection(. )hat I mean is that the Po*eys can send commands to xPlane +ut at the moment it is very difficult to send info from xPlane to the PoKeys card. In a nutshell ...the PoKeys is the ideal solution ,in my mind- for switches, +uttons, potentiometers, etc. (,rumor is that PoKeys is developing a plug-in for xPlane.o what if I want my home-made coc*pit to display /av# 0re1uency 2ow would I +uild an interface that shows when my landing gear is down 2ow would I +uild a 0laps indicator 2opefully I can explain in this +asic tutorial. 3n4oy, 5arc

This Tutorial is based around the Teensy2 card.


The card comes in two flavors: Teensy2 and Teensy2++ The latter has some more inputs/outputs.

Unlike the PoKeys card, the Teensy2 needs pro rammin . !on"t et scared, the #rduino lan ua e is not that difficult. The $oard is %&'( cheap and can $e purchased here: http://www.p)rc.com/teensy/ 'emem$er that * was ravin a$out the PoKeys +ustomer ,erviceThey even replied to me on a ,unday. /ell customer service on the Teensy card is P00' or non1e2istin . 3at least in my e2perience4 * received one defective card and send twice an email. *"ve $een waitin for 56 days since the last email and still no reply...

1. First Example:
Display Nav1 frequency on an LCD Display Flap Position on an LCD Display Elevator trim on a second LCD
+ontrary to popular $elief, you can hookup more than one 7+! to the Teensy.

Spaghetti

1.1 Parts used:


0ne Teensy2++ $oard 829.66 3will also work with the re ular 85:.66 Teensy2 4 Two 5:;2 7+! "s 3<!99=>6 compati$le4 82.?? &ach 3@o +hina.4

1.2 Hooking up the Teensy2++:


The card comes with a pin1layout illustration for +++ and #rduino. /e will use the #rduino pin layout. The +hip itself is powered $y U,A. This is convenient $ut $e careful to B0T 0%&'70#! your U,A device and Teensy++ #s * mentioned $efore, you can hook1up several 7+!"s to the card. Keep in mind that the 7+! $ackli hts mi ht consume Cuite some power. * would su est to use an e2ternal D% source for the $ackli hts. 0n the other hand, the Teensy seemed to $e comforta$le drivin my 2 7+!"s.

Pin 5D 3Aackli ht4 of the 7+! is normally connected to +D%olt. * connected a 9=6 0hm resistor in series 3226 0hm will work to4 This reduces the $ri htness $ut most importantly the current draw. Pin E 3+ontrast4 is connected via a 56K potentiometer. *f you do not see a readout F tweak the pot.

1.3 The Code Explained: *mportant:


Botes or remarks start with // Thus anythin after the // will not $e compiled # num$er is a num$er is a num$er FBot really as in computer lan ua e, we distin uish in1$etween Float, Integer, Double, String, etc. &2amples of *nte er: 1D: , 5D:, 2E66 &2amples of !ou$le: 52.D: , 52E9.=: , 19D6.66 &2amples of Aoolean: 5 or 6 3yes or no4 &2amples of Gloat: 16.62D:=>?D , 6.D:=929 # strin H plain te2t and is enclosed with I I The 2Plane !ata'efs can $e found here: http://www.2sCuawk$o2.net/2psdk/docs/!ata'efs.html ,o what the heck are !atarefs!ata'efs are the million of parameters, 2Plane can send to the Teensy 3* mi ht have sli htly e2a erated4 'emem$er to use the full path of the !ata'ef.

WARN N! F"R #AT "WNER$ #AT$ lo%e Teensy boards. The more &ires' the more fun they tend to ha%e &ith it.

$o here &e (o)

Jinclude K7iCuid+rystal.hL // most devices $elon to a cate ory. *n order to access the 3code4 parameters for that device, the appropriate li$rary has to $e loaded. K7iCuid+rystal.hL is the li$rary for <!99=>6 compati$le 7+!"s 7iCuid+rystal lcd5352, 55, D, 9, E, 24M 7iCuid+rystal lcd2352, 56, D, 9, E, 24M //7i$raryBame Bame0f7+!3', pinJ, &na$le pinJ, !9 pinJ, !D pinJ, !: pinJ, != pinJ4 //Bote that $oth 7+!"s use the same pins e2cept for the &na$le pin. Gli ht,im*nte er BavGreCuency<NM //,end1an1*nte er1from12Plane 2Plane1parameter 3in this case the Bav5 GreCuency4 Gli ht,im*nte er GlapsM //,end1an1*nte er1from12Plane 2Plane1parameter 3in this case the Glaps Position4 Gli ht,imGloat Trim&lvM //,end1a1Gloat%alue1from12Plane 2Plane1parameter 3in this case the &levation Trim4 dou$le dBavM //!eclare a dou$le 3used for formattin the GreCuency4 int iTrimM //!eclare an *nte er 3used for formattin the Trim Position4 void setup34 O //&ach code 3called sketch4 has to have a setup BavGreCuency<N H ;plane'ef3Psim/cockpit2/radios/actuators/nav5QfreCuencyQhNP4M //!eclare the Bav5 GreCuency !ata'ef 2Plane !ata'ef"s can $e found:http://www.2sCuawk$o2.net/2psdk/docs/!ata'efs.html BavGreCuency<N.on+han e3updateQlcd4M // update the 7+! when ;1Plane chan es //on+han e tells the software to only update the 7+! when there is a chan e in freCuency. This is ood practice as we do not want to kill our frame1rate. Thus when there is a chan e in freCuency, the software will )ump to the IupdateQ7+!R su$routine Glaps H ;Plane'ef 3Psim/fli htmodel/controls/win 5lQfla5defP4M //!eclare the Plap GreCuency !ata'ef Glaps.on+han e3updateQlcd4M //on+han e tells the software to only update the 7+! when there is a chan e in flap position. This is ood practice as we do not want to kill our frame1rate. Thus when there is a chan e in flap position, the software will )ump to the IupdateQ7+!R su$routine Trim&lv H ;Plane'ef 3Psim/fli htmodel/controls/elvQtrimP4M //!eclare the &levator Trim !ata'ef lcd5.$e in35:, 24M //!eclare the Type of 7+! 3num$er1of1characters , num$er1of1te2t1lines4 lcd5.print3PB#%5P4M //!isplay IB#%5R on the top row of the first 7+! lcd5.set+ursor36,54M

//Sove the cursor on the first 7+! to the second line 3character1position, line1position4. The top line is 6 lcd5.print3PG7#P,P4M //!isplay IG7#P,R on the $ottom row of the first 7+! lcd2.$e in35:, 24M //!eclare the Type of 7+! for the second one 3num$er1of1characters , num$er1of1te2t1lines4 lcd2.print3PT'*SP4M //!isplay IT'*SR on the top row of the second 7+! T void loop34 O //start the loop Gli ht,im.update34M // Beeds to $e there to et 2Plane data lcd2.set+ursor3:, 64M /Sove the cursor on the second 7+! to the first line, :th position 3character1position, line1position4. iTrim H Trim&lv U 566M //Gormat the &levator Trim !ata send from 2Plane. The !ata is a Float and will look like per e2ample 16.66259D:E9 That would $e very difficult to read. ,o we multiply the !ata with 566. Bow the result is 12.59D:E9 #s we declared iTrim as an Integer in the $e innin of the code, the actual display will show 12 lcd2.print3iTrim4M //!isplay the &levator Trim !ata to the top row of the second 7+! lcd2.print3P P4M //!isplay some $lank characters 3to erase previous data4 T void updateQlcd3lon val4 O //,tart the updateQlcd su$routine dBav H BavGreCuency<N M //7oad the 2Plane Bav5 GreCuency in the Double, called dB#% //The 2Plane Bav5 GreCuency is an inte er and would display as per e2ample 55E>D lcd5.set+ursor3:, 64M /Sove the cursor on the first 7+! to the first line, :th position 3character1position, line1position4. lcd5.print3dBav /5664M //!isplay the Bav5 GreCuency $ut divide it $y 566. Thus the !isplay will read 55E.>D lcd5.set+ursor3:, 54M /Sove the cursor on the first 7+! to the second line, :th position 3character1position, line1position4. lcd5.print3Glaps4M //!isplay the Glaps Position lcd5.print3P P4M //!isplay some $lank characters 3to erase previous data4 T

*oila) That &as not that bad' &asn+t it,

1.4 Here is the code again


Jinclude K7iCuid+rystal.hL 7iCuid+rystal lcd5352, 55, D, 9, E, 24M 7iCuid+rystal lcd2352, 56, D, 9, E, 24M Gli ht,im*nte er BavGreCuency<NM Gli ht,im*nte er GlapsM Gli ht,imGloat Trim&lvM dou$le dBavM int iTrimM

ithout the co!!ents

void setup34 O BavGreCuency<N H ;Plane'ef3Psim/cockpit2/radios/actuators/nav5QfreCuencyQhNP4M BavGreCuency<N.on+han e3updateQlcd4M // update the 7+! when ;1Plane chan es Glaps H ;Plane'ef 3Psim/fli htmodel/controls/win 5lQfla5defP4M Glaps.on+han e3updateQlcd4M Trim&lv H ;Plane'ef 3Psim/fli htmodel/controls/elvQtrimP4M //Trim&lv.on+han e3updateQlcd4M lcd5.$e in35:, 24M lcd5.print3PB#%5P4M lcd5.set+ursor36,54M lcd5.print3PG7#P,P4M lcd2.$e in35:, 24M lcd2.print3PT'*SP4M T void loop34 O Gli ht,im.update34M lcd2.set+ursor3:, 64M iTrim H Trim&lv U 566M lcd2.print3iTrim4M lcd2.print3P P4M //lcd2.print35?E, A(T&4M T void updateQlcd3lon val4 O dBav H BavGreCuency<N M lcd5.set+ursor3:, 64M lcd5.print3dBav /5664M lcd5.set+ursor3:, 54M lcd5.print3Glaps4M lcd5.print3P P4M M T

2. Additional -#. info and code


2.1 Creating Custo! Characters:
(ou can create up to ei ht custom characters of D2> pi2els 3num$ered 6 to =4. The appearance of each custom character is specified $y an array of ei ht $ytes, one for each row. Example /smiley face0 Jinclude K7iCuid+rystal.hL 7iCuid+rystal lcd352, 55, D, 9, E, 24M $yte smileyV>W H O A66666, A56665, A66666, A66666, A56665, A65556, A66666, TM void setup34 O lcd.create+har36, smiley4M lcd.$e in35:, 24M lcd.write364M T void loop34 OT +omple2 ---7uckily some$ody created some tools which makes life easy: http://mikeyancey.com/hamcalc/lcdQcharacters.php or http://sourcefor e.net/pro)ects/arduinolcd/

2.2 "isplay Extended Characters:


The <!99=>6 has its own +haracter set 3#,+* $ased4 *f per e2ample you want to use the Ide reesR sym$ol ... lcd.print/ 1F-A2$ 34510 T6 $ W -- N"T W"R7 Aelow is the correct code lcd.print3IG7#P, E6R4M lcd.print33char422E4M // 22E is the #,+* num$er for the de rees sym$ol

HD44780 ASCI set

3. $ample code for most common components


3.1 #$%TCH &E" '(
int ledPin H 5EM void setup34O pinSode3ledPin, 0UTPUT4M ,erial.$e in3?:664M O void loop34T di ital/rite3ledPin, <*@<4M T

3.2 )&%(* &E"


int ledPin H 5EM void setup34O pinSode3ledPin, 0UTPUT4M ,erial.$e in3?:664M O void loop34T di ital/rite3ledPin, <*@<4M delay356664M di ital/rite3ledPin, 70/4M delay356664M T

3.3 C'((ECT + P'TE(T%',ETEint potentiometerPin H EM int pot%al H 6M void setup34O O void loop34T pot%al H analo 'ead3potentiometerPin4 ,erial.println3pot%al4M T

3.4 C'(T-'& &E" )-%.HT(E##


int potentiometerPin H EM int ledPin H ?M int pot%al H 6M void setup34O O

ith a P'TE(T%',ETE-

void loop34T pot%al H analo 'ead3potentiometerPin4 ,erial.println3pot%al4M analo /rite3ledPin, pot%al/94M //convert 6X562E to 6X2DD T

3./ C'((ECT + #$%TCH


int $uttonPin H EM int pot%al H 6M void setup34O O void loop34T if3di ital'ead3$uttonPin4 HH <*@<4 O ,erial.println3I$utton is pressed"4M T else O ,erial.println33I$utton B0T pressedR4M T delay356664M T

3.0 C'((ECT + #E-1'


Jinclude K,ervo.hL ,ervo myservoM int servoPos H 6M void setup34O myservo.attach3?4M O void loop34T myservo.write3servoPos4M // Nero to 5>6 delay35D4M T

3.2 C'(T-'& + #E-1'


Jinclude K,ervo.hL ,ervo myservoM int potpin H 6M int potPos M

ith a P'TE(T%',ETE-

void setup34O myservo.attach3?4M O void loop34 O potPos H analo 'ead3potpin4M potPos H map3potPos, 6, 562E, 6 ,5>64M // scale value myservo.write3potPos4M delay35D4M T

3.3 C'(T-'& &C"


Jinclude K7iCuid+rystal.hL 7iCuid+rystal lcd5352,55,D,9,E,24M void setup34O lcd5.print3I* 7ove 2PlaneR4M O void loop34 OT

8. Teensy $oft&are setup


/.1 %nstall the Teensy 4+rduino so5t are
10 *n order to load the code into your Teensy you need to download the Teensy 7oader software. http://www.p)rc.com/teensy/loader.html

(ou can test the Teensy followin the instructions $elow. http://www.p)rc.com/teensy/firstQuse.html Note: My Teensy did not ha e a !ush"button as !i#tured in their instru#tions$ I had to !ush a !a!er#li! in the tiny hole$ %&' you tested your Teensy$ I theory you #ould start !rogra((ing but the Teensy )oader is *inda bare"bones' not ery +le,ible and does not !ro(!t +or errors in the #ode$ So -e need so(e (ore so+t-are$'

20 !ownload the #rduino software here: http://arduino.cc/en/Sain/,oftware *nstall the #rduino you )ust downloaded 3and remem$er the path.4 Al(ost done but no- -e ha e to (a*e the Arduino so+t-are #o(!atible -ith the Teensy$ 30 !ownload Teensyduino here: htt!:..---$!/r#$#o(.teensy.td0do-nload$ht(l *nstall Teensyduino. 3it will ask for the #rduino path4 90 *n order to interface with ;plane, you need to install the Teensy Plu in. This Plu in is $rilliant and * did not see any si nificant frame1rate loss $y usin it. The Plu in can $e downloaded here: http://www.p)rc.com/teensy/Teensy+ontrolsQ5.6.Nip &2tract the 1i! and copy it to ;1Plane"s 'esources/plu ins folder. 80 'un #rduino. :0 *f the installation worked you should see (our Teensy $oard under Tools L Aoards ,elect your Teensy Aoard

;0 Under Tools L U,A Type, select PGli ht ,im +ontrolsP

<0 0pen the $link e2ample in Gile L &2amples L Teensy L U,AQGli ht,im L AlinkTransponder. =0 +lick PUploadP to pro ram your Teensy $oard. 140 'un ;1Plane. The 7&! should $link.

/.2 Testing your pro6ect.


(ou can display the !ata'ef data, send $y 2Plane to the Teensy, within 2Plane. +lick the Teensy Plu in 3in 2Plane4

+lick $ho& #ommunication

The !ata'ef data will scroll over the screen.

:. Future Tutorials.
* am still awaitin some parts 3from +hina4 The ne2t tutorial3s4 should include: Auildin an interface for analo ue au es usin the Teensy 3per e2ample Glap Position @au e4 Auildin an interface for !i ital +olour !isplays. There are Cuite a few cheap cell phone displays availa$le on the internet. The oal 3or dream4 is to raphically confi ure them so they will mimic the <,*, GS,, <U!, etc.

$o $tay tuned 2lease lea%e feedbac>)


Thanks, Marc 3Ael a52E9D4

Вам также может понравиться