{"id":11931,"date":"2020-01-25T23:46:28","date_gmt":"2020-01-25T23:46:28","guid":{"rendered":"http:\/\/pcbjunkie.net\/?page_id=11931"},"modified":"2020-01-31T13:14:11","modified_gmt":"2020-01-31T13:14:11","slug":"making-ic-pinout-stickers-in-python","status":"publish","type":"page","link":"https:\/\/pcbjunkie.net\/index.php\/guides\/making-ic-pinout-stickers-in-python\/","title":{"rendered":"Making IC Pinout Stickers in Python"},"content":{"rendered":"\n<p>I have to fix a number of my PCBs. Some that are currently broken, I need for my JAMMA adapter project. It&#8217;s been holding things up more that I like.<\/p>\n\n\n\n<p>While I&#8217;ve been working on these I decided to spend a day on creating various stickers for RAM, ROM and CPUs that can be stuck on the chip and will list label each pin for easy probing.<\/p>\n\n\n\n<p>I managed to whip this out quick. I works but maybe an online repository with a number of these that people can use is the way to go. I may consider it when I have some free time.<\/p>\n\n\n\n<p>In the mean time, this code Python code takes in your pin list, the chip size and your printer DPI settings and generates an image of the correct size that can be printed on a label printer.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">from PIL import Image, ImageDraw, ImageFont\nimport os\n\nclass ICPins:\n  def __init__(self, name, pins, package):\n    self.name = name\n    self.pins = pins\n    self.package = package\n    # DIP body widths are .25\" (standard) and .5\" (wide)\n    self.width = .5\n    # DIP leg spacing is .1\"\n    self.pinspacing = .1\n    self.padx = 5\n    self.pady = 5\n    self.dpi = 300\n    self.fontsize = 12\n\n \n  def to_img(self):\n    filename = self.name + \".png\" \n    # calculate sizes based on input and DPI\n    y = self.pady\n    x = self.padx\n    if (self.package == \"DIP\"):\n        pinspacing = int(self.pinspacing * self.dpi)\n        width = int(self.width * self.dpi)\n        #fontsize = int(self.pinspacing * 72) - 1\n        fontsize = self.fontsize\n        sizex = width + (self.padx * 2)\n        sizey = int((len(self.pins) * pinspacing) \/\/ 2 + self.pady * 2)\n        fnt = ImageFont.truetype('arial.ttf', fontsize)\n        print(sizex, sizey, pinspacing, fontsize, fnt.getsize('A')[0], fnt.getsize('A')[1])\n\n        # create image\n        image = Image.new(mode = \"RGB\", size = (sizex, sizey), color = \"white\")\n        draw = ImageDraw.Draw(image)\n\n        # draw pins\n        leftpins = self.pins[:len(self.pins)\/\/2]\n        rightpins = self.pins[len(self.pins)\/\/2:]\n        for pin in leftpins:\n            draw.text((x,y), pin, font=fnt, fill=(0,0,0))\n            y = y + pinspacing\n        x = x + width\n        y = y - pinspacing\n        for pin in rightpins:\n            w, h = fnt.getsize(pin)\n            draw.text((x - w - self.padx, y), pin, font=fnt, fill=(0,0,0))\n            y = y - pinspacing\n\n        shape = [(0, 0), (sizex - 1, sizey - 1)] \n        draw.rectangle(shape, outline = \"black\") \n   \n    # save file\n    image.save(filename)\n    # show file\n    os.system(filename)\n\npins = [\"A11\", \"A12\", \"A13\", \"A14\", \"A15\", \"CLK\", \"D4\", \"D3\", \"D5\", \"D6\", \"VCC\", \"D2\", \"D7\", \"D0\", \"D1\", \"\/INT\", \"\/NMI\", \"\/HALT\", \"\/MREQ\", \"\/IRQ\", \"\/RD\", \"\/WR\", \"\/BUSACK\", \"\/WAIT\", \"\/BUSRQ\", \"\/RST\", \"\/M1\", \"\/REFSH\", \"GD\", \"A0\", \"A1\", \"A2\", \"A3\", \"A4\", \"A5\", \"A6\", \"A7\", \"A8\", \"A9\", \"A10\"]\nic = ICPins(\"Z80\", pins, \"DIP\")\nic.to_img()<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Here&#8217;s an image that was generated from the above Z80 definition.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"160\" height=\"610\" src=\"https:\/\/pcbjunkie.net\/wp-content\/uploads\/2020\/01\/Z80.png\" alt=\"\" class=\"wp-image-11932\" srcset=\"https:\/\/pcbjunkie.net\/wp-content\/uploads\/2020\/01\/Z80.png 160w, https:\/\/pcbjunkie.net\/wp-content\/uploads\/2020\/01\/Z80-79x300.png 79w\" sizes=\"auto, (max-width: 160px) 100vw, 160px\" \/><\/figure>\n\n\n\n<p>I hope this can come in handy to someone. If you would like to see this as a web tool, let me know and I can probably make this a repository of pinouts for the common ICs and maybe even allow you to add and create your own stickers.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have to fix a number of my PCBs. Some that are currently broken, I need for my JAMMA adapter project. It&#8217;s been holding things up more that I like. While I&#8217;ve been working on these I decided to spend a day on creating various stickers for RAM, ROM and CPUs that can be stuck &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/pcbjunkie.net\/index.php\/guides\/making-ic-pinout-stickers-in-python\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Making IC Pinout Stickers in Python&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":360,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-11931","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/pcbjunkie.net\/index.php\/wp-json\/wp\/v2\/pages\/11931","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pcbjunkie.net\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/pcbjunkie.net\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/pcbjunkie.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pcbjunkie.net\/index.php\/wp-json\/wp\/v2\/comments?post=11931"}],"version-history":[{"count":5,"href":"https:\/\/pcbjunkie.net\/index.php\/wp-json\/wp\/v2\/pages\/11931\/revisions"}],"predecessor-version":[{"id":13492,"href":"https:\/\/pcbjunkie.net\/index.php\/wp-json\/wp\/v2\/pages\/11931\/revisions\/13492"}],"up":[{"embeddable":true,"href":"https:\/\/pcbjunkie.net\/index.php\/wp-json\/wp\/v2\/pages\/360"}],"wp:attachment":[{"href":"https:\/\/pcbjunkie.net\/index.php\/wp-json\/wp\/v2\/media?parent=11931"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}