Posts

Variable interface levels on FT232RL USB to serial converter

VCCIO

VCCIO


Here is a neat trick I learned today – changing FTDI FT232 interface levels on the fly. An ever popular FT232RL-based USB to serial converter typically comes in two varieties: one is configured for 0-5V logic levels on its TTL pins and the other one for 3.3V. It is usually done by connecting VCCIO pin of FT232 either to 5V coming from USB VBUS or 3.3V from FT232RL internal regulator. Both Sparkfun’s Basic Breakout and Adafruit’s FTDI Friend are made this way. This power arrangement works quite well for simple situations. For more difficult ones, it is possible to make this circuit more clever with a simple modification.

I’m currently working on a controller with battery backup. If regular 5V disappears, the MCU gets its power from a small lithium battery. Debug messages are sent to a PC via UART and I need to see them in both modes of operation, the most interesting being events which occur during the power switch. For the reference, ithium battery through a Shottky diode gives ~2.9V.

That’s how I handle this: The VCCIO pin is disconnected from the rest of the circuit and connected directly to a power pin of the MCU. Since voltage on VCCIO defines the TTL level, the serial communication is functional throughout the whole voltage range of my system. Title picture shows the implementation. I’m using very old Sparkfun “full” FT232RL breakout board, where all pins are available on the side headers. More compact “basic” boards can also be used by simply opening both sides of the power selector jumper and using pad named ‘VCC’ or ‘POWER’ (the pad which is typically used to provide power to the MCU) to connect to MCU power.

I have tested the functionality down to 2.7V and everything works quite nicely. I haven’t checked the datasheet for VCCIO voltage limits but I would imagine it should stop working at about 1.8V. In any case, undervoltage shouldn’t cause any damage to the chip.

Oleg.

Xbox360 controller support added to USB Host Shield 2.0 library

xbox360 announcement

xbox360 announcement

Kristian Lauszus from TKJ Electronics made another contribution to USB Host Shield 2.0 library – support for Microsoft Xbox360 game controller.

Files XBOXUSB.cpp and XBOXUSB.h contain the main functionality. An example sketch (a screenshot of which was used for the title picture) can be found in the examples directory. Also, check the EXTRAREADME file for additional information as well as Kristian’s github page.

I’d like to note that Kristian is a developer of support code for Sony controllers – Dualshock 3, Navigation, and Motioncontroller – in the current version of the USB Host library. The Xbox360 code
is another nice contribution. Once again – thank you Kristian!

Oleg.

MIDI support for USB Host 2.0 Library

usb code

usb code

This is a short announcement for those who might have missed a recent comment to this post. Yuuichi Akagawa developed USB MIDI driver for USB Host 2.0 library and made it available on gitHub. The repository has source code, single and multiple device examples, function reference and supported device list.

Thank you, Yuuichi, for your great contribution!

Oleg.

Advanced brushless DC motor controller

BLDC rev.0

BLDC rev.0

I got pretty tired of coding recently and had to switch my brain to something as distant from USB protocol as possible. Also, I’ve being planning a quadcopter build for which I need a motor controller less basic than PPM-driven R/C electronic speed controller AKA ESC. I needed something fast, reliable and scalable and at the same time not too hard to understand. After studying several existing open source designs I decided to make my own. This article is a status report of testing the initial prototype of sensorless brushless DC motor controller.

The prototype can be seen in the middle of the title picture (click on it to make it bigger). The green board contains a controller ( Allegro A4960 ) plus power stage – 6 N-type MOSFETS. In addition to performing typical control functions – setting speed and direction of 3-phase brushless sensorless DC motor, this controller also has a tachometer and fault indicator outputs as well as number of configuration registers available via SPI interface. The controller IC consists of 2 main functional blocks – a logical interface and power bridge driver. The former is compatible with 3.3V and 5V logic and the latter is specified in 5.5V-50V range (startup is possible from as low as 6V), making it suitable for projects ranging from 2S LiPo-powered models to electric scooter drives.


Continue reading Advanced brushless DC motor controller

Interfacing PS3 controllers to Arduino via wired USB

ps3 usb code

ps3 usb code

This is a short announcement about a new feature added to USB Host Shield 2.0 Library. Kristian Lauszus from TKJ Electronics developed and contributed code for interfacing to several Sony PS3 game controllers and has been working on refining it for several months. Two days ago he posted a pull request on GitHub with the following comment:

I don’t know if you could post it on your blog too, so people will know that it now also supports the controllers via USB?

Since the beginning, Kristian concentrated on Bluetooth interface for the controllers. This is the preferred way, however, the standard wired USB interface is as good as Bluetooth dongle plus it is 100% compatible. Take a look at this example showing how to initialize PS3 controller and access its buttons, joysticks and accelerometers.

Kudos to Kristian for this nice piece of code!

Oleg.

Using Logitech Extreme 3D Pro joystick with Arduino HID library

Logitech joystick connected to Arduino

Logitech joystick connected to Arduino

HID report parsing explained in the previous article works pretty well with properly aligned HID reports. The analog controls are placed on a byte or word boundary and buttons occupy dedicated fields. The majority of HID devices are designed this way, however, some other devices are not that simple to interface and today I’m going to show how to handle one of those.

A Logitech Extreme 3D Pro joystick is one nice HID device. It is good looking, well-built, and have a twist handle, which adds third axis to a stick making this model popular among FPV fliers since you can control pitch, roll and yaw with one hand. Also, X and Y axis are 10 bits which gives good precision. There is one problem with this joystick – its input report.

Logitech, in its infinite wisdom, decided to pack all the high and low resolution analog controls plus 12 buttons in 6 bytes of input report. The report looks like this – 10 bits of X, 10 bits of Y, and 4 bits of hat switch. After that, things become easier – one byte of Rz AKA “twist handle”, one byte of buttons, one byte of throttle (called “slider” in the report), and finally, one partially filled byte holding the rest of the buttons. Take a look at the screenshot below – two most important controls are not byte aligned, therefore, simple straightforward parsing of the report is not possible. Also, USBHID_descr won’t show this report correctly.

To demonstrate how to deal with this report I wrote a simple Arduino sketch. It was made by modifying an example from the previous article. I also made it as simple as possible – as soon as any of the controls changes its value, new report is printed on the serial terminal. The sample output is shown below followed by code explanation.

Continue reading Using Logitech Extreme 3D Pro joystick with Arduino HID library

Adjusting inverter control in Tektronix 7104 oscilloscope power supply

Access to 109V test point

Access to 109V test point

In this short article I want to share a trick that I learned today while checking the power supply of my trusty Tektronix 7104 oscilloscope. Step A2 of calibration section of the manual calls for measuring/adjusting of pre-regulated 109V voltage on TP1326 test point. Typically, test point access for this step requires removing power supply cover which takes time and exposes high voltages. The test setup presented on a title picture( click on it to make it bigger) shows how to access this test point leaving power supply cover in place.

The power supply cover is at ground potential so don’t try to reach the test point with non-insulated probe. I used Tektronix Klip Chip IC probe threaded through nearby ventilation hole to grab the test point post. The post is clearly seen through a larger hole, through which an adjustment potentiometer R1293 is usually accessed. A flashlight is handy.

Next picture shows the closeup of the test connection. A test probe is supported by a “Third Hand” thingy – I wanted to observe voltage fluctuations in the course of two hours to make sure it stays within limits.

I’m hoping this trick will be useful for somebody dealing with similar power supply.

Oleg.

Developing Arduino code for HID Joystick

This article focuses on how to use the existing USB code library and HID report descriptor info to implement joystick functionality.  Human readable HID report descriptor and report information can be easily obtained using USBHID_desc.pde sketch – see previous article for details. This information will help you getting field details such as size and count info. Also, if you don’t have Arduino Mega or 2560 to run USBHID_desc, report descriptor for your device can be obtained using one of many PC tools known as USB analyzers, or even the official usb.org device verification tool. This article is written by Alex Glushchenko – a developer behind second revision of USB Host Library as well as majority of device support code.

As you may already know report is a data structure used by HID device to return the information about the certain device parameters such as joystick coordinates or button events, or receive new settings such as switching on/off LEDs on keyboard.  

Report descriptor is a data structure which describes report or reports, if there are few in number, field sequence, sizes and counts.  Each report descriptor consists of several items. Each item describes some field property. I am not going too deep into details on items, explaining only the most important ones which are absolutely necessary in writing your own report parser.  

The items usually describe type of field (input/output/feature), minimum, maximum field values, units, value meaning (usage) etc.

Continue reading Developing Arduino code for HID Joystick

Visualizing HID device reports and report descriptors

Screenshot of USBHID_desc sketch output
Human Interface Device class of USB devices has a unique property – a report descriptor which contains information about data that device is sending to the host as well as data that can be sent to the device. This property allows for variety of devices – keyboards, mice, joysticks, digital scales, uninterruptible power sources, GPS receivers, and even toy missile launchers to belong to a single class – HID. A vendor just needs to pick a usage table which contains controls similar to vendor’s device – every OS has a generic support for HID devices so in most cases specific device driver is not necessary. The report descriptor again makes this possible – it contains definitions or report fields therefore a generic parser can process reports from any arbitrary HID device. However, this generic parser will take too much space on small microcontroller systems such as Arduino due to the amount of constants that needs to be present in the program code.

It shall be noted that a HID report itself is a simple structure of fixed fields and when this structure is known a very lightweight parser can easily be developed. HID development in legacy USB library has stopped at this point; I thought people will just take a look at the spec and write report parser for their device. It soon became evident that very few are actually willing to do this and in rev.2.0 of the library the HID report parsing is semi-automatic – a report descriptor has to be analyzed first using USBHID_desc utility presented in this article and then actual reports for the device can be parsed using library facilities (an article about coding report parsing is here).

Continue reading Visualizing HID device reports and report descriptors

Simulating cable disconnect on USB Host Shield 2.0

A MOSFET controlling VBUS

A MOSFET controlling VBUS


Today I want to show a simple USB Host Shield 2.0 modification which allows controlling power to USB peripheral. I learned this technique from Camille’s comment to one of digital camera USB control articles. In short, the idea was to cut VBUS connection between USB host and peripheral, simulating disconnect state. P-channel MOSFET, inserted into VBUS, worked as a switch. I designed this capability into USB Host Shield 2.0 but never needed the functionality therefore this useful feature was left undocumented. Recently I started working with very interesting Nikon P&S camera which can be turned on and off with VBUS power so I finally made this modification. It is very simple.

Take a look at the title picture (click on it to make it larger). The modification uses existing VBUS power select pads of the shield. Out of the box, the one labeled 5V is shorted with solder bridge. First step is to remove this bridge with a solder wick so both pads are clean.

It can be seen that a MOSFET in SOT-23 package fits nicely on those pads (I’m using FDN306P). Drain and source pins are soldered to VBUS and 5V, respectively, and gate, which hangs in the air, is routed to an unused digital pin via an 1M resistor. When digital pin is low the MOSFET conducts. When digital pin goes high the MOSFET switches off disconnecting VBUS from the peripheral.

If you are going to drive high-power peripherals, like digital cameras or phones, it is a good idea to add some capacitance to 5V. I’m using 220uF low-ESR organic polymer tantalum cap in 1210 package which fits nicely on 0.1″ spaced 5V and GND pins of the shield; an ordinary leaded 100-200uF aluminum capacitor will work as well.

Oleg.