<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Yihui's Blog</title>
 <link href="http://xiongyihui.github.io/" rel="self"/>
 <link href="http://xiongyihui.github.io"/>
 <updated>2014-05-07T23:33:31-07:00</updated>
 <id>http://xiongyihui.github.io</id>
 <author>
   <name>Yihui Xiong</name>
   <email>xiongyihui3@gmail.com</email>
 </author>

 
 <entry>
   <title>Capacitive Touch</title>
   <link href="http://xiongyihui.github.io/2014/05/06/Simplest-Capacitive-Touch"/>
   <updated>2014-05-06T00:00:00-07:00</updated>
   <id>http://xiongyihui.github.io/2014/05/06/Simplest-Capacitive-Touch</id>
   <content type="html">
&lt;p&gt;Capacitive touch is widely used in our dairly life. Curious about how it works?
Let’s build a capacitive button based on &lt;a href=&quot;http://mbed.org&quot;&gt;mbed platform&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/capacitive_touch.jpg&quot; alt=&quot;Capacitive Touch&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The capacitance of a capacitive button will be changed when with a human touch.
There are several ways to measure the change of the capacitance. Here we use the
charging/discharging time of a simple RC circuit to correlate the capacitance.&lt;/p&gt;

&lt;h2 id=&quot;hardware&quot;&gt;Hardware&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;An mbed board (Arch is used here)&lt;/li&gt;
  &lt;li&gt;An apple with a bite&lt;/li&gt;
  &lt;li&gt;A wire&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Use the wire to connect the Arch’s P0_11 with the apple.&lt;/p&gt;

&lt;h2 id=&quot;software&quot;&gt;Software&lt;/h2&gt;
&lt;p&gt;The pull-down feature of a general porpuse I/O is used to discharging the 
capacitor of the touch button. A Ticker is used to measure the discharging time 
of the capacitor every 1/64 seconds.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Capacitive Touch Program&lt;/em&gt; - &lt;a href=&quot;https://mbed.org/compiler/#import:/users/yihui/code/Arch_Capacitive_Touch/;platform:Seeeduino-Arch&quot;&gt;Import program to mbed online compiler&lt;/a&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-cpp&quot;&gt;#include &quot;mbed.h&quot;
 
DigitalOut led(LED1);
DigitalInOut touch(P0_11);       // Connect a wire to P0_11
Ticker tick;
 
uint8_t touch_data = 0;         // data pool
 
void detect(void)
{
    uint8_t count = 0;
    touch.input();              // discharge the capacitor
    while (touch.read()) {
        count++;
        if (count &amp;gt; 4) {
            break;
        }
    }
    touch.output();
    touch.write(1);             // charge the capacitor
    
    if (count &amp;gt; 2) {
        touch_data = (touch_data &amp;lt;&amp;lt; 1) + 1;
    } else {
        touch_data = (touch_data &amp;lt;&amp;lt; 1);
    }
    
    if (touch_data == 0x01) {
        led = 1;                // touch
    } else if (touch_data == 0x80) {
        led = 0;                // release
    }
}
 
int main()
{
    touch.mode(PullDown);
    touch.output();
    touch.write(1);
    
    tick.attach(detect, 1.0 / 64.0);
    
    while(1) {
        // do something
    }
}
&lt;/code&gt;&lt;/pre&gt;

</content>
 </entry>
 
 <entry>
   <title>nRF51822 with pyOCD and Arch</title>
   <link href="http://xiongyihui.github.io/2014/03/31/nRF51822-with-pyOCD-and-Arch"/>
   <updated>2014-03-31T00:00:00-07:00</updated>
   <id>http://xiongyihui.github.io/2014/03/31/nRF51822-with-pyOCD-and-Arch</id>
   <content type="html">&lt;p&gt;I’m quite excited that Bluetooth Low Energy (nRF51822) is comming to mbed. So I’m exploring what we can do with BLE (nRF51822). Preparing tools to get started with new things is always the beginning.&lt;/p&gt;

&lt;p&gt;Here we use &lt;a href=&quot;https://github.com/mbedmicro/CMSIS-DAP&quot;&gt;CMSIS-DAP&lt;/a&gt; and &lt;a href=&quot;https://github.com/mbedmicro/pyOCD&quot;&gt;pyOCD&lt;/a&gt;. &lt;a href=&quot;https://github.com/mbedmicro/CMSIS-DAP&quot;&gt;CMSIS-DAP&lt;/a&gt; is the software running on mbed interface to provide drag-n-drop, USB2UART communication and SWD debug. pyOCD is an Open Source python library or programming and debugging ARM Cortex-M microcontrollers using CMSIS-DAP.&lt;/p&gt;

&lt;p&gt;First, use &lt;a href=&quot;http://mbed.org/platforms/Seeeduino-Arch/&quot;&gt;Arch&lt;/a&gt; as an mbed interface to run &lt;a href=&quot;https://github.com/mbedmicro/CMSIS-DAP&quot;&gt;CMSIS-DAP&lt;/a&gt;. &lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Download &lt;a href=&quot;https://github.com/xiongyihui/CMSIS-DAP/raw/lpc11u24/interface/mdk/lpc11u24/lpc11u24_nrf51822_if_mbed.bin&quot;&gt;mbed interface firmware for Arch&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;Connect Arch with PC, long press Arch’s button and replace firmware.bin with the new firmware in “CRP DISABLD” drive on windows. use &lt;code&gt;dd if=lpc11u24_nrf51822_if_mbed.bin of={path-to}/firmware.bin conv=notrunc&lt;/code&gt; on &lt;a href=&quot;http://mbed.org/users/seeed/notebook/programming-seeeduino-arch/&quot;&gt;Linux/Mac&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Quick press the button. “MBED” drive will pop up.&lt;/li&gt;
  &lt;li&gt;Install the &lt;a href=&quot;http://mbed.org/handbook/Windows-serial-configuration&quot;&gt;mbed interface driver&lt;/a&gt; for windows to enable USB2UART function&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/debug_adapter.png&quot; alt=&quot;CMSIS-DAP debug adapter&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Second, setup pyOCD for nRF51822. We need pyOCD, pyUSB(Linux) or pyWinUSB(Windows) and &lt;a href=&quot;https://github.com/xiongyihui/pyOCD/raw/master/util/flash_nrf51822.py&quot;&gt;flash_nrf51822.py&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On Ubuntu&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-shell&quot;&gt;sudo apt-get install python-setuptools
sudo easy_install pyusb
sudo easy_install pyocd
sudo easy_install intelhex
wget https://github.com/xiongyihui/pyOCD/raw/master/util/flash_nrf51822.py
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;On windows, install pyWinUSB instread of pyUSB.&lt;/p&gt;

&lt;p&gt;Third, flash a hex file generated by mbed online compiler or an application binary file to nRF51822.&lt;/p&gt;

&lt;p&gt;The hex file includes threee parts — Code Region 0 (CR0), Code Region 1 (CR1) and User Information Configuration Registers (UICR). To flash the hex file, run&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo python flash_nrf51822.py -i {ble.hex}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To flash an application binary with an offset 0x14000&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo python flash_nrf51822.py -b {app.bin}
&lt;/code&gt;&lt;/pre&gt;

</content>
 </entry>
 
 <entry>
   <title>aqemu on Ubuntu 13.10</title>
   <link href="http://xiongyihui.github.io/2013/12/13/aqemu-on-ubuntu-13.10"/>
   <updated>2013-12-13T00:00:00-08:00</updated>
   <id>http://xiongyihui.github.io/2013/12/13/aqemu-on-ubuntu-13.10</id>
   <content type="html">
&lt;p&gt;aqemu does not work very well on Ubuntu 13.10. There is a bug which could cause
a segmentation fault.&lt;/p&gt;

&lt;h2 id=&quot;condition&quot;&gt;Condition&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Ubuntu 13.10 64bit&lt;/li&gt;
  &lt;li&gt;aqemu 0.8.2&lt;/li&gt;
  &lt;li&gt;qemu 1.5.0&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;bug&quot;&gt;Bug&lt;/h2&gt;
&lt;p&gt;aqmeu uses an arbitrary list of qemu/kvm versions in 
Edit_Emulator_Version_Window.cpp&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;// Add Items
if( Emulators[currentRow].Get_Type() == VM::QEMU )
{
    ui.CB_Versions-&amp;gt;clear();

    ui.CB_Versions-&amp;gt;addItem( tr(&quot;QEMU 0.9.0&quot;) );
    ui.CB_Versions-&amp;gt;addItem( tr(&quot;QEMU 0.9.1&quot;) );
    ui.CB_Versions-&amp;gt;addItem( tr(&quot;QEMU 0.10.X&quot;) );
    ui.CB_Versions-&amp;gt;addItem( tr(&quot;QEMU 0.11.X&quot;) );
    ui.CB_Versions-&amp;gt;addItem( tr(&quot;QEMU 0.12.X&quot;) );
    ui.CB_Versions-&amp;gt;addItem( tr(&quot;QEMU 0.13.X&quot;) );
}
else if( Emulators[currentRow].Get_Type() == VM::KVM )
{
    ui.CB_Versions-&amp;gt;clear();

    ui.CB_Versions-&amp;gt;addItem( tr(&quot;KVM 7X&quot;) );
    ui.CB_Versions-&amp;gt;addItem( tr(&quot;KVM 8X&quot;) );
    ui.CB_Versions-&amp;gt;addItem( tr(&quot;KVM 0.11.X&quot;) );
    ui.CB_Versions-&amp;gt;addItem( tr(&quot;KVM 0.12.X&quot;) );
    ui.CB_Versions-&amp;gt;addItem( tr(&quot;KVM 0.13.X&quot;) );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&quot;solution&quot;&gt;Solution&lt;/h2&gt;
&lt;ol&gt;
  &lt;li&gt;If your aqemu does not work already, remove &lt;code&gt;~/.config/ANDronSoft&lt;/code&gt; first.&lt;/li&gt;
  &lt;li&gt;Run aqemu. In the “First Start Wizard”, do not search Emulators and 
directly click “next” in the “Find Emulators” page.&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;When the main window shows up, go to &lt;code&gt;File-&amp;gt;Advanced Settings&lt;/code&gt; menu.
Change the settings as the following image.&lt;/p&gt;

    &lt;p&gt;&lt;img src=&quot;/assets/images/AdvancedSettings.png&quot; alt=&quot;AdvancedSettings&quot; /&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

</content>
 </entry>
 
 <entry>
   <title>Hello World</title>
   <link href="http://xiongyihui.github.io/2013/06/18/hello-world"/>
   <updated>2013-06-18T00:00:00-07:00</updated>
   <id>http://xiongyihui.github.io/2013/06/18/hello-world</id>
   <content type="html">
&lt;p&gt;&lt;img src=&quot;/assets/images/cat.png&quot; alt=&quot;cat&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;here-is-the-beginning&quot;&gt;Here is the beginning.&lt;/h2&gt;
</content>
 </entry>
 
 
</feed>