Fritzing customized part principle - Fritzing 自訂元件原則

設計 Arduino 或 Resberry pi 的人,大概都用過 Fritzing 來設計電路

雖然它是免費的(當然也接受捐款,我也捐款過),但是缺點是零件(Part)種類無法包山包海。

大家最常遇到的問題是,找不到自己正在使用的零件,所以得靠第三方(別人的)的零件庫。

雖然有第三方零件庫,但說真的,在台灣的玩家常買對岸的零件時,或特製零件(某些賣場會找工廠批量設計生產)時都會找不到零件庫可以用或是下載。

雖然,網路上也接受客製化元件庫設計,不過是要收費的,對於學生/經濟力較弱的人來說,真的都是困難,不過 Fritzing 官方網站也有教您自己如何設計元件,也歡迎您把設計元件庫放在 GitHub 上分享給別人,不過前提是你要搞懂 Fritzing 設計元件的原理和方法。

所以,我把 Fritzing 使用自訂元件的原理,和設計方法簡單的說明一下,讓有心自己設計的人可以很方便的上手。

由於原理和實作內容可能不少,所以我分成幾篇來處理:

注意我使用的 Fritzing 版本是 0.93b 的版本作業系統是 Windows ,而網路上的中文教學大部分是舊版的而且不少使用 Linux (先說聲抱歉,我沒有用過 Linux,路徑請自行轉換),所以使用上有很大落差,尤其常常會找不到對應的功能表。

關係圖

檔案位置
※沒相關資料夾的人請先安裝 Fritzing ,然後執行一次就會產生下面需要的資料夾。

Fritzing 的自訂元件通常會放在 %user%\Documents\Fritzing 下,這底下會有 Parts 和 Bins 兩個資料夾:

這個 bins 就是 Fritzing 畫面右邊那個元件庫啦~

裡面會看到 search.fzb 和 my_parts.fzb 就是對應搜尋放大鏡My Parts 元件庫(Library)的。(圖案是MINE...雖然意思是一樣,但對我們這種歪國人來說,第一時間真容易搞錯)


如果你在下拉式功能新增自己的元件庫 New Bin 然後儲存 Save Bin,就會在 bins 路徑下看到你新增的庫檔案喔~


而另一個 part 顧名思義就是放元件的設計圖的,這層有兩個主要的資料夾:user 和 svg


user 放置你的自訂元件描述檔(*.fzb),你可以把接下來的user看成是『自訂的』意思。
svg 放置圖檔(*.svg)

而進入 svg 裡面又有一個 user,再進入 user 後會看到圖檔分類資料夾: breadboard、icon、pcb、schematic

breadboard 零件外觀圖(零件貼在麵包板上使用的圖)
icon 零件概略圖(顯示在零件庫上的圖案)
pcb 設計 pcb 用的接線圖
schematic 電路圖,用來表示電路形狀的電路圖

這裡面的設計圖案,全都使用SVG向量檔案格式喔!!

建議軟體
目前 Fritzing 建議大家使用的是 Adobe Illustrator 來設計向量圖(記得要存成SVG)

當然,口袋不夠深的就用 Inkscape 了(我就是....)

什麼是fzb
    Fritzing bins 的縮寫,元件庫檔案,檔案內容是XML格式,並不複雜,內容大概是:

<?xml version="1.0" encoding="UTF-8"?>
<module fritzingVersion="0.9.3b.04.19.5c895d327c44a3114e5fcc9d8260daf0cbb52806" icon="Mine.png">
    <title>My Parts</title>
    <instances>
        <instance moduleIdRef="Keyes_Rotary_Decoder_Switch_5812070981c131c2523c4b742f878507_12" modelIndex="5868" path="C:/Users/user/Documents/Fritzing/parts/user/Keyes_Rotary_Decoder_Switch_5812070981c131c2523c4b742f878507_12.fzp">
            <views/>
        </instance>
        <instance moduleIdRef="LCD 2004A 20x4 IIC_189cbb099f50a650d8ed5245f2d61f6d_8" modelIndex="5913" path="C:/Users/user/Documents/Fritzing/parts/user/LCD 2004A 20x4 IIC_189cbb099f50a650d8ed5245f2d61f6d_8.fzp">
            <views/>
        </instance>
        <instance moduleIdRef="MH-Real-Time-Clock-Module-2_DS1302_842a2ca78fa9e77c46110042b1521fc8_7" modelIndex="85411603" path="C:/Users/user/Documents/Fritzing/parts/user/MH-Real-Time-Clock-Module-2_DS1302_842a2ca78fa9e77c46110042b1521fc8_7.fzp">
            <views/>
        </instance>
    </instances>
</module>


注意看可以看出個端倪,就是描述這個元件庫的名稱<title>與這個庫裡面有哪些元件<instances>,每個元件<instance>裡面又描述編號moduleIdRef、索引modelIndex、元件描述檔路徑path。


什麼是fzp
    Fritzing parts 的縮寫,元件描述檔案,內容也是XML格式,大概的樣式如下

<?xml version='1.0' encoding='UTF-8'?>
<module referenceFile="mystery_part_sip_3_100mil.fzp" moduleId="Keyes_Rotary_Decoder_Switch_5812070981c131c2523c4b742f878507_12">
 <version>4</version>
 <author>wildox</author>
 <title>Rotary Decoder with switch</title>
 <label>Rotary Decoder with switch</label>
 <date>週日 十月 8 2017</date>
 <tags>
  <tag>mystery part</tag>
  <tag>fritzing core</tag>
 </tags>
 <properties>
  <property name="variant">v1</property>
  <property name="family">My parts</property>
  <property name="pin spacing">100mil</property>
  <property name="hole size"></property>
  <property name="pins">5</property>
  <property name="layout">Single Row</property>
  <property name="layer"></property>
  <property name="chip label">keyes</property>
  <property name="package">THT</property>
  <property name="part number"></property>
  <property name="editable pin labels">false</property>
 </properties>
 <taxonomy>part.mystery.magical.3.pins</taxonomy>
 <description>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
p, li { white-space: pre-wrap; }
&lt;/style>&lt;/head>&lt;body style=" font-family:'PMingLiU'; font-size:9pt; font-weight:400; font-style:normal;">
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">This Rotary decoder using pullup resistor and with a switch at push down button&lt;/p>&lt;/body>&lt;/html></description>
 <views>
  <iconView>
   <layers image="icon/Keyes_Rotary_Decoder_Switch_842a2ca78fa9e77c46110042b1521fc8_1_icon.svg">
    <layer layerId="icon"/>
   </layers>
  </iconView>
  <breadboardView>
   <layers image="breadboard/Keyes_Rotary_Decoder_Switch_842a2ca78fa9e77c46110042b1521fc8_1_breadboard.svg">
    <layer layerId="breadboard"/>
   </layers>
  </breadboardView>
  <schematicView>
   <layers image="schematic/Keyes_Rotary_Decoder_Switch_842a2ca78fa9e77c46110042b1521fc8_1_schematic.svg">
    <layer layerId="schematic"/>
   </layers>
  </schematicView>
  <pcbView>
   <layers image="pcb/Keyes_Rotary_Decoder_Switch_842a2ca78fa9e77c46110042b1521fc8_1_pcb.svg">
    <layer layerId="silkscreen"/>
    <layer layerId="copper0"/>
    <layer layerId="copper1"/>
   </layers>
  </pcbView>
 </views>
 <connectors>
  <connector name="CLK" type="male" id="connector0">
   <description>Clock</description>
   <views>
    <breadboardView>
     <p terminalId="connector0terminal" layer="breadboard" svgId="connector0pin"/>
    </breadboardView>
    <schematicView>
     <p terminalId="connector0terminal" layer="schematic" svgId="connector0pin"/>
    </schematicView>
    <pcbView>
     <p layer="copper0" svgId="connector0pin"/>
     <p layer="copper1" svgId="connector0pin"/>
    </pcbView>
   </views>
  </connector>
  <connector name="DAT" type="male" id="connector1">
   <description>Data</description>
   <views>
    <breadboardView>
     <p terminalId="connector1terminal" layer="breadboard" svgId="connector1pin"/>
    </breadboardView>
    <schematicView>
     <p terminalId="connector1terminal" layer="schematic" svgId="connector1pin"/>
    </schematicView>
    <pcbView>
     <p layer="copper0" svgId="connector1pin"/>
     <p layer="copper1" svgId="connector1pin"/>
    </pcbView>
   </views>
  </connector>
  <connector name="SW" type="male" id="connector2">
   <description>switch</description>
   <views>
    <breadboardView>
     <p terminalId="connector2terminal" layer="breadboard" svgId="connector2pin"/>
    </breadboardView>
    <schematicView>
     <p terminalId="connector2terminal" layer="schematic" svgId="connector2pin"/>
    </schematicView>
    <pcbView>
     <p layer="copper0" svgId="connector2pin"/>
     <p layer="copper1" svgId="connector2pin"/>
    </pcbView>
   </views>
  </connector>
  <connector name="+" type="male" id="connector4">
   <description>Vcc</description>
   <views>
    <breadboardView>
     <p layer="breadboard" svgId="connector4pin"/>
    </breadboardView>
    <schematicView>
     <p layer="schematic" svgId="connector4pin"/>
    </schematicView>
    <pcbView>
     <p layer="copper0" svgId="connector4pin"/>
     <p layer="copper1" svgId="connector4pin"/>
    </pcbView>
   </views>
  </connector>
  <connector name="GND" type="male" id="connector5">
   <description>GND</description>
   <views>
    <breadboardView>
     <p layer="breadboard" svgId="connector5pin"/>
    </breadboardView>
    <schematicView>
     <p layer="schematic" svgId="connector5pin"/>
    </schematicView>
    <pcbView>
     <p layer="copper0" svgId="connector5pin"/>
     <p layer="copper1" svgId="connector5pin"/>
    </pcbView>
   </views>
  </connector>
 </connectors>
</module>


這個內容比較複雜,簡單說幾個地方:
<properties>放置這個元件的主要特性描述
<iconView>底下 layers image 放置 icon 圖檔的檔案位置
<breadboardView>底下 layers image 放置 breadboard 圖檔的檔案位置
<schematicView>底下 layers image 放置 schematic 圖檔的檔案位置
<pcbView>底下 layers image 放置 pcb 圖檔的檔案位置

※注意上面的檔案路徑是相對路徑,而fzb是絕對路徑

另外<connectors>這一大段是在描述每個連接點<connector>在 breadboard、schematic、pcb 這些圖上面的位置,而這些位置一般都是對應到SVG檔案裏面的某個元素ID,所以當你在設計SVG的時候,有正確使用 Fritzing 官方網站的建議設計方式,可以在你設計新元件時載入圖片後,編輯器就會自動對應上該圖片上的連接點喔。




留言

這個網誌中的熱門文章

【研究】列印的條碼為什麼很難刷(掃描)

C# 使用 Process.Start 執行外部程式

統一發票列印小程式