The code supporting USB Mass Storage Class of devices has been added to USB Host Shield 2.0 library and is available to download on GitHub. Mass storage devices include USB Flash drives, memory card readers, external hard drives/CD-ROMs, smartphones/tablets, and some others – almost anything that shows as a drive while connected to a PC (exceptions are digital cameras as well as some phones pretending to be digital cameras). Andrew Kroll (who made this release possible) – thank you very much!
At present, the code example, also featuring Andrew’s FAT and extended memory implementation, can only be run on “big” Arduinos such as Mega and Mega 2560. Another FAT implementation, developed by Alex Glushchenko, is being tested – there is a slight possibility that at least some functionality can be demonstrated on a regular UNO board. On the other hand, the mass storage component can be used without a file system by simply reading/writing physical sectors; this approach can save a lot of memory. The documentation for the mass storage class code is available here.
Many hours has been spent testing the code; it should work with any device which claims to support “mass storage bulk only” transport. While newer (less than 5 years old) won’t cause any problems, older ones could be finicky. If your device shows odd behaviour with this code, please let me know – I will trade it for the good working one.
Allan Caplan sent me a write-up and pictures of putting together headers on USB Host Shield 2.0. The post can be used as an assembly guide for the shield. The following text and pictures were taken straight from Allan’s Evernote which he kindly shared with me and gave me permission to repost. I just wanted to add that after assembly is is a good idea to load and run the quality control routine to make sure the shield works.
Assembling the USB Host Shield (v2.0) is pretty well straight forward, even without instructions. Some people have complained about the lack of instructions, so here goes. This guide assumes you are familiar with basic soldering techniques, and basic Arduino know-how.
1. Unpack the shield. You should see something similar to this: two 8 pin headers; two 6 pin headers; one 2X3 pin header
2. Insert the pins. It should be explanatory where they go – along the outer rows, one side has two banks of 8 and the other has 2 banks of 6. Now, if you have a third hand this may get easy. When I do soldering like this I like to insert all the headers and turn the card upside down, like this:
6x and 8x headers from the bottom
3. Before you start soldering, make sure the header you are working on is straight!
4. Did you check that your header is straight?
5. OK, go ahead and solder. I like to work on each header at a time, making sure it’s straight before starting. Once done, you should have something that looks like this (from the top)
6x, 8x headers from the top
6. Time for the 2×3 header. Insert it like so. Again if you have a third hand this will be easier, if you don’t make sure your header is straight before soldering!
7. That’s it! If you did things correctly you should have a functioning USB Host Shield! Go ahead and fit it on your Arduino board (make sure it’s straight, I didn’t realize mine was crooked in the picture)
Final alignment check
8. You just soldered, clean up your workspace and go wash your hands.
9. Find the instructions for uploading software and running the QC program.
USB Host Library Documentation
This is short but very important announcement. Kristian from TKJ Electronics started a documentation project – here is the link to the post on his blog. Kristian configured Doxygen and set up the framework to build the documentation from the source code of the library. In addition to all that, Kristian documented all the code he has contributed to the USB Host library 2.0. Results can be seen here.
Documenting a function is now as easy as adding a specially-formatted comment at the beginning of the function. In the near future, I will start adding comments to the core USB functions as well to help people understand the internals of the library. It is going to take a bit of time to document everything but even what is available now is a very good beginning – thank you, Kristian!
Discovering Arduino Bluetooth
This is a second article about Bluetooth connectivity using USB Host library for Arduino. Previous article described Android connectivity
; today, I will show how to connect an Arduino to a Windows machine using USB Host Shield ( available at the store
) and USB Bluetooth dongle.
The biggest issue with Bluetooth on a Windows machine is third-party Bluetooth stacks. They all work well but behave slightly differently and it is not possible to write a step-by-step walkthrough valid for any Windows PC. My setup is 64-bit Windows 7 with Broadcomm Bluetooth stack; other Windows versions and Bluetooth stacks will be slightly different.If you have any difficulties following the text, leave a comment and I’ll try to help. Also, Bluetooth protocols time out very quickly – 5-10 minutes, sometimes less. If you get a timeout at any step simply start over again; sometimes, resetting Arduino may be necessary.
First thing that needs to be done is to make a working Arduino setup. Previous article on the topic gives plenty of information about necessary gear, compatible Bluetooth dongles and expected terminal output. Once this is done, install Bluetooth on Windows. On Win7, the installation consists of plugging in a Bluetooth dongle to USB port and watching the progress of installation process which will start automatically. At the end of the installation system will give you the warning that your PC is not discoverable – ignore it. If installation is successful a Bluetooth icon will appear in the system tray.
The next step is to pair Arduino to a PC. At this point, an Arduino-USB Host Shield-Bluetooth dongle combo shall be put together as described earlier, tested, and set up as follows:
- Powered from external supply – optional but highly recommended, at least for the first attempt. If you decide to use external supply, connect it before USB cable
- Connected to a PC with USB cable. It could be the same PC to which you are going to pair your Arduino via Bluetooth
- Terminal to Arduino opened. It can be Serial Monitor in Arduino IDE or third-party terminal program such as Putty or Teraterm. If everything is wired correctly and Bluetooth dongle is good you should see the following output in the terminal window:
Continue reading Using USB Bluetooth dongle on Arduino to connect to Windows PC
Wireless Xbox360 code
[EDIT] Four simultaneous controllers are now confirmed to work [/EDIT]
This is a short announcement of another nice contribution to the USB Host 2.0 library code. Kristian Lauszus from TKJ Electronics announced release of wireless Xbox360 controller support for USB Host 2.0 library; up until now only wired Xboxen were supported.
As announced, up to 4 controllers are supported, however, only one has been tested so far. If you have (or can borrow) multiple Xbox controllers, please help Kristian test his code.
Arduino connected to Nexus S
Since Kristian’s release of SPP service for USB Host 2.0 library
I got many e-mails with questions about Bluetooth serial communications in general and using the SPP class in particular. While establishing a Bluetooth connection is quite easy when using PCs/smartphones/tablets, the Arduino implementation is less user-friendly (for a good reason) and somewhat confusing. This article is intended to be a short tutorial of Arduino USB Bluetooth connectivity using an Android device as a peer – in my opinion, the simplest one to set up and communicate.
To follow this tutorial, you will need the following:
- An Arduino board ( I sell them too )
- full-size USB Host Shield 2.0
- USB Host Shield 2.0 library downloaded and installed in your Arduino library directory
- An SPP example sketch
- Bluetooth dongle – see below for detailed discussion
- Android device – a phone or tablet. The accuracy of this tutorial has been checked on Nexus S phone and Nexus 7 tablet, both running Jelly Bean 4.1.1 OS.
- A Bluetooth terminal emulator app for Android – I use Blueterm
The hardware setup is shown on the title photo (click on it to make it larger). It is a good idea to use external power supply at least in the beginning – some Bluetooth dongles are not happy when powered together with Arduino board/USB Host shield from USB cable. On a side note, it is always a good idea to use external power supply while experimenting with USB devices, especially when using current Arduino boards with their weak regulators. Also, Bluetooth code requires plenty of resources. The example used in this article compiles in ~24K and even though it would work on standard Arduino, any meaningful project will likely require a bigger board, like a Mega.
Continue reading Using USB Bluetooth dongle on Arduino to connect to Android phone
Bulb mode activation code screenshot
Last week my friend Hans and I spent some time in my lab exploring which features of his Nikon D300 are available via PTP protocol. Hans is working on extended range HDR-capable intervalometer and he needed to find out a way to switch his camera into bulb mode using Arduino
board and USB Host shield
. After we finished I realized that while bulb mode is not tricky to activate, it is not obvious either and no hints exist in the code and examples showing how to do this. This short article is intended to fill the void.
In PTP, shooting parameters, such as shutter speed, aperture, ISO, etc. are changed by setting certain device property. For each parameter there exists a list of allowed values of this property, each property value corresponding to a parameter value. For some parameters, property and parameter value lists are dynamic. For example, starting and ending aperture values are different for different lenses; additionally, the aperture step can be changed in camera settings. Stepping can also be changed for shutter speed and exposure compensation and this can also happen during PTP session if a photographer decides to switch modes – in this case a property may become unavailable, like shutter speed in aperture priority mode. Therefore, before changing a property value for one of these parameters it is necessary to somehow retrieve a list of available property values.
The property value list retrieval mechanism is slightly different for different cameras. On Canon DSLRs, a special event is generated by the camera and sent back to PTP host at the beginning of the session and also each time camera mode was changed, lens were swapped and so on. The application needs to track those events and constantly maintain current value list for each property. On Nikon DSLR, it is possible to simply get value list for a property any time it is needed. To save memory, the list is not stored but simply requested from the camera each time a property needs changing. It is combined with actual property change in two templates –
StepDown. If you need to increase, for example, shutter speed – call
StepUp. If you need to decrease it, call
If you “step up” shutter speed on Nikon DSLR manually, the last 2 values will be 30 seconds and bulb. If you step up shutter speed using
StepUp method using Nkremote sketch it will stop at 30 seconds. This happens because bulb mode is not included in the list of available property values for shutter speed but simply defined as
0xffffffff. As a result,
StepUp doesn’t know that another value is available. It is still possible, however, to set the property directly and I will show you how to do it.
Continue reading PTP 2.0 library function turns on Bulb mode on Nikon DSLR camera via USB
Stack of shields
This is Part 1 of 3-part series of articles. Part 2 talks about hardware modifications while Part 3 explains how to deal with incompatible data formats.
Serial Peripheral Interface AKA SPI bus is a popular way to communicate peripheral IO controllers to a micro over short distances and many microcontrollers have SPI interface built-in, including Arduino. Consequently, many Arduino shields use SPI to communicate to Arduino; USB Host shield is one of them. When more than one such shield is connected to Arduino, several SPI slave devices start sharing SPI bus. SPI is designed to allow bus sharing and if correct signals are present at correct moments all devices get along just fine. In practice, however, nothing usually works as desired, shields are interfering and fixing it requires hardware and software modifications. I was recently tasked with connecting 3 SPI slave devices to Arduino and this article shows how I did it.
A reader is expected to be familiar with SPI bus in general and Arduino implementation in particular. In addition, Tronixstuff has SPI tutorial, which is a little bit more user-friendly.
1. The problem
Arduino shields with SPI interface generally have 2 sources of interference – 1 on hardware level and one in software.
SPI bus consists of 3 shared data lines – SCK, MISO and MOSI, plus one “Slave Select” AKA SS line per each device. All transfers are initiated by the host and proceed in both directions simultaneously. Only one device, the one whose SS line is asserted low, is participating in the transfer by driving its MISO line – all other devices are expected to have their MISO line in a third state.
Due to peculiarities in Atmega SPI implementation, designers of Arduino shields prefer using default SS line, which is assigned to pin 10 on standard-sized Arduino boards. If two shields are driven by the same SS, they will have their MISO line active at the same time. Best-case consequence of it is only one of the shields in the stack being able to communicate, worst-case is destroyed MISO line transmitters. Therefore, the first step in any multi-shield SPI project is to make sure each shield uses its own SS line and never expect this to be the case in default configuration.
Continue reading Running multiple slave devices on Arduino SPI bus
Compatible Bluetooth Dongles
[EDIT] Here is Kristian’s post with more detailed explanation of the example sketch.[/EDIT]
Kristian Lauszus from TKJ Electronics, a man behind PS3 and Xbox360 code in USB Host Shield 2.0 library did it again! I’m pleased to announce that the library now supports standard RFCOMM/SPP implementation, thanks to Kristian’s work.
RFCOMM is basic Bluetooth service and SPP is serial port emulator on top of this. The code allows interfacing standard USB Bluetooth dongles to Arduino boards using USB Host Shield v.2.0. Bluetooth dongles (the ones I’ve tested can be seen on a title picture ) are widely available, cost much less than specialized serial Bluetooth modules (I have a couple of powerful class 1 dongles bought on eBay for $1 shipped) and won’t occupy precious serial port on Arduino board. Even though most dongles are compatible with the code, there are also some that don’t work. The code has been tested for compatibility with all major OSes – Linux, MacOS and Windows 7, as well as Android devices. It will likely work with any RFCOMM client, however, more testing is necessary.
The example code is a simple SPP server. It needs to be started before attempting to connect to it from a PC/phone. Once started, the state of the server is printed on a terminal. After that, the device can be discovered/paired/connected to; it is then possible to send characters from one device to the other by means of a keyboard. In the coming days I will write a series of posts with details of connecting different Bluetooth devices to Arduino. In the mean time, enjoy the code! Please give it a try and let me know what you think.
Kristian Lauszus from TKJ Electronics made another contribution to USB Host Shield 2.0 library – support for Microsoft Xbox360 game controller.
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!