Bluetooth SPP with Android


Android has had Bluetooth (BT) Serial Port Profile (SPP) server and client capability since API Level 5 (version 2). Two Android devices, one acting as a server and the other as client, can communicate over BT SPP.

bt-spp-server

Bluetooth SPP Server Terminal app allows you to simulate a BT SPP peripheral. I used it recently to simulate a Push-To-Talk button for an app called Zello running on another Android device.

Bluetooth Terminal is an open source app that can be used to create a BT SPP client connection with other devices, and exchange text and binary data.

USB Serial firmware for ATmega32U4


This post shows how to create USB Serial firmware for the ATmega32U4 found on Adrafruit’s excellent breakout board, using Atmel Studio 7. The design of the breakout board is available at GitHub, so is the Fritzing part used in the figure below. The source code of the USB Serial firmware discussed here can also be forked at GitHub.

Screen Shot 2016-10-28 at 10.02.24.png

Source code

Creation of source code with Atmel Studio 7 is described in post Arduino USB Serial firmware from scratch. Choose adafruit_u4 as the board for LUFA Board Support (driver).

The code has been adapted to blink the same LED when receiving and transmitting data, because the breakout board has just one LED to indicate that.

Flash using JTAGICE3

See the wiring diagram above to see how JTAGICE3 can be wired to the ICSP header on the breakout board. The Device Programming dialog can then be used to program flash memory on the MCU as shown below.

screen-shot-2016-10-28-at-10-27-19.png

Test

The converter can be tested by using another USB Serial converter connected to RX and TX wires shown in the wiring diagram. Note that the wire ending with TX should be connected to RX on the other converter, similarly the wire ending with RX should be connected to TX.

Troubleshooting tips

The breakout board ships from Adafruit in USB powered mode. That makes it ideal as a USB Serial adapter because it can be powered from the PC it is plugged into.

If your USB host device does not provide enough current on VBUS, you can cut the VCC solder jumper on the other side, and provide 3.3V at the VCC header pin.

Screen Shot 2016-11-14 at 12.11.11.png

Atmel has a detailed application note on USB that has recommendations you should take into consideration in your designs.

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 http://127.0.0.1:8080/Callback.

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…).

lufa-install

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.

usb-serial-lufa.png

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

usb-serial-project.png

usb-serial-project-board.png

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

usb-serial-asf-wizard.png

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

usb-serial-symbols.png

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.

usb-serial-flip

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).

lufa-install.png

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

dfu-lufa-example.png

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

dfu-optimize-for-size.png

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

dfu-jtagice3.png