<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">

<channel>
	<title>Circuits@Home</title>
	
	<link>http://www.circuitsathome.com</link>
	<description>A Solder Joint</description>
	<lastBuildDate>Wed, 11 Jan 2012 02:58:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/chome" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="chome" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Arduino 1.0-compatible USB Host Library released</title>
		<link>http://www.circuitsathome.com/mcu/arduino-1-0-compatible-usb-host-library-released</link>
		<comments>http://www.circuitsathome.com/mcu/arduino-1-0-compatible-usb-host-library-released#comments</comments>
		<pubDate>Wed, 11 Jan 2012 02:58:28 +0000</pubDate>
		<dc:creator>oleg</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[MCU]]></category>
		<category><![CDATA[USB]]></category>
		<category><![CDATA[USB Shield]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[MAX3421E]]></category>
		<category><![CDATA[USB Host Shield]]></category>

		<guid isPermaLink="false">https://www.circuitsathome.com/?p=6950</guid>
		<description><![CDATA[<p> 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 &#8211; the USB Host Library is now compiles in 1.0 as well as pre-1.0 versions of Arduino IDE. Enjoy!</p> <p>Several important changes have been made to the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="https://www.circuitsathome.com/wp/wp-content/uploads/2012/01/code_288-216-02.jpg"><img src="https://www.circuitsathome.com/wp/wp-content/uploads/2012/01/code_288-216-02.jpg" alt="" title="" width="288" height="216" class="alignright size-full wp-image-6954" /></a><br />
<a href="https://github.com/felis/USB_Host_Shield_2.0">Fresh update of USB Host Library 2.0</a> has just been posted to GitHub. The primary purpose of this release is to maintain compatibility with Arduino releases &#8211;  the USB Host Library is now compiles in 1.0 as well as pre-1.0 versions of Arduino IDE. Enjoy!</p>
<p>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:</p>
<ol>
	<strong>
<li>PL2302 driver.</strong> 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 <code>PL2302</code>; 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 <code>PL2303 Pl(&#038;Usb, &#038;AsyncOper);</code></li>
<p>	<strong>
<li>NAK handling.</strong> A bug preventing long polls of an endpoint has been fixed. Previously, if <code>bmNakPower</code> member of <code>epInfo</code> 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 <code>bmNakPower</code> with <code>USB_NAK_DEFAULT</code> or <code>USB_NAK_MAX_POWER</code>. If a single poll is desired, as is often the case with interrupt endpoints, specify <code>USB_NAK_NOWAIT</code> and if more than maximum number of NAKs (up to 5 seconds) is necessary, specify <code>USB_NAK_NONAK</code>.</li>
<p>	<strong>
<li>Code speed.</strong> An unnecessary delay of 20ms has been found (thank you, Alex for discovering this!) and removed from <code>USB::setAddress()</code> 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&#8217;s probably why.</li>
</ol>
<p>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, <code>USBTRACE (Serial.print(F(s)))</code> 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.</p>
<p>This is the end of announcement &#8211; download the code, play with it and if you have any issues please share your findings in the comments.</p>
<p>Oleg.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.circuitsathome.com/mcu/arduino-1-0-compatible-usb-host-library-released/feed</wfw:commentRss>
		<slash:comments>59</slash:comments>
		</item>
		<item>
		<title>USGlobalsat ND-100S GPS receiver works with USB Host library</title>
		<link>http://www.circuitsathome.com/mcu/usglobalsat-nd-100s-gps-receiver-works-with-usb-host-library</link>
		<comments>http://www.circuitsathome.com/mcu/usglobalsat-nd-100s-gps-receiver-works-with-usb-host-library#comments</comments>
		<pubDate>Thu, 10 Nov 2011 15:45:14 +0000</pubDate>
		<dc:creator>oleg</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[GPS]]></category>
		<category><![CDATA[MCU]]></category>
		<category><![CDATA[USB]]></category>
		<category><![CDATA[USB Shield]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[gps]]></category>
		<category><![CDATA[MAX3421E]]></category>
		<category><![CDATA[nd-100s]]></category>
		<category><![CDATA[pl2303]]></category>
		<category><![CDATA[receiver]]></category>
		<category><![CDATA[USB Host Shield]]></category>

		<guid isPermaLink="false">https://www.circuitsathome.com/?p=6874</guid>
		<description><![CDATA[<p class="wp-caption-text">ND-100S GPS receiver connected to USB Host shield</p> <p>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.</p> <p>ND-100S from [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_6877" class="wp-caption alignleft" style="width: 298px"><a href="/wp/wp-content/uploads/2011/11/pl2303_nd_100s.jpg"><img src="/wp/wp-content/uploads/2011/11/pl2303_nd_100s-288x216.jpg" alt="ND-100S GPS receiver connected to USB Host shield" title="ND-100S GPS receiver connected to USB Host shield" width="288" height="216" class="size-thumbnail wp-image-6877" /></a><p class="wp-caption-text">ND-100S GPS receiver connected to USB Host shield</p></div>
<p>After posting an article about <a href="/mcu/communicating-to-gps-receiver-using-usb-host-shield">interfacing USB GPS receiver to Arduino</a> 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.</p>
<p><a href="http://www.usglobalsat.com/p-590-nd-100s.aspx">ND-100S from USGlobalsat</a> is small, inexpensive (less than $30 shipped at <a href="http://www.dealextreme.com/p/37137?r=69855103">DealExtreme</a>) GPS receiver with excellent characteristics. Below are some bullet points:</p>
<ul>
<li><strong>Lightweight</strong> &#8211; 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.</li>
<li><strong>Sensitive</strong> &#8211; 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.</li>
<li><strong>Easy to use</strong> &#8211; the module uses Prolific PL2303 USB to serial converter supported by <a href="https://github.com/felis/USB_Host_Shield_2.0">USB Host library 2.0</a> and the sketch from the <a href="/mcu/communicating-to-gps-receiver-using-usb-host-shield">previous article</a> works without any modifications. Also, the module has status LED showing when GPS position is fixed &#8211; 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.</li>
</ul>
<p>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 &#8211; will post as soon as I have more information about it.</p>
<p>Oleg.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.circuitsathome.com/mcu/usglobalsat-nd-100s-gps-receiver-works-with-usb-host-library/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Exchanging data between USB devices and Android phone using Arduino and USB Host shield</title>
		<link>http://www.circuitsathome.com/mcu/exchanging-data-between-usb-devices-and-android-phone-using-arduino-and-usb-host-shield</link>
		<comments>http://www.circuitsathome.com/mcu/exchanging-data-between-usb-devices-and-android-phone-using-arduino-and-usb-host-shield#comments</comments>
		<pubDate>Sun, 06 Nov 2011 02:21:55 +0000</pubDate>
		<dc:creator>oleg</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[MCU]]></category>
		<category><![CDATA[USB]]></category>
		<category><![CDATA[USB Shield]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ADK]]></category>
		<category><![CDATA[barcode scanner]]></category>
		<category><![CDATA[CueCat]]></category>
		<category><![CDATA[MAX3421E]]></category>
		<category><![CDATA[USB device]]></category>
		<category><![CDATA[USB Host Shield]]></category>

		<guid isPermaLink="false">https://www.circuitsathome.com/?p=6795</guid>
		<description><![CDATA[<p class="wp-caption-text">CueCat connected to Android phone</p> <p>Today, I&#8217;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.</p> <p>A phone is USB [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_6796" class="wp-caption alignright" style="width: 298px"><a href="/wp/wp-content/uploads/2011/11/adk_cuecat_title.jpg"><img src="/wp/wp-content/uploads/2011/11/adk_cuecat_title-288x216.jpg" alt="CueCat connected to Android phone" title="CueCat connected to Android phone" width="288" height="216" class="size-thumbnail wp-image-6796" /></a><p class="wp-caption-text">CueCat connected to Android phone</p></div>
<p>Today, I&#8217;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.</p>
<p>A phone is USB device, too, and since two USB devices are unable to communicate to each other directly, I&#8217;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 <a href="/mcu/programming/android-adk-terminal-emulator-for-arduino">ADK terminal emulator</a> article and another one from an article explaining <a href="/mcu/connecting-barcode-scanner-arduino-usb-host-shield">interfacing with a barcode scanner</a>. Refer to  these articles if you have questions about a specific piece.</p>
<p>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 <a href="https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/adk/adk_barcode/adk_barcode.pde">examples section</a> of USB Host library rev.2.0 distribution on gitHub. The library itself shall be installed in Arduino IDE tree as well.</p>
<p>To receive data from Arduino you&#8217;ll need <a href="/chome_downloads/ArduinoTerminalBeta.apk">Arduino Terminal</a> application installed on your phone. The <a href="/chome_downloads/ArduinoTerminalSrc.zip">source code</a> of application is also available &#8211; it is released under GPL2, if you make modifications to the code, please make them available for other people!</p>
<p>Finally, we will need some hardware &#8211; an <a href="/products-page/arduino-boards/arduino-uno-dip/">Arduino board</a>, <a href="/products-page/arduino-shields/usb-host-shield-2-0-for-arduino/">USB Host shield</a>, a USB hub, &#8220;declawed&#8221; 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.</p>
<p><span id="more-6795"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**/</span>
<span style="color: #808080; font-style: italic;">/* A sketch demonstrating data exchange between two USB devices - a HID barcode scanner and ADK-compatible Android phone */</span>
<span style="color: #808080; font-style: italic;">/**/</span>
<span style="color: #339933;">#include &lt;avrpins.h&gt;</span>
<span style="color: #339933;">#include &lt;max3421e.h&gt;</span>
<span style="color: #339933;">#include &lt;usbhost.h&gt;</span>
<span style="color: #339933;">#include &lt;usb_ch9.h&gt;</span>
<span style="color: #339933;">#include &lt;Usb.h&gt;</span>
<span style="color: #339933;">#include &lt;usbhub.h&gt;</span>
<span style="color: #339933;">#include &lt;avr/pgmspace.h&gt;</span>
<span style="color: #339933;">#include &lt;address.h&gt;</span>
&nbsp;
<span style="color: #339933;">#include &lt;adk.h&gt;</span>
&nbsp;
<span style="color: #339933;">#include &lt;hidboot.h&gt;</span>
&nbsp;
USB Usb<span style="color: #339933;">;</span>
USBHub Hub1<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>Usb<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
USBHub Hub2<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>Usb<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     
HIDBoot<span style="color: #339933;">&lt;</span>HID_PROTOCOL_KEYBOARD<span style="color: #339933;">&gt;</span> Keyboard<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>Usb<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
ADK adk<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>Usb<span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;Circuits@Home, ltd.&quot;</span><span style="color: #339933;">,</span>
            <span style="color: #ff0000;">&quot;USB Host Shield&quot;</span><span style="color: #339933;">,</span>
            <span style="color: #ff0000;">&quot;Arduino Terminal for Android&quot;</span><span style="color: #339933;">,</span>
            <span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #339933;">,</span>
            <span style="color: #ff0000;">&quot;http://www.circuitsathome.com&quot;</span><span style="color: #339933;">,</span>
            <span style="color: #ff0000;">&quot;0000000000000001&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
class KbdRptParser <span style="color: #339933;">:</span> public KeyboardReportParser
<span style="color: #009900;">&#123;</span>
&nbsp;
protected<span style="color: #339933;">:</span>
	virtual <span style="color: #993333;">void</span> OnKeyDown	<span style="color: #009900;">&#40;</span>uint8_t mod<span style="color: #339933;">,</span> uint8_t key<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	virtual <span style="color: #993333;">void</span> OnKeyPressed<span style="color: #009900;">&#40;</span>uint8_t key<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">void</span> KbdRptParser<span style="color: #339933;">::</span><span style="color: #202020;">OnKeyDown</span><span style="color: #009900;">&#40;</span>uint8_t mod<span style="color: #339933;">,</span> uint8_t key<span style="color: #009900;">&#41;</span>	
<span style="color: #009900;">&#123;</span>
    uint8_t c <span style="color: #339933;">=</span> OemToAscii<span style="color: #009900;">&#40;</span>mod<span style="color: #339933;">,</span> key<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#41;</span>
        OnKeyPressed<span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* what to do when symbol arrives */</span>
<span style="color: #993333;">void</span> KbdRptParser<span style="color: #339933;">::</span><span style="color: #202020;">OnKeyPressed</span><span style="color: #009900;">&#40;</span>uint8_t key<span style="color: #009900;">&#41;</span>	
<span style="color: #009900;">&#123;</span>
<span style="color: #993333;">const</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span> new_line <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
uint8_t rcode<span style="color: #339933;">;</span>
uint8_t keylcl<span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> adk.<span style="color: #202020;">isReady</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #000000; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
&nbsp;
  keylcl <span style="color: #339933;">=</span> key<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> keylcl <span style="color: #339933;">==</span> <span style="color: #208080;">0x13</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    rcode <span style="color: #339933;">=</span> adk.<span style="color: #202020;">SndData</span><span style="color: #009900;">&#40;</span> strlen<span style="color: #009900;">&#40;</span> new_line <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>uint8_t <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>new_line <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    rcode <span style="color: #339933;">=</span> adk.<span style="color: #202020;">SndData</span><span style="color: #009900;">&#40;</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>keylcl <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>    
&nbsp;
  Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span> keylcl <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot; : &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
  Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span> keylcl<span style="color: #339933;">,</span> HEX <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
KbdRptParser Prs<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  Serial.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">115200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>ADK demo start&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>Usb.<span style="color: #202020;">Init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;OSCOKIRQ failed to assert&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//halt</span>
  <span style="color: #009900;">&#125;</span><span style="color: #666666; font-style: italic;">//if (Usb.Init() == -1...</span>
&nbsp;
  Keyboard.<span style="color: #202020;">SetReportParser</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>HIDReportParser<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;</span>Prs<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  delay<span style="color: #009900;">&#40;</span> <span style="color: #0000dd;">200</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  Usb.<span style="color: #202020;">Task</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><div id="attachment_6820" class="wp-caption alignleft" style="width: 298px"><a href="/wp/wp-content/uploads/2011/11/adk_cuecat_setup.jpg"><img src="/wp/wp-content/uploads/2011/11/adk_cuecat_setup-288x216.jpg" alt="Connecting CueCat to Android phone - a full setup" title="Connecting CueCat to Android phone - a full setup" width="288" height="216" class="size-thumbnail wp-image-6820" /></a><p class="wp-caption-text">Connecting CueCat to Android phone - a full setup</p></div><br />
The main functionality of this sketch is contained in <code>OnKeyPressed()</code> callback &#8211; when a &#8220;key&#8221; is pressed, i.e., symbol arrives from the scanner, this symbol is sent out as-is to the phone or, if a special &#8220;end-of-barcode&#8221; character is received, it is substituted with newline character. Certain lines of this sketch deserve some explanation:</p>
<ul>
<li><strong>Line 17.</strong> An instance of <code>USB</code> object is declared. All USB devices refer to it.</li>
<li><strong>Lines 18-19.</strong>Two instances of USB hub are declared. I need two because 7-port hub I&#8217;m using consists of two cascaded 4-port hubs and I need to support both.</li>
<li><strong>Line 20.</strong>An instance of HID boot device is declared.</li>
<li><strong>Line 22.</strong>An instance of ADK device is declared.</li>
<li><strong>Lines 30-69.</strong>Redefining of HID methods.</li>
<li><strong>Lines 38-44.</strong>This method is called when a new keycode appears in input report. The code is translated into ASCII and the main <code>OnKeyPressed()</code> callback is called.</li>
<li><strong>Lines 46-69.</strong>The main callback.</li>
<li><strong>Lines 53-55.</strong>It returns immediately if ADK device is not ready.</li>
<li><strong>Lines 59-61.</strong>Here I test if &#8220;end-of-barcode&#8221; symbol has been received and replace it with a newline.</li>
<li><strong>Lines 62-64.</strong>Otherwise, the symbol simply gets sent to the phone.</li>
<li><strong>Lines 66-68.</strong>These lines print received symbol to serial terminal.</li>
</ul>
<p>The <code>setup()</code> and <code>loop()</code> functions at the end of the sketch don&#8217;t do anything exciting. The former initializes serial port, Usb subsystem and keyboard report parser. The latter calls <code>Usb.Task()</code> periodically; the callbacks described above are in fact called from here. If you want to modify this code to use in your project and if your application is going to do anything inside <code>loop()</code> make sure not to block <code>Usb.Task()</code> for too long.</p>
<p>A picture above shows all the hardware necessary to run this sketch, neatly arranged for your viewing pleasure. A 1000mah LiPo battery is connected to <a href="https://www.adafruit.com/products/14">MintyBoost</a> and 5V from MintyBoost is connected to USB port of Arduino via standard USB cable. The Android phone draws 500ma until fully charged, CueCat needs another 100ma when active and Arduino/USB Host duo needs some milliamps as well; tiny MintyBoost provides that much power while staying cool.</p>
<p>The USB Host shield sits on top of Arduino and connects to USB hub uplink port with ordinary USB cable. CueCat and Nexus S are connected to USB hub downlink ports. If everything is working, CueCat shall start emitting red light from its nose and Android phone shall auto-start Arduino Terminal application. Now just tap &#8220;clear&#8221; in the terminal, scan the barcode and see it appear on the screen. Pretty easy, huh?</p>
<p>Oleg.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.circuitsathome.com/mcu/exchanging-data-between-usb-devices-and-android-phone-using-arduino-and-usb-host-shield/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>CueCat meets Arduino, works with HID boot code</title>
		<link>http://www.circuitsathome.com/mcu/cuecat-meets-arduino-works-with-hid-boot-code</link>
		<comments>http://www.circuitsathome.com/mcu/cuecat-meets-arduino-works-with-hid-boot-code#comments</comments>
		<pubDate>Sun, 23 Oct 2011 21:53:21 +0000</pubDate>
		<dc:creator>oleg</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[MCU]]></category>
		<category><![CDATA[USB]]></category>
		<category><![CDATA[USB Shield]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[boot]]></category>
		<category><![CDATA[CueCat]]></category>
		<category><![CDATA[HD44780]]></category>
		<category><![CDATA[HID]]></category>
		<category><![CDATA[MAX3421E]]></category>
		<category><![CDATA[USB Host Shield]]></category>

		<guid isPermaLink="false">https://www.circuitsathome.com/?p=6762</guid>
		<description><![CDATA[<p><p class="wp-caption-text">CueCat meets Arduino</p> 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, [...]]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_6764" class="wp-caption alignleft" style="width: 298px"><a href="/wp/wp-content/uploads/2011/10/cuecat_lcd.jpg"><img src="https://www.circuitsathome.com/wp/wp-content/uploads/2011/10/cuecat_lcd-288x216.jpg" alt="CueCat meets Arduino" title="CueCat meets Arduino" width="288" height="216" class="size-thumbnail wp-image-6764" /></a><p class="wp-caption-text">CueCat meets Arduino</p></div><br />
Soon after posting <a href="/mcu/connecting-barcode-scanner-arduino-usb-host-shield">Arduino barcode scanner article</a> I started receiving questions about <a href="http://en.wikipedia.org/wiki/CueCat">CueCat</a>. 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. <a href="http://www.mavin.com/cuecat/">Declawed</a> 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.</p>
<p>I tested &#8220;declawed&#8221;  USB CueCat with my code &#8211; it initializes as HID boot keyboard and works very well. No modifications are needed to the sketch from the previous article &#8211; 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.</p>
<p>One last advantage of CueCat I&#8217;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 <a href="https://www.adafruit.com/products/14">Mintyboost from Adafruit Industries</a> with its output connected to Arduino USB port.</p>
<p>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 &#8211; try it with my code and let me know if you have any issues.</p>
<p>Oleg.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.circuitsathome.com/mcu/cuecat-meets-arduino-works-with-hid-boot-code/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Interfacing Arduino to USB GPRS modem</title>
		<link>http://www.circuitsathome.com/mcu/interfacing-arduino-to-usb-gprs-modem</link>
		<comments>http://www.circuitsathome.com/mcu/interfacing-arduino-to-usb-gprs-modem#comments</comments>
		<pubDate>Thu, 20 Oct 2011 19:19:34 +0000</pubDate>
		<dc:creator>oleg</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[MCU]]></category>
		<category><![CDATA[USB]]></category>
		<category><![CDATA[USB Shield]]></category>
		<category><![CDATA[wireless]]></category>
		<category><![CDATA[AT command]]></category>
		<category><![CDATA[cell]]></category>
		<category><![CDATA[dealextreme]]></category>
		<category><![CDATA[gprs]]></category>
		<category><![CDATA[gsm]]></category>
		<category><![CDATA[interface]]></category>
		<category><![CDATA[MAX3421E]]></category>
		<category><![CDATA[modem]]></category>
		<category><![CDATA[phone]]></category>
		<category><![CDATA[sms]]></category>
		<category><![CDATA[text message]]></category>
		<category><![CDATA[USB Host Shield]]></category>

		<guid isPermaLink="false">https://www.circuitsathome.com/?p=6683</guid>
		<description><![CDATA[<p><p class="wp-caption-text">Cheap GPRS modem from Dealextreme</p> 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&#8217;s battery level, signal strength and connection status. For many [...]]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_6685" class="wp-caption alignright" style="width: 298px"><a href="/wp/wp-content/uploads/2011/10/dx_gprs_modem_title.jpg"><img src="/wp/wp-content/uploads/2011/10/dx_gprs_modem_title-288x216.jpg" alt="Cheap GPRS modem from Dealextreme" title="Cheap GPRS modem from Dealextreme" width="288" height="216" class="size-thumbnail wp-image-6685" /></a><p class="wp-caption-text">Cheap GPRS modem from Dealextreme</p></div><br />
Some time ago I started writing about <a href="/mcu/programming/interfacing-arduino-to-a-cellular-phone">connecting Arduino to cellular network</a>. 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&#8217;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&#8217;m going to talk about one such piece of hardware which can be connected to Arduino board using <a href="/products-page/arduino-shields/usb-host-shield-2-0-for-arduino/">USB Host Shield</a>.</p>
<p><a href="http://www.dealextreme.com/p/12057?r=69855103">USB Tri-band GPRS Modem</a> 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 <a href="http://www.portech.com.tw/data/BenQ%20M23%20AT.pdf">BenQ M23</a> GSM/GPRS Wireless module and uses Prolific PL-2303 USB-to-serial converter. As explained <a href="http://www.brodyradford.com/2011/01/hacking-the-dealextreme-gprs-modem/">on this page</a>, the PL-2303 in the modem uses non-default USB PID; make sure to grab <a href="https://github.com/felis/USB_Host_Shield_2.0">the latest version of my library</a>, which transparently supports both PIDs.</p>
<p>To explore the functionality of this device I wrote a <a href="https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.pde">simple program</a> which is based on <a href="/mcu/building-pl2303-usb-to-serial-converter-from-old-data-cable">Xbee terminal</a>. The program initializes the PL-2303 and waits for user input passing keystrokes to the modem and displaying replies to the screen. Let&#8217;s run it and see what this little modem is capable of.<br />
<span id="more-6683"></span><br />
The hardware arrangement is shown on title picture. During normal operation the system can be powered from USB; depending on your Arduino board you may need to disconnect the modem during programming. All interactions occur via terminal emulator running on a PC &#8211; I use putty on Windows and minicom on Linux. Using serial monitor built into Arduino IDE is not recommended. The modem needs activated SIM card to function, I use prepaid SIM from T-Mobile and also successfully used it with AT&#038;T.</p>
<p>If everything is connected correctly sketch will output  the following:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
</pre></td><td class="code"><pre class="basic" style="font-family:monospace;">Start
PL Init
Addr:1
NC:1
0000: 09 02 27 00 01 01 00 A0 FA 09 04 00 00 03 FF 00
0010: 00 00 07 05 81 03 0A 00 01 07 05 02 02 40 00 00
0020: 07 05 83 02 40 00 00 Conf.Val: 01
Iface Num: 00
Alt.Set: 00
Endpoint descriptor:
Length:         07
Type:           05
Address:        81
Attributes:     03
MaxPktSize:     000A
Poll Intrv:     01
Conf.Val: 01
Iface Num: 00
Alt.Set: 00
Endpoint descriptor:
Length:         07
Type:           05
Address:        02
Attributes:     02
MaxPktSize:     0040
Poll Intrv:     00
Conf.Val: 01
Iface Num: 00
Alt.Set: 00
Endpoint descriptor:
Length:         07
Type:           05
Address:        83
Attributes:     02
MaxPktSize:     0040
Poll Intrv:     00
Conf:1
PL configured</pre></td></tr></table></div>

<p>The last message (line 38) shows that PL-2303 has been recognized and successfully configured. Type <code>at</code> on the keyboard and press <code>Enter</code>. If you see <code>OK</code> on the next line the modem is alive and answering.</p>

<div class="wp_syntax"><div class="code"><pre class="basic" style="font-family:monospace;">...
Conf:1
PL configured
at
OK</pre></div></div>

<p>Now let&#8217;s see if a modem is connected to a network. Type <code>at+creg?</code> and press <code>Enter</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="basic" style="font-family:monospace;">at+creg?
+CREG: 0, 1
&nbsp;
OK</pre></div></div>

<p>The second number in reply indicates the state of registration. My output (1) means the modem is happily registered with home network. Other numbers you may see are &#8220;0&#8243; &#8211; no service, &#8220;2&#8243; &#8211; searching for operator, &#8220;3&#8243; &#8211; registration denied. </p>
<p>If modem is registered, it is possible to determine the cell operator:</p>

<div class="wp_syntax"><div class="code"><pre class="basic" style="font-family:monospace;">at+cops?
+COPS: 0,0,&quot;T-Mobile 260&quot;
&nbsp;
OK</pre></div></div>

<p>When modem is online, we can do something useful. I&#8217;ve already sent several text messages to this number, let&#8217;s take a look at them by using <code>+CMGL</code> command:</p>

<div class="wp_syntax"><div class="code"><pre class="basic" style="font-family:monospace;">at+cmgl=1
+CMGL: 1,1,,50
07912160130320F8040B919127163673F500001101814190044A23F3F61C6496BFDBA0F3FB7D6697152D503BACAFCBDF76C0B91D4EB35DE3771B
+CMGL: 2,1,,57
07912160130320F5040B919127163673F500001101814124244A2B66F9BB0D3ABFDF677619447F83885850FB4D2EB7152D503BACAFCBDF76C0B91D4EB35DE3771B
+CMGL: 3,1,,53
07912160130320F8000B919127163673F500001101817184554A26F4F29C0E9A81CCF2771B747EBFCFECB2A2056A87F575F9DB0E38B7C369B66BFC6E03
+CMGL: 4,1,,53
07912160130320F8040B919127163673F500001101817145154A26F4F29C0EA281CCF2771B747EBFCFECB2A2056A87F575F9DB0E38B7C369B66BFC6E03
&nbsp;
OK</pre></div></div>

<p>What you see is output in so-called PDU format. Many GSM devices have this format turned on at power-up. It is OK for computers but not so easy for humans. Luckily for us, this modem also supports SMS text mode, which can be turned on using <code>+CMGF</code> command:</p>

<div class="wp_syntax"><div class="code"><pre class="basic" style="font-family:monospace;">at+cmgf=1
OK
at+cmgl=&quot;ALL&quot;
+CMGL: 1,&quot;REC READ&quot;,&quot;19725555555&quot;,,&quot;11/10/18,14:09:40-36&quot;,145,35
sms from google
               - m...v@gmail.com
+CMGL: 2,&quot;REC READ&quot;,&quot;19725555555&quot;,,&quot;11/10/18,14:42:42-36&quot;,145,43
from google to DX modem
                       - m...v@gmail.com
+CMGL: 3,&quot;REC READ&quot;,&quot;19725555555&quot;,,&quot;11/10/18,17:48:55-36&quot;,145,38
test 3 from google
                  - m...v@gmail.com
+CMGL: 4,&quot;REC READ&quot;,&quot;19725555555&quot;,,&quot;11/10/18,17:54:51-36&quot;,145,38
test 4 from google
                  - m...v@gmail.com
&nbsp;
OK</pre></div></div>

<p>Sending messages is also easy. It is done using <code>+CMGS</code> command. The command takes recipient&#8217;s phone number as a parameter and outputs a prompt where a message can be entered. End of message is indicated by pressing <code>Ctrl+z</code>, make sure your terminal program passes this code unchanged to the modem (putty works correctly here). Here is an example:</p>

<div class="wp_syntax"><div class="code"><pre class="basic" style="font-family:monospace;">at+cmgs=&quot;19725555555&quot;
&gt; test from T-Mobile to google
&gt;
+CMGS: 34
&nbsp;
OK</pre></div></div>

<p>There is much more that can be done with this little modem (or to any GSM phone for that matter). Some things, like placing or receiving calls, are pretty easy to do, while others, like accessing internet, would require some extra programming. In coming weeks I&#8217;m planning to develop code to support a cell phone in unattended mode; in the mean time, try to talk to your phone via terminal and let me know if you have any issues.</p>
<p>Oleg.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.circuitsathome.com/mcu/interfacing-arduino-to-usb-gprs-modem/feed</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>Connecting barcode scanner to Arduino using USB Host Shield</title>
		<link>http://www.circuitsathome.com/mcu/connecting-barcode-scanner-arduino-usb-host-shield</link>
		<comments>http://www.circuitsathome.com/mcu/connecting-barcode-scanner-arduino-usb-host-shield#comments</comments>
		<pubDate>Sun, 16 Oct 2011 19:01:17 +0000</pubDate>
		<dc:creator>oleg</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[DIY]]></category>
		<category><![CDATA[LCD]]></category>
		<category><![CDATA[MCU]]></category>
		<category><![CDATA[USB]]></category>
		<category><![CDATA[USB Shield]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[barcode]]></category>
		<category><![CDATA[boot]]></category>
		<category><![CDATA[HD44780]]></category>
		<category><![CDATA[HID]]></category>
		<category><![CDATA[MAX3421E]]></category>
		<category><![CDATA[reader]]></category>
		<category><![CDATA[RFID]]></category>
		<category><![CDATA[scanner]]></category>
		<category><![CDATA[USB Host Shield]]></category>

		<guid isPermaLink="false">https://www.circuitsathome.com/?p=6624</guid>
		<description><![CDATA[<p class="wp-caption-text">Scanning barcodes using Arduino and USB Host Shield</p> <p>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 [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_6625" class="wp-caption alignright" style="width: 298px"><a href="/wp/wp-content/uploads/2011/10/hid_boot_bc_title.jpg"><img src="https://www.circuitsathome.com/wp/wp-content/uploads/2011/10/hid_boot_bc_title-288x216.jpg" alt="Scanning barcodes using Arduino and USB Host Shield" title="Scanning barcodes using Arduino and USB Host Shield" width="288" height="216" class="size-thumbnail wp-image-6625" /></a><p class="wp-caption-text">Scanning barcodes using Arduino and USB Host Shield</p></div>
<p>An addition of Human Input Device Class support to  USB Host Shield library 2.0, <a href="/mcu/hid-support-for-usb-host-shield-library-2-0-released">announced several days ago</a> 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 &#8211; boot keyboard/mouse, has been released along with the library. The beauty of boot protocol lies in the simplicity of device report &#8211; 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 &#8211; only what is needed. In today&#8217;s article I will show practical application of HID boot device building a simple gadget. </p>
<p>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 &#8220;not-so-human&#8221; 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 &#8211; 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.<br />
<span id="more-6624"></span><br />
Let&#8217;s talk a little bit about necessary parts. First of all, we&#8217;ll need <a href="/products-page/arduino-boards/arduino-uno-dip/">Arduino board</a> and <a href="/products-page/arduino-shields/usb-host-shield-2-0-for-arduino/">USB Host Shield</a>. I use standard 16&#215;2 HD44780-compatible LCD display, connected similarly to one in <a href="http://www.arduino.cc/en/Tutorial/LiquidCrystal">Arduino LiquidCrystal tutorial</a>. Since USB Host shield uses pins 11 and 12 to interface to Arduino, I had to move corrsponding LCD signals to pins 6 and 7; the rest of the connections shall be made exactly like in the tutorial. Lastly, we need compatible handheld barcode scanner. The best place to search for one is <a href="http://www.ebay.com/sch/i.html?_from=R40&#038;_trksid=p5197.m570.l1313&#038;_nkw=usb+barcode+scanner&#038;_sacat=See-All-Categories">eBay</a>; look for phrases &#8220;no driver required&#8221; and &#8220;USB HID device&#8221; in product description.</p>
<p>To make sure a device is indeed a boot keyboard, take a look at device descriptors using <a href="https://github.com/felis/USB_Host_Shield_2.0/tree/master/examples/USB_desc">USB_Desc</a> example from USB Host library &#8211; a sample output is given below. Class, Subclass, Protocol in interface descriptor (lines 29-31) should be 03, 01, 01. If Subclass is zero, boot protocol is not supported. Non-boot scanner is still useful but accessing it is going to be slightly more complicated. I will cover HID report protocol in one of the next articles.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
</pre></td><td class="code"><pre class="basic" style="font-family:monospace;">Device descriptor:
Descriptor Length:      12
Descriptor type:        01
USB version:            0100
Device class:           00
Device Subclass:        00
Device Protocol:        00
Max.packet size:        08
Vendor  ID:             04B4
Product ID:             0100
Revision ID:            0100
Mfg.string index:       01
Prod.string index:      02
Serial number index:    00
Number of conf.:        01
&nbsp;
Configuration descriptor:
Total length:           0022
Num.intf:               01
Conf.value:             01
Conf.string:            04
Attr.:                  A0
Max.pwr:                64
&nbsp;
Interface descriptor:
Intf.number:            00
Alt.:                   00
Endpoints:              01
Intf. Class:            03
Intf. Subclass:         01
Intf. Protocol:         01
Intf.string:            05
Unknown descriptor:
Length:         09
Type:           21
Contents:       00011001223F000705
&nbsp;
Endpoint descriptor:
Endpoint address:       81
Attr.:                  03
Max.pkt size:           0008
Polling interval:       0A</pre></td></tr></table></div>

<p>Below is the sketch which needs to be compiled and loaded into Arduino. I wrote it by copying the <a href="https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/HID/USBHIDBootKbd/USBHIDBootKbd.pde">keyboard example</a>, taking out all unnecessary code and adding LCD support. The sketch can be copied from this page and pasted to Arduino IDE window.  An explanation of key pieces is given after the listing.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #ff0000; font-style: italic;">/*
&nbsp;
Portable barcode scanner. Uses USB HID barcode scanner, Arduino Board, USB Host Shield and HD44780-compatible LCD display
&nbsp;
  The circuit:
 * LCD RS pin to digital pin 7
 * LCD Enable pin to digital pin 6
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
&nbsp;
*/</span>
&nbsp;
<span style="color: #339900;">#include &lt;LiquidCrystal.h&gt;</span>
<span style="color: #339900;">#include &lt;avr/pgmspace.h&gt;</span>
&nbsp;
<span style="color: #339900;">#include &lt;avrpins.h&gt;</span>
<span style="color: #339900;">#include &lt;max3421e.h&gt;</span>
<span style="color: #339900;">#include &lt;usbhost.h&gt;</span>
<span style="color: #339900;">#include &lt;usb_ch9.h&gt;</span>
<span style="color: #339900;">#include &lt;Usb.h&gt;</span>
<span style="color: #339900;">#include &lt;usbhub.h&gt;</span>
<span style="color: #339900;">#include &lt;avr/pgmspace.h&gt;</span>
<span style="color: #339900;">#include &lt;address.h&gt;</span>
<span style="color: #339900;">#include &lt;hidboot.h&gt;</span>
&nbsp;
<span style="color: #339900;">#include &lt;printhex.h&gt;</span>
<span style="color: #339900;">#include &lt;message.h&gt;</span>
<span style="color: #339900;">#include &lt;hexdump.h&gt;</span>
<span style="color: #339900;">#include &lt;parsetools.h&gt;</span>
&nbsp;
<span style="color: #339900;">#define DISPLAY_WIDTH 16</span>
&nbsp;
<span style="color: #666666;">// initialize the LCD library with the numbers of the interface pins</span>
LiquidCrystal lcd<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">7</span>, <span style="color: #0000dd;">6</span>, <span style="color: #0000dd;">5</span>, <span style="color: #0000dd;">4</span>, <span style="color: #0000dd;">3</span>, <span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
USB     Usb<span style="color: #008080;">;</span>
<span style="color: #666666;">//USBHub     Hub(&amp;Usb);</span>
HIDBoot<span style="color: #000080;">&lt;</span>HID_PROTOCOL_KEYBOARD<span style="color: #000080;">&gt;</span>    Keyboard<span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>Usb<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">class</span> KbdRptParser <span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> KeyboardReportParser
<span style="color: #008000;">&#123;</span>
&nbsp;
<span style="color: #0000ff;">protected</span><span style="color: #008080;">:</span>
	<span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> OnKeyDown	<span style="color: #008000;">&#40;</span>uint8_t mod, uint8_t key<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> OnKeyPressed<span style="color: #008000;">&#40;</span>uint8_t key<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">void</span> KbdRptParser<span style="color: #008080;">::</span><span style="color: #007788;">OnKeyDown</span><span style="color: #008000;">&#40;</span>uint8_t mod, uint8_t key<span style="color: #008000;">&#41;</span>	
<span style="color: #008000;">&#123;</span>
    uint8_t c <span style="color: #000080;">=</span> OemToAscii<span style="color: #008000;">&#40;</span>mod, key<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>c<span style="color: #008000;">&#41;</span>
        OnKeyPressed<span style="color: #008000;">&#40;</span>c<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/* what to do when symbol arrives */</span>
<span style="color: #0000ff;">void</span> KbdRptParser<span style="color: #008080;">::</span><span style="color: #007788;">OnKeyPressed</span><span style="color: #008000;">&#40;</span>uint8_t key<span style="color: #008000;">&#41;</span>	
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">static</span> uint32_t next_time <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>      <span style="color: #666666;">//watchdog</span>
<span style="color: #0000ff;">static</span> uint8_t current_cursor <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>  <span style="color: #666666;">//tracks current cursor position  </span>
&nbsp;
    <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> millis<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&gt;</span> next_time <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
      lcd.<span style="color: #007788;">clear</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
      current_cursor <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
      delay<span style="color: #008000;">&#40;</span> <span style="color: #0000dd;">5</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>  <span style="color: #666666;">//LCD-specific </span>
      lcd.<span style="color: #007788;">setCursor</span><span style="color: #008000;">&#40;</span> <span style="color: #0000dd;">0</span>,<span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span><span style="color: #666666;">//if( millis() &gt; next_time ...</span>
&nbsp;
    next_time <span style="color: #000080;">=</span> millis<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">+</span> <span style="color: #0000dd;">200</span><span style="color: #008080;">;</span>  <span style="color: #666666;">//reset watchdog</span>
&nbsp;
    <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> current_cursor<span style="color: #000040;">++</span> <span style="color: #000080;">==</span> <span style="color: #008000;">&#40;</span> DISPLAY_WIDTH <span style="color: #000040;">+</span> <span style="color: #0000dd;">1</span> <span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>  <span style="color: #666666;">//switch to second line if cursor outside the screen</span>
      lcd.<span style="color: #007788;">setCursor</span><span style="color: #008000;">&#40;</span> <span style="color: #0000dd;">0</span>,<span style="color: #0000dd;">1</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    Serial.<span style="color: #007788;">println</span><span style="color: #008000;">&#40;</span> key <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    lcd.<span style="color: #007788;">print</span><span style="color: #008000;">&#40;</span> key <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
KbdRptParser Prs<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">void</span> setup<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    Serial.<span style="color: #007788;">begin</span><span style="color: #008000;">&#40;</span> <span style="color: #0000dd;">115200</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    Serial.<span style="color: #007788;">println</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Start&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>Usb.<span style="color: #007788;">Init</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">==</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        Serial.<span style="color: #007788;">println</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;OSC did not start.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    delay<span style="color: #008000;">&#40;</span> <span style="color: #0000dd;">200</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    Keyboard.<span style="color: #007788;">SetReportParser</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>, <span style="color: #008000;">&#40;</span>HIDReportParser<span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">&amp;</span>Prs<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #666666;">// set up the LCD's number of columns and rows: </span>
    lcd.<span style="color: #007788;">begin</span><span style="color: #008000;">&#40;</span>DISPLAY_WIDTH, <span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    lcd.<span style="color: #007788;">clear</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    lcd.<span style="color: #007788;">noAutoscroll</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    lcd.<span style="color: #007788;">print</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Ready&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    delay<span style="color: #008000;">&#40;</span> <span style="color: #0000dd;">200</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> loop<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  Usb.<span style="color: #007788;">Task</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<ul>
<li><strong>Lines 5-15.</strong> This comment contains information about necessary LCD connections</li>
<li><strong>Lines 46-52.</strong> <code>KeyboardReportParser</code> declaration. Compare with <a href="https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/HID/USBHIDBootKbd/USBHIDBootKbd.pde">keyboard example</a>. Here, we only need <code>OnKeyDown()</code> and <code>OnKeyPressed()</code> methods.</li>
<li><strong>Lines 54-60.</strong> <code>OnKeyDown()</code> callback definition. When a keyboard key is pressed, it receives scan code of this key plus modifiers (Ctrl, Alt, Shift). Since our LCD takes ASCII codes the callback performs scan code to ASCII conversion and then calls <code>OnKeyPressed()</code></li>
<li><strong>Line 63.</strong> <code>OnKeyPressed()</code> definition</li>
<li><strong>Lines 68-73.</strong>Clears the display before outputting first symbol of new barcode, i.e., if pause between symbols is larger than 200ms. Note delay in line 71 &#8211; my display is old and slow and unless I wait a little, it won&#8217;t print the first symbol of the sequence. Newer displays should work fine without it</li>
<li><strong>Lines 81-82.</strong> The output. A symbol is sent to serial terminal and LCD</li>
</ul>
<p>The rest of the sketch contains standard initialization of <code>USB Host</code> and <code>Liquidcrystal</code> libraries, as well as periodic calling of <code>Usb.Task()</code>, from which keyboard callbacks are called.</p>
<div id="attachment_6626" class="wp-caption alignleft" style="width: 298px"><a href="/wp/wp-content/uploads/2011/10/hid_boot_rfid.jpg"><img src="https://www.circuitsathome.com/wp/wp-content/uploads/2011/10/hid_boot_rfid-288x216.jpg" alt="Reading RFID tags with Arduino/USB Host Shield" title="Reading RFID tags with Arduino/USB Host Shield" width="288" height="216" class="size-thumbnail wp-image-6626" /></a><p class="wp-caption-text">Reading RFID tags with Arduino/USB Host Shield</p></div>
<p>Lastly, a bonus material for those who managed to keep reading the article to this place. Since the sketch assumes HID boot device, it can be used with many different devices. For example, it is possible to produce an output using ordinary keyboard (due to watchdod, in order to get more than one symbol on the LCD display, you&#8217;d have to type pretty fast). Also, the same setup makes pretty good RFID reader &#8211; many inexpensive USB readers in 125KHz class are implemented as HID boot keyboards. Picture on the left shows one such device connected to Arduino. It also shows a way of providing power via Arduino USB port using portable USB charger. RFID cloning, anyone?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.circuitsathome.com/mcu/connecting-barcode-scanner-arduino-usb-host-shield/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>HID support for USB Host Shield Library 2.0 released</title>
		<link>http://www.circuitsathome.com/mcu/hid-support-for-usb-host-shield-library-2-0-released</link>
		<comments>http://www.circuitsathome.com/mcu/hid-support-for-usb-host-shield-library-2-0-released#comments</comments>
		<pubDate>Wed, 12 Oct 2011 17:01:56 +0000</pubDate>
		<dc:creator>oleg</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[DIY]]></category>
		<category><![CDATA[MCU]]></category>
		<category><![CDATA[USB]]></category>
		<category><![CDATA[USB Shield]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[HID]]></category>
		<category><![CDATA[host]]></category>
		<category><![CDATA[keyboard]]></category>
		<category><![CDATA[MAX3421E]]></category>
		<category><![CDATA[mouse]]></category>
		<category><![CDATA[shield]]></category>

		<guid isPermaLink="false">https://www.circuitsathome.com/?p=6562</guid>
		<description><![CDATA[<p class="wp-caption-text">HID r.2.0 released</p> <p>I pleased to announce that after a long and difficult development period Human Input Device AKA HID class support has been added to USB Host Shield Library r.2.0 and is available on gitHub &#8211; I suggest downloading the whole directory, since some modifications has been also made to core files [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_6564" class="wp-caption alignright" style="width: 298px"><a href="/wp/wp-content/uploads/2011/10/hid_release_title.jpg"><img src="/wp/wp-content/uploads/2011/10/hid_release_title-288x216.jpg" alt="HID r.2.0 released" title="HID r.2.0 released" width="288" height="216" class="size-thumbnail wp-image-6564" /></a><p class="wp-caption-text">HID r.2.0 released</p></div>
<p>I pleased to announce that after a long and difficult development period Human Input Device AKA HID class support has been added to USB Host Shield Library r.2.0 and is available on gitHub &#8211; I suggest downloading <a href="https://github.com/felis/USB_Host_Shield_2.0">the whole directory</a>, since some modifications has been also made to core files to accommodate a new class. HID devices include popular devices like keyboards, mice, joysticks, game controllers, bar code scanners, RFID and magnetic card readers, digital scales and UPSes, to name a few.</p>
<p>I previously wrote about interfacing to HID devices <a href="/mcu/arduino-usb-host-part-4-peripherals">here</a>, <a href="/mcu/how-to-drive-usb-keyboard-from-arduino">here</a>, and <a href="/communicating-arduino-with-hid-devices-part-1">here</a>. The code examples in these articles were written for legacy USB Host Shield library and can&#8217;t be compiled with current revision, however, the basic principles are the same &#8211; the device is periodically polled by the host and sends back data block called <em>report</em> containing changes in device controls (buttons, switches, jog dials etc.) since the last poll. Even though different devices have different report formats, for a certain device, report format is stored in the device in data structure called <em>report descriptor</em>. Therefore, it is possible to learn about device controls from the device itself by parsing its report descriptor.</p>
<p>There is one special case where report format is known in advance. Almost all HID keyboards and mice support so-called <em>boot protocol</em> intended for communication to very simple systems like PC configuration screen when computer runs from BIOS. Keyboard boot protocol report consists of 8 bytes containing state of modifier keys (CTRL, SHIFT,etc.) in the first byte, second byte being reserved,  and up to 6 key scan codes in the rest of the report. Mouse boot protocol report consists of 3 bytes, first of which contains state of left, right and middle buttons and other 2 store X and Y travel since last poll. </p>
<p>In many cases boot protocol capabilities are more than enough for an Arduino project; for this reason, boot protocol class is the first to be released. To demonstrate operations of this class, 2 simple sketches has been developed, one for <a href="https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/HID/USBHIDBootMouse/USBHIDBootMouse.pde">mouse</a>, another for <a href="https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/HID/USBHIDBootKbd/USBHIDBootKbd.pde">keyboard</a>.<br />
<span id="more-6562"></span><br />
Sketches are designed for <a href="/products-page/arduino-shields/usb-host-shield-2-0-for-arduino/">USB Host Shield 2.0</a> attached to compatible <a href="/products-page/arduino-boards/arduino-uno-dip/">Arduino board</a>. Also, it is recommended to use external power supply while working with HID devices &#8211; I&#8217;ve seen many devices which would refuse to function when Arduino receives power from its USB port only.  </p>
<p>The operation of <a href="https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/HID/USBHIDBootMouse/USBHIDBootMouse.pde">mouse sketch</a> is quite simple: any mouse movement and/or button press causes a corresponding callback to be called. Below is the sketch output:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="basic" style="font-family:monospace;">000200
dx=2 dy=0
000100
dx=1 dy=0
0002FF
dx=2 dy=-1
020000
R Butt Dn
dx=0 dy=0
000000
R Butt Up
020000
R Butt Dn
030000
L Butt Dn
020000
L Butt Up</pre></td></tr></table></div>

<p>Sketch prints mouse report in hex and human-readable form. For example, lines 2 and 4 show mouse movement, lines 8 and 9 show first report when a button was pressed with no movement, the rest is just various button presses/releases.</p>
<p>The <a href="https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/HID/USBHIDBootKbd/USBHIDBootKbd.pde">keyboard sketch</a> is more advanced. It polls the keyboard, tracks key presses, converts scan codes to ASCII and also sends output report to turn keyboard LEDs on/off when CAPS LOCK, Num Lock, or Scroll Lock key is pressed. Here is the output:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
</pre></td><td class="code"><pre class="basic" style="font-family:monospace;">00001A0000000000
DN      &gt;1A&lt;
ASCII: w
0000000000000000
UP      &gt;1A&lt;
0000080000000000
DN      &gt;08&lt;
ASCII: e
0000000000000000
UP      &gt;08&lt;
00000B0000000000
DN      &gt;0B&lt;
ASCII: h
00000B0700000000
DN      &gt;07&lt;
ASCII: d
00000B070A090000
DN      &gt;0A&lt;
ASCII: g
DN      &gt;09&lt;
ASCII: f
0000070A09000000
UP      &gt;0B&lt;
0000070900000000
UP      &gt;0A&lt;
000007090B000000
DN      &gt;0B&lt;
ASCII: h
0000000000000000
UP      &gt;07&lt;
UP      &gt;09&lt;
UP      &gt;0B&lt;
0000390000000000
DN      &gt;39&lt;
0000390000000000
0000000000000000
UP      &gt;39&lt;
0000390000000000
DN      &gt;39&lt;
0000000000000000
UP      &gt;39&lt;</pre></td></tr></table></div>

<p>HID boot devices are quite common, inexpensive and easy to interface to Arduino using USB Host Shield. Two demo sketches should provide good example of HID boot class usage as well as serve as templates to incorporate into other projects. If you still have questions, please ask them in the comments &#8211; I will be glad to help. In coming weeks I&#8217;m going to write another article or two showing ways to use this new class. Stay tuned!</p>
<p>Oleg.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.circuitsathome.com/mcu/hid-support-for-usb-host-shield-library-2-0-released/feed</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>Focus stacking assistant var.Mini – build log</title>
		<link>http://www.circuitsathome.com/camera-control/focus-stacking-assistant-var-mini-build-log</link>
		<comments>http://www.circuitsathome.com/camera-control/focus-stacking-assistant-var-mini-build-log#comments</comments>
		<pubDate>Sun, 09 Oct 2011 06:04:01 +0000</pubDate>
		<dc:creator>oleg</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Camera Control]]></category>
		<category><![CDATA[DIY]]></category>
		<category><![CDATA[Low Power]]></category>
		<category><![CDATA[MCU]]></category>
		<category><![CDATA[USB]]></category>
		<category><![CDATA[USB Shield]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Canon DSLR]]></category>
		<category><![CDATA[focus]]></category>
		<category><![CDATA[PTP]]></category>
		<category><![CDATA[QM]]></category>
		<category><![CDATA[QP]]></category>
		<category><![CDATA[stacking]]></category>
		<category><![CDATA[USB Host Shield]]></category>

		<guid isPermaLink="false">https://www.circuitsathome.com/?p=6483</guid>
		<description><![CDATA[<p class="wp-caption-text">Focus Stacking Assistant var.Mini</p> <p>After spending a week with focus stacking assistant I realized that I need more units. I&#8217;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&#8217;m hoping to finish soon). Full-size Arduinos [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_6484" class="wp-caption alignright" style="width: 298px"><a href="/wp/wp-content/uploads/2011/10/fsa_mini_title.jpg"><img src="/wp/wp-content/uploads/2011/10/fsa_mini_title-288x216.jpg" alt="Focus Stacking Assistant var.Mini" title="Focus Stacking Assistant var.Mini" width="288" height="216" class="size-thumbnail wp-image-6484" /></a><p class="wp-caption-text">Focus Stacking Assistant var.Mini</p></div>
<p>After spending a week with <a href="/camera-control/focus-stacking-assistant-for-eos-cameras">focus stacking assistant</a> I realized that I need more units.  I&#8217;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&#8217;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 <a href="http://www.sparkfun.com/products/9220">Arduino Pro Mini 3.3V</a>, <a href="/products-page/arduino-shields/usb-host-shield-for-arduino-pro-mini/">USB Host Mini</a>, and a small home made PCB with buttons and LED. Finished mini-assistant can be seen on title picture and uses <a href="https://github.com/felis/FSA-EOS">the same code</a> as its big brother. What follows is a build log of mini-controller. It follows traditional layout, used, for example, <a href="http://www.instructables.com/id/Building-the-YaNis-EOS-Controller/">here</a> &#8211; 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.<br />
<div id="attachment_6498" class="wp-caption aligncenter" style="width: 1034px"><a href="/wp/wp-content/uploads/2011/10/fsa_mini_corners.jpg"><img src="/wp/wp-content/uploads/2011/10/fsa_mini_corners.jpg" alt="Step 1. The base." title="Step 1. The base." width="1024" height="768" class="size-full wp-image-6498" /></a><p class="wp-caption-text">Step 1. The base.</p></div></p>
<p><span id="more-6483"></span></p>
<p>I started by mounting 4 pins in the corners of USB Host Mini as depicted above. Doing it this way would allow me to take the unit apart later, if necessary, by simply cutting through wires. Following Arduino Pro Mini notation the &#8220;corner&#8221; pins are  D9 and RST in the top row and D10 and GND in the bottom row.</p>
<div id="attachment_6501" class="wp-caption aligncenter" style="width: 1034px"><a href="/wp/wp-content/uploads/2011/10/uhm_apm.jpg"><img src="/wp/wp-content/uploads/2011/10/uhm_apm.jpg" alt="Step 2. Mounting Arduino Pro Mini" title="Step 2. Mounting Arduino Pro Mini" width="1024" height="768" class="size-full wp-image-6501" /></a><p class="wp-caption-text">Step 2. Mounting Arduino Pro Mini</p></div>
<p>Next picture shows Arduino Pro Mini on top of USB Host Mini. It also shows proper placement of programming/serial header to connect USB to TTL-serial converter (Sparkfun <a href="http://www.sparkfun.com/products/9873">FTDI Basic Breakout &#8211; 3.3V</a> or similar).<br />
<div id="attachment_6522" class="wp-caption aligncenter" style="width: 1034px"><a href="/wp/wp-content/uploads/2011/10/uhm_apm_final.jpg"><img src="/wp/wp-content/uploads/2011/10/uhm_apm_final.jpg" alt="Step 3. Complete USB Host Mini - Arduino Pro Mini connections" title="Step 3. Complete USB Host Mini - Arduino Pro Mini connections" width="1024" height="768" class="size-full wp-image-6522" /></a><p class="wp-caption-text">Step 3. Complete USB Host Mini - Arduino Pro Mini connections</p></div></p>
<p>Next picture shows all connections &#8211; pins D10-D13, VCC and GND on one side and D5-D9, GND and RST on another. Note also that pins D9 and D11-D13 are made short &#8211; they won&#8217;t connect to the control board which will be mounted on the top.<br />
<div id="attachment_6528" class="wp-caption aligncenter" style="width: 1034px"><a href="/wp/wp-content/uploads/2011/10/fsa_controls.jpg"><img src="/wp/wp-content/uploads/2011/10/fsa_controls.jpg" alt="Step 4. Controls" title="Step 4. Controls" width="1024" height="768" class="size-full wp-image-6528" /></a><p class="wp-caption-text">Step 4. Controls</p></div></p>
<p>This is how the next board in stack looks like &#8211; it contains buttons, indicator LED, power connector and power switch. It can be made from a piece of perfboard or etched. <a href="/wp/wp-content/uploads/2011/10/fsa_mini_rev0.zip">Schematic diagram and board layout</a> in Eagle CAD format are provided to help with fabrication.<br />
 <div id="attachment_6539" class="wp-caption aligncenter" style="width: 1034px"><a href="/wp/wp-content/uploads/2011/10/fsa_mini_final.jpg"><img src="/wp/wp-content/uploads/2011/10/fsa_mini_final.jpg" alt="Step 5. Completed unit" title="Step 5. Completed unit" width="1024" height="768" class="size-full wp-image-6539" /></a><p class="wp-caption-text">Step 5. Completed unit</p></div></p>
<p>This is completed unit with control board soldered on top and small lipo battery connected to the board and secured with rubber band. It also shows last minute modification &#8211; a blue wire reconnecting LiPo from VCC to RAW pin. MAX3421E works best while powered from 3.3V +-10% (3.0-3.6V). Fresh LiPo outputs 4.2V dropping quickly to ~3.7V and stays around this voltage until drained pretty close to the end of discharge. This voltage is slightly out of spec and depending on a particular battery, MAX3421E chip, and several other factors your camera will or will not be detected reliably by MAX3421E when LiPo is connected directly to VCC. If voltage from LiPo is too high and camera is not detected, the remedy is simple &#8211; cut the trace going from middle pin of power switch to VCC and solder a wire from this pin to RAW. This will give you slightly less run time from a battery &#8211; that&#8217;s why current revision of control board connects battery to VCC. If enough people report issues with this arrangement, I&#8217;ll make this mod permanent by modifying the PCB layout.</p>
<p>I am currently refining the construction (the PCB layout posted is already slightly different from the board depicted in the article) and planning on writing another post after building another 2-3 units. I&#8217;m very interested to hear from other builders &#8211; if you encounter any issues and/or would like to suggest an improvement, please let me know!</p>
<p>Oleg.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.circuitsathome.com/camera-control/focus-stacking-assistant-var-mini-build-log/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Focus stacking assistant for EOS cameras</title>
		<link>http://www.circuitsathome.com/camera-control/focus-stacking-assistant-for-eos-cameras</link>
		<comments>http://www.circuitsathome.com/camera-control/focus-stacking-assistant-for-eos-cameras#comments</comments>
		<pubDate>Mon, 03 Oct 2011 02:54:03 +0000</pubDate>
		<dc:creator>oleg</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Camera Control]]></category>
		<category><![CDATA[DIY]]></category>
		<category><![CDATA[MCU]]></category>
		<category><![CDATA[USB]]></category>
		<category><![CDATA[USB Shield]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Canon DSLR]]></category>
		<category><![CDATA[focus]]></category>
		<category><![CDATA[PTP]]></category>
		<category><![CDATA[QM]]></category>
		<category><![CDATA[QP]]></category>
		<category><![CDATA[stacking]]></category>
		<category><![CDATA[USB Host Shield]]></category>

		<guid isPermaLink="false">https://www.circuitsathome.com/?p=6396</guid>
		<description><![CDATA[<p class="wp-caption-text">Focus Stacking Assistant</p> <p>[EDIT] Here is a build log of mini-variant of this device.[/EDIT]</p> <p>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 [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_6418" class="wp-caption alignright" style="width: 298px"><a href="/wp/wp-content/uploads/2011/09/fsa_00_title.jpg"><img src="/wp/wp-content/uploads/2011/09/fsa_00_title-288x216.jpg" alt="Focus Stacking Assistant" title="Focus Stacking Assistant" width="288" height="216" class="size-thumbnail wp-image-6418" /></a><p class="wp-caption-text">Focus Stacking Assistant</p></div>
<p><strong>[EDIT]</strong> Here is a <a href="/camera-control/focus-stacking-assistant-var-mini-build-log">build log of mini-variant</a> of this device.<strong>[/EDIT]</strong></p>
<p>One of my favorite shooting techniques is <a href="http://en.wikipedia.org/wiki/Focus_stacking">focus stacking</a>. Many pictures on Circuits@Home site are made using this technique. I use <a href="http://www.heliconsoft.com/heliconfocus.html">Helicon Focus</a> 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 <a href="/products-page/arduino-boards/arduino-uno-dip/">Arduino</a>, <a href="/products-page/arduino-shields/usb-host-shield-2-0-for-arduino/">USB Host Shield</a> and several small parts.</p>
<p>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 &#8220;near&#8221; of &#8220;far&#8221; points, after both points are set shooting sequence can be run &#8211; it always starts from &#8220;near&#8221; 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.</p>
<p>The controller can also be set to &#8220;free run&#8221; mode. Long press on third button starts shooting sequence from current lens position (which in this case can be set by hand using lens&#8217; focusing ring) towards infinity and will run indefinitely. It can be stopped at any moment by pressing on a focus move button.</p>
<p>A single LED shows states of the controller. Short blink once a second indicates &#8220;idle&#8221; state &#8211; controller is connected to the camera, PTP session is open. Continuous frequent blinking means some kind of an error &#8211; 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.</p>
<p>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.<br />
<span id="more-6396"></span><br />
Let&#8217;s now talk about how building the assistant. Links to Arduino board and USB Host Shield has been given at the beginning of the article, refer to <a href="/usb-host-shield-hardware-manual">USB Host Shield hardware manual</a> for connection instructions. The protoshield is also handy, I prefer <a href="http://www.adafruit.com/products/55">ones from Adafruit</a>, maybe I&#8217;m just lucky but I&#8217;m always receiving blue ones which match nicely with Arduino and host shield. You will also need some wire, a LED, current-limiting resistor (Adafruit sells all of that), and 3-4 <a href="http://www.circuitsathome.com/products-page/components/tactile-switch-6x6mm-pcb-mount/">tactile switches</a>. The connections can be figured out from title picture, here is <a href="/wp/wp-content/uploads/2011/10/fsa_fs_sch.pdf">&#8220;formal&#8221; schematic</a> just in case.</p>
<p>The <a href="https://github.com/felis/FSA-EOS">control software</a> is hosted on gitHub. It depends on <a href="https://github.com/felis/USB_Host_Shield_2.0">USB Host Shield library r.2.0</a>, <a href="https://github.com/felis/PTP_2.0">PTP library r.2.0</a> and <a href="http://www.state-machine.com/">Quantum Leaps</a> state machine framework AKA QP (the code uses standard Arduino variant of QP from Quantum Leaps site, not the modification made for PTP library examples!). The state machine design has been made using QM modeling tool and model file is included in the repo for your viewing pleasure.</p>
<p>The code has been extensively tested with Canon 5D Mark II and XSi cameras, it should work with any Canon DSLR with LiveView function. The code is in beta, it is a little slow and maximum exposure time is around 1-2 sec depending on the camera and lens model. In coming weeks I&#8217;m going to build and test Mini variant of the circuit and write code for Nikon DSLRs. As always, stay tuned for the updates and if you build this circuit, please share your experience in the comments!</p>
<p>Oleg.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.circuitsathome.com/camera-control/focus-stacking-assistant-for-eos-cameras/feed</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>dslrrc – another Arduino+Android wireless EOS controller</title>
		<link>http://www.circuitsathome.com/camera-control/dslrrc-another-arduinoandroid-wireless-eos-controller</link>
		<comments>http://www.circuitsathome.com/camera-control/dslrrc-another-arduinoandroid-wireless-eos-controller#comments</comments>
		<pubDate>Fri, 30 Sep 2011 01:10:20 +0000</pubDate>
		<dc:creator>oleg</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Camera Control]]></category>
		<category><![CDATA[USB Shield]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[dslrrc]]></category>
		<category><![CDATA[PTP]]></category>
		<category><![CDATA[USB Host Shield]]></category>

		<guid isPermaLink="false">https://www.circuitsathome.com/?p=6401</guid>
		<description><![CDATA[<p></p> <p>Here is another exciting camera control project &#8211; an improvement of Yanis controller which I covered some time ago. The author &#8211; Ziggy from Crisp Concept used Yanis hardware as-is but developed his own control code for both Arduino and Android. Several additional commands has been implemented, most notably video recording and LiveView [...]]]></description>
			<content:encoded><![CDATA[<p><iframe width="560" height="315" src="http://www.youtube.com/embed/SGD2XRlYzfc" frameborder="0" allowfullscreen></iframe></p>
<p>Here is another exciting camera control project &#8211; an improvement of <a href="http://theiopage.blogspot.com/2011/08/yanis-android-wireless-eos-controller.html">Yanis controller</a> which <a href="/camera-control/arduinoandroid-wireless-eos-controller">I covered</a> some time ago. The author &#8211; Ziggy from <a href="http://crispconcept.com">Crisp Concept</a> used Yanis hardware as-is but developed his own  control code for both Arduino and Android. Several additional commands has been implemented, most notably video recording and LiveView zoom control. </p>
<p>The project is hosted on <a href="http://code.google.com/p/dslrrc-eos-dslr-android-wireless-remote-controller/">Google Code</a>. The source code of Arduino sketch is posted there and can be used for learning how to use commands not covered in PTP library examples. It should be noted that Ziggy uses modified versions of old PTP and USB Host libraries &#8211; you&#8217;d need to use them instead of standard ones in order for sketch to compile.</p>
<p>I&#8217;m hoping parallel development will  be beneficial for Manishi&#8217;s and Ziggy&#8217;s projects. I&#8217;m following both with great interest and will  be posting updates here. Stay tuned!</p>
<p>Oleg.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.circuitsathome.com/camera-control/dslrrc-another-arduinoandroid-wireless-eos-controller/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

