<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Relay on Ulis Notes</title>
    <link>https://wolf-u.li/en/tag/relay/</link>
    <description>Recent content in Relay on Ulis Notes</description>
    <generator>Hugo</generator>
    <language>en</language>
    <copyright>Copyright 2006-CURRENTYEAR Uli Wolf - All rights reserved</copyright>
    <lastBuildDate>Wed, 13 Mar 2024 14:16:33 +1300</lastBuildDate>
    <atom:link href="https://wolf-u.li/en/tag/relay/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>BIGTREETECH Relay 1.2: Change Timeout and enable turning on by pin</title>
      
      
      <link>https://wolf-u.li/bigtreetech-relay-1.2-change-timeout-and-enable-turning-on-by-pin</link>
      <pubDate>Wed, 13 Mar 2024 14:16:33 +1300</pubDate>
      <guid>https://wolf-u.li/bigtreetech-relay-1.2-change-timeout-and-enable-turning-on-by-pin</guid>
      <description>&lt;p&gt;For some applications (like when you want to connect the 
&lt;a href=&#34;https://shareasale.com/r.cfm?b=1890927&amp;u=3683758&amp;m=131011&amp;urllink=https%3a%2f%2fbiqu.equipment%2fcollections%2fcontrol-board%2fproducts%2fbigtreetech-manta-e3ez-v1-0-for-ender3-ender3pro-ender5%3fvariant%3d40286567727202&amp;afftrack=&#34;&gt;BIGTREETECH E3EZ*&lt;/a&gt;

) you might want to increase the timeout for the shutdown of the 
&lt;a href=&#34;https://shareasale.com/r.cfm?b=1890927&amp;u=3683758&amp;m=131011&amp;urllink=https%3a%2f%2fbiqu.equipment%2fproducts%2fbigtreetech-reply-v1-2-automatic-shutdown-module-after-printing&amp;afftrack=&#34;&gt;BIGTREETECH Relay 1.2*&lt;/a&gt;

. Especially in the case of the E3EZ the issue is that the power of the PSU is also the power for the Onboard CPU (e.g. 
&lt;a href=&#34;https://shareasale.com/r.cfm?b=1890927&amp;u=3683758&amp;m=131011&amp;urllink=https%3a%2f%2fbiqu.equipment%2fcollections%2fcontrol-board%2fproducts%2fpi4b-adapter-v1-0%3fvariant%3d40353646051426&amp;afftrack=&#34;&gt;CB1*&lt;/a&gt;

 or CM4). So when this power cuts too fast, the PSU would be switched off before the CPU has shutdown. Lastly you might want to be able to start the relay through the pins (and not just shut it down) instead of resetting the device.
&lt;ins class=&#34;adsbygoogle&#34; style=&#34;display:block; text-align:center;&#34; data-ad-layout=&#34;in-article&#34; data-ad-format=&#34;fluid&#34; data-ad-client=&#34;ca-pub-2322978122735420&#34; data-ad-slot=&#34;3161252284&#34;&gt;&lt;/ins&gt;&lt;/p&gt;</description>
      
         <content:encoded><![CDATA[<p>For some applications (like when you want to connect the 
<a href="https://shareasale.com/r.cfm?b=1890927&u=3683758&m=131011&urllink=https%3a%2f%2fbiqu.equipment%2fcollections%2fcontrol-board%2fproducts%2fbigtreetech-manta-e3ez-v1-0-for-ender3-ender3pro-ender5%3fvariant%3d40286567727202&afftrack=">BIGTREETECH E3EZ*</a>

) you might want to increase the timeout for the shutdown of the 
<a href="https://shareasale.com/r.cfm?b=1890927&u=3683758&m=131011&urllink=https%3a%2f%2fbiqu.equipment%2fproducts%2fbigtreetech-reply-v1-2-automatic-shutdown-module-after-printing&afftrack=">BIGTREETECH Relay 1.2*</a>

. Especially in the case of the E3EZ the issue is that the power of the PSU is also the power for the Onboard CPU (e.g. 
<a href="https://shareasale.com/r.cfm?b=1890927&u=3683758&m=131011&urllink=https%3a%2f%2fbiqu.equipment%2fcollections%2fcontrol-board%2fproducts%2fpi4b-adapter-v1-0%3fvariant%3d40353646051426&afftrack=">CB1*</a>

 or CM4). So when this power cuts too fast, the PSU would be switched off before the CPU has shutdown. Lastly you might want to be able to start the relay through the pins (and not just shut it down) instead of resetting the device.
<ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-2322978122735420" data-ad-slot="3161252284"></ins></p>
<h2 id="research">Research</h2>
<p>I was researching that for a bit until i found some hints that this is possible. It all started with the finding of the <link rel=dns-prefetch href=//github.com /> <a href="https://github.com/bigtreetech/BIGTREETECH-Relay-V1.2/blob/master/BIGTREETECH%20Relay%20V1.2/BIGTREETECH%20Relay%20V1.2/Firmware/STC15W201S.hex"
    title="original firmware" 
     target="_blank" rel="nofollow noopener noreferrer" >
  original firmware&nbsp;<svg xmlns="http://www.w3.org/2000/svg" class="icon" aria-hidden="true" focusable="false" viewBox="0 -128 512 640">
    <path d="M384 320c-17.67 0-32 14.33-32 32v96H64V160h96c17.67 0 32-14.32 32-32s-14.33-32-32-32L64 96c-35.35 0-64 28.65-64 64V448c0 35.34 28.65 64 64 64h288c35.35 0 64-28.66 64-64v-96C416 334.3 401.7 320 384 320zM488 0H352c-12.94 0-24.62 7.797-29.56 19.75c-4.969 11.97-2.219 25.72 6.938 34.88L370.8 96L169.4 297.4c-12.5 12.5-12.5 32.75 0 45.25C175.6 348.9 183.8 352 192 352s16.38-3.125 22.62-9.375L416 141.3l41.38 41.38c9.156 9.141 22.88 11.84 34.88 6.938C504.2 184.6 512 172.9 512 160V24C512 10.74 501.3 0 488 0z"/>
  </svg></a> and a hint <link rel=dns-prefetch href=//github.com /> <a href="https://github.com/bigtreetech/BIGTREETECH-Relay-V1.2/issues/19"
    title="how to upload it" 
     target="_blank" rel="nofollow noopener noreferrer" >
  how to upload it&nbsp;<svg xmlns="http://www.w3.org/2000/svg" class="icon" aria-hidden="true" focusable="false" viewBox="0 -128 512 640">
    <path d="M384 320c-17.67 0-32 14.33-32 32v96H64V160h96c17.67 0 32-14.32 32-32s-14.33-32-32-32L64 96c-35.35 0-64 28.65-64 64V448c0 35.34 28.65 64 64 64h288c35.35 0 64-28.66 64-64v-96C416 334.3 401.7 320 384 320zM488 0H352c-12.94 0-24.62 7.797-29.56 19.75c-4.969 11.97-2.219 25.72 6.938 34.88L370.8 96L169.4 297.4c-12.5 12.5-12.5 32.75 0 45.25C175.6 348.9 183.8 352 192 352s16.38-3.125 22.62-9.375L416 141.3l41.38 41.38c9.156 9.141 22.88 11.84 34.88 6.938C504.2 184.6 512 172.9 512 160V24C512 10.74 501.3 0 488 0z"/>
  </svg></a>. But then i found an Issue where the discussion went into the right direction: Obtaining the <link rel=dns-prefetch href=//github.com /> <a href="https://github.com/sobieh/bttrelay/tree/main/original"
    title="sourcecode" 
     target="_blank" rel="nofollow noopener noreferrer" >
  sourcecode&nbsp;<svg xmlns="http://www.w3.org/2000/svg" class="icon" aria-hidden="true" focusable="false" viewBox="0 -128 512 640">
    <path d="M384 320c-17.67 0-32 14.33-32 32v96H64V160h96c17.67 0 32-14.32 32-32s-14.33-32-32-32L64 96c-35.35 0-64 28.65-64 64V448c0 35.34 28.65 64 64 64h288c35.35 0 64-28.66 64-64v-96C416 334.3 401.7 320 384 320zM488 0H352c-12.94 0-24.62 7.797-29.56 19.75c-4.969 11.97-2.219 25.72 6.938 34.88L370.8 96L169.4 297.4c-12.5 12.5-12.5 32.75 0 45.25C175.6 348.9 183.8 352 192 352s16.38-3.125 22.62-9.375L416 141.3l41.38 41.38c9.156 9.141 22.88 11.84 34.88 6.938C504.2 184.6 512 172.9 512 160V24C512 10.74 501.3 0 488 0z"/>
  </svg></a> and an instruction how to update <link rel=dns-prefetch href=//github.com /> <a href="https://github.com/sobieh/bttrelay/blob/main/readme.md"
    title="this" 
     target="_blank" rel="nofollow noopener noreferrer" >
  this&nbsp;<svg xmlns="http://www.w3.org/2000/svg" class="icon" aria-hidden="true" focusable="false" viewBox="0 -128 512 640">
    <path d="M384 320c-17.67 0-32 14.33-32 32v96H64V160h96c17.67 0 32-14.32 32-32s-14.33-32-32-32L64 96c-35.35 0-64 28.65-64 64V448c0 35.34 28.65 64 64 64h288c35.35 0 64-28.66 64-64v-96C416 334.3 401.7 320 384 320zM488 0H352c-12.94 0-24.62 7.797-29.56 19.75c-4.969 11.97-2.219 25.72 6.938 34.88L370.8 96L169.4 297.4c-12.5 12.5-12.5 32.75 0 45.25C175.6 348.9 183.8 352 192 352s16.38-3.125 22.62-9.375L416 141.3l41.38 41.38c9.156 9.141 22.88 11.84 34.88 6.938C504.2 184.6 512 172.9 512 160V24C512 10.74 501.3 0 488 0z"/>
  </svg></a>. And finally also a hint how to extend the <link rel=dns-prefetch href=//github.com /> <a href="https://github.com/bigtreetech/BIGTREETECH-Relay-V1.2/issues/4#issuecomment-1483891298#issuecomment-1483891298"
    title="timeout" 
     target="_blank" rel="nofollow noopener noreferrer" >
  timeout&nbsp;<svg xmlns="http://www.w3.org/2000/svg" class="icon" aria-hidden="true" focusable="false" viewBox="0 -128 512 640">
    <path d="M384 320c-17.67 0-32 14.33-32 32v96H64V160h96c17.67 0 32-14.32 32-32s-14.33-32-32-32L64 96c-35.35 0-64 28.65-64 64V448c0 35.34 28.65 64 64 64h288c35.35 0 64-28.66 64-64v-96C416 334.3 401.7 320 384 320zM488 0H352c-12.94 0-24.62 7.797-29.56 19.75c-4.969 11.97-2.219 25.72 6.938 34.88L370.8 96L169.4 297.4c-12.5 12.5-12.5 32.75 0 45.25C175.6 348.9 183.8 352 192 352s16.38-3.125 22.62-9.375L416 141.3l41.38 41.38c9.156 9.141 22.88 11.84 34.88 6.938C504.2 184.6 512 172.9 512 160V24C512 10.74 501.3 0 488 0z"/>
  </svg></a>.</p>
<p>Fortunately, the user sobieh had changed the firmware in his <link rel=dns-prefetch href=//github.com /> <a href="https://github.com/sobieh/bttrelay/"
    title="repository" 
     target="_blank" rel="nofollow noopener noreferrer" >
  repository&nbsp;<svg xmlns="http://www.w3.org/2000/svg" class="icon" aria-hidden="true" focusable="false" viewBox="0 -128 512 640">
    <path d="M384 320c-17.67 0-32 14.33-32 32v96H64V160h96c17.67 0 32-14.32 32-32s-14.33-32-32-32L64 96c-35.35 0-64 28.65-64 64V448c0 35.34 28.65 64 64 64h288c35.35 0 64-28.66 64-64v-96C416 334.3 401.7 320 384 320zM488 0H352c-12.94 0-24.62 7.797-29.56 19.75c-4.969 11.97-2.219 25.72 6.938 34.88L370.8 96L169.4 297.4c-12.5 12.5-12.5 32.75 0 45.25C175.6 348.9 183.8 352 192 352s16.38-3.125 22.62-9.375L416 141.3l41.38 41.38c9.156 9.141 22.88 11.84 34.88 6.938C504.2 184.6 512 172.9 512 160V24C512 10.74 501.3 0 488 0z"/>
  </svg></a> so that the relay doesn&rsquo;t need a reset but - and that made it unusable for me - he also changed a couple timeouts and the behaviour of the relay was modified so that it is enabled when the pin is pulled low. For regular cases (where the pc managing the printer is running 24/7) this makes sense but for mine (BTT E3EZ Board with a CB1 onboard) it doesn&rsquo;t.</p>
<p>So i needed to get into assembly which - thanks to ChatGPT was less complicated than i thought.</p>
<h2 id="custom-firmware-description">Custom Firmware Description</h2>
<p>So there it is - the firmware for the BIGTREETECH Relay 1.2 with the following features:</p>
<ul>
<li>Shutdown Delay of 30 seconds (allows to shutdown a CB1 or CM4 embedded on your mainboard)</li>
<li>Startup delay of 30 seconds (allows to start towards klipper without triggering a shutdown)</li>
<li>Checks every 3 seconds for a changed pin (meaning that it can take up to 33 seconds to shutdown your relay)</li>
</ul>
<h2 id="custom-firmware-implementation">Custom Firmware implementation</h2>
<h3 id="prerequisites---hardware">Prerequisites - Hardware</h3>
<p>To implement the modified firmware you will need a serial adapter, e.g. a CH340 (
<a href="http://s.click.aliexpress.com/e/_DFxV9kb">Aliexpress*</a>
 or 
<a href="https://www.amazon.de/s?k=CH340&tag=lebendeswolfuli-21" target="_blank">Amazon*</a>
) and a Windows Host.</p>
<h3 id="prerequisites---software">Prerequisites - Software</h3>
<ul>
<li>Clone the repository from <link rel=dns-prefetch href=//github.com /> <a href="https://github.com/SirUli/bigtreetech-relay-1.2-firmware"
    title="here" 
     target="_blank" rel="nofollow noopener noreferrer" >
  here&nbsp;<svg xmlns="http://www.w3.org/2000/svg" class="icon" aria-hidden="true" focusable="false" viewBox="0 -128 512 640">
    <path d="M384 320c-17.67 0-32 14.33-32 32v96H64V160h96c17.67 0 32-14.32 32-32s-14.33-32-32-32L64 96c-35.35 0-64 28.65-64 64V448c0 35.34 28.65 64 64 64h288c35.35 0 64-28.66 64-64v-96C416 334.3 401.7 320 384 320zM488 0H352c-12.94 0-24.62 7.797-29.56 19.75c-4.969 11.97-2.219 25.72 6.938 34.88L370.8 96L169.4 297.4c-12.5 12.5-12.5 32.75 0 45.25C175.6 348.9 183.8 352 192 352s16.38-3.125 22.62-9.375L416 141.3l41.38 41.38c9.156 9.141 22.88 11.84 34.88 6.938C504.2 184.6 512 172.9 512 160V24C512 10.74 501.3 0 488 0z"/>
  </svg></a>.</li>
<li>Obtain &amp; Install <link rel=dns-prefetch href=//www.keil.com /> <a href="https://www.keil.com/demo/eval/c51.htm"
    title="Keil C51 Development Tools" 
     target="_blank" rel="nofollow noopener noreferrer" >
  Keil C51 Development Tools&nbsp;<svg xmlns="http://www.w3.org/2000/svg" class="icon" aria-hidden="true" focusable="false" viewBox="0 -128 512 640">
    <path d="M384 320c-17.67 0-32 14.33-32 32v96H64V160h96c17.67 0 32-14.32 32-32s-14.33-32-32-32L64 96c-35.35 0-64 28.65-64 64V448c0 35.34 28.65 64 64 64h288c35.35 0 64-28.66 64-64v-96C416 334.3 401.7 320 384 320zM488 0H352c-12.94 0-24.62 7.797-29.56 19.75c-4.969 11.97-2.219 25.72 6.938 34.88L370.8 96L169.4 297.4c-12.5 12.5-12.5 32.75 0 45.25C175.6 348.9 183.8 352 192 352s16.38-3.125 22.62-9.375L416 141.3l41.38 41.38c9.156 9.141 22.88 11.84 34.88 6.938C504.2 184.6 512 172.9 512 160V24C512 10.74 501.3 0 488 0z"/>
  </svg></a></li>
<li>Add the path to your C51.exe to the Windows PATH variables</li>
<li>Obtain and Install <link rel=dns-prefetch href=//www.python.org /> <a href="https://www.python.org/downloads/"
    title="Python 3" 
     target="_blank" rel="nofollow noopener noreferrer" >
  Python 3&nbsp;<svg xmlns="http://www.w3.org/2000/svg" class="icon" aria-hidden="true" focusable="false" viewBox="0 -128 512 640">
    <path d="M384 320c-17.67 0-32 14.33-32 32v96H64V160h96c17.67 0 32-14.32 32-32s-14.33-32-32-32L64 96c-35.35 0-64 28.65-64 64V448c0 35.34 28.65 64 64 64h288c35.35 0 64-28.66 64-64v-96C416 334.3 401.7 320 384 320zM488 0H352c-12.94 0-24.62 7.797-29.56 19.75c-4.969 11.97-2.219 25.72 6.938 34.88L370.8 96L169.4 297.4c-12.5 12.5-12.5 32.75 0 45.25C175.6 348.9 183.8 352 192 352s16.38-3.125 22.62-9.375L416 141.3l41.38 41.38c9.156 9.141 22.88 11.84 34.88 6.938C504.2 184.6 512 172.9 512 160V24C512 10.74 501.3 0 488 0z"/>
  </svg></a></li>
<li>Run:
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">pip install stcgal
</span></span></code></pre></td></tr></table>
</div>
</div></li>
</ul>
<h3 id="build-firmware">Build Firmware</h3>
<ul>
<li>Change to the cloned git repository</li>
<li>Run build.bat</li>
</ul>
<h3 id="upload-firmware">Upload Firmware</h3>
<p>This instruction is to be used at your own risk. We are not liable for any damage.</p>
<ul>
<li><strong>Disconnect any mains voltage</strong></li>
<li>Connect the relay board to any USB to Serial adapter</li>
<li>Run upload.bat COM# where # is your COM port number. To find the number, check the Windows Device Manager</li>
<li>Reset the board with reset button</li>
</ul>
]]></content:encoded>
    </item>
  </channel>
</rss>
