<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="/feed.xml" rel="self" type="application/atom+xml" /><link href="/" rel="alternate" type="text/html" /><updated>2024-09-29T04:21:36+00:00</updated><id>/feed.xml</id><title type="html">Greg Woods - Occasionally Useful</title><subtitle>Personal blog of Greg Woods with an emphasis on microcontroller, computing, and other hobby projects</subtitle><author><name>{&quot;bio&quot;=&gt;&quot;Personal blog with an emphasis on microcontrollers, computing, and other hobby projects.&quot;, &quot;location&quot;=&gt;&quot;Lancashire, UK&quot;, &quot;links&quot;=&gt;[{&quot;label&quot;=&gt;&quot;Instagram&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-instagram&quot;, &quot;url&quot;=&gt;&quot;https://www.instagram.com/gregwoodslancs/&quot;}, {&quot;label&quot;=&gt;&quot;GitHub&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-github&quot;, &quot;url&quot;=&gt;&quot;https://github.com/gregwoods&quot;}, {&quot;label&quot;=&gt;&quot;Twitter&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-twitter-square&quot;, &quot;url&quot;=&gt;&quot;https://twitter.com/gregwoods&quot;}]}</name></author><entry><title type="html">MicroPython on ESP32 Development with VS Code</title><link href="/2020-06-05-micropython-on-esp32-development-with-vscode" rel="alternate" type="text/html" title="MicroPython on ESP32 Development with VS Code" /><published>2020-06-05T06:49:00+00:00</published><updated>2020-06-05T06:49:00+00:00</updated><id>/micropython-on-esp32-development-with-vscode</id><content type="html" xml:base="/2020-06-05-micropython-on-esp32-development-with-vscode"><![CDATA[<blockquote>
  <p><strong>UPDATE:</strong> This post is a work in progress, it reflects my current thinking on the best way to start and run a micropython project on an ESP32, but I’ve been looking into this for only a few days, so it may change a lot.</p>
</blockquote>

<!---
PREVIOUS: Flashing the MicroPython firmware on an ESP32

* Notes: WORK IN PROGRESS: tidy up later
* ToDO: Add header image with board and micropython logo
--->

<h2 id="be-organised">Be Organised!</h2>

<p>Don’t just dump your code anywhere, make a decision about where to put it! For me, this is <strong>C:\Users\Gregw\microcontroller-home</strong></p>

<p>From Windows Terminal</p>

<ul>
  <li>Set up folder structure. Adjust to taste! Don’t forget the tab key to autocomplete partial folder and file names.</li>
</ul>

<pre><code class="language-dos">cd \Users\gregw\
mkdir microcontroller-home
cd microcontroller-home
</code></pre>

<p>Getting to a REPL prompt is a good start, but you need to be able to write code in a capable editor, with intellisense, or context-aware auto-completion, because you’re 50x more productive when you can type a dot after the name of an object, and your editor suggests all applicable properties and methods on that object. Without this, you’ll be spending over 99% of your time trawling documentation.</p>

<blockquote>
  <p>I’ve tried out VS Code extensions for <code class="language-plaintext highlighter-rouge">ampy</code>, <code class="language-plaintext highlighter-rouge">rshell</code> and the <code class="language-plaintext highlighter-rouge">MicroPython IDE</code>, with varied degrees of success (tip: don’t bother even trying the MicroPyhton IDE in Windows, it does nothing).</p>
</blockquote>

<p>The Best Options I can find are…</p>

<ul>
  <li>micropy-cli</li>
  <li>Pymakr</li>
</ul>

<h2 id="global-setup">Global Setup</h2>

<ul>
  <li>It is assumed you’ve installed all the prereqs listed in the previous post</li>
  <li><a href="https://nodejs.org/en/download/">Install NodeJs</a>
    <ul>
      <li>use the LTS version, 64bit msi for Windows
I also accepted the recommendation to install additional tools, which includes the  windows package manager “chocolatey”</li>
    </ul>
  </li>
</ul>

<p>I’ve chosen to install the following globally, as you will likely use
these tools in many projects.</p>

<p>|I am also not using virtual environments for each project, 
since micropython dependencies are managed separately by micropy-cli.</p>

<pre><code class="language-dos">cd c:\users\gregw\microcontroller-home
pip install esptool micropy-cli
micropy stubs search "esp32"
micropy stubs add "esp32-micropython-1.12.0"
</code></pre>

<h2 id="new-project-setup">New Project Setup</h2>

<p>Blinking an LED is the Hello World of the microcontroller world.</p>

<p>These step apply to all new projects. I am using a separate python virtual environment for each project, which is a couple more steps for each projec, but keeps each project nicely self-contained.</p>

<p>After a <em>lot</em> of thought, I’ve decided on the following project naming convention…</p>

<p><em>projectname-device-platform/language</em></p>

<p>Once you get hundreds of projects stacking up, you come to realise that good naming matters a lot. More on naming in another post.</p>

<pre><code class="language-dos">micropy init oled-esp32-upy
    select all 5 options using space bar and up/down arrows, with Enter to Ok your selection
    then select the stub: esp32-micropython-1.12.0
cd oled-esp32-upy
code .
</code></pre>

<p>When VS Code opens, it will ask if you want to install the recommended Extensions. Go ahead and do it.</p>

<p>I will not be using VS Code’s Workspaces feature, but if you regularly switch between different types of projects e.g. Rust and MicroPython, Workspaces are extremely useful.</p>

<ul>
  <li>Install the VS Code <strong>PyMakr</strong> extension</li>
</ul>

<h2 id="each-session">Each Session</h2>

<p>Once the above steps have been done once in a project folder, next time you want to work on that same project, you just need to navigate to that folder and start VS Code.</p>

<pre><code class="language-dos">cd c:\users\gregw\microcontroller-home\oled-esp32-upy
code .
</code></pre>

<h2 id="hello-world-on-the-display">Hello World on the Display</h2>

<p>Copy code from https://raw.githubusercontent.com/micropython/micropython/master/drivers/display/ssd1306.py
to src/ssd1306.py</p>

<ul>
  <li>“install” it using micropy’s package manager so we get intellisense</li>
</ul>

<pre><code class="language-dos">micropy install -p ./src/ssd1306.py ssd1306
</code></pre>

<ul>
  <li>main.py</li>
</ul>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">machine</span><span class="p">,</span> <span class="n">ssd1306</span>
<span class="n">i2c</span> <span class="o">=</span> <span class="n">machine</span><span class="p">.</span><span class="n">I2C</span><span class="p">(</span><span class="n">scl</span><span class="o">=</span><span class="n">machine</span><span class="p">.</span><span class="n">Pin</span><span class="p">(</span><span class="mi">4</span><span class="p">),</span> <span class="n">sda</span><span class="o">=</span><span class="n">machine</span><span class="p">.</span><span class="n">Pin</span><span class="p">(</span><span class="mi">5</span><span class="p">))</span>
<span class="n">oled</span> <span class="o">=</span> <span class="n">ssd1306</span><span class="p">.</span><span class="n">SSD1306_I2C</span><span class="p">(</span><span class="mi">128</span><span class="p">,</span> <span class="mi">64</span><span class="p">,</span> <span class="n">i2c</span><span class="p">,</span> <span class="mh">0x3c</span><span class="p">)</span>
<span class="n">oled</span><span class="p">.</span><span class="n">fill</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="n">oled</span><span class="p">.</span><span class="n">text</span><span class="p">(</span><span class="s">"Hello World"</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="n">oled</span><span class="p">.</span><span class="n">show</span><span class="p">()</span>
</code></pre></div></div>

<ul>
  <li>Upload your modified main.py</li>
</ul>

<p>TODO: screenshot of vscode pymakr integration (animated gif better)</p>

<h2 id="references">References</h2>

<p><a href="https://lemariva.com/blog/2019/08/micropython-vsc-ide-intellisense">Setup <strong>microPy</strong> and <strong>PyMakr</strong> in VS Code</a>
<a href="https://randomnerdtutorials.com/esp32-built-in-oled-ssd1306/">Pinout of ESP32 with onboard OLED</a>
<a href="https://diyprojects.io/">sample code to print Hello World on the OLED</a>
<a href="oled-display-ssd1306-micropython-example-digital-barometer-bme280-i2c/#.XtrFi0VKiKc">Another example using the OLED and a digital barometer</a></p>]]></content><author><name>{&quot;bio&quot;=&gt;&quot;Personal blog with an emphasis on microcontrollers, computing, and other hobby projects.&quot;, &quot;location&quot;=&gt;&quot;Lancashire, UK&quot;, &quot;links&quot;=&gt;[{&quot;label&quot;=&gt;&quot;Instagram&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-instagram&quot;, &quot;url&quot;=&gt;&quot;https://www.instagram.com/gregwoodslancs/&quot;}, {&quot;label&quot;=&gt;&quot;GitHub&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-github&quot;, &quot;url&quot;=&gt;&quot;https://github.com/gregwoods&quot;}, {&quot;label&quot;=&gt;&quot;Twitter&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-twitter-square&quot;, &quot;url&quot;=&gt;&quot;https://twitter.com/gregwoods&quot;}]}</name></author><category term="microcontroller" /><category term="embedded" /><category term="micropython" /><category term="esp32" /><summary type="html"><![CDATA[Once you have working MicroPython firmware on an ESP32 board, you need to write code. You can't stay in REPL forever, so lets set up our developer environment using Visual Studio Code]]></summary></entry><entry><title type="html">Flashing MicroPython Firmware onto an ESP32</title><link href="/2020-05-26-micropython-on-esp32-from-scratch" rel="alternate" type="text/html" title="Flashing MicroPython Firmware onto an ESP32" /><published>2020-05-26T13:55:31+00:00</published><updated>2020-05-26T13:55:31+00:00</updated><id>/flashing-micropython-firmware-on-esp32</id><content type="html" xml:base="/2020-05-26-micropython-on-esp32-from-scratch"><![CDATA[<ul>
  <li>ToDO: Add header image with board and micropython logo</li>
</ul>

<p>This is a little diversion from Rust on the STM32. My nephew has been doing some Python at school, and also had a project in mind for an ESP8266/ESP32. I had a couple of spares, so it’s time to flash MicroPython onto them and have a play.</p>

<p>It is worth noting that using microPython on a board like the ESP32 is not a well polished experience. It may be worth going for a more expensive board that was built with microPython in mind, or going for the even more polished <a href="https://learn.adafruit.com/welcome-to-circuitpython/what-is-circuitpython">CircuitPython</a>.</p>

<h2 id="setting-up-your-host-pc">Setting up your host PC</h2>

<ul>
  <li><strong>Essential:</strong> Install <a href="https://www.python.org/downloads/windows/">Python 3.x 64bit Windows</a> - you’re host PC uses various Python tools to flash microPython to the board, upload your code, and perform other tasks
    <ul>
      <li><a href="https://www.python.org/downloads/">Use the Windows Installer Version</a></li>
      <li><a href="https://docs.python.org/3/using/windows.html#:~:text=The%20full%20installer%20contains%20all,IDLE%20or%20other%20development%20environments.">Don’t use the Windows Store version</a></li>
      <li>I left everything default except…</li>
      <li>Add Python 3.8 to PATH: Yes</li>
      <li>Note: I did not use the Customize Installation option, which can be used to install Python in C:\Program Files, as this can cause extra permissions problems when running pip from a non-elevated command prompt.</li>
    </ul>
  </li>
  <li><strong>Recommended:</strong> Install <a href="https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html">Putty</a>. You need a way to communicate with serial ports. Putty is one way to do it, and is commonly used for a variety of tasks, so it is worth getting used to its quirky UI.  Use the 64bit MSI (“Windows Installer”)</li>
  <li><strong>Recommended:</strong> Install <a href="https://code.visualstudio.com/">Visual Studio Code</a> Because you don’t want to be writing code in the REPL, or Notepad!</li>
  <li><strong>Recommended</strong> Install <a href="https://aka.ms/terminal">Windows Terminal</a>. Because it is a lot more user friendly than the 30 year old Command Prompt.</li>
  <li><strong>Optional:</strong> Python Virtual Environments are very useful, as they allow you to create independent environments for different projects, each with their own sets of packages. Read about <a href="https://docs.python.org/3/tutorial/venv.html">Virtual Environments here</a>. I’ll be using venv in this tutorial.</li>
</ul>

<h2 id="flash-micropython-onto-the-esp32">Flash MicroPython onto the ESP32</h2>

<ul>
  <li><a href="https://micropython.org/download/esp32/">Download the ESP32 firmware</a>. I used the latest <strong>stable</strong> one based on <strong>ESP-IDF v3.x</strong>, and save or copy it to your working folder.
    <ul>
      <li>Note: by using the stable version of MicroPython, we don’t need the extra step of “disabling debug output”</li>
    </ul>
  </li>
  <li>Find the COM port of your ESP32
    <ul>
      <li>Open Device Manager (right click the Windows Logo and choose Device Manager)</li>
      <li>Expand <strong>Ports (COM &amp; LPT)</strong></li>
      <li>Plug in you ESP32. You should see a new COM port appear, and then disappear when you remove it. Make a note of the COM port, e.g. COM3
<img src="../assets/images/device-manager-com-port.png" alt="Finding the ESP32's COM port in Device Manager" /></li>
    </ul>
  </li>
  <li>Erase the deviceh, then upload new firmware (change COM port number as appropriate)
    <ul>
      <li>Hold down the <strong>Boot</strong> button on the ESP32 board as you hit <em>Enter</em> on the following command, and keep it pressed until you see something useful happening. This may or may not be needed for the next step as well.</li>
    </ul>
  </li>
</ul>

<pre><code class="language-dos">esptool.py --port COM3 erase_flash
esptool.py --chip esp32 --port COM3 write_flash -z 0x1000 esp32-idf3-20191220-v1.12.bin
</code></pre>

<ul>
  <li>If the above commands run without error then MicroPython should be installed on your board!</li>
</ul>

<p>Reference (and additonal info if things go wrong): <a href="https://docs.micropython.org/en/latest/esp32/tutorial/intro.html">Getting started with MicroPython on the ESP32</a></p>

<h2 id="using-putty-to-connect-to-the-repl-prompt">Using Putty to Connect to the REPL Prompt</h2>

<p>After initial setup, the only way to get a REPL prompt is over a serial port. This is where <strong>Putty</strong> comes in. Putty can be used for various types of connection to remote devices and servers, but we are just interested in the simple case of a <strong>Serial</strong> connection.</p>
<ol>
  <li>Select the <strong>Serial</strong> radio button</li>
  <li>Change <strong>Serial line</strong> to that used by your ESP32 board. Mine was COM3</li>
  <li>Change the Speed (also known as baud rate) to 115200</li>
  <li>Optional: You can give these setting a name (in <strong>Saved Sessions</strong>), and <strong>Save</strong> it for future use</li>
</ol>

<p><img src="../assets/images/putty-serial-connection.png" alt="Creating a Putty serial connection" /></p>

<p>Once connected you should get a REPL prompt in your Putty session.</p>

<p>You can mess around in REPL getting WiFi to work, and this is good for testing stuff out, but you’re going to want those WiFi settings to run when the board starts up, so for this you need to write a <strong>boot.py</strong> and be able to upload it.</p>

<p>The tutorial at <a href="https://docs.micropython.org/en/latest/esp8266">docs.micropython.org</a> are excellent. From this point I would skip straight to <a href="https://docs.micropython.org/en/latest/esp8266/tutorial/network_basics.html">tutorial/network_basics</a> to learn how to do stuff with Wifi. They do everything in REPL, but if you want something to happen at every boot of the device, you should add it to <strong>boot.py</strong></p>

<p>NEXT: Setting up your dev environment and writing some code</p>

<h2 id="other-references">Other References</h2>

<ul>
  <li><a href="https://www.agilepartner.net/en/micropython-esp8266-and-vscode/">Micropython, ESP8266 and VSCode</a></li>
  <li><a href="https://docs.micropython.org/en/latest/esp8266/tutorial/repl.html">Getting a MicroPython REPL prompt - official docs</a></li>
  <li><a href="https://pythonforundergradengineers.com/upload-py-files-to-esp8266-running-micropython.html">Running MicroPython on the ESP8266 - a useful guide</a></li>
</ul>]]></content><author><name>{&quot;bio&quot;=&gt;&quot;Personal blog with an emphasis on microcontrollers, computing, and other hobby projects.&quot;, &quot;location&quot;=&gt;&quot;Lancashire, UK&quot;, &quot;links&quot;=&gt;[{&quot;label&quot;=&gt;&quot;Instagram&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-instagram&quot;, &quot;url&quot;=&gt;&quot;https://www.instagram.com/gregwoodslancs/&quot;}, {&quot;label&quot;=&gt;&quot;GitHub&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-github&quot;, &quot;url&quot;=&gt;&quot;https://github.com/gregwoods&quot;}, {&quot;label&quot;=&gt;&quot;Twitter&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-twitter-square&quot;, &quot;url&quot;=&gt;&quot;https://twitter.com/gregwoods&quot;}]}</name></author><category term="microcontroller" /><category term="embedded" /><category term="micropython" /><category term="esp32" /><summary type="html"><![CDATA[How to get microPython onto an ESP32, how to connect to it and write code. Some example code includes displaying text on an onboard OLED. I've tried to make this page completely noob friendly, and focused on Windows (the official docs are Linux-biased)]]></summary></entry><entry><title type="html">Converting a Simple HAL-based STM32F1 blinky to STM32F4</title><link href="/microcontroller/embedded/rust/stm32/blackpill/bluepill/convert-stm32f1-blink-to-stm32f4/" rel="alternate" type="text/html" title="Converting a Simple HAL-based STM32F1 blinky to STM32F4" /><published>2020-04-12T13:55:31+00:00</published><updated>2020-04-12T13:55:31+00:00</updated><id>/microcontroller/embedded/rust/stm32/blackpill/bluepill/convert-stm32f1-blink-to-stm32f4</id><content type="html" xml:base="/microcontroller/embedded/rust/stm32/blackpill/bluepill/convert-stm32f1-blink-to-stm32f4/"><![CDATA[<p><img src="/assets/images/blackpill.jpg" alt="STM32F411 Black Pill" /></p>

<p>Yes, I know I could just grab the blink example from the stm32f4xx-hal repo. But this much more time-consuming way teaches more about both chips, and increses
my familiarity with the all-important reference manuals.</p>

<ul>
  <li>Clone the F1 repo, give <code class="language-plaintext highlighter-rouge">clone</code> a second parameter to change the name of the folder you clone into</li>
  <li>Then disconnect it from the original remote, because you wouldn’t want to push the converted code to the original repo</li>
</ul>

<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git clone https://github.com/GregWoods/01-blink-f1-rs.git 01-blink-f4-rs
</code></pre></div></div>

<ul>
  <li>Create the new repo in github</li>
</ul>

<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code>gh repo create 01-blink-f4-rs
</code></pre></div></div>

<ul>
  <li>And follow the instructions on the new repo default page, to connect your new remote to your local repo</li>
</ul>

<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code>got remote remove origin
git remote add origin https://github.com/GregWoods/01-blink-f4-rs.git
git push <span class="nt">-u</span> origin master
</code></pre></div></div>

<h2 id="change-the-setup">Change the Setup</h2>

<ul>
  <li><code class="language-plaintext highlighter-rouge">.cargo/config</code>
    <ul>
      <li>change <code class="language-plaintext highlighter-rouge">thumbv7m-none-eabi</code> to <code class="language-plaintext highlighter-rouge">thumbv7em-none-eabihf</code> (2 instances)</li>
      <li>change <code class="language-plaintext highlighter-rouge">arm-none-eabi-gdb</code> to <code class="language-plaintext highlighter-rouge">arm-none-eabihf-gdb</code> (1 instance)</li>
    </ul>
  </li>
  <li><code class="language-plaintext highlighter-rouge">cargo.toml</code>
    <ul>
      <li>change your package name from <code class="language-plaintext highlighter-rouge">01-blink-f1-rs</code> to <code class="language-plaintext highlighter-rouge">01-blink-f4-rs</code></li>
      <li>change the hal dependency to <code class="language-plaintext highlighter-rouge">[dependencies.stm32f1xx-hal]</code></li>
      <li>and change the features list: remove <code class="language-plaintext highlighter-rouge">stm32f103</code>, use <code class="language-plaintext highlighter-rouge">stm32f411</code> (or ```stm32f401`` for the cheaper verison of the black pill)</li>
      <li>Add a version number to <code class="language-plaintext highlighter-rouge">stm32f4xx-hal</code>. Currently 0.7.0 (we need this the first time, becaue we don’t have a valid value in cargo.lock) Trying to build will report a list of possible versions)</li>
      <li>remove the ```medium`` feature from the hal crate</li>
    </ul>
  </li>
  <li><code class="language-plaintext highlighter-rouge">memory.x</code>
    <ul>
      <li>The FLASH and RAM start addresses are the same</li>
      <li>But the sizes for the stm32f411 are: FLASH 512K; RAM: 128K  (as far as I can tell)</li>
    </ul>
  </li>
  <li><code class="language-plaintext highlighter-rouge">.vscode/launch.json</code>
    <ul>
      <li>replace <code class="language-plaintext highlighter-rouge">STM32F103VCT6</code> with <code class="language-plaintext highlighter-rouge">STM32F411CEU6</code></li>
      <li>Replace <code class="language-plaintext highlighter-rouge">target/stm32f1x.cfg</code> with <code class="language-plaintext highlighter-rouge">target/stm32f4x.cfg</code></li>
      <li>Change the svd from <code class="language-plaintext highlighter-rouge">STM32F103.svd</code> to <code class="language-plaintext highlighter-rouge">STM32F411.svd</code></li>
      <li>Change the executable path, replace <code class="language-plaintext highlighter-rouge">thumbv7m-none-eabi</code> with <code class="language-plaintext highlighter-rouge">thumbv7em-none-eabihf</code></li>
    </ul>
  </li>
  <li>Go and download <a href="https://www.st.com/en/microcontrollers-microprocessors/stm32f411.html#resource">STM32F411.svd</a></li>
  <li><code class="language-plaintext highlighter-rouge">main.rs</code>
    <ul>
      <li>change the use statement from <code class="language-plaintext highlighter-rouge">stm32f1xx_hal</code> to <code class="language-plaintext highlighter-rouge">stm32f4xxx_hal</code></li>
      <li>replace <code class="language-plaintext highlighter-rouge">pac</code> from the ‘use’, with <code class="language-plaintext highlighter-rouge">stm32</code> - an odd naming inconsistency between the stm32f1 and stm32f4 hal projects</li>
      <li><code class="language-plaintext highlighter-rouge">rustup target install thumbv7em-none-eabihf</code> to install the missing bits of the toolchain</li>
    </ul>
  </li>
</ul>

<h2 id="change-the-code">Change the Code</h2>

<p>Run <code class="language-plaintext highlighter-rouge">cargo build</code> and fix the bugs one by one referring to the hal repo: <a href="https://github.com/stm32-rs/stm32f4xx-hal">github.com/stm32-rs/stm32f4xx-hal</a></p>

<p>I’m not entirely sure you’ll get the errors come back in the same order as listed here! It is likely I fixed more than one at once.</p>

<h2 id="error-1">Error 1</h2>

<pre><code class="language-Rust">16 | use stm32f1xx_hal::{
   |     ^^^^^^^^^^^^^ use of undeclared type or module `stm32f1xx_hal`
</code></pre>

<p>An easy one. Change <code class="language-plaintext highlighter-rouge">stm32f1xx_hal</code> to <code class="language-plaintext highlighter-rouge">stm32f4xx_hal</code></p>

<h2 id="error-2">Error 2</h2>

<pre><code class="language-Rust">18 |     pac,
   |     ^^^ no `pac` in the root
</code></pre>

<p>In this hal, the peripheral access crate (pac) is called stm32.
Which leads to our next fix…</p>

<h2 id="error-3">Error 3</h2>

<pre><code class="language-Rust">    |     let dp = pac::Peripherals::take().unwrap();
    |              ^^^ use of undeclared type or module `pac`
</code></pre>

<p>Change to</p>

<pre><code class="language-Rust">    let dp = stm32::Peripherals::take().unwrap();
</code></pre>

<h2 id="error-4">Error 4</h2>

<pre><code class="language-Rust">    |     let mut flash = dp.FLASH.constrain();
    |                              ^^^^^^^^^ method not found in `stm32f4::stm32f411::FLASH`
</code></pre>

<p>‘constrain’ is not a thing in the Reference Manual. So this is something added by the HAL, probably to keep the rust compiler happy. In the hal code, inside flash.rs is the following comment…
    /// Constrains the FLASH peripheral to play nicely with the other abstractions</p>

<p>The stm32f4xx-hal doesn’t have a flash.rs. A quick search in the github repo shows it uses stm32.FLASH from the PAC.
Before I went down a rabbit hole, I noticed that the probably fix for the next will mean we don’t need to use FLASH at this time.
So <strong>I remove the line</strong>. I will have to revisit this sometime, but not today!</p>

<h2 id="error-5">Error 5</h2>

<pre><code class="language-Rust">    |     let clocks = rcc.cfgr.freeze(&amp;mut flash.acr);
    |                           ^^^^^^ expected 0 parameters
</code></pre>

<p>‘freeze’ doesn’t appear to be a feature of RCC_CFGR registers as far as I can tell. This is something “Rusty”.
According to ‘freeze’ in the stm32f1xx-hal, an ‘acr’ parameter exists, but is not used!
It looks like the stm32f4 hal has simply removed this unused param, so we should be able to remove it here. Easy!</p>

<h2 id="error-6">Error 6</h2>

<pre><code class="language-Rust">    |     let mut gpioc = dp.GPIOC.split(&amp;mut rcc.apb2);
    |                              ^^^^^ expected 0 parameters
</code></pre>

<p>The syntax of ‘splitting’ the GPIO port remains a mystery to me for now, and passing rcc.apb2 is even more confusing. The fact that the stm32f4 doesn’t require this parameter is all I need to know for now!</p>

<h2 id="error-7">Error 7</h2>

<pre><code class="language-Rust">     |
     |     let mut led = gpioc.pc13.into_push_pull_output(&amp;mut gpioc.crh);
     |                              ^^^^^^^^^^^^^^^^^^^^^ expected 0 parameters
</code></pre>

<p>Examine the Reference Manual and HAL.
In the <strong>stm32f4</strong> reference manual, there are no search results for CRL or CRH. Things are obviously done a bit differently to the <strong>stm32f1</strong>, where ```CRH`` is ‘Port Configuration Register High’</p>

<h3 id="stm32f1">stm32f1</h3>

<p>For port configuration, the MODE bits(2 bits per gpio line) and CNF bits (also 2 bits per ‘pin’) for each GPIO pin are interleaved, so we can only store 8 pins worth of setting within 32 bits.</p>

<p><img src="/assets/images/stm32f1-port-config-crh.png" alt="images/stm32f1-port-config-crh.png" /></p>

<p>The CRL register is the same, but for GPIO pins 0..7</p>

<h3 id="stm32f4">stm32f4</h3>

<p>The arragement is simpler for this chip. The settings for all 16 pins on a single GPIO port are stored in one 32 bit register.</p>

<p><img src="/assets/images/stm32f4-port-mode-register.png" alt="images/stm32f4-port-mode-register.png" /></p>

<p>Therefore the HAL simply doesn’t need to refer to CRH or CRL, it just uses the MODE register directly.</p>

<h2 id="error-8">Error 8</h2>

<pre><code class="language-Rust">    |     let mut timer = Timer::syst(cp.SYST, &amp;clocks).start_count_down(1.hz());
    |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 3 parameters
</code></pre>

<p>Looking at the <code class="language-plaintext highlighter-rouge">stm32f4xx-hal</code> code, in <code class="language-plaintext highlighter-rouge">timer.rs</code>, we find:</p>

<pre><code class="language-Rust">    impl Timer&lt;SYST&gt; {
        /// Configures the SYST clock as a periodic count down timer
        pub fn syst&lt;T&gt;(mut syst: SYST, timeout: T, clocks: Clocks) -&gt; Self
        where
            T: Into&lt;Hertz&gt;,
</code></pre>

<p>well, this is handy - the timeout in Hertz is set in the constructor, instead of in the chained <code class="language-plaintext highlighter-rouge">start_count_down</code>.</p>

<p>Fixing that has shown another error</p>

<pre><code class="language-Rust">    |
    |     let mut timer = Timer::syst(cp.SYST, 1.hz(), &amp;clocks);
    |                                                  ^^^^^^^
    |                                                  |
    |                                                  expected struct `stm32f4xx_hal::rcc::Clocks`, found `&amp;stm32f4xx_hal::rcc::Clocks`
    |                                                  help: consider removing the borrow: `clocks`
</code></pre>

<p>As is often the case, the compiler suggests the fix. I’m unsure of the consequences of giving syst ownership of clocks, but that is for another day.</p>

<p>Our converted line looks like:</p>

<pre><code class="language-Rust">    let mut timer = Timer::syst(cp.SYST, 1.hz(), clocks);
</code></pre>

<p>We can fix a couple of compiler warnings about variables which don’t need to be mutable, and everything is good.</p>

<p>This should all now build, and the debugger can step into the code.</p>]]></content><author><name>{&quot;bio&quot;=&gt;&quot;Personal blog with an emphasis on microcontrollers, computing, and other hobby projects.&quot;, &quot;location&quot;=&gt;&quot;Lancashire, UK&quot;, &quot;links&quot;=&gt;[{&quot;label&quot;=&gt;&quot;Instagram&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-instagram&quot;, &quot;url&quot;=&gt;&quot;https://www.instagram.com/gregwoodslancs/&quot;}, {&quot;label&quot;=&gt;&quot;GitHub&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-github&quot;, &quot;url&quot;=&gt;&quot;https://github.com/gregwoods&quot;}, {&quot;label&quot;=&gt;&quot;Twitter&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-twitter-square&quot;, &quot;url&quot;=&gt;&quot;https://twitter.com/gregwoods&quot;}]}</name></author><category term="microcontroller" /><category term="embedded" /><category term="rust" /><category term="stm32" /><category term="blackpill" /><category term="bluepill" /><summary type="html"><![CDATA[As part of my Rust on stm32 journey, here I convert a simple HAL based blinky program from the STM32F103 (Blue Pill) to the STM32F411 (Black Pill) before referring to the Reference Manual, PAC and HAL crates.]]></summary></entry><entry><title type="html">Buying a CPU… My 65W rule</title><link href="/hardware/budget/the-65w-rule-for-upgrading-the-pc/" rel="alternate" type="text/html" title="Buying a CPU… My 65W rule" /><published>2020-03-30T19:32:31+00:00</published><updated>2020-03-30T19:32:31+00:00</updated><id>/hardware/budget/the-65w-rule-for-upgrading-the-pc</id><content type="html" xml:base="/hardware/budget/the-65w-rule-for-upgrading-the-pc/"><![CDATA[<blockquote>
  <p>Or… Computing for tightwads</p>
</blockquote>

<p>For my 6 yearly PC upgrade, how do I decide which CPU to buy? My pockets aren’t deep enough to simply buy the best there is, so price/performance is a major consideration.</p>

<p>The last CPU I purchased new was an Intel Core i3-xxxx. Even at the time it was towards the bottom of the pile.</p>

<p>I was playing a lot of Flight Simulator X at the time, and from what I’d read, it was a lot happier on Intel silicon than AMD, which I’d always been a fan of up to that point. Also, FSX only uses a single core, so it was important to get a high clock speed, and not important to get quad cores.</p>

<p>The top end Intel CPUs, with the ‘K’ suffix, meaning clock multiplier unlocked, have always commanded a much higher price. Too high for the extra performance gained, especially for those not interested in overclocking.</p>

<p>The i3-2130 at 3.40GHz was the obvious choice. It was in the price performance sweet spot.</p>

<p>Fast forward to 2019, and I’m playing Dirt Rally now and again. It generally runs great on the old i3, but there are occasional glitches - dramatic drops in framerate, which can be worrying when hurtling down a Hellenic mountainside.
I’m also getting itchy for an upgrade, but to get an up to date CPU, I need to replace motherboard and RAM too.</p>

<p>For an interim upgrade I looked at the CPUs my motherboard supports. It supports both 2nd and 3rd gen Intel Core i-series chips,  so I sourced an i5-3550 on eBay for £32. When I run the Dirt Rally benchmark again, I see no real difference in average frame rate, but the lowest framerate has dramatically increased. It barely hiccups now. It was likely Windows performing some background task that was causing the slowdowns, and adding 2 more cores made a dramatic difference.</p>

<p>But What Next?</p>

<p>Probably back to AMD. The Ryzen 5 3600 is looking good value, under £200, and is rated at 65W perfect for a tightwad.</p>

<p>*My self imposed 65W limit isn’t about running costs, it is simply a way to avoid getting carried away with buying the latest and greatest CPU in the range, and paying too much for the privilege. I also value a quiet PC, and the lower wattage devices help keep temperatures down even with stock or low cost coolers.</p>]]></content><author><name>{&quot;bio&quot;=&gt;&quot;Personal blog with an emphasis on microcontrollers, computing, and other hobby projects.&quot;, &quot;location&quot;=&gt;&quot;Lancashire, UK&quot;, &quot;links&quot;=&gt;[{&quot;label&quot;=&gt;&quot;Instagram&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-instagram&quot;, &quot;url&quot;=&gt;&quot;https://www.instagram.com/gregwoodslancs/&quot;}, {&quot;label&quot;=&gt;&quot;GitHub&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-github&quot;, &quot;url&quot;=&gt;&quot;https://github.com/gregwoods&quot;}, {&quot;label&quot;=&gt;&quot;Twitter&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-twitter-square&quot;, &quot;url&quot;=&gt;&quot;https://twitter.com/gregwoods&quot;}]}</name></author><category term="hardware" /><category term="budget" /><summary type="html"><![CDATA[So much choice and so little money. How do you decide your priorities when upgrading your PC. Here is my thought process...]]></summary></entry><entry><title type="html">Why Learn Embedded Rust on the STM32F103 Blue Pill</title><link href="/microcontroller/embedded/rust/stm32/bluepill/why-learn-embedded-rust-on-the-stm32-blue-pill/" rel="alternate" type="text/html" title="Why Learn Embedded Rust on the STM32F103 Blue Pill" /><published>2020-03-12T19:32:31+00:00</published><updated>2020-03-12T19:32:31+00:00</updated><id>/microcontroller/embedded/rust/stm32/bluepill/why-learn-embedded-rust-on-the-stm32-blue-pill</id><content type="html" xml:base="/microcontroller/embedded/rust/stm32/bluepill/why-learn-embedded-rust-on-the-stm32-blue-pill/"><![CDATA[<p><img src="/assets/images/bluepill-in-breadboard.jpg" alt="STM32F103 Blue Pill on a breadboard" /></p>

<p>I have spent quite a bit of time recently trying to learn the Rust programming language for use on the $2 ARM Cortex M3 STM32 board, commonly known as the “Blue Pill”. The learning process has often been frustrating, and it has not been quick. But I feel I can share some code, and tips which can make it less painful.</p>

<h1 id="where-have-i-come-from">Where have I come from?</h1>

<p>I am a full time developer working on the Microsoft stack for a number of years in the high level C# realm. As a hobbyist, I have a strong interest in microcontrollers, and have tinkered with PIC and AVR using assembly language, C, and Arduino. I love the Arduino platform due to it’s accessibility for noobs, but I’ve been itching to move away from it. Why?</p>

<h1 id="why-the-blue-pill">Why the Blue Pill?</h1>

<h2 id="cost">Cost</h2>

<p>For the same price as an 8MHz 8bit Arduino Pro Mini clone, I can buy a 72MHz, 32 bit Arm Cortex M3 board (and for not much more, a Cortex M4F)</p>

<h2 id="features">Features</h2>

<p>For my projects, both Arduino and Arm Cortex M3 boards will have all the features I need, but the stm32 boards have greater horsepower, which allows the running of a simple RTOS, along with more complex code in interrupt handlers.</p>

<h2 id="debugging">Debugging</h2>

<p>It is possible to do real debuggiong on the stm32 board, when connected to an ST-Link debugger. It should be possible to stop using printing-to-the-console to debug, and instead set breakpoints and step through the code like a real programmer!</p>

<h1 id="why-rust">Why Rust?</h1>

<p>I love the simplicity of Arduino code. This simplicity is all due to the friendly design of the libraries. But, it is still C++, and once your code starts getting even slightly complex, you hit all the problems of C++, including various abuses of pointers which cause hard to find runtime bugs. 
Rust promises the speed of C/C++ with a more robust system of memory safety, whereby the compiler always knows which code block a variable belongs to, and thus can check for many sources of bugs at compile time (this is a gross oversimplification. Go and read the docs yourself)
I don’t have the clout to convince anyone that Rust is worth the effort, but you have to at least check it out. Start with the official docs <a href="https://www.rust-lang.org/what/embedded">rust-lang.org/what/embedded</a></p>

<p>It also helps that Rust has a very helpful compiler. Compiler error messages are not the afterthought that they are in C++. They system has been carefully thought out, and is exceedingly helpful to noobs.</p>

<h1 id="the-trap">The Trap</h1>

<p>It is always dangerous to learn a new tool or lanaguage and then use it for absolutely everything, no matter how inappropriate it may be. For some projects, an 8 bit microcontroller on Arduino may be the best choice. But, to maximise the little time I have for learning the new platform, I will be focusing my efforts on Rust on the STM32 for current hobby projects.</p>

<p><a href="/microcontroller/embedded/rust/stm32/bluepill/how-to-learn-embedded-rust-on-the-stm32f103-blue-pill/">Next - How to Learn</a></p>]]></content><author><name>{&quot;bio&quot;=&gt;&quot;Personal blog with an emphasis on microcontrollers, computing, and other hobby projects.&quot;, &quot;location&quot;=&gt;&quot;Lancashire, UK&quot;, &quot;links&quot;=&gt;[{&quot;label&quot;=&gt;&quot;Instagram&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-instagram&quot;, &quot;url&quot;=&gt;&quot;https://www.instagram.com/gregwoodslancs/&quot;}, {&quot;label&quot;=&gt;&quot;GitHub&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-github&quot;, &quot;url&quot;=&gt;&quot;https://github.com/gregwoods&quot;}, {&quot;label&quot;=&gt;&quot;Twitter&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-twitter-square&quot;, &quot;url&quot;=&gt;&quot;https://twitter.com/gregwoods&quot;}]}</name></author><category term="microcontroller" /><category term="embedded" /><category term="rust" /><category term="stm32" /><category term="bluepill" /><summary type="html"><![CDATA[I have spent quite a bit of time recently trying to learn the Rust programming language for use on the $2 ARM Cortex M3 STM32 board, commonly known as the “Blue Pill”. The learning process has often been frustrating, and it has not been quick. But I feel I can share some code, and tips which can make it less painful. Where have I come from? I am a full time developer working on the Microsoft stack for a number of years in the high level C# realm. As a hobbyist, I have a strong interest in microcontrollers, and have tinkered with PIC and AVR using assembly language, C, and Arduino. I love the Arduino platform due to it’s accessibility for noobs, but I’ve been itching to move away from it. Why? Why the Blue Pill? Cost For the same price as an 8MHz 8bit Arduino Pro Mini clone, I can buy a 72MHz, 32 bit Arm Cortex M3 board (and for not much more, a Cortex M4F) Features For my projects, both Arduino and Arm Cortex M3 boards will have all the features I need, but the stm32 boards have greater horsepower, which allows the running of a simple RTOS, along with more complex code in interrupt handlers. Debugging It is possible to do real debuggiong on the stm32 board, when connected to an ST-Link debugger. It should be possible to stop using printing-to-the-console to debug, and instead set breakpoints and step through the code like a real programmer! Why Rust? I love the simplicity of Arduino code. This simplicity is all due to the friendly design of the libraries. But, it is still C++, and once your code starts getting even slightly complex, you hit all the problems of C++, including various abuses of pointers which cause hard to find runtime bugs. Rust promises the speed of C/C++ with a more robust system of memory safety, whereby the compiler always knows which code block a variable belongs to, and thus can check for many sources of bugs at compile time (this is a gross oversimplification. Go and read the docs yourself) I don’t have the clout to convince anyone that Rust is worth the effort, but you have to at least check it out. Start with the official docs rust-lang.org/what/embedded It also helps that Rust has a very helpful compiler. Compiler error messages are not the afterthought that they are in C++. They system has been carefully thought out, and is exceedingly helpful to noobs. The Trap It is always dangerous to learn a new tool or lanaguage and then use it for absolutely everything, no matter how inappropriate it may be. For some projects, an 8 bit microcontroller on Arduino may be the best choice. But, to maximise the little time I have for learning the new platform, I will be focusing my efforts on Rust on the STM32 for current hobby projects. Next - How to Learn]]></summary></entry><entry><title type="html">How to Learn Embedded Rust on the STM32F103 Blue Pill</title><link href="/microcontroller/embedded/rust/stm32/bluepill/how-to-learn-embedded-rust-on-the-stm32f103-blue-pill/" rel="alternate" type="text/html" title="How to Learn Embedded Rust on the STM32F103 Blue Pill" /><published>2020-03-12T19:32:31+00:00</published><updated>2020-03-12T19:32:31+00:00</updated><id>/microcontroller/embedded/rust/stm32/bluepill/how-to-learn-embedded-rust-on-the-stm32f103-blue-pill</id><content type="html" xml:base="/microcontroller/embedded/rust/stm32/bluepill/how-to-learn-embedded-rust-on-the-stm32f103-blue-pill/"><![CDATA[<p><img src="/assets/images/bluepill-with-stlink.jpg" alt="STM32F103 Blue Pill with STLink V2 Debugger" /></p>

<h2 id="the-waters-not-that-deep---youll-be-fine">The water’s not <em>that</em> deep - you’ll be fine</h2>

<p>You will find tutorials and blog posts telling you how easy it is to get started in Rust on an STM32 platform.</p>

<p>They lie!</p>

<p>Or at least, they are written by experienced embedded developers who are simply transitioning to Rust.</p>

<p>As an Arduino developer, you are familiar with:</p>

<ul>
  <li>downloading the IDE</li>
  <li>changing the board type</li>
  <li>copy-pasting some demo code</li>
  <li>change the odd pin assignment</li>
  <li>compile and upload</li>
  <li>Done!</li>
</ul>

<h2 id="this-is-not-arduino">This is <em>not</em> Arduino</h2>

<p>Instead you are now faced with:</p>

<ul>
  <li>Manual setup of your toolchain</li>
  <li>Manual configuration of your debugging tool/uploader</li>
  <li>No out of the box integration with your IDE</li>
  <li>Blog posts which are outdated, whose code won’t compile anymore</li>
  <li>Libraries at a much lower level than Arduino ones</li>
  <li>Having to be very familiar with your chip’s data sheets</li>
</ul>

<h2 id="the-wrong-way-to-learn">The Wrong Way to Learn</h2>

<p>My initial approach to learning, which has usually served me well, was</p>

<ul>
  <li>Avoid any dusty official documentation, it takes too long to digest all that detail</li>
  <li>Find a respectable looking blog-with-code</li>
  <li>Relicate the steps in the blog; make some trial and error modifictions; add some interesting looking libraries to tinker with peripherals</li>
  <li>Glue together the various bits of experimentation into your actual project</li>
</ul>

<p>I wasted a lot of time.
Rust and the libraries in the ecosystem have changed in the last 3 years, and most of the blog posts were written by seasoned embedded developers who were early adopters in Rust. Although I learned something from every one of them, it was not the right apporoach to learning a whole new language and ecosystem.</p>

<h2 id="take-your-time-structure-your-learning">Take Your Time, Structure Your Learning</h2>

<p>The right way is to take your time and use the official docs - they are excellent, and shouldn’t be rushed.
I am using a multi-faceted approach.</p>

<ul>
  <li>Learn Rust on its own - with no embedded distractions
    <ul>
      <li><a href="https://doc.rust-lang.org/book/">The book</a></li>
      <li><a href="https://doc.rust-lang.org/stable/rust-by-example/">Rust by Example</a></li>
      <li><a href="https://rust-lang-nursery.github.io/rust-cookbook/">Rust Cookbook</a> - because it’s good to see how other people write Rust</li>
      <li><a href="https://www.rust-lang.org/learn">Lots more official Rust documentation</a></li>
      <li>Various Rust books from my <a href="https://www.packtpub.com">Packt Publishing subscription</a></li>
    </ul>
  </li>
  <li><a href="https://rust-embedded.github.io/book/">Get started with embedded Rust</a> Start at the beginning. Don’t fast forward until you’ve completed the next step, QEMU
    <ul>
      <li><a href="https://rust-embedded.github.io/book/start/qemu.html">Use the emulator QEMU</a> even if you never plan on using the emulator ever again, it helps you grasp the toolchain and ecosystem.</li>
      <li><a href="https://github.com/GregWoods/stm32-01-blink">Get your first blinky working in a VS Code environment</a>  This is my own quickstart code. It is using a HAL, so it is skipping ahead a few steps, but I find it useful to have a ready to go starter project</li>
    </ul>
  </li>
  <li>Learn the chip
    <ul>
      <li><a href="https://vivonomicon.com/2019/05/23/hello-rust-blinking-leds-in-a-new-language/">Learn about SVDs and Peripheral Access Crates using this excellent tutorial from Vivonomicon</a></li>
      <li><a href="https://www.st.com/resource/en/reference_manual/cd00171190-stm32f101xx-stm32f102xx-stm32f103xx-stm32f105xx-and-stm32f107xx-advanced-arm-based-32-bit-mcus-stmicroelectronics.pdf">Get to know the 1134 page Reference Manual</a>. This is not optional! But you don’t need to read it cover to cover
        <ul>
          <li>Get to understand the blinky code from the point of view of the Reference Manual. Start at chapter 9 “General-purpose and alternate-function I/Os (GPIOs and AFIOs)”. Comparing the Reference Manual to the code you’ve written using your PAC, will help you grasp how the STM32 registers work for IO.</li>
        </ul>
      </li>
      <li><a href="https://github.com/stm32-rs/stm32f1xx-hal">Go and get a HAL, and learn to use it</a> But make sure you get the right one. There are deprecated projects out there to catch the unwary.
        <ul>
          <li>After using the Peripheral Access Crate directly, the HAL, to me anyway, is more complex and less intuitive due to it’s use of the inversion-of-control principle. But, getting used to the way it works should help you write code which can be ported to other chips</li>
        </ul>
      </li>
      <li><a href="http://www.rtfm-lang.org/">Get to know RTFM - Real-Time-For-the-Masses</a>. I’m yet to get into this, but it does feel like the right way to go for most projects.</li>
    </ul>
  </li>
</ul>

<p>The above list is not a strict sequence, I am learning a little about each of the 3 top level areas each week.
Progress, for me at least, is not particularly fast, which can be frustrating when you have projects in mind.
Which is why the next point helps.</p>

<h2 id="keep-a-learning-log">Keep a Learning Log</h2>

<p>This has helped me to avoid the feeling that I’m not getting anywhere. It helps me see what to study and try out next. I abbreviate book titles.</p>

<p>I use a simple table in OneNote</p>

<p>Excerpt…</p>

<table>
  <thead>
    <tr>
      <th>Date</th>
      <th>Notes</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>older</td>
      <td>Pckt RustIn7days, ch1, ch2   Got a bit stuck on Traits with Generics</td>
    </tr>
    <tr>
      <td>2020-01-29</td>
      <td>RBE ch1, ch2</td>
    </tr>
    <tr>
      <td>2020-01-30</td>
      <td>RBE ch3   skipped linked list example</td>
    </tr>
    <tr>
      <td> </td>
      <td>RBE ch4   variable shadowing. Not sure of the point!</td>
    </tr>
    <tr>
      <td> </td>
      <td>RBE ch5, ch6, ch7, ch8.3</td>
    </tr>
    <tr>
      <td>2020-01-31</td>
      <td>RBE -&gt;8.5.1   Refs!! Destructuring. See also RB (RustBook) 4.1,4.2</td>
    </tr>
    <tr>
      <td>2020-02-03</td>
      <td>RBE  8.5.3, 8.6, 8.7 9, 9.1   Binding… didn’t really get it, but likely don’t need to!</td>
    </tr>
    <tr>
      <td> </td>
      <td>If…let  - stupid syntax, blame Swift</td>
    </tr>
    <tr>
      <td> </td>
      <td>while…let skipped</td>
    </tr>
  </tbody>
</table>

<p>I’ve seen lots of more complex Learning logs online, but for me, just a running virtual bookmark is enough.
Notes may be a page or chapter reference. Sometimes I’ll note an immportant topic I convered. I’ll note any code I worked on.
My log isn’t well written or consistent in its type of content.
I don’t go into great detail about what I’ve learnt, it isn’t a summary. It is more to track progress.</p>

<p>I’ve found it a great help.</p>

<p>So that is my Rust learning story so far. I hope it helps!</p>]]></content><author><name>{&quot;bio&quot;=&gt;&quot;Personal blog with an emphasis on microcontrollers, computing, and other hobby projects.&quot;, &quot;location&quot;=&gt;&quot;Lancashire, UK&quot;, &quot;links&quot;=&gt;[{&quot;label&quot;=&gt;&quot;Instagram&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-instagram&quot;, &quot;url&quot;=&gt;&quot;https://www.instagram.com/gregwoodslancs/&quot;}, {&quot;label&quot;=&gt;&quot;GitHub&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-github&quot;, &quot;url&quot;=&gt;&quot;https://github.com/gregwoods&quot;}, {&quot;label&quot;=&gt;&quot;Twitter&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-twitter-square&quot;, &quot;url&quot;=&gt;&quot;https://twitter.com/gregwoods&quot;}]}</name></author><category term="microcontroller" /><category term="embedded" /><category term="rust" /><category term="stm32" /><category term="bluepill" /><summary type="html"><![CDATA[It's a long journey from Arduino to Embedded Rust. So avoid false starts, and take it slow!]]></summary></entry><entry><title type="html">Rust syntax highlighting test</title><link href="/rust/test/rust-syntax-highlighting-test/" rel="alternate" type="text/html" title="Rust syntax highlighting test" /><published>2020-03-10T17:58:31+00:00</published><updated>2020-03-10T17:58:31+00:00</updated><id>/rust/test/rust-syntax-highlighting-test</id><content type="html" xml:base="/rust/test/rust-syntax-highlighting-test/"><![CDATA[<h1 id="rust-sample">Rust Sample</h1>

<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><table class="rouge-table"><tbody><tr><td class="gutter gl"><pre class="lineno">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
</pre></td><td class="code"><pre><span class="c1">#[entry]</span>
<span class="n">fn</span> <span class="n">main</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="o">!</span> <span class="p">{</span>
    <span class="k">if</span> <span class="n">let</span> <span class="p">(</span><span class="no">Some</span><span class="p">(</span><span class="nb">p</span><span class="p">),</span> <span class="no">Some</span><span class="p">(</span><span class="n">cp</span><span class="p">))</span> <span class="o">=</span> <span class="p">(</span><span class="n">stm32</span><span class="o">::</span><span class="no">Peripherals</span><span class="o">::</span><span class="n">take</span><span class="p">(),</span> <span class="no">Peripherals</span><span class="o">::</span><span class="n">take</span><span class="p">())</span> <span class="p">{</span>
        <span class="sr">//</span> <span class="no">Constrain</span> <span class="n">clocking</span> <span class="n">registers</span>
        <span class="n">let</span> <span class="n">mut</span> <span class="n">flash</span> <span class="o">=</span> <span class="nb">p</span><span class="o">.</span><span class="no">FLASH</span><span class="p">;</span>
        <span class="n">let</span> <span class="n">mut</span> <span class="n">rcc</span> <span class="o">=</span> <span class="nb">p</span><span class="o">.</span><span class="no">RCC</span><span class="p">.</span><span class="nf">configure</span><span class="p">().</span><span class="nf">sysclk</span><span class="p">(</span><span class="mi">48</span><span class="p">.</span><span class="nf">mhz</span><span class="p">()).</span><span class="nf">freeze</span><span class="p">(</span><span class="o">&amp;</span><span class="n">mut</span> <span class="n">flash</span><span class="p">);</span>
        <span class="n">let</span> <span class="n">gpioa</span> <span class="o">=</span> <span class="nb">p</span><span class="o">.</span><span class="no">GPIOA</span><span class="p">.</span><span class="nf">split</span><span class="p">(</span><span class="o">&amp;</span><span class="n">mut</span> <span class="n">rcc</span><span class="p">);</span>

        <span class="sr">/* (Re-)configure PA7 as output */</span>
        <span class="n">let</span> <span class="n">ws_data_pin</span> <span class="o">=</span>
            <span class="n">cortex_m</span><span class="o">::</span><span class="n">interrupt</span><span class="o">::</span><span class="n">free</span><span class="p">(</span><span class="n">move</span> <span class="o">|</span><span class="n">cs</span><span class="o">|</span> <span class="n">gpioa</span><span class="p">.</span><span class="nf">pa7</span><span class="p">.</span><span class="nf">into_push_pull_output_hs</span><span class="p">(</span><span class="n">cs</span><span class="p">));</span>

        <span class="n">let</span> <span class="n">timer</span> <span class="o">=</span> <span class="no">Timer</span><span class="o">::</span><span class="n">tim1</span><span class="p">(</span><span class="nb">p</span><span class="o">.</span><span class="no">TIM1</span><span class="p">,</span> <span class="no">MegaHertz</span><span class="p">(</span><span class="mi">3</span><span class="p">),</span> <span class="o">&amp;</span><span class="n">mut</span> <span class="n">rcc</span><span class="p">);</span>

        <span class="sr">//</span> <span class="no">Get</span> <span class="n">delay</span> <span class="n">provider</span>
        <span class="n">let</span> <span class="n">mut</span> <span class="n">delay</span> <span class="o">=</span> <span class="no">Delay</span><span class="o">::</span><span class="n">new</span><span class="p">(</span><span class="n">cp</span><span class="o">.</span><span class="no">SYST</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">mut</span> <span class="n">rcc</span><span class="p">);</span>

        <span class="n">let</span> <span class="n">mut</span> <span class="n">ws</span> <span class="o">=</span> <span class="no">Ws2812</span><span class="o">::</span><span class="n">new</span><span class="p">(</span><span class="n">timer</span><span class="p">,</span> <span class="n">ws_data_pin</span><span class="p">);</span>
        <span class="n">let</span> <span class="n">mut</span> <span class="ss">data: </span><span class="p">[</span><span class="no">RGB8</span><span class="p">;</span> <span class="mi">3</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="no">RGB8</span><span class="o">::</span><span class="n">default</span><span class="p">();</span> <span class="mi">3</span><span class="p">];</span>
        <span class="n">let</span> <span class="ss">empty: </span><span class="p">[</span><span class="no">RGB8</span><span class="p">;</span> <span class="mi">3</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="no">RGB8</span><span class="o">::</span><span class="n">default</span><span class="p">();</span> <span class="mi">3</span><span class="p">];</span>

        <span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="no">RGB8</span> <span class="p">{</span>
            <span class="ss">r: </span><span class="mi">0</span><span class="p">,</span>
            <span class="ss">g: </span><span class="mi">0</span><span class="p">,</span>
            <span class="ss">b: </span><span class="mh">0x10</span><span class="p">,</span>
        <span class="p">};</span>
        <span class="n">data</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="no">RGB8</span> <span class="p">{</span>
            <span class="ss">r: </span><span class="mi">0</span><span class="p">,</span>
            <span class="ss">g: </span><span class="mh">0x10</span><span class="p">,</span>
            <span class="ss">b: </span><span class="mi">0</span><span class="p">,</span>
        <span class="p">};</span>
        <span class="n">data</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="no">RGB8</span> <span class="p">{</span>
            <span class="ss">r: </span><span class="mh">0x10</span><span class="p">,</span>
            <span class="ss">g: </span><span class="mi">0</span><span class="p">,</span>
            <span class="ss">b: </span><span class="mi">0</span><span class="p">,</span>
        <span class="p">};</span>

        <span class="kp">loop</span> <span class="p">{</span>
            <span class="n">ws</span><span class="p">.</span><span class="nf">write</span><span class="p">(</span><span class="n">data</span><span class="p">.</span><span class="nf">iter</span><span class="p">().</span><span class="nf">cloned</span><span class="p">()).</span><span class="nf">unwrap</span><span class="p">();</span>
            <span class="n">delay</span><span class="p">.</span><span class="nf">delay_ms</span><span class="p">(</span><span class="mi">10</span> <span class="n">as</span> <span class="n">u16</span><span class="p">);</span>
            <span class="n">ws</span><span class="p">.</span><span class="nf">write</span><span class="p">(</span><span class="n">empty</span><span class="p">.</span><span class="nf">iter</span><span class="p">().</span><span class="nf">cloned</span><span class="p">()).</span><span class="nf">unwrap</span><span class="p">();</span>
            <span class="n">delay</span><span class="p">.</span><span class="nf">delay_ms</span><span class="p">(</span><span class="mi">10</span> <span class="n">as</span> <span class="n">u16</span><span class="p">);</span>
        <span class="p">}</span>
    <span class="p">}</span>
    <span class="kp">loop</span> <span class="p">{</span>
        <span class="n">continue</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">}</span>
</pre></td></tr></tbody></table></code></pre></figure>]]></content><author><name>{&quot;bio&quot;=&gt;&quot;Personal blog with an emphasis on microcontrollers, computing, and other hobby projects.&quot;, &quot;location&quot;=&gt;&quot;Lancashire, UK&quot;, &quot;links&quot;=&gt;[{&quot;label&quot;=&gt;&quot;Instagram&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-instagram&quot;, &quot;url&quot;=&gt;&quot;https://www.instagram.com/gregwoodslancs/&quot;}, {&quot;label&quot;=&gt;&quot;GitHub&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-github&quot;, &quot;url&quot;=&gt;&quot;https://github.com/gregwoods&quot;}, {&quot;label&quot;=&gt;&quot;Twitter&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-twitter-square&quot;, &quot;url&quot;=&gt;&quot;https://twitter.com/gregwoods&quot;}]}</name></author><category term="rust" /><category term="test" /><summary type="html"><![CDATA[Rust Sample]]></summary></entry><entry><title type="html">Using Windows Command Prompt Colours with Node Js</title><link href="/windows/shell/using-windows-command-prompt-colours-with-node-js/" rel="alternate" type="text/html" title="Using Windows Command Prompt Colours with Node Js" /><published>2015-04-09T17:58:31+00:00</published><updated>2020-03-01T17:58:31+00:00</updated><id>/windows/shell/using-windows-command-prompt-colours-with-node-js</id><content type="html" xml:base="/windows/shell/using-windows-command-prompt-colours-with-node-js/"><![CDATA[<blockquote>
  <p><strong>UPDATE:</strong> 5 years after the original post… Microsoft has improved the UI for the command prompt colours… by introducing the new “Windows Terminal”. It is in the Microsoft Store. Go and get it. It has json based config just like VS Code, easy colour schemes, and support for various shells, including command prompt, Powershell, Powershell Core, and Linux through Windows Subsystem for Linux (WSL)</p>
</blockquote>

<p>I have happily used the Windows command prompt for years. As a matter of habit, I always change the font to Consolas 14pt and background colour to something a little less harsh than #000000. Usually a muted dark blue or green. When doing so, I’ve simply changed any one of the colour swatches to my desired colour and assign it to the “Screen Background” radio button. This seems to be how the dialog was designed, and it works fine when using standard windows command prompt. However, some recent tinkering with Node.Js made it all go horribly wrong.</p>

<p><img src="/assets/2015/04/node-prompt-gone-wrong.png" alt="node in windows command prompt, with invisible text" /></p>

<p>As you can see, some of the text from the output of the REPL session has disappearred into the background.</p>

<p><img src="/assets/2015/04/cmd-prompt-colors-dialog-bad-annotated.png" alt="My incorrect idea of how the colours dialog works" /></p>

<p>Above: My incorrect idea of how the colours dialog works</p>

<p>The reason is that my mental model of how the Command Prompt Properties ‘Colours’ tab works, was completely wrong.</p>

<p>According to my mental model, I…</p>

<ul>
  <li>Pick a colour tile, any tile from the ‘palette’ of available colours</li>
  <li>Modify it using the RGB values</li>
  <li>Assign it the “Screen Background” radio button</li>
  <li>Job done! My everything looks great, until I use node</li>
  <li>Through lots of trail and error and looking at how Unix terminals treat colours, I”ve come to realise that not only is my mental model completely wrong, but this dialog box is really really badly designed.</li>
</ul>

<p>This mental model works fine if you are only every using ‘DOS’ commands. But node was designed for Unix-y environments.</p>

<p>It turns out that windows command prompt has a lot more in common with Linux than I ever thought. It seems that these 16 colour chips correspond with the ANSI colours used by all terminals. They are not simply a colour palette to pick and choose from.</p>

<p><img src="/assets/2015/04/cmd-prompt-colors-dialog-annotated1.png" alt="A better mental model of how this dialog works" /></p>

<p>Above: A better mental model of how this dialog works</p>

<p>Therefore the correct way to use this dialog appears to be</p>

<ul>
  <li>Select the first colour chip</li>
  <li>Change it to your background colour</li>
  <li>Make sure it is still assigned to the “Screen Background” radio button</li>
  <li>Ensure the next 7 colours are clearly visible on your background colour</li>
  <li>Note that I had to deselect the colour value box before switching to another ‘swatch’ or it would transpose the colour value I was editing onto the new swatch, making things really awkward.</li>
</ul>

<p>Here is my colour scheme after 10 minutes of playing around. They are shown in the image.</p>

<table>
  <thead>
    <tr>
      <th>Colour ‘tile’</th>
      <th>R,G,B Colours</th>
      <th>Base colour</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>1</td>
      <td>40, 40, 40</td>
      <td>Black – This tile should always be your background colour</td>
    </tr>
    <tr>
      <td>2</td>
      <td>128, 140, 255</td>
      <td>Blue</td>
    </tr>
    <tr>
      <td>3</td>
      <td>100, 210, 100</td>
      <td>Green</td>
    </tr>
    <tr>
      <td>4</td>
      <td>128, 240, 240</td>
      <td>Cyan</td>
    </tr>
    <tr>
      <td>5</td>
      <td>255, 128, 128</td>
      <td>Red</td>
    </tr>
    <tr>
      <td>6</td>
      <td>255, 128, 255</td>
      <td>Magenta</td>
    </tr>
    <tr>
      <td>7</td>
      <td>255, 255, 128</td>
      <td>Yellow</td>
    </tr>
    <tr>
      <td>8</td>
      <td>220, 220, 220</td>
      <td>White – this tile should always be your text colour</td>
    </tr>
  </tbody>
</table>

<p>I’ve ignored the other 8 colours, I’ve yet to see them used.</p>

<p>If nothing else, this post is a reminder to me how this obscure dialog works.  I suspect this dialog has been around since Windows 3! It would be a good exercise in UI Design to re-fashion it to better fit how it works.</p>]]></content><author><name>{&quot;bio&quot;=&gt;&quot;Personal blog with an emphasis on microcontrollers, computing, and other hobby projects.&quot;, &quot;location&quot;=&gt;&quot;Lancashire, UK&quot;, &quot;links&quot;=&gt;[{&quot;label&quot;=&gt;&quot;Instagram&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-instagram&quot;, &quot;url&quot;=&gt;&quot;https://www.instagram.com/gregwoodslancs/&quot;}, {&quot;label&quot;=&gt;&quot;GitHub&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-github&quot;, &quot;url&quot;=&gt;&quot;https://github.com/gregwoods&quot;}, {&quot;label&quot;=&gt;&quot;Twitter&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-twitter-square&quot;, &quot;url&quot;=&gt;&quot;https://twitter.com/gregwoods&quot;}]}</name></author><category term="windows" /><category term="shell" /><summary type="html"><![CDATA[UPDATE: 5 years after the original post… Microsoft has improved the UI for the command prompt colours… by introducing the new “Windows Terminal”. It is in the Microsoft Store. Go and get it. It has json based config just like VS Code, easy colour schemes, and support for various shells, including command prompt, Powershell, Powershell Core, and Linux through Windows Subsystem for Linux (WSL) I have happily used the Windows command prompt for years. As a matter of habit, I always change the font to Consolas 14pt and background colour to something a little less harsh than #000000. Usually a muted dark blue or green. When doing so, I’ve simply changed any one of the colour swatches to my desired colour and assign it to the “Screen Background” radio button. This seems to be how the dialog was designed, and it works fine when using standard windows command prompt. However, some recent tinkering with Node.Js made it all go horribly wrong. As you can see, some of the text from the output of the REPL session has disappearred into the background. Above: My incorrect idea of how the colours dialog works The reason is that my mental model of how the Command Prompt Properties ‘Colours’ tab works, was completely wrong. According to my mental model, I… Pick a colour tile, any tile from the ‘palette’ of available colours Modify it using the RGB values Assign it the “Screen Background” radio button Job done! My everything looks great, until I use node Through lots of trail and error and looking at how Unix terminals treat colours, I”ve come to realise that not only is my mental model completely wrong, but this dialog box is really really badly designed. This mental model works fine if you are only every using ‘DOS’ commands. But node was designed for Unix-y environments. It turns out that windows command prompt has a lot more in common with Linux than I ever thought. It seems that these 16 colour chips correspond with the ANSI colours used by all terminals. They are not simply a colour palette to pick and choose from. Above: A better mental model of how this dialog works Therefore the correct way to use this dialog appears to be Select the first colour chip Change it to your background colour Make sure it is still assigned to the “Screen Background” radio button Ensure the next 7 colours are clearly visible on your background colour Note that I had to deselect the colour value box before switching to another ‘swatch’ or it would transpose the colour value I was editing onto the new swatch, making things really awkward. Here is my colour scheme after 10 minutes of playing around. They are shown in the image. Colour ‘tile’ R,G,B Colours Base colour 1 40, 40, 40 Black – This tile should always be your background colour 2 128, 140, 255 Blue 3 100, 210, 100 Green 4 128, 240, 240 Cyan 5 255, 128, 128 Red 6 255, 128, 255 Magenta 7 255, 255, 128 Yellow 8 220, 220, 220 White – this tile should always be your text colour I’ve ignored the other 8 colours, I’ve yet to see them used. If nothing else, this post is a reminder to me how this obscure dialog works. I suspect this dialog has been around since Windows 3! It would be a good exercise in UI Design to re-fashion it to better fit how it works.]]></summary></entry><entry><title type="html">Snooping on Live Arduino Serial Communication</title><link href="/2015/01/snooping-on-live-arduino-serial-communication/" rel="alternate" type="text/html" title="Snooping on Live Arduino Serial Communication" /><published>2015-01-25T16:10:55+00:00</published><updated>2015-01-25T16:10:55+00:00</updated><id>/2015/01/snooping-on-live-arduino-serial-communication</id><content type="html" xml:base="/2015/01/snooping-on-live-arduino-serial-communication/"><![CDATA[<p>Using the Arduino IDE, we can bring up the Serial Monitor to send and receive data from the Arduino. However, if you’re using Windows, this completely ties up the COM port so that it cannot be used for anything else. If your Arduino needs to communication with other piece of software on your PC, that software gets exclusive access to that port so you can no longer use the Serial Monitor. Needless to say, it would be very nice to be able to peek at real data being sent between your PC app and the Arduino. A reliable way I’ve found to do this in Window is using com0com and hub4com. Here’s how it works.</p>

<h2 id="note-on-driver-types-it-is-relevant">Note on driver types <strong>(it is relevant!)</strong></h2>

<p>On Windows 8.1 64 bit (and true for 64 bit Vista and Win7 as far as I know) you have 3 types of driver…</p>

<ul>
  <li>Signed driver - This is preferred. It is how you are used to installing and using windows devices, but the developer must pay for it to be signed. Not an option for com0com.</li>
  <li>Unsigned driver - every time you want to use the unsigned virtual COM ports, you must reboot your PC twice to get to the Allow Unsigned Driver option. It is a pain. This is true of the latest com0com 3.0.0.0. If using 64bit Windows, avoid like the plague</li>
  <li>Test Signed Driver - you can run a simple command line instruction to tell Windows to allow Test-Signed drivers. The setting persists between reboot, so it is convenient. For com0com, this is true for the signed version of 2.2.2.0</li>
</ul>

<h2 id="installation">Installation</h2>

<p>Use version 2.2.2.0 because it is signed. When installing, I unchecked the option to add a default pair of COM ports. I preferred a clean start Run the command: bcdedit -set TESTSIGNING ON Once com0com is installed, go and get hub4com, unzip, rename the readme file and copy the whole lot into your com0com folder.</p>

<h3 id="note">Note</h3>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>v2.2.2.0 signed doesn't have the graphical setupg program, so need to use setupc for everthing

com0com command prompt: list
</code></pre></div></div>

<h2 id="my-scenario">My Scenario</h2>

<p>I have an Arduino on COM3, and some PC Software which talks to it, called “PC Lap Counter” (PCLC) - it’s a race management solution for slotcar racing. PCLC sends race and lap info to the Arduino over the serial connection, but I want to be able to look in on this info as it is happening.</p>

<h3 id="step-1-setup-the-virtual-com-port-pairs">Step 1: Setup the Virtual COM port Pairs</h3>

<p>Set up 2x com0com pairs using the com0com command line setupc.exe</p>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code>    install 0 <span class="nv">PortName</span><span class="o">=</span>COM5 -&lt;/span&gt;
    install 1 <span class="nv">PortName</span><span class="o">=</span>COM6 -&lt;/span&gt;
</code></pre></div></div>

<p>maybe need another COM port for a second putty session for injecting input</p>

<ul>
  <li>COM5 is to be used by PC Lap Counter, and is paired with CNCB0</li>
  <li>COM6 is used by Putty for monitoring, and is paired with CNCB1</li>
  <li>COM3 is physical COM port which Arduino is attached to</li>
  <li>Note that these COM ports will persist after reboot, whereas the hub4com routes need making every time.</li>
</ul>

<h3 id="step-2-join-the-com-port-pairs-together-with-hub4coms-routes">Step 2: Join the COM port pairs together with hub4com’s Routes</h3>

<p>From std command prompt…</p>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code>hub4com <span class="nt">-baud</span><span class="o">=</span>9600 <span class="nt">-octs</span><span class="o">=</span>off <span class="nt">-ox</span><span class="o">=</span>on <span class="nt">-route</span><span class="o">=</span>0,2:All <span class="nt">-no-default-fc-route</span><span class="o">=</span>0,1:All <span class="se">\\</span>.<span class="se">\C</span>NCB0 <span class="se">\\</span>.<span class="se">\C</span>NCB1  <span class="se">\\</span>.<span class="se">\C</span>OM3
</code></pre></div></div>

<p>unsure what the -no-default-fc-route is all about. Try without!</p>

<p>This routes PC Lap Counter to both Putty and Arduino. Plus, routes Arduino serial output to Putty</p>

<h3 id="step-3-snoop-away">Step 3: Snoop away</h3>

<p>Using Putty, create a new ‘Serial’ connection. In the above example, it is connected to COM6 at 9600baud</p>]]></content><author><name>{&quot;bio&quot;=&gt;&quot;Personal blog with an emphasis on microcontrollers, computing, and other hobby projects.&quot;, &quot;location&quot;=&gt;&quot;Lancashire, UK&quot;, &quot;links&quot;=&gt;[{&quot;label&quot;=&gt;&quot;Instagram&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-instagram&quot;, &quot;url&quot;=&gt;&quot;https://www.instagram.com/gregwoodslancs/&quot;}, {&quot;label&quot;=&gt;&quot;GitHub&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-github&quot;, &quot;url&quot;=&gt;&quot;https://github.com/gregwoods&quot;}, {&quot;label&quot;=&gt;&quot;Twitter&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-twitter-square&quot;, &quot;url&quot;=&gt;&quot;https://twitter.com/gregwoods&quot;}]}</name></author><category term="microcontroller" /><category term="programming" /><summary type="html"><![CDATA[Using the Arduino IDE, we can bring up the Serial Monitor to send and receive data from the Arduino. However, if you’re using Windows, this completely ties up the COM port so that it cannot be used for anything else. If your Arduino needs to communication with other piece of software on your PC, that software gets exclusive access to that port so you can no longer use the Serial Monitor. Needless to say, it would be very nice to be able to peek at real data being sent between your PC app and the Arduino. A reliable way I’ve found to do this in Window is using com0com and hub4com. Here’s how it works. Note on driver types (it is relevant!) On Windows 8.1 64 bit (and true for 64 bit Vista and Win7 as far as I know) you have 3 types of driver… Signed driver - This is preferred. It is how you are used to installing and using windows devices, but the developer must pay for it to be signed. Not an option for com0com. Unsigned driver - every time you want to use the unsigned virtual COM ports, you must reboot your PC twice to get to the Allow Unsigned Driver option. It is a pain. This is true of the latest com0com 3.0.0.0. If using 64bit Windows, avoid like the plague Test Signed Driver - you can run a simple command line instruction to tell Windows to allow Test-Signed drivers. The setting persists between reboot, so it is convenient. For com0com, this is true for the signed version of 2.2.2.0 Installation Use version 2.2.2.0 because it is signed. When installing, I unchecked the option to add a default pair of COM ports. I preferred a clean start Run the command: bcdedit -set TESTSIGNING ON Once com0com is installed, go and get hub4com, unzip, rename the readme file and copy the whole lot into your com0com folder. Note v2.2.2.0 signed doesn't have the graphical setupg program, so need to use setupc for everthing com0com command prompt: list My Scenario I have an Arduino on COM3, and some PC Software which talks to it, called “PC Lap Counter” (PCLC) - it’s a race management solution for slotcar racing. PCLC sends race and lap info to the Arduino over the serial connection, but I want to be able to look in on this info as it is happening. Step 1: Setup the Virtual COM port Pairs Set up 2x com0com pairs using the com0com command line setupc.exe  install 0 PortName=COM5 -&lt;/span&gt;  install 1 PortName=COM6 -&lt;/span&gt; maybe need another COM port for a second putty session for injecting input COM5 is to be used by PC Lap Counter, and is paired with CNCB0 COM6 is used by Putty for monitoring, and is paired with CNCB1 COM3 is physical COM port which Arduino is attached to Note that these COM ports will persist after reboot, whereas the hub4com routes need making every time. Step 2: Join the COM port pairs together with hub4com’s Routes From std command prompt… hub4com -baud=9600 -octs=off -ox=on -route=0,2:All -no-default-fc-route=0,1:All \\.\CNCB0 \\.\CNCB1  \\.\COM3 unsure what the -no-default-fc-route is all about. Try without! This routes PC Lap Counter to both Putty and Arduino. Plus, routes Arduino serial output to Putty Step 3: Snoop away Using Putty, create a new ‘Serial’ connection. In the above example, it is connected to COM6 at 9600baud]]></summary></entry><entry><title type="html">Getting into Arduino - Better late than Never</title><link href="/2014/10/getting-into-arduino-better-late-than-never/" rel="alternate" type="text/html" title="Getting into Arduino - Better late than Never" /><published>2014-10-03T07:58:28+00:00</published><updated>2014-10-03T07:58:28+00:00</updated><id>/2014/10/getting-into-arduino-better-late-than-never</id><content type="html" xml:base="/2014/10/getting-into-arduino-better-late-than-never/"><![CDATA[<p>I’ve always had an interest in making stuff which interfaces with the world, but in the days before microcontrollers, and without a solid electronics background, making stuff was hard. Much too hard. Flashing an LED with a 555 timer is reasonably straightforward- but anything more and you need a LOT of breadboard space, and a lot more time than I could spare.</p>

<p>Then along came the microcontroller. I can’t remember whether I discovered PIC or AVR first, but whenever a new development board was being given away for free or nearly free, I’d be on it. Writing little test programs wasn’t overly difficult. Setting up the development environment however, was. Often, between long droughts of development, my PC would have been rebuilt, and I’d lost all that setup time and effort. As far as the programming went, I have always enjoyed low level coding (starting with hand written Z80 machine code on a Sinclair ZX81). But enjoyment wasn’t the only goal - a finished project matters. And hour upon hour could be spent at too a low a level to feel like progress was being made.</p>

<p>I heard about Arduino, discovered it was AVR based and had a bootloader - which didn’t seems a compelling reason to go with it, since AVRISP programming worked fine. The boards were also far too big, and too expensive compared to the $1 (£1 to me) chips I was used to buying. I was perhaps also swayed by a slight preference towards PICs over AVRs. The Arduino marketing didn’t help me either. I read it as “Helping whimsical arty types create pointless trinkets with overpriced, overspecified boards so they don’t have to learn the hard way”. I liked the hard way. So I wrote Arduino off as a toy.</p>

<p>How wrong I was.</p>

<p>I recently resurrected my childhood love of slot car racing (Scalextric) by building up a reasonable collection of Scalextric Digital track and cars. I explored the PC based Race management Systems which add a whole new dimension. My ‘maker’ mentality was reawakened at the thought of interfacing with all this digital information flying round the track and doing useful things with it, like a leader board or F1 style start lights (my current project combines these into an ‘onmi gantry’ - more later). Each of the three PC based Race Management applications supported Arduino in one way or the other. So I put aside old prejudices and ordered a couple of cheap, Chinese clones of the Arduino Pro Mini and FTDI programmer. No bigger than a DIL chip, the Pro Mini appealed to my barebones mentality. After a couple of days reading around the subject, waiting for the slow boat from China to arrive, I bought an Uno. The price was more reasonable than I’d remembered - and all the tutorials referred to them, so I decided, for once, to make things as easy as humanly possible so I could concentrate on getting my project finished. The fact that the Uno can be used to burn the bootloader onto bare Atmel chip was another compelling reason to have an Uno.</p>

<p>I’m now a week into Arduino programming, and I can say I’ve done more in a week than I would have done in months with a bare AVR/PIC. Having the bootloader does make a big difference. When you can’t get a line of code to work… change - upload - test - repeat. Valuable seconds saved dozens of times in a programming session add up to a more pleasurable experience. The fact that I can go to a brand new PC, download the IDE, load up my files from Dropbox and carry on coding from where I left off is also useful. But the real appeal of Arduino is the libraries and other support material. The various hardware shields don’t interest me too much, but the libraries developed to support them are amazing. To think, I used to to have to read chip datasheets to write code. Now I download the library and I’m good to go. LCD screens, LED matrices, NeoPixels, Serial communication, I2C sensors - all have superb libraries which mean that getting a project finished is now a real possibility.</p>

<p>Finally, if anyone thinks, as I did, that cheap ARM cored boards spell the death of the 8 bit microcontroller - they are wrong. There are many projects where even an 8MHz processor is technically overkill. My next project is adding realistic looking running lights to an RC Helicopter. It seems ridiculous that such processing power is being used for such a trivial task. But doing it from discreet components would be a huge undertaking without an Electrical Engineering background. The finished project would be so big and heavy that the heli wouldn’t be able to lift off! Being able to adjust the timing of the flashing lights with a line of code is awesome compared to swapping out resistors and capacitors. An Arduino Pro Mini does the job nicely for a couple of bucks, and grams. You wouldn’t want to use the size and expense of a Raspberry Pi or BeagleBone for those kind of tasks!</p>

<p>So, in case you haven’t figured it out, I’m a bit pleased with the Arduino. Rather than feeling like I may have missed the boat, I believe it’s a good time to start out. The platform is mature, the community solid, the glitches ironed out and libraries already written. So if there are any hardware tinkerers out there who, like me, are stubbornly refusing to take a look at Arduino - Jump on the bandwagon, the ride is surprisingly smooth.</p>]]></content><author><name>{&quot;bio&quot;=&gt;&quot;Personal blog with an emphasis on microcontrollers, computing, and other hobby projects.&quot;, &quot;location&quot;=&gt;&quot;Lancashire, UK&quot;, &quot;links&quot;=&gt;[{&quot;label&quot;=&gt;&quot;Instagram&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-instagram&quot;, &quot;url&quot;=&gt;&quot;https://www.instagram.com/gregwoodslancs/&quot;}, {&quot;label&quot;=&gt;&quot;GitHub&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-github&quot;, &quot;url&quot;=&gt;&quot;https://github.com/gregwoods&quot;}, {&quot;label&quot;=&gt;&quot;Twitter&quot;, &quot;icon&quot;=&gt;&quot;fab fa-fw fa-twitter-square&quot;, &quot;url&quot;=&gt;&quot;https://twitter.com/gregwoods&quot;}]}</name></author><category term="microcontroller" /><category term="arduino" /><category term="programming" /><summary type="html"><![CDATA[I’ve always had an interest in making stuff which interfaces with the world, but in the days before microcontrollers, and without a solid electronics background, making stuff was hard. Much too hard. Flashing an LED with a 555 timer is reasonably straightforward- but anything more and you need a LOT of breadboard space, and a lot more time than I could spare. Then along came the microcontroller. I can’t remember whether I discovered PIC or AVR first, but whenever a new development board was being given away for free or nearly free, I’d be on it. Writing little test programs wasn’t overly difficult. Setting up the development environment however, was. Often, between long droughts of development, my PC would have been rebuilt, and I’d lost all that setup time and effort. As far as the programming went, I have always enjoyed low level coding (starting with hand written Z80 machine code on a Sinclair ZX81). But enjoyment wasn’t the only goal - a finished project matters. And hour upon hour could be spent at too a low a level to feel like progress was being made. I heard about Arduino, discovered it was AVR based and had a bootloader - which didn’t seems a compelling reason to go with it, since AVRISP programming worked fine. The boards were also far too big, and too expensive compared to the $1 (£1 to me) chips I was used to buying. I was perhaps also swayed by a slight preference towards PICs over AVRs. The Arduino marketing didn’t help me either. I read it as “Helping whimsical arty types create pointless trinkets with overpriced, overspecified boards so they don’t have to learn the hard way”. I liked the hard way. So I wrote Arduino off as a toy. How wrong I was. I recently resurrected my childhood love of slot car racing (Scalextric) by building up a reasonable collection of Scalextric Digital track and cars. I explored the PC based Race management Systems which add a whole new dimension. My ‘maker’ mentality was reawakened at the thought of interfacing with all this digital information flying round the track and doing useful things with it, like a leader board or F1 style start lights (my current project combines these into an ‘onmi gantry’ - more later). Each of the three PC based Race Management applications supported Arduino in one way or the other. So I put aside old prejudices and ordered a couple of cheap, Chinese clones of the Arduino Pro Mini and FTDI programmer. No bigger than a DIL chip, the Pro Mini appealed to my barebones mentality. After a couple of days reading around the subject, waiting for the slow boat from China to arrive, I bought an Uno. The price was more reasonable than I’d remembered - and all the tutorials referred to them, so I decided, for once, to make things as easy as humanly possible so I could concentrate on getting my project finished. The fact that the Uno can be used to burn the bootloader onto bare Atmel chip was another compelling reason to have an Uno. I’m now a week into Arduino programming, and I can say I’ve done more in a week than I would have done in months with a bare AVR/PIC. Having the bootloader does make a big difference. When you can’t get a line of code to work… change - upload - test - repeat. Valuable seconds saved dozens of times in a programming session add up to a more pleasurable experience. The fact that I can go to a brand new PC, download the IDE, load up my files from Dropbox and carry on coding from where I left off is also useful. But the real appeal of Arduino is the libraries and other support material. The various hardware shields don’t interest me too much, but the libraries developed to support them are amazing. To think, I used to to have to read chip datasheets to write code. Now I download the library and I’m good to go. LCD screens, LED matrices, NeoPixels, Serial communication, I2C sensors - all have superb libraries which mean that getting a project finished is now a real possibility. Finally, if anyone thinks, as I did, that cheap ARM cored boards spell the death of the 8 bit microcontroller - they are wrong. There are many projects where even an 8MHz processor is technically overkill. My next project is adding realistic looking running lights to an RC Helicopter. It seems ridiculous that such processing power is being used for such a trivial task. But doing it from discreet components would be a huge undertaking without an Electrical Engineering background. The finished project would be so big and heavy that the heli wouldn’t be able to lift off! Being able to adjust the timing of the flashing lights with a line of code is awesome compared to swapping out resistors and capacitors. An Arduino Pro Mini does the job nicely for a couple of bucks, and grams. You wouldn’t want to use the size and expense of a Raspberry Pi or BeagleBone for those kind of tasks! So, in case you haven’t figured it out, I’m a bit pleased with the Arduino. Rather than feeling like I may have missed the boat, I believe it’s a good time to start out. The platform is mature, the community solid, the glitches ironed out and libraries already written. So if there are any hardware tinkerers out there who, like me, are stubbornly refusing to take a look at Arduino - Jump on the bandwagon, the ride is surprisingly smooth.]]></summary></entry></feed>