PmodJSTK 2 Controller LabVIEW Code

Introduction: PmodJSTK 2 Controller LabVIEW Code

About: I work as a Product Marketing Engineer at NI. In my free time, I love tinkering and finding creative ways to solve everyday problems.

This instructable will go over the LabVIEW code that I wrote for the Sumobot controller. This will be an in-depth explanation of the code. If you're not interested in the explanation, the LabVIEW VI is attached in the last step. The code shown is the code for the Raspberry Pi 2 Sumobot controller, it is the same as the code used for the BeagleBone Black Controller. LabVIEW 2014 and Linx 3.0 are required to run this code. Below are some related Instructables:

Sumobot (LabVIEW Code)

Raspberry Pi SumoBot

BeagleBone Black MiniSumo Bot

Step 1: Front Panel

This is the front panel, right here is where you will enter the chip select channel and the SPI channel for each of your PmodJSTK 2's and here is where you will see their output value.

Step 2: Reading From the Pmod JSTK2

The first diagram is a LINX open, it is set to Local I/O because we are using a Raspberry Pi 2 and the BeagleBone Black and the code that you write in LabVIEW actually gets deployed to the board.

Screen Shot 2016-08-22 at 2.13.34 PM

After LINX is opened, a reference to the each of the PmodJSTK2’s is opened, and the settings that we set on the front panel are fed in.

Screen Shot 2016-08-22 at 2.16.12 PM

Inside the While Loop is a JSTK read for the right and left sides, you feed in the Chipselect and SPI channel for each, and they output a value that specifies the position of the joystick and whether or not the button is being pressed.

Screen Shot 2016-08-22 at 2.27.56 PM

The data that comes out of bundle all the values from both Joysticks and then use a “flatten to string” to convert it to a string.

Step 3: Sending Controller Values Over UDP

We use UDP(User Datagram Protocol) to continuously send the joystick values over Wi-Fi.

Screen Shot 2016-08-22 at 2.13.47 PM

First a UDP socket is opened, and the port is fed in. The IP address that will be fed into the UDP write and tell it what IP address to send to is specified here

Screen Shot 2016-08-22 at 2.06.40 PM

We bundle all the values from both Joysticks and then use a “flatten to string” to convert it to a string before we feed it into the UDP write.

Screen Shot 2016-08-22 at 2.06.51 PM

This will continue to send to the port specified here until the stop button is pressed, after which it will leave the loop and close the LINX reference as well as the UPD socket.

Step 4: Receiving Controller Values Over UDP

In the corresponding Surobot code, there are a few things you need to do before the data can be read.

Screen Shot 2016-08-22 at 2.39.39 PM

First, a UDP open block opens a UDP socket. The IP address and port fed in here match the one fed into the UDP write in the controller’s code.

Screen Shot 2016-08-22 at 2.39.52 PM

The UDP read outputs the string we sent over, and we feed it into a “unflatten from string” and specify its type to output our data bundle. Next, it is fed into an unbundle block which outputs each value from the PmodJSTKs.

Step 5: Finished

For the full Sumobot LabVIEW code go to this link and for the Sumobot setup code go to this link. The LabVIEW code for the BeagleBone Black and the Raspberry Pi 2 is attached below. Thank you for reading my instructable, please comment with any questions you may have.

Be the First to Share


    • Make It Bridge

      Make It Bridge
    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge
    • For the Home Contest

      For the Home Contest