One of the main motivations for adding asynchronous CDC support code to rev.2.0 of USB Host Library was to be able to use cell phones in Arduino projects – establish simple data exchange via SMS, take pictures or connect to the Internet. Second hand phones are inexpensive yet quite capable. Also, m2m (machine to machine) SIM cards start at $4-$6/mo, some even allow for free incoming SMS. All that makes a cell phone an attractive communication option for hobby projects. In this post, I will be talking about basics of cell phone control using data port and AT commands. I will also present simple terminal emulator sketch – to use the code you will need an Arduino board, USB Host Shield, as well as USB Host Shield 2.0 library.
Modern (<10 year old) phones have standard GSM chip interface implemented and accessible via so-called “data port”. The oldest phones implement TTL level asynchronous serial interface by means of “custom” USB data cable, which is just proprietary connector on one end, standard USB connector on the other end, and USB-to-serial converter chip (almost always Prolific PL2303) between them. Newer cell phones have USB-to-serial converter built-in. Motorola phones usually terminate data port on standard mini-USB connector, others, like Samsung and Sony Ericsson, use proprietary cable. The USB-to-serial converter in these phones is almost always standard CDC ACM type.
Many functions of the phone can be accessed by AT commands, similar to commands used to control Hayes phone modems. Standard GSM commands are defined in 3GPP TS 07.07 (look for the latest version, which is 7.8.0). Cell phone manufacturers also define their own AT commands. In documentation AT commands are usually presented in uppercase, however, most phones accept lowercase just as well. A command shall be followed by CR,LF (usually Enter key). If a command is accepted, OK is returned, along with response. If command is not recognized, ERROR is returned. Some commands will be accepted in certain phone states and rejected in others. Continue reading Interfacing Arduino to a Cellular Phone
What started as a quick re-factoring effort transformed to a major redevelopment, but finally all pieces fit together tightly and I am pleased to announce that initial release of USB Host Shield library ver.2.0 has been posted to github. This new version contains several major improvements:
Only 5 Arduino pins are now required for USB Host Shield to function – 3 standard SPI pins (SCK, MISO, MOSI) and 2 remappable pins (SS and INT).
The low-level interface to MAX3421E has been re-designed. Arduino pin manipulation routines has been replaced with mechanism inspired by Konstantin Chizhov’s C++ AVR pin templates. As a result, low-level transfers became approximately 3.5 times faster. Also, pin reassignment can be done much easier by passing pin numbers into MAX3421E template during instantiation.
The high-level interface to USB devices has been re-designed as well. It is now possible to connect USB hub to the shield and have many devices on USB bus, up to 7 daisy-chained 8-port hubs plus up to 44 devices connected to hub ports left after daisy-chaining, memory permitting. Also, a standard mechanism of device initialization/polling/releasing has been added to enumeration.
Several minor code improvements has also been made. NAK_LIMIT is now tied to an endpoint – it is now possible to have NAK_LIMIT set to 1 for interrupt endpoint and 32000 for bulk endpoint of the same device simultaneously. Control transfer function now accepts callback in order to split long chunks of data, if necessary. inTranser() function now is able to return actual number of bytes received.
Support for several popular device classes has been added. Device initialization and event handling is now moved to a library specific to device class, therefore user application does’n need to do this and only needs to process actual device data. The following devices are now supported by the library code: Continue reading USB Host Shield library Version 2.0 released.
Arduino developer known as Krulkip sent me this little article along with Arduino sketch and video clip. To fit it into the blog I had to do some reformatting; what follows is Krulkip’s article – enjoy!
The WebMail Notifier has pretty light and optional sound alert software to tell you when you have email on one or all of your accounts, including Facebook. Dream Cheeky did what we do best with this product… helping you be more unproductive at the office. Now when you sneak off to the bathroom to check personal emails on your Blackberry, your trip will definitely not be wasted.
WebMail Notifier supports: Gmail, Yahoo, Outlook Express, POP3, Weibo, Facebook, Twitter, etc.
I wanted to control the Webmail Notifier from an arduino. As this is a USB device i needed to use the usb-host-shield manufactured by circuitsahome. With a little help from Oleg from circuitsathome and with the windows program from Frederic Delhoume i finally managed to get it working. What was needed was to send the unit two initialization sequences:
Soon after Google ADK announcement it was discovered that $300 Arduino-based ADK hardware kit (out of stock at the time of this writing) is not really necessary; the same functionality can be achieved with standard Arduino board and USB Host Shield. Today, one of the developers sent me a link to GoogleADK – site, which explains how to build Google ADK hardware from standard components and use it.
The site shows how USB Host Shield looks like when all headers are soldered in place. It also has Get Started page which gives step-by-step instructions on installing necessary software components on Linux box. Word of caution – the link on this page points to the product page of old rev.1.xx shield, even though all pictures show the current rev.2.0 one.
At present, the site is pretty lean but it is a good start nevertheless. I will be monitoring it to see if any new content would come up. Arduino-Android tandem offers very interesting capabilities and I’m hoping to see many cool Android-based projects soon.
Android Open Accessory Development Kit, announced on Google IO the other day is a hot topic. Android Open Accessory support, introduced in Android 3.1 (tablet OS) and backported to 2.3.4 (phone OS), allows external USB devices to interact with Android phone/tablet switched to so-called “accessory” mode. Because phones are USB functions (AKA devices) this accessory device must act as USB host. Arduino USB Host Shield has been around for couple of years providing USB Host functionality for standard and Mega form factor official Arduinos, as well as several clones. Luckily for all Arduino enthusiasts out there, Google decided to adopt this very architecture for hardware component of ADK. As a result, said enthusiasts now have well defined and documented code layer to interact with Android devices, ready to run on Arduino board of their choice. Well, almost.
The ADK code is targeted for ADK hardware component, which is just Arduino Mega 2560 and USB Host Shield combined on a single PCB. However, they decided to move some pins around; as a result in order to use the code with standard “Arduino plus Shield” setup certain code modifications are necessary. One such modification has been posted on Romfont. I tried it and the code works well, however, this approach has issues. First, it creates yet another distro. Second, the code modification exercise would have to be repeated each time Google releases new version of ADK. Finally, it’s difficult to have both standard and Google USB librares installed in Arduino IDE at the same time. Given all that, I decided to take different approach.
Google’s variant of USB Host Shield library differs very little from official library. The only significant difference is newInTransfer() member function of USB class, which returns real length of received packet. In order to support AndroidAccessory component in official library, I simply added this function to the library code and made a new release – it is now available on gitHub. I placed it into “dev” branch for now – it will be moved to “master” after a period of testing.
[ EDIT ] Here is a link to The Tx Project source code [/EDIT]
This is another RC car related post. This time, Santiago Saldana has created a device that allows you to control any RC car,plane,helicopter, etc. using any HID joystick. The “Tx Project” makes use of an Arduino, an Assan Hack Module, a HD44780 LCD, and a USB Host Shield v1.0. The project also makes use of a Trimersion Headset for FPV control of the RC Car, a Microsoft Sidewinder Racing Wheel, and a 900 Mhz Video transmitter / receiver. Code is open source and will be made available after beta testing, or upon request if there is interest. The code makes us of my MAX3421E and USB Host libraries as well as borrowing HID parser code from the LUFA project.
First video is from an earlier version, but demonstrates the devices flexibility in USB device input. The second video is from a presentation Santiago made at Wake Forest University’s Computer Science department.
About a year ago, I posted an article about 2-channel rotary encoder interfacing with MCU using lookup table. With its linear program flow, inherent noise immunity and small processing requirements, this method produces extremely efficient code. The article attracted quite a bit of attention with many interesting comments and several code modifications. Today, I want to demonstrate slightly different way of reading the encoder – via interrupt service routine (ISR).
I’m currently involved in a project built with QP Event-Driven Real Time Framework running on 8-bit AVR micro. Rather than implementing periodic polling, I wanted to generate encoder events as they occur. AVR Atmega, as well as many other micros have external interrupt source called “Pin Change”, ideally suited for an encoder. As the name implies, pin change interrupt occurs when certain digital port pin changes state from low to high or vice versa. When an encoder is rotated, one pin changes state from say low to high, then other goes from low to high, than the first one goes from high to low, then the other one goes from high to low. The cycle then repeats. In order to properly react to every state change we want to be able to generate interrupt on every transition on each pin and that is exactly how pin change interrupt works.
I am developing for custom built AVR-based board and all code snippets are pasted directly from project files. This code can be used on bare metal Atmega as well as Arduino board with no changes and can also be adopted for other micros with only minor modifications, such as port and pin names. Encoder’s A and B pins are connected to Port B pins 0 and 1, common pin is connected to ground. To prevent floating inputs, internal pull-ups are turned on.
[EDIT] r2.0-compatible PTP code has been released, see here [/EDIT]
A significant progress has recently been made in Arduino USB Host 2.0 library development. The estimated release date is still several months away; however, I just can’t wait that long to share my excitement. A hub support is now fully incorporated into the library, as well as all necessary multi-device support – connect/disconnect, initialization and event handling. The very first device class implemented for the new library is ever-popular PTP digital camera control. A short Youtube video shows Arduino controlling two different camera systems simultaneously.
Some interesting numbers: a sketch used to drive cameras in the video takes 19K and contains one instance of USB, one instance of hub, one instance of EOS and one instance of Powershot class. The same sketch with only one camera instance takes 17K, which means one camera instance occupies roughly 2K. Since ~30K of program memory is available on Atmega328P-based Arduino board, it should be possible to drive seven cameras with a single Arduino! Also, I’m using development version of code with lots of debug strings and other less-than-necessary stuff – release version will definitely be smaller.
Watch the video, stay tuned to the code development and please let me know what you think about all that! Multi-camera control opens new exciting possibilities – anyone interested in (relatively) cheap 3D video rig?
This is first iteration of camera controller layout inspired by Fernando Radi’s project. I designed a PCB containing Arduino Pro Mini, USB Host Mini, as well as other small parts necessary to complete the circuit. The whole thing is about the size of 16×2 LCD display and 1 inch high.
Next picture shows the controller with LCD removed. LCD connector is at the top left. Two resistors below the connector set the screen contrast. Slide switch next to LCD connector turns backlight on/off while power switch sits at the top right. USB Host Mini and Arduino Pro Mini are mounted underneath the LCD; encoder and “Back” button are placed to the right of LCD.
Project files include Eagle schematic and board layout, as well as a pdf of bottom side of PCB ready to be used in toner transfer process. EOSCamController code can be run on this board with no modifications. Some encoders have their A,B outputs swapped so if you see screen navigation moving backwards, swap encoder outputs. If you want to build this controller, refer to Eagle board layout file for part and jumper placement.
Cam.controller with LCD off
In the next iteration of the layout, I’m planning to move power switch to the left closer to backlight switch and use right-angle encoder and “Back” button. I will also try to find space for a LiPo charger. Stay tuned and please leave a comment if you have better layout in mind!
Fernando Radi sent me pictures of the project he’s recently finished. It is Arduino Digital Camera Controller ( which has been posted back in January as a proof-of-concept circuit ) with some clever modifications – Fernando used Mini variant of the shield, Arduino Pro Mini and ultra-tiny LCD. As a result, the controller is very small. Make sure to read Fernando’s comment to the article linked above for construction details. Also, I suggest visiting Fernando’s blog – I don’t know Spanish well enough to read his posts but his photographs are very good!
..Electronics is not my field of expertise and I do not have any tool other than a Dremel, so the enclosure is not fancy but small enough and fit my needs. BTW, the one in the picture was the third attempt, dremel is very slippery 😉
This quote from Fernando’s e-mail triggered another idea that I want to share with my readers. I understand that many people who want to make a camera controller are not familiar with building electronic circuits from small parts. To help them, I’d like to put together a kit containing necessary parts (i.e., USB Host, Arduino, LCD, switches, buttons, etc.) plus PCB to solder parts to and a small enclosure. A PCB will be laid out using large traces so that builders who possess home made PCB fabrication skills can save some money. I’m thinking about using standard size LCD instead of super tiny one to keep the circuit simple. Estimated end-user price for this kit is going to be $75-80. Let me know what you think about the kit and especially price. I’m currently playing with overall layout and hoping to post something in about a week or two.
Thanks again, Fernando for sharing your project with us!