|
By Oleg Mazurov  A fragment of PS3 Bluetooth code
I’m quite pleased to announce that ever-popular Sony PS3 game controllers are now supported by current (rev.2.0) USB Host Library. Kristian Lauszus from TKJ Electronics developed a library to interface with Dualshock 3, as well as Move Navigation and Motion controllers via a Bluetooth dongle (only CSR-based ones are supported at the moment). This library has been merged into the main code and I will start maintaining it as soon as my Dualshock 3 arrives.
Sony PS3 controllers are advanced versions of ordinary HID joysticks. They can be interfaced via USB or Bluetooth, the buttons can be read as analog or digital and controller contains rumble motor which can be activated remotely to indicate a hit, for example. The controller also contains a gyroscope and accelerometers so it is possible to control a robot by simply waving and/or rotating the controller.
Kristian got his inspiration from Richard Ibbotson’s articles, as well as works by Tomoyuki Tanaka and others (full list can be found in PS3README file). His Wiki page gives implementation details, communication protocol, differences between controllers, as well as plenty of links to other sources of PS3 controller interfacing knowledge.
Kristian developed this library as a part of his Balancing robot project. The project is very well documented – if you are interested in robots, PID or remote control, please take a look. I also enjoyed watching this video presentation, give it a shot to see balancing robot in action.
Oleg.
By Oleg Mazurov 
While playing with some cheap USB to RS-232 converters which use counterfeit PL2303 chips I found a bug in acm code which was sitting there from initial release. This bug was causing sluggish response from serial devices, as well as random 0x0d and 0x06 error codes. The bug is now fixed and corrected version of the library has been posted on GitHub a moment ago.
As a side effect to aforementioned bug fix some new functionality is now available. First, ACM and PL2303 classes now have isReady() method which can be used to check if certain device has been enumerated, initialized, and ready for service. This method is now used in all sample sketches, see, for example, pl2303_tinygps.pde, line 98.
Another addition is a block of code which performs proper PL2303 initialization. It is a mix of Linux pl2303.c code and Windows Prolific driver USB protocol traces. This block was added during troubleshooting; it turned out that it doesn’t make any difference on PL2303-based devices that I have – either genuine or counterfeit. However, it is tempting to be able to simulate “proper” manufacturer-recommended behaviour in the code so I decided to keep the initialization. It is turned off by default; if desired, it can be added during compilation by defining PL2303_COMPAT (see cdcprolific.h, line 41 and cdcprolific.cpp, lines 159-179 ). The block adds ~500 bytes to the binary so don’t turn it on just in case.
Please check the new code with your devices and let me know if you can see any improvements or new issues.
Oleg.
By Oleg Mazurov 
Fresh update of USB Host Library 2.0 has just been posted to GitHub. The primary purpose of this release is to maintain compatibility with Arduino releases – the USB Host Library is now compiles in 1.0 as well as pre-1.0 versions of Arduino IDE. Enjoy!
Several important changes have been made to the code, some related to 1.0 compatibility and some not. The library examples were all tested and corrected, the information below is intended for developers using the library in their own projects:
- PL2302 driver.
Arduino 1.0 defines PL symbol internally (thank you, Paul for finding this out!), therefore, I needed to change name of Prolific class driver. The new name is PL2302 ; I updated library examples to compile correctly, if someone uses this class in their own development, the right way to define an instance of Prolific device is now PL2303 Pl(&Usb, &AsyncOper);
- NAK handling.
A bug preventing long polls of an endpoint has been fixed. Previously, if bmNakPower member of epInfo structure was left unitialized the transfer to this endpoint would stop after receiving a single NAK. With current version, the endpoint would be polled for up to 5 seconds. This is rarely desirable, so please initialize bmNakPower with USB_NAK_DEFAULT or USB_NAK_MAX_POWER . If a single poll is desired, as is often the case with interrupt endpoints, specify USB_NAK_NOWAIT and if more than maximum number of NAKs (up to 5 seconds) is necessary, specify USB_NAK_NONAK .
- Code speed.
An unnecessary delay of 20ms has been found (thank you, Alex for discovering this!) and removed from USB::setAddress() member function. As a result, every USB transfer is now 20ms faster. While generally a good thing, it could inadvertently affect data exchanges with slow endpoints. If after upgrading to the current version you start seeing more NAKs, that’s probably why.
One nice thing about Arduino 1.0 is built-in PROGMEM support for strings. It is now possible to free about 300-400 bytes of RAM by redefining USBTRACE and USBTRACE2 macros used in debugging output (thank you, John, for the tip!). For example, USBTRACE (Serial.print(F(s))) will move all USBTRACE strings to PROGMEM. The code size will increase so be careful with this feature if your code size is close to the limit for your Arduino board.
This is the end of announcement – download the code, play with it and if you have any issues please share your findings in the comments.
Oleg.
By Oleg Mazurov  ND-100S GPS receiver connected to USB Host shield
After posting an article about interfacing USB GPS receiver to Arduino I started receiving e-mails from people asking about a decent inexpensive GPS receiver compatible with USB Host library. After some research and testing I finally found a device which I really like.
ND-100S from USGlobalsat is small, inexpensive (less than $30 shipped at DealExtreme) GPS receiver with excellent characteristics. Below are some bullet points:
- Lightweight – my scale shows 19g for the dongle without connector cover. It is possible to get weight close to 15g by removing the case, USB connector and hardwiring the module to USB Host shield.
- Sensitive – SiRF Star III high sensitivity GPS chip allows this module to lock in less than a minute from my basement (!). Outdoor performance is simply amazing while power consumption stays around 50ma.
- Easy to use – the module uses Prolific PL2303 USB to serial converter supported by USB Host library 2.0 and the sketch from the previous article works without any modifications. Also, the module has status LED showing when GPS position is fixed – comes in handy during field tests when serial console is not available. The dongle ships with semi-rigid USB cable which can be used as a raiser.
Overall, ND-100S is very small, sensitive and inexpensive GPS receiver. It can be used with USB Host shield using PL2303 USB to serial converter support in USB Host library rev.2.0. I have a couple of projects in mind which would use this receiver – will post as soon as I have more information about it.
Oleg.
By Oleg Mazurov  CueCat connected to Android phone
Today, I’d like to show how to exchange data between USB device and ADK-capable Android phone. I will be using CueCat barcode scanner as source device; the data will be received by the phone and displayed on a screen using Arduino Terminal Android application.
A phone is USB device, too, and since two USB devices are unable to communicate to each other directly, I’m using Arduino board equipped with USB Host shield to relay data between devices. The sketch which runs on Arduino is a mix of two other pieces of code, one from ADK terminal emulator article and another one from an article explaining interfacing with a barcode scanner. Refer to these articles if you have questions about a specific piece.
Below is a full text of an Arduino sketch. It can be pasted from this page in Arduino IDE, compiled, and loaded into the board. It is also included in the examples section of USB Host library rev.2.0 distribution on gitHub. The library itself shall be installed in Arduino IDE tree as well.
To receive data from Arduino you’ll need Arduino Terminal application installed on your phone. The source code of application is also available – it is released under GPL2, if you make modifications to the code, please make them available for other people!
Finally, we will need some hardware – an Arduino board, USB Host shield, a USB hub, “declawed” CueCat or any other HID boot barcode scanner, as well as ADK-compatible Android phone. We will also need a 5V power supply capable of providing ~700ma of electrical current. I will show arrangement of all necessary pieces after explaining the sketch code.
Continue reading Exchanging data between USB devices and Android phone using Arduino and USB Host shield
By Oleg Mazurov  CueCat meets Arduino
Soon after posting Arduino barcode scanner article I started receiving questions about CueCat. Many of these cat-shaped devices were distributed free of charge in the US at the end of the dot com craze and even though company which developed and distributed them went out of business long time ago, the USB CueCats are still available for very reasonable price. Declawed CueCat with USB interface can be purchased for as little as $13 total in the US and non-modified ones for even less; at the same time, typical no-name handheld barcode scanner goes for around $25 on eBay and will be shipped from China.
I tested “declawed” USB CueCat with my code – it initializes as HID boot keyboard and works very well. No modifications are needed to the sketch from the previous article – just plug in the device and start scanning. CueCat reads many different barcode systems, including UPC and ISBN. Since CueCat is in constant scanning mode (no button needs to be pressed to initiate a scan), it can be used for applications like automated inventory control or as a part of a motion feedback circuit in CNC/robotics project.
One last advantage of CueCat I’d like to point out is low power consumption. As can be seen on a title picture, an Arduino, USB Host Shield, CueCat and HD44780-compatible LCD display can be run from a small LiPo boosted to 5V by Mintyboost from Adafruit Industries with its output connected to Arduino USB port.
CueCat is compact and inexpensive barcode scanner still available for sale despite being discontinued many years ago. It is implemented as USB HID boot device and supported by USB Host library. If you were living in the US in 2000, chances are you already have one or even several of these cat-shaped devices laying around – try it with my code and let me know if you have any issues.
Oleg.
By Oleg Mazurov  Cheap GPRS modem from Dealextreme
Some time ago I started writing about connecting Arduino to cellular network. Using standard GSM AT commands, a program running on Arduino can place and take calls, send and receive SMS, shoot pictures, access the Internet while monitoring phone’s battery level, signal strength and connection status. For many of these tasks any old phone works quite well, however, there are times when a specialized piece of hardware is desired. Today I’m going to talk about one such piece of hardware which can be connected to Arduino board using USB Host Shield.
USB Tri-band GPRS Modem from DealExtreme is just an ordinary GSM cell phone minus keyboard, display, battery, and built-in microphone/speaker. What is left makes inexpensive (~$25), lightweight (25 grams) and compact (see title picture) GSM/GPRS module to use in DIY projects. It supports a standard subset of GSM commands as well as some proprietary ones. The modem is built around BenQ M23 GSM/GPRS Wireless module and uses Prolific PL-2303 USB-to-serial converter. As explained on this page, the PL-2303 in the modem uses non-default USB PID; make sure to grab the latest version of my library, which transparently supports both PIDs.
To explore the functionality of this device I wrote a simple program which is based on Xbee terminal. The program initializes the PL-2303 and waits for user input passing keystrokes to the modem and displaying replies to the screen. Let’s run it and see what this little modem is capable of.
Continue reading Interfacing Arduino to USB GPRS modem
By Oleg Mazurov  Scanning barcodes using Arduino and USB Host Shield
An addition of Human Input Device Class support to USB Host Shield library 2.0, announced several days ago allows using powerful and inexpensive input devices with USB interface in Arduino projects. Sample sketches demonstrating sending and receiving data to one of the most useful HID device types – boot keyboard/mouse, has been released along with the library. The beauty of boot protocol lies in the simplicity of device report – a data packet containing information about button presses and mouse movements. However, samples were designed to demonstrate all features of the class and because of that, they are somewhat heavy. In real-life applications, it is often not necessary to implement each and every virtual function – only what is needed. In today’s article I will show practical application of HID boot device building a simple gadget.
Originally, HID boot protocol was meant to be used with keyboards and mice. When USB became popular, other keyboard-emulating devices, such as barcode scanners and magnetic card readers have been migrated from PS/2 standard to USB while keeping their keyboard-emulating property. As a result, many modern “not-so-human” input devices behave exactly like a keyboard including boot protocol support. A gadget that I demonstrate today is portable autonomous barcode scanner built using Arduino board, USB Host shield, handheld USB barcode scanner and LCD display (see title picture). The operation is simple – when handheld scanner button is pressed, it scans the barcode and sends it to Arduino symbol by symbol. Arduino then outputs these symbols on LCD display. LCD is erased before outputting each new barcode by tracking time between arrival of two consecutive symbols. To keep the code simple, I intentionally did not implement any data processing, however, since Arduino sketch for the gadget compiles in just a little over 14K, there is plenty of memory space left for expansion.
Continue reading Connecting barcode scanner to Arduino using USB Host Shield
By Oleg Mazurov  Focus Stacking Assistant var.Mini
After spending a week with focus stacking assistant I realized that I need more units. I’d like to have one unit dedicated for studio work, another to carry in camera bag and yet another one to control my Nikon (code for which I’m hoping to finish soon). Full-size Arduinos are big and expensive and I wanted this controller to be cheap and portable so I built my next controller using Arduino Pro Mini 3.3V, USB Host Mini, and a small home made PCB with buttons and LED. Finished mini-assistant can be seen on title picture and uses the same code as its big brother. What follows is a build log of mini-controller. It follows traditional layout, used, for example, here – a sandwich where Arduino Pro Mini sits on top of USB Host Mini. In addition to that, I needed to add another board on top of the sandwich to carry control and indication bits.
 Step 1. The base.
Continue reading Focus stacking assistant var.Mini – build log
By Oleg Mazurov  Focus Stacking Assistant
[EDIT] Here is a build log of mini-variant of this device.[/EDIT]
One of my favorite shooting techniques is focus stacking. Many pictures on Circuits@Home site are made using this technique. I use Helicon Focus for post processing and even though this program has camera control built-in, it obviously requires a computer close to the object of shooting. In order to be able to control my camera in the field, I wanted to replace a laptop with simple lightweight controller able to move focus of camera lens and take pictures between steps. In this article, I will show how to build one from Arduino, USB Host Shield and several small parts.
Finished circuit can be seen on the title picture. As you may already have guessed, the sequence of shots used to produce the picture has been made with the very unit depicted on it. Focus stacking assistant is controlled by 3 buttons: first moves focus towards the camera, second moves focus away from the camera, third button starts shooting sequence. Long press on focus move button sets “near” of “far” points, after both points are set shooting sequence can be run – it always starts from “near” point. The sequence can be stopped at any time by pressing on any of focus move buttons. It is important to understand that after a point is set, subsequent focus moves must be performed with focus move buttons only.
The controller can also be set to “free run” mode. Long press on third button starts shooting sequence from current lens position (which in this case can be set by hand using lens’ focusing ring) towards infinity and will run indefinitely. It can be stopped at any moment by pressing on a focus move button.
A single LED shows states of the controller. Short blink once a second indicates “idle” state – controller is connected to the camera, PTP session is open. Continuous frequent blinking means some kind of an error – most likely, controller not being able to initialize the camera or open PTP session. 3 short blinks act as a feedback to long press, focus move, etc. Additionally, more detailed diagnostic is output to Arduino serial console.
Even while connected to the camera, Focus Stacking Assistant allows camera buttons to function as usual. For example, camera LCD can be turned on and zoom area can be moved to the area of interest and then zoomed in to help focusing. Shooting mode, as well as aperture/shutter speed/ISO can be changed. It is also possible to access or erase images on the card and perform other manipulations as necessary.
Continue reading Focus stacking assistant for EOS cameras
|
|