Monthly Archives: October 2012

Accessing GPIO pins of Max 3421 IC in USB Host Shield

USB Host Shield

One of my favorite Arduino shield is the USB Host Shield by circuits @ home. Both the hardware and the software of this shield are excellent and well written.

I was playing around with the shield by connecting a USB Missile Launcher and had a closer look at the shield. I realized when I had a closer look that the GPIO pins of the Max 3421 IC, present in the shield have separate headers and are not directly used by the shield.

In this tutorial, I will explain how you can access these GPIO pins of the Max 3421 IC which present in the shield.

Max 3421 IC

The USB Host Shield uses the Max 3421 IC to provide the USB Host capabilities for Arduino.

If you are wondering what is an USB Host shield or what is USB Host mode, then do read my article about USB Host Shield and Arduino, which I wrote a couple of weeks ago.

GPIO Pins

Every micro controller will have a set of pins that can be used for general input and output. These pins are know as GPIO (General Purpose Input and Output) pins. In Arduino, the GPIO pins of the AVR micro-controller are mapped to the headers that are available on both sides of the board. The Max 3421 IC that is used inside the shield has 8 input and 8 output pins.

Accessing the GPIO pins

After realizing about the GPIO pins, I immediately was trying to see if there is a way by which I can access them. I checked out the datasheet and found that these pins are controlled by the IOPINS1 and IOPINS1 registers (similar to the ports in AVR/Arduino). I then checked the USB Host Shield library and found two methods, gpioRd() and gpioWr() that allows you to access these pins.

Arduino Library

The problem with those two functions is that, you have to read or write all 8 pins at once, and then do some bit manipulation to control individual pins. The bit manipulation that you have to do is not complex, but at the same time it is not as easy as doing digitalWrite() or digitalRead().

So I immediately wrote an Arduino library, that abstracts out this bit manipulation and provides simple functions like write() and read(), that can be used to write or read from the pins individually.

I have also created an example sketch which shows you how you can use this library to control the pins individually.

Video

You can see the library in action in the below video. Here I have connected 8 led’s to each of the GOut pins and I am controlling them separately.

Try out the library and do let me know if you have any feedback or comments.

Happy hacking 🙂

Controlling USB Missile Launchers using Arduino

USB Missile Launcher

While cleaning my room the other day, I stumbled upon a couple of old toys which I bought from US for myself. (Who said you have to grow up 😉 )

I was going through the packs and found an old USB Missile Launcher and thought of putting it into some good use.

USB Missile Launcher

USB Missile LauncherSo what exactly is a USB Missile Launcher? It is a small geek office toy, which you can use to launch missiles (unfortunately foam as of now) on your team mates (or your manager).

I bought mine from ThinkGeek, but they seem to available in lot of other places as well.

USB Interface

The interesting part of the device is that you can connect it to your computer using USB and control its movement as well as firing of missiles. The device which I bought came with a windows only software which allows you to control it from your computer.

I did a quick web search and found that the USB interface used by the device is pretty straight forward. You just have to make a USB ctrl request with a particular code for each direction.

Python Code

I quickly wrote a python script using PyUSB, and was able to take aim and launch the missiles 🙂

The following is the main part of the code, which just involved in making a ctrl request

Connecting to Arduino

While it was fun controlling the device from the computer, it quickly dawned on me that using a computer is an over kill for such a trivial task. I then thought it would be cool, if I can control it from an Arduino.

USB Host Shield

I quickly stacked a USB Host Shield on top of the Arduino so that I can easily control the device.

If you are wondering what is a USB Host shield, then do read my article about USB Host Shield and Arduino, which I wrote a couple of weeks ago. In short, a USB Host Shield, gives USB Host capabilities to an Arduino.

Making it work

After stacking the USB Host shield on top of Arduino, all I needed to do was to make the ctrl request. I quick scanned the USB Host Shield library and found that the USB class had a ctrlReq method, which sends the proper request to the device.

I called that method with the same data that I passed in the python code and the device started responding to my commands. Mission accomplished 🙂

Video

I quickly wrote a sketch that took commands from the serial monitor and controlled the missile launcher based on it. You can see it in action in the below video.

Arduino Library and Examples

I quickly wrote an Arduino library to control the USB missile launcher. The library abstracts out the low-level code and commands, so that you can just use the library instead of worrying about the commands that you need to send through USB.

I also created two example sketches, which shows you how to use the library. You can find these inside the examples folder of the library.

Try out the library and do let me know if you face any issues.

Happy missile launching 😉

Capabilities of Arduino

Today, I spoke about Arduino and its different capabilities at Mobile internals workshop conducted by CIS. The talk discussed the different ways by which we can use Arduino to interface with different external devices.

It was very similar to the talk that I gave at board hackthon, but I have added additional details about Leanardo and Due in this presentation.

Slides

You can view the slides from my slideshare account. I have also embedded it here for each reference. You can also checkout my other presentations and slides from my talks page.

Buying Arduino in Bangalore

As it used to happen in my other talks about Arduino, even today lot of people asked me about places where they can buy Arduino in Bangalore. I have already collect a list of places from where you can buy Arduino in Bangalore. You can refer to that page, in case you are planning to buy Arduino in Bangalore.

Arduino Workshop

I am conducting an Arduino workshop on Nov 3rd and 4th. The workshop consists of hands-on sessions, where you can learn about Arduino and then use that knowledge to build a fully autonomously bot from scratch. You can find more details about the workshop from the workshop page.

Talk on Open source hardware by Ian of Dangerous Prototypes

Ian Lesnet, founder of Dangerous Prototypes will be giving a talk titled “Profit by Sharing: Anatomy of an Open Source Hardware Business” this Wednesday (Oct 24th) at CIS office, in Bangalore.

About Ian and Dangerous Prototypes

Ian builds a new open hardware project every month at DangerousPrototypes.com. Copies of the projects are available from Seeed Studio’s open hardware manufacturing service.

Ian’s entire business model is based on open source hardware. So who can give us more insights better than him 🙂

When and Where

The event happens between 3:00 to 5:00 PM at Center for Internet and Society (CIS) office. You can find a map to the location at CIS website.

There is no registration for the event, you can just walk in. If you need any information about the event or have trouble in reaching the venue, then feel free to contact me or leave a comment below.