OAUTH 2 with google-oauth-java-client

This post is a quick reference for running the dailymotion-cmdline-sample, a Java console sample app for the google-oauth-java-client OAUTH 2 library.

The sample app performs authorization code grant specified in the OAUTH 2 RFC, and receives user’s authorization code via an embedded Jetty HTTP server. That code is then exchanged for an access token.

Clone the google-oauth-java-client repo at GitHub.

git clone git@github.com:google/google-oauth-java-client.git

Install Apache Maven if you don’t already have it. You’ll need Oracle’s JDK to use Maven and compile the sample app. On Mac OS X Maven can be installed using Homebrew.

brew install maven

Head into the cloned repo and compile.

cd google-oauth-java-client
mvn compile

Head into the sample app folder and execute the sample app.

cd samples/dailymotion-cmdline-sample
mvn -X exec:java -Dexec.mainClass="com.google.api.services.samples.dailymotion.cmdline.DailyMotionSample"

The first execution will fail. You’ll need to create a dailymotion.com developer account, which can be created at http://www.dailymotion.com/profile/developer. Create a new API key. The only value that really matters is the Callback URL which should be

Enter your API credentials in rc/main/java/com/google/api/services/samples/dailymotion/cmdline/OAuth2ClientCredentials.java. Compile and exec again. The application should list your favorite videos if all goes well.

Arduino USB Serial firmware from scratch

I have need to change the USB descriptors of the Arduino Uno R3, for a project that will have it acting as a peripheral to another device.

This post documents how you can make from scratch the USB Serial firmware for ATmega16U2 on the Arduino Uno R3, using Atmel Studio 7 and its LUFA Library extension. It can be flashed quite easily using the built-in DFU firmware and Atmel’s FLIP tool. Source code is available at GitHub.

Install LUFA Library extension if not already installed (Tools -> Extensions and Updates…).


Source files that perform the actual USB/serial proxying are reused from USB to Serial Converter example project for at90usb1287 (File -> New -> Example Project…). Go ahead and create that project and grab the files. Some additions to the USB/serial code such as allowing a sketch to be uploaded from the Arduino IDE, have been taken from the official source code at GitHub.


Create a new project for the ATmega16U2 (File -> New -> Project…).



Use ASF Wizard (ASF -> ASF Wizard) to add LUFA modules and remove the Generic board support (driver) module.


Configure GCC symbols (Project -> Properties). Change BOARD to BOARD_UNO, and add F_CPU=16000000UL, and F_USB=16000000UL.


Resolve build errors by mostly eliminating code. Source code that builds without errors is available for comparison at GitHub. Program (Tools -> Device Programming) the firmware using the FLIP tool.


Reboot the Arduino.

Arduino USB DFU firmware from scratch

The Device Firmware Upgrade (DFU) firmware for the ATmega16U2 on Arduino UNO R3 is used to flash the USB Serial firmware, among others, using Atmel’s FLIP tool.

This post documents how you can build from scratch DFU firmware using Atmel Studio 7 and its LUFA Library extension. You’ll need an ISP/ICSP programmer to program the ATmega16U2.

You can install the LUFA extension from the Extensions and Updates dialog (Tools -> Extensions and Updates).


Create a new project based on the DFU Bootloader example (File -> New -> Example Project…).


Change the compiler optimization setting to -Os in toolchain properties (Project -> Properties).


Build the solution and flash (Tools -> Device Programming) using an ISP/ICSP programmer connected to the ICSP2 header.



Unbricking a JTAGICE3

Atmel Studio 7 prompted me to upgrade a JTAGICE3 tool recently. I went ahead with the upgrade since I couldn’t use the tool without it, and I have done it with the JTAGICE mkII on several occasions. After the upgrade was successfully completed, I found the JTAGICE3 in a state that is generally referred as bricked.

I left it aside for a couple of weeks until I decided to visit AVRFREAKS, and found a solution.

You’ll need to put JTAGICE3 in bootloader mode. Short the pads highlighted in the image below, and plug it in.


Then, from Windows command line run

C:\Program Files (x86)\Atmel\Studio\7.0\atbackend>atfw -t jtagice3 -a "C:\Program Files (x86)\Atmel\Studio\7.0\tools\JTAGICE3\jtagice3_fw.zip"

USB Descriptors of Arduino UNO

I’ve been studying the USB interface of Arduino UNO so that I can interface it to an embedded host. It appears as a serial port on Linux, OS X, and Windows 10, without need for custom drivers. The Arduino IDE can reprogram the device over the serial port. Makers also use it to output debug information.



Here’s the detailed device descriptor as seen on Linux with lsusb -v

Bus 001 Device 005: ID 2341:0043 Arduino SA Uno R3 (CDC ACM)
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            2 Communications
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0         8
  idVendor           0x2341 Arduino SA
  idProduct          0x0043 Uno R3 (CDC ACM)
  bcdDevice            0.01
  iManufacturer           1
  iProduct                2
  iSerial               220
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           62
    bNumInterfaces          2
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0xc0
      Self Powered
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         2 Communications
      bInterfaceSubClass      2 Abstract (modem)
      bInterfaceProtocol      1 AT-commands (v.25ter)
      iInterface              0
      CDC Header:
        bcdCDC               10.01
      CDC ACM:
        bmCapabilities       0x06
          sends break
          line coding and serial state
      CDC Union:
        bMasterInterface        0
        bSlaveInterface         1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval             255
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass        10 CDC Data
      bInterfaceSubClass      0 Unused
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x04  EP 4 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               1

Interface descriptor with class Data Interface Class (bInterfaceClass=0x0A) is used for serial communications. Endpoint with bEndpointAddress 0x03 is used for input, and bEndpointAddress 0x04 for output.