Posts

GitHub repository for USB protocol traces

Beagle Analyzer USB hub  trace

Beagle Analyzer USB hub trace


I’m the proud owner of Totalphase Beagle USB 480 protocol analyzer. It helps tremendously in debugging USB code and the software which translates binary traces into human-readable form is free allowing sharing the trace files. Some time ago I needed to capture and share analyzer traces of certain Bluetooth dongles with developers of USB Host Shield 2.0 library. Instead of sharing the traces privately I decided instead to put them into another GitHub repo for everyone to see and learn.

At the moment, the repository contains just a handful of Bluetooth traces, captured on Windows and Linux machines. I will be expanding the repo with other interesting traces generated during my development. Also, if anyone wants a trace from a device not already in the repo – just ask.

Enjoy,
Oleg.

HID support for USB Host Shield Library 2.0 released

HID r.2.0 released

HID r.2.0 released

I pleased to announce that after a long and difficult development period Human Input Device AKA HID class support has been added to USB Host Shield Library r.2.0 and is available on gitHub – I suggest downloading the whole directory, since some modifications has been also made to core files to accommodate a new class. HID devices include popular devices like keyboards, mice, joysticks, game controllers, bar code scanners, RFID and magnetic card readers, digital scales and UPSes, to name a few.

I previously wrote about interfacing to HID devices here, here, and here. The code examples in these articles were written for legacy USB Host Shield library and can’t be compiled with current revision, however, the basic principles are the same – the device is periodically polled by the host and sends back data block called report containing changes in device controls (buttons, switches, jog dials etc.) since the last poll. Even though different devices have different report formats, for a certain device, report format is stored in the device in data structure called report descriptor. Therefore, it is possible to learn about device controls from the device itself by parsing its report descriptor.

There is one special case where report format is known in advance. Almost all HID keyboards and mice support so-called boot protocol intended for communication to very simple systems like PC configuration screen when computer runs from BIOS. Keyboard boot protocol report consists of 8 bytes containing state of modifier keys (CTRL, SHIFT,etc.) in the first byte, second byte being reserved, and up to 6 key scan codes in the rest of the report. Mouse boot protocol report consists of 3 bytes, first of which contains state of left, right and middle buttons and other 2 store X and Y travel since last poll.

In many cases boot protocol capabilities are more than enough for an Arduino project; for this reason, boot protocol class is the first to be released. To demonstrate operations of this class, 2 simple sketches has been developed, one for mouse, another for keyboard.

Continue reading HID support for USB Host Shield Library 2.0 released

USB Host Shield 2.0 released

USB Host 2.0 connected to Arduino Mega 2560

USB Host 2.0 connected to Arduino Mega 2560

A major revision of USB Host Shield for Arduino has been released and is available in the store. The board’s improved layout makes this shield compatible with more Arduinos, makes it easier to use and opens new possibilities. The main differences from rev.1xx are outlined below:

  1. The SPI interface has been moved to ICSP header making shield compatible out of the box with “big” Arduinos – Mega and 2560. Standard size boards, such as Duemilanove, UNO, as well as clones with classic connector layout, are also compatible with this revision of the shield. This compatibility is maintained on a software level as well – all necessary code changes are performed using conditional compilation preprocessor directives.
  2. USB connector has been moved to the opposite side of the board. All external connectors are now in the same place making enclosure layout easier.
  3. MAX3421E RESET line is no longer handled by dedicated Arduino pin. While MAX_RESET pin is still used in current version of USB Host library, it will be dropped from the next major revision of the code.
USB Host Shield 2.0 with AVR Dragon

USB Host Shield 2.0 with AVR Dragon

Besides “Mega-formfactor” compatibility, connecting to Arduino SPI signals on ICSP connector has several advantages. First of all, in this layout traces are much shorter and as a result, the shield works more reliably at higher SPI speeds and/or larger signal and power noise. Second, since the 2X3 connector, which comes bundled with the shield, is of ‘stackable’ variety, it is possible to connect AVR Dragon or other ICSP programmer to Arduino while USB Host Shield is mounted – picture on the left shows the arrangement. Finally, pins 11-13, occupied by SPI signals on “classic” Arduinos, are vacant on Megas and also uncommitted on the shield. Therefore, they can be used for other purposes without USB library code modifications.

The shield comes in 2 configurations. One, called “Standard” is compatible with official full-size Arduino boards (Duemilanove, UNO, Mega, Mega 2560, and possibly others), as well as clones which supply both 3.3V and 5V to the shield. One example of such clone is BlackWidow; if you are aware about other compatible clones, please let me know.

Another configuration, called “3.3V” is designed for battery-operated projects. It is compatible with Sparkfun’s Arduino Pro 3.3V board (I’m not aware of any other 3.3V-only full-size clones). It also supplies 3.3V to VBUS instead of spec’d 5V, therefore some bus-powered devices may function erratically (but not necessarily; I actually use bus-powered USB flash drive during final testing of production 3.3V shields). Self-powered devices, such as digital cameras, usually don’t care about VBUS voltage at all. Additionally, board layout makes it possible to mount external power supplies to generate 5V from 3.3V and vice versa, if necessary.

The shield is compatible with current version of USB library. It is also very similar to rev.1.xx shield and information from previously posted articles is mostly valid for 2.0 board. Schematic and Eagle CAD files are also available for download. I am currently working on detailed description of the shield and hoping to get it ready in a week or two.

Along with this shield I will continue producing rev.1.21 board – there are still “not-so-compatible” Arduino clones around. However, next major revision of USB library will not be compatible with rev.1xx shields; it will be possible to make it work after minor hardware/software modifications.

As always, your questions and comments about the product are welcome and appreciated.

Oleg.

Canon Powershot camera control project

Sandro Benigno from DIY Drones released camera control code for Arducam project. The goal of the project is to control Powershot camera mounted on UAV while feeding camera’s video output back to operator. Telemetry from UAV will also be sent back mixed in video using MAX7456 OSD ( on-screen display ) generator IC. Needless to say, I’m very interested in camera control side of this project.

The capabilities of the code can be seen in a video above. From my experience, Powershot cameras use identical control commands for different models so this code would work with other cameras with no or very minimal changes. For example, I tested it on my A640 and it works just fine. On the other hand, not every Powershot camera can be controlled over USB; suitable model numbers can be deduced from this gphoto list.

The project-related discussion is hosted on DIY Drones.

USB Host Mini in store

USB Host mini in test fixture

USB Host mini in test fixture

The first batch of USB Host Minis is built, tested, and boards are available in store. It is designed to be employed in lightweight, battery-operated circuits, for example, used for digital camera control. It can also be used as general MAX3421E breakout board. Title picture shows the board proudly sitting in its’ own ghetto-style Sparkfun-inspired pogo bed.

The design follows Arduino Mini minimalistic approach. It is 3.3V only and mates quite nicely with Sparkfun 3.3V Arduino Pro Mini. Only essential control and GPIO signals are available – no power supplies, level converters, or even jumpers are provided due to lack of space. However, since rearranging control signals is often necessary, extra pads have been placed for this purpose. They can be seen on product picture at the top and to the left of MAX3421E IC.

The board has VBUS routed to 3.3V. Even though the voltage is lower than specified 5V, the shield has been tested to work flawlessly with numerous self-powered devices, such as digital cameras, as well as some bus-powered devices, such as Sandisk Cruzer flash drive. However, if 5V VBUS is necessary, board can be easily modified – the trace from 3.3V to VBUS can be cut and 5V applied using a pad placed on the board for this purpose. It can be arranged using single 5V supply; since Arduino Pro Mini has on-board LDO, 5V can be applied to VRAW and VBUS while shield will be getting its’ 3.3V power from Arduino board, as usual.

Bottom picture shows my favourite arrangement – Arduino Pro Mini sits on top of the shield with its’ programming connector easily accessible from either side. Also, Arduino reset switch is easily accessible this way.

Project files and schematic are available in Downloads section. If you have any questions about this design, e-mail me or leave a comment here.

Oleg.

USB Host Mini and Arduino Pro Mini

USB Host Mini and Arduino Pro Mini

Digital camera control using Arduino USB Host Shield. Part 2 – Canon EOS Cameras.

ptptask2
New version of PTP Library for Arduino USB Host Shield has been posted on GitHub. In this version, PTP::Task() has been completely rewritten to provide for non-blocking state machine-type execution. Another major addition is comprehensive support for Canon EOS cameras – many camera functions including changes of shooting parameters, Live View, focus move, are now well understood and supported. The library is released under GNU General Public License version 2.

In addition to the code library, a manual page has been created outlining EOS-specific extensions to PTP protocol, a code example, and library reference. Similar page for basic PTP functions is planned also.

The code is stable (more or less) and no application interface changes are planned at this moment. It is, however, incompatible with an old version, which is preserved in “legacy” branch of GitHub repo. The camera interface has not changed much and migration of old projects should be easy. If you have issues with migration, comment below and I will try to help.

Oleg.

Arduino USB Host Mini – first prototype.

First prototype of USB Host Mini

First prototype of USB Host Mini

This is the status update on Arduino USB Host Mini development, announced 3 weeks ago. I received rev.0 PCBs last Saturday – BatchPCB is faster than ever! I made a test build (see title picture) and after fixing one major and several minor mistakes placed an order for what I’m hoping will be the final pre-production sample.

The prototype was built to sit on top of Arduino Pro Mini to make access to the parts easier during troubleshooting. On the final board USB connector is placed slightly further away from the pins; it will be possible to place Arduino on top of the shield so that the height of the “sandwich” will be less or equal to the height of USB connector.

In 2-3 weeks I’m hoping to finalize the design and start producing the USB Host Mini. Stay tuned!

Oleg.

Controlling robotic arm with Arduino and USB mouse

Many people asked me to post a video showing an arm from inverse kinematics article in action. While making a video, I realized that shots of the arm following a pattern of computer-generated coordinates is going to be less than exciting and decided to add manual control. The video below shows the result. In addition to the video, a HID introductory page has been written describing HID communication basics as well as some simple Arduino code. Enjoy! ( Youtube link, where HD quality video can be selected ).

Arduino sketch written for this video is on gitHub.

Arduino USB Host Mini – initial revision

USB Host mini rev.0

USB Host mini rev.0

This post announces starting of development of new Arduino USB Host Shield variant. There are several projects in the works (thanks, guys for letting me know!), where standard size Arduino board is too big. Since electronics of USB Host Shield is pretty simple, it was decided to shrink the board as much as possible. Here is the first iteration.

The initial revision of USB Host Shield in Mini form factor is shown on title picture, It is intended to be used with Sparkfun’s 3.3V Arduino Pro Mini. Intended applications include digital camera control devices, robots, as well as any other projects where size and weight has to be minimized. The Gerbers was sent to BatchPCB; I’m expecting boards back in couple of weeks. The main goals of this first prototype are manufacturability check as well as checking claims made below.

The Mini Host is simplified version of full-sized shield; only USB and GPIO are available. By default, VBUS is routed to VCC, therefore only self-powered USB devices are expected to function (even though I have at least one USB flash drive which works fine powered from 3.3V VBUS). I also provided extra pads to simplify signal re-routing, however, since there was no place left for jumpers a trace has to be cut instead. The same has been arranged for VBUS – if 5V power is necessary, Arduino Pro Mini/Shield combination can be powered with 5V on RAW pin, the VCC trace cut off VBUS and RAW and VBUS connected.

As soon as first prototype is tested, I will post CAD files and also make boards available at BatchPCB. Stay tuned!

Oleg.

Towards an FT232 Driver for the USB Host Shield- Part 0

FTDI232RL IC on a breakout board

FTDI232RL IC on a breakout board

Based on some discussion on the Arduino Forum, Richard has added this blog entry as work in progress on developing a library to support FTDI Serial port devices on the USB Host Shield. While cautious to publish at this early testing stage, the content here should help parallel developers.

My thoughts last year were that an FT232 driver for the Host Shield was not really useful. It seemed rather reverse to add a USB host plus a USB device to achieve something that can be done with a piece of wire. However USB is coming to be the baseline interface and is now the only interface offered on many serial devices.

USB Shield Hardware
Since my last blog update, Sparkfun have released their own version of the USB Host Shield. Great to have another source of the shield, with good stock at many International Sparkfun distributors. However they did add a couple of problems too:
Sparkfun swapped the RESET and the GPX pins from the original from Oleg. This means the shield will not work with the libraries from Oleg without a modification.
The current Max3421e_constants.h from Oleg has:

/* Arduino pin definitions for USB Host Shield signals. They can be changed here or while calling constructor */
#define MAX_SS 10
#define MAX_INT 9
//#define MAX_GPX 8
#define MAX_RESET 7

These work for the shield from Oleg, and existing published code and libraries without change.

However for the Sparkfun Shield they must be changed in Max3421e_constants.h, or optionally changed when the constructor is called to:


#define MAX_SS 10
#define MAX_INT 9
//#define MAX_GPX 7
#define MAX_RESET 8


Continue reading Towards an FT232 Driver for the USB Host Shield- Part 0