<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>GPIO Simulator | no dogma blog</title><link>https://nodogmablog.bryanhogan.net/tag/gpio-simulator/</link><atom:link href="https://nodogmablog.bryanhogan.net/tag/gpio-simulator/index.xml" rel="self" type="application/rss+xml"/><description>GPIO Simulator</description><generator>Wowchemy (https://wowchemy.com)</generator><language>en-us</language><lastBuildDate>Fri, 04 Dec 2026 00:00:00 +0000</lastBuildDate><image><url>https://nodogmablog.bryanhogan.net/media/icon_hu9c23d68d4e9f1f9acfa8237e5c2ea674_3344_512x512_fill_lanczos_center_3.png</url><title>GPIO Simulator</title><link>https://nodogmablog.bryanhogan.net/tag/gpio-simulator/</link></image><item><title>Raspberry PI GPIO Simulator</title><link>https://nodogmablog.bryanhogan.net/2026/12/raspberry-pi-gpio-simulator/</link><pubDate>Fri, 04 Dec 2026 00:00:00 +0000</pubDate><guid>https://nodogmablog.bryanhogan.net/2026/12/raspberry-pi-gpio-simulator/</guid><description>&lt;p>&lt;em>Download &lt;a href="media/PiMorseCode.zip">full source code.&lt;/a>&lt;/em>&lt;/p>
&lt;p>When programming the GPIO of a Raspberry Pi, it is not always possible to have a Pi at hand with appropriate wires and connected devices. Last week I was working on my &lt;a href="https://nodogmablog.bryanhogan.net/2026/11/morse-code-with-net-on-a-raspberry-pi/">Morse code application&lt;/a> for the Pi while on the train. Running it locally on my laptop leads to a runtime error because my laptop doesn&amp;rsquo;t have a GPIO.&lt;/p>
&lt;p>I looked on the web for GPIO simulator and found a few old, not maintained projects which probably won&amp;rsquo;t work with .NET.&lt;/p>
&lt;p>How about creating one with an LLM? As you will guess, this was easy. It took a few back-and-forths and some tweaks, but I now have a GPIO simulator that I can include in my .NET Raspberry Pi projects when testing.&lt;/p>
&lt;p>In fact, you can leave the simulator project in place even when deploying. The simulator&amp;rsquo;s code will be bypassed when running on the Pi.&lt;/p>
&lt;p>Here&amp;rsquo;s how it looks -&lt;/p>
&lt;video width="320" height="240" controls>
&lt;source src="media/gpio-sim.mp4" type="video/mp4">
Your browser does not support the video tag.
&lt;/video>
&lt;p>It&amp;rsquo;s available on NuGet - &lt;a href="https://www.nuget.org/packages/RaspberryPi.GpioSim/" target="_blank" rel="noopener">https://www.nuget.org/packages/RaspberryPi.GpioSim/&lt;/a>.&lt;/p>
&lt;p>It is simple to use. Add the &lt;code>RaspberryPi.GpioSim&lt;/code> Nuget package to your project -
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-cfg" data-lang="cfg">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#000">dotnet add package RaspberryPi.GpioSim &lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;/p>
&lt;p>Then add the &lt;code>using RaspberryPi.GpioSim&lt;/code> reference to the project. Normally you would do something like line 7, &lt;code>using var pinController....&lt;/code>, but instead use lines 9 and 10. Then write the code as normal.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-csharp" data-lang="csharp">&lt;span style="display:flex;">&lt;span style="white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1&lt;/span>&lt;span>&lt;span style="color:#00f">using&lt;/span> &lt;span style="color:#000">System.Device.Gpio&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2&lt;/span>&lt;span>&lt;span style="color:#00f">using&lt;/span> &lt;span style="color:#000">RaspberryPi.GpioSim&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3&lt;/span>&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4&lt;/span>&lt;span>&lt;span style="color:#888;font-style:italic">// Real GPIO on a Raspberry Pi, the simulator everywhere else.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5&lt;/span>&lt;span>&lt;span style="color:#888;font-style:italic">// Override with --simulate or --real; simulator options: --display board|log, --script &amp;lt;file&amp;gt;.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6&lt;/span>&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7&lt;/span>&lt;span>&lt;span style="color:#888;font-style:italic">// using var piController = new GpioController(); // use the line below instead&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8&lt;/span>&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9&lt;/span>&lt;span>&lt;span style="color:#00f">using&lt;/span> &lt;span style="color:#000">var&lt;/span> &lt;span style="color:#000">hw&lt;/span> = &lt;span style="color:#000">GpioHost&lt;/span>.&lt;span style="color:#000">Create&lt;/span>(&lt;span style="color:#000">args&lt;/span>);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10&lt;/span>&lt;span>&lt;span style="color:#00f">var&lt;/span> &lt;span style="color:#000">piController&lt;/span> = &lt;span style="color:#000">hw&lt;/span>.&lt;span style="color:#000">Controller&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11&lt;/span>&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12&lt;/span>&lt;span>&lt;span style="color:#888;font-style:italic">// normal GPIO code from here on &lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13&lt;/span>&lt;span>&lt;span style="color:#00f">var&lt;/span> &lt;span style="color:#000">gpio24&lt;/span> = &lt;span style="color:#000">piController&lt;/span>.&lt;span style="color:#000">OpenPin&lt;/span>(&lt;span style="color:#3af">24&lt;/span>, &lt;span style="color:#000">PinMode&lt;/span>.&lt;span style="color:#000">Output&lt;/span>);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14&lt;/span>&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">15&lt;/span>&lt;span>&lt;span style="color:#888;font-style:italic">// ...&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;p>Here is the repository - &lt;a href="https://github.com/bryanjhogan/RaspberryPi-GPIO-Simulator" target="_blank" rel="noopener">https://github.com/bryanjhogan/RaspberryPi-GPIO-Simulator&lt;/a>.&lt;/p>
&lt;p>&lt;em>Download &lt;a href="media/PiMorseCode.zip">full source code.&lt;/a>&lt;/em>&lt;/p></description></item></channel></rss>