Tag Archives: Arduino

Improvements in XArduino 2.0 for PythonInterface

Over the past week, I revamped the code for the Arduino switch box project I started in April of last year.  Before I talk about the improvements in XArduino 2.0, it is important to understand the motivations behind these changes.  At some point between April and the end of the 2012, I stopped using my Arduino switch box due to performance issues.  Those issues were as follows:

  • Generally poor performance causing low FPS
  • Intermittent lag between switch action, and dataref change or command execution (multiple seconds)
  • High frequency of malformed output

I’ll talk about how I addressed each of these problems below.

Bitwise functions in lieu of string manipulation

While comma-separated text may offer a simple solution for spreadsheet standardization, parsing comma-separated data every frame can cause some lag.  In the first release of XArduino, the output looked something like this:

Once the “H” was detected, the Python code would read all the data between that letter and the carriage return at the end of the string.  Next, Python would check the integrity of the string by ensuring there was a comma every other character, and the line length was the appropriate number of characters.  Each value in the string represented the switch position (0 = first position, 1 = second position, etc.).

Only one piece of this methodology was reused in XArduino 2.0.  The string still starts with a single letter and ends with a carriage return, but instead of displaying each switch position in a comma-separated string, the switch positions are stored in a 16-bit number on multiple lines (if necessary).  Multiple lines are necessary when using more than 16 two-position switches because the Arduino Uno and Mega are both limited to 16-bit numbers.  The switch positions are decoded from the number using bitwise operators.

Continuous output vs. event-driven output

In XArduino 1.0, a new line was outputted every 50 ms regardless of whether or not a change had occurred.  In XArduino 2.0, a new line is only generated when a switch position changes.  This prevents the intermittent, but significant, lag associated with Arduino’s internal caching mechanism.  To deal with the limited potential for malformed lines, each time a change occurs, the string is outputted three times.  Increasing the baud rate also helped deal with the frequency of malformed lines.  Together, these changes also generally improved performance.

What’s new in XArduino 2.0

  • Improved performance by 50-100% (i.e. no measurable impact on FPS)
  • Allow multiple commands per switch position
  • COM port and baud rate set in configuration file instead of code
  • Moved from string-based output to 16-bit numbers
  • Fixed majority of malformed lines in communication between Arduino and pyserial
  • Fixed delay in switch command/dataref by preventing endless polling
  • Increased default baud rate to 56K

Source Code: https://github.com/cstrosser/XArduino/tree/release-2.0

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

How to create a trim indicator for X-Plane using Arduino

After successfully implementing switches, buttons, and LEDs with the Arduino microcontroller, I decided to take on servos.  Please forgive my makeshift indicator, which was constructed using a post-it note!  I am still looking for a good method for creating something more professional and open to suggestions.  The code is good, but the aesthetics are still undoubtedly in the “proof of concept” phase.

As you can see, the servos will work out of the box for the most part.  Each servo requires power, ground, and a digital pin.  To compensate for the USB output, I drilled a circular hole using a 5/8″ drill bit.  If you have more precise tools, you can make this as pretty as you want.  Personally, I would have preferred the USB output extend from the rear, but to accomplish this we would need some kind of female-female 90-degree connector, or a larger project box.

Required Hardware

Source Code

Arduino

 

PythonInterface

 

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

Arduino project for X-Plane 10

Recently, after wrapping my head around X-Plane’s plugin API, I embarked on my first journey into the Arduino Uno.  The Arduino Uno is a USB-based microcontroller board with 14 digital IO pins, and 6 analog inputs.  On Windows, the Arudino board uses standard USB COM drivers, so no need to fiddle with driver installation.  On my computer, the Arduino uses COM11.

As you can see, I wasn’t going for aesthetics.  The switch box serves as a functional proof of concept, and opens the door for future projects.

Arduino Uno and Other Hardware

Although I could have undoubtedly purchased lower cost parts on the internet, I decided to grab them from my local Radio Shack:

The Arduino Uno board:

The breadboard and microcontroller side-by-side:

As you can see, it can get a bit crowded, so organization is key.  I used the following system of organization:

  • Red – 5V power
  • Black – Ground
  • Green – Digital IO pin
  • Orange/Blue – Jumpers

Integration with X-Plane 10

I used two external libraries to integrate Arduino with X-Plane 10.  PythonInterface allows programmers to avoid having to compile C++ code, which makes debugging MUCH easier.  pySerial provides an interface between Python and serial communication devices, and has a very small learning curve.

In case anyone is interested in starting an Arduino/X-Plane project, I posted all my code on GitHub.  I will keep the plugin free and open source, and likely continue to improve it as long as I am using Arduino.  I still have some refactoring I want to do, so keep that in mind as you look at the code!

Well, that’s all for now.  I hope this has been somewhat interesting.  I’m open to questions, comments, and suggestions.  This is a learning process, and there’s always room for improvement.

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS