Saturday, May 20, 2017

How to install Java, SDKMAN!, Groovy, and Grails on the Windows Subsystem for Linux

This article explains how to install various development tools using the new Windows Subsystem for Linux that is available on Windows 10.

Install Windows Subsystem for Linux

In order to use the Windows Subsystem for Linux, it must be installed. The following link explains how to install this functionality in Windows 10:
https://msdn.microsoft.com/en-us/commandline/wsl/install_guide

Update Bash on Ubuntu on Windows 

Once installed, it is a good idea to update to the latest version of the Ubuntu binaries. Issuing the following commands from the Bash shell will accomplish this:

me@COMPUTER:~$ sudo apt-get update 
me@COMPUTER:~$ sudo apt-get upgrade 
Source: https://msdn.microsoft.com/en-us/commandline/wsl/faq#how-do-i-update-bash-on-ubuntu-on-windows

Install zip and unzip

Before you can install the Java JDK or any of the other tools, zip and unzip will need to be installed.

Install unzip

To install unzip:
me@COMPUTER:~sudo apt-get install unzip

To verify unzip was installed correctly:
me@COMPUTER:~unzip -v

Install zip

To install zip:
me@COMPUTER:~sudo apt-get install zip

To verify zip was installed correctly:
me@COMPUTER:~zip -v


Install the latest Java JDK

A nice shell script that can be used to install the Java JDK on the Windows Subsystem for Linux can be found on the following Stack Overflow article:
http://stackoverflow.com/questions/36478741/installing-oracle-jdk-on-windows-subsystem-for-linux#41072208

The URL for the latest version of the Java JDK can be found at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

To verify which version of Java was installed:
me@COMPUTER:~$ java -version 


Install SDKMAN! 

SDKMAN! is a tool for managing parallel versions of multiple Software Development Kits on most Unix based systems. Instructions on how to install SDKMAN! can be found on the SDKMAN! website:
http://sdkman.io/install.html

Once SDKMAN! is installed, it can be used to install other tools, like Groovy or Grails.

Install Groovy

To install Groovy, issue the following command from the Bash shell:
me@COMPUTER:~sdk install groovy

Install Grails

To install Grails, issue the following command from the Bash shell:
me@COMPUTER:~sdk install grails

Once grails is installed, the steps outlined in the Grails documentation can be followed to create a “Hello World” application:
http://docs.grails.org/latest/guide/gettingStarted.html#creatingAnApplication

Note: I had to create the helloworld directory and navigate to it before I issued the create-app command:
me@COMPUTER:~mkdir helloworld
me@COMPUTER:~cd helloworld
me@COMPUTER:~/helloworldgrails create-app helloworld

Once I created my Grails application and the HelloController, I was able to start my application from either the Bash shell or the Windows Command Line using the following commands:

Bash Shell

me@COMPUTER:~/helloworld./gradlew bootRun
:compileJava NO-SOURCE
:compileGroovy
:buildProperties
:processResources
:classes
:findMainClass
:bootRun
Grails application running at http://localhost:8080 in environment: development

> Building 85% > :bootRun

Windows Command Line 

C:\...\helloworld>gradlew bootRun
:compileJava NO-SOURCE
:compileGroovy
:buildProperties
:processResources
:classes
:findMainClass
:bootRun
Grails application running at http://localhost:8080 in environment: development

> Building 85% > :bootRun



Friday, May 05, 2017

Inspect HTTP Requests with RequestBin

I came across this handy website for inspecting HTTP requests, called RequestBin (https://requestb.in/). RequestBin creates a URL that will collect requests made to it and lets you review the requests in a human-friendly way. RequestBin is a great tool for debugging what your HTTP application is sending. The following are some screenshots of the data RequestBin provides:



Friday, November 25, 2016

Arduino Joystick Library - Version 2.0

Introduction

Since I released the original Arduino Joystick Library (see http://mheironimus.blogspot.com/2015/11/arduino-joystick-library.html or http://www.instructables.com/id/Arduino-LeonardoMicro-as-Game-ControllerJoystick/ for more details) I have received numerous requests for enhancements. Most of these requests fall into the following two categories:

  • Increase the precision of the axes.
  • Make a version with only a specified set of features.
To accommodate these requests (and a few others) I have release Version 2.0 of the Arduino Joystick Library.

Out of the box the Arduino Leonardo and the Arduino Micro appear to the host computer as a generic keyboard and mouse. This article discusses how the Arduino Leonardo and the Arduino Micro can also appear as one or more generic Game Controllers or Joysticks. The Arduino Joystick Library Version 2.0 can be used with Arduino IDE 1.6.6 (or above) to add one or more joysticks (or gamepads) to the list of HID devices an Arduino Leonardo or Arduino Micro (or any Arduino clone that is based on the ATmega32u4) can support. This will not work with Arduino IDE 1.6.5 (or below) or with non-32u4 based Arduino devices (e.g. Arduino UNO, Arduino MEGA, etc.).

Features


The joystick or gamepad can have the following features:
  • Buttons (default: 32)
  • Up to 2 Hat Switches
  • X, Y, and/or Z Axis (up to 16-bit precision)
  • X, Y, and/or Z Axis Rotation (up to 16-bit precision)
  • Rudder (up to 16-bit precision)
  • Throttle (up to 16-bit precision)
  • Accelerator (up to 16-bit precision)
  • Brake (up to 16-bit precision)
  • Steering (up to 16-bit precision)
These features are configured using the Joystick_ class’s constructor.

Installation


The latest build of Version 2.0 of the Arduino Joystick Library can be downloaded from the following GitHub repository:
https://github.com/MHeironimus/ArduinoJoystickLibrary/tree/version-2.0

The library can also be downloaded directly using the following URL:
https://github.com/MHeironimus/ArduinoJoystickLibrary/archive/version-2.0.zip

Copy the Joystick folder to the Arduino Libraries folder (typically located at %userprofile%\Documents\Arduino\libraries on Microsoft Windows machines). On Microsoft Windows machines, only, this can be done by executing deploy.bat. The library should now appear in the Arduino IDE list of libraries.

Included Examples


The example Arduino sketch files listed below are included in this library. These will appear in the Arduino Example menu when the Arduino Joystick Library is installed.

Example Description
JoystickTest Simple test of the Joystick library. It exercises many of the Joystick library’s functions when pin A0 is grounded.
MultipleJoystickTest Creates 4 Joysticks using the library and exercises the first 16 buttons, the X axis, and the Y axis of each joystick when pin A0 is grounded.
JoystickButton Creates a Joystick and maps pin 9 to button 0 of the joystick, pin 10 to button 1, pin 11 to button 2, and pin 12 to button 3.
JoystickKeyboard Creates a Joystick and a Keyboard. Maps pin 9 to Joystick Button 0, pin 10 to Joystick Button 1, pin 11 to Keyboard key 1, and pin 12 to Keyboard key 2.
GamepadExample Creates a simple Gamepad with an Up, Down, Left, Right, and Fire button.
DrivingControllerTest Creates a Driving Controller and tests 4 buttons, the Steering, Brake, and Accelerator when pin A0 is grounded.
FlightControllerTest Creates a Flight Controller and tests 32 buttons, the X and Y axis, the Throttle, and the Rudder when pin A0 is grounded.
HatSwitchTest Creates a joystick with two hat switches. Grounding pins 4 - 11 cause the hat switches to change position.

Running the JoystickTest Example



The JoystickTest example sketch is included with the library. I recommend using this example to verify everything is working properly before beginning to write your own sketch files. Load, compile, and upload this example sketch file to an Arduino Leonardo or Micro using the Arduino IDE (version 1.6.6 or above).


Once you have uploaded the JoystickTest sketch file to the Arduino Leonardo or Micro, perform the following steps to verify everything is working properly. Note: the following steps are for Windows 10. If you have a different version of Windows or a different operating system, these steps may differ. Open the “Devices and Printers” window. This can be done by clicking the Start menu or pressing the Windows Key and typing “Devices and Printers”.

The Arduino Leonardo or Arduino Micro should appear in the list of devices.


Right mouse click on the Arduino Leonardo or Arduino Micro to display the settings menu.


Select “Game controller settings” to get to the “Game Controllers” dialog.



The Arduino Leonardo or Micro should appear in the list of installed game controllers. Select the Arduino Leonardo or Micro and click the Properties button to display the game controller test dialog.



While this dialog has focus, ground pin A0 on the Arduino to activate the test script. The test script will test the game controller functionality in the following order:
  • 32 buttons
  • throttle and rudder
  • X and Y Axis
  • Z Axis
  • 2 Hat Switches
  • X, Y, and Z Axis Rotation

Simple Gamepad Example


Once the Arduino Leonardo or Micro has been tested using the JoystickTest example, I suggest making a simple gamepad controller. This controller will have five buttons: up, down, left, right, and fire.

Connecting the Buttons


Connect one end of each button to the ground pin. Connect the other end of each button as indicated below:

Arduino Pin Description
2
Up
3
Right
4
Down
5
Left
6
Fire

Sketch File


Upload the GamepadExample example sketch file to the Arduino Leonardo or Micro. This example is included with the Arduino Joystick Library.


Test


Open the game controller properties or use the joystick testing application of your choice to test the behavior of your gamepad.



Joystick Library API


The complete documentation for the Arduino Joystick Library can be found at https://github.com/MHeironimus/ArduinoJoystickLibrary/tree/version-2.0.