Showing posts with label KiCAD. Show all posts
Showing posts with label KiCAD. Show all posts

Sunday, October 4, 2020

Desktop Software API's in Python (KiCAD, FreeCAD, Blender, QGIS)

Python wraps around everything

For the last couple of years I have mostly written Satellite Data Processing code in Python and plenty of Flask/Django web services. However Python is also an excellent automation tool for GUI based applications allowing custom plugins to be written and functionality provided out of the box extended by users.

The first desktop application I seriously looked at Python plugins for was QGIS. It was early days of learning how to wrap C++ code using SWIG/SIP etc. In the old mailing list you can find a much younger me making inane comments about mixing wrapper metaphors in QGIS with SWIG + SIP. We have come a long way since then and SIP based bindings are the mainstay of QGIS plugins.

QGIS

QGIS has so many Python plugins that they need a registry of their own. Occasionally QGIS Python gets twisted around itself due to multiple Pythons in the user enviroment. You can also flip the python API around and instead of building a plugin you can turn QGIS into a custom desktop application. Which is what I have done with my basic Airport Viewer demo.

QGIS being a fairly extensive and complex C++ application which takes hours to compile, being able to make small quick changes in python is invaluable.

KiCAD

At the time of writing KiCAD has an extensive Python API for processing the automating the PCB layout part of the workflow and this has lead to many innovations in automating traditionally laborious hand layout or even performing complex simulations / optimization to set trace lengths. For example Josh Johnson has one for laying parts out in a circle and Greg Davill has several for length matching and rendering file generation. My personal favourite among the KiCAD scripts is the one for generation of Interactive BOM.

I am really looking forward to Python script support in the Schematic Editor. Meanwhile programmatic Schematic generation tools like Skidl provide schematic oriented Python fun.

The rendering of the PCB's is often done in Blender. Which has its own set of Python nicities.

Blender

My first foray in creating a Blender API based application was during the Kinect USB protocol hacking days. The data stream had just been decoded and I wanted an easy pipeline to a commonly installed / open-source 3D display software. The Python API is mature enough for people these days to quickly put together motion capture plugins for Blender. This plugin however demonstrates the challenges for creating native plugins for blender, the .pyd files for Python have to be recreated for different versions of Blender for ABI compaitibility.

Getting the binaries working has had me thrashing about and posting in forums, then sticking to a working Blender build with Python 2.7 for about 5 years since I did not want to touch it and break it. My integration actually reversed the embedding process, i.e. instead of using additional modules in the Blender embedded python I embedded Blender in a 3D GIS automation.

Native plugin weirdness aside, Blender Python API is a really powerful tool for creating procedural objects from waves / fluid simulation to astrophysics with amuse.

FreeCAD

FreeCAD is sort of the third part of my physical electrical / mechnical design triumvirate. I occasionally design parts for KiCAD in FreeCAD, or bring multiple boards together to test enclosure fit. FreeCAD also has an extensive python library which is leveraged by KiCAD part library maintainers to parametrically generate parts.

The scripting in FreeCAD can be used much like the PCB layout scripts in KiCAD to create this with circular symmetry, like ball bearings which are difficult and repetitive to do by hand.

Final words

There are lots of other pieces of desktop software I have used that have started shipping with Python API's to address the never ending demand from users to easily automate repeated tasks. The live process for making this blogpost in somewhat recursive fashion can be found here.

I have even made videos withs a proprietary one, I will live that here for anyone interested in my attempts at a voiceover.

Saturday, June 22, 2019

KiCon 2019 - Chicago in a weekend

Getting away from a fast paced start-up to attend conferences is a hard ask. However I managed to get away for a few days to attend the inaugural KiCad conference in Chicago a few weeks ago.
The pace has been such that only after about a month I am getting a chance to write it all up. The first night I managed to attend the Hardware Happy Hour at the Ballast Point. I got to see some amazing stuff including pneumatics for an autoplaying piano using layers of PCB.
The huge selection of beers and the chicago dogs were definitely unexpected bonuses.
Tour of MHub assembly area with pick and place machine and large Molex sign. Also got to see Chris Gammell's desk and pick up some Amazon and Mouser shopping to bring back to Nairobi.
I could definitely use the pick-n-place machine in my house and I hope Chris makes use of it whenever he can.
I also got to speak to some companies I have worked with remotely but not met the principles and representatives in person, including CrowdSupply, Aisler, SnapEDA, Hologram and of course DigiKey. It was great to speak to the KiCAD dev team as well, perhaps I can contribute on the MSVC windows native build. I also managed to score credits freebies from all the sources.
Here are pure notes to self on various topics that I picked up on 2-days of super varied and dense conferencing. Some are commands I would like to run some, are techniques I learnt and some are pure stories I picked up.

Schematics are a drug, use code instead

  • pip install skidl

Auto-routers are evil but useful

  • Triangles (Topological/ Using TIN mesh)
  • Maze solving
  • Shape based ( Rectangles)
  • Channel Based
  • FreeRouting
  • Adaptive heuristics using deep learning
  • Linear increase in PCB complexity

High-frequency simulation (in GhZ range) for PCB's

  • OpenEMS ( MEEP)
  • Wilkinson filter
  • Important in Radar Design

Prototyping in a few hours

  • Isolation milling
  • Midwest Circuit Technologies
  • Bantam tools. Binary save.
  • 1/32" end mill 0.8mm tool
  • 10 mill trace

Rendering photorealistic PCB's

  • Render layers to image texture
  • Use Blender cycles based render with bump maps for silk-screen and traces

Contributing to KiCAD

  • Development in LaunchPad + Github
  • Starter bugs are available

More HF PCB's

  • 30MHz to 3Ghz, with narrow bins
  • 5.6GSPS digitizer
  • Tuned lines. Right angles create problems.
  • Use footprint, Arc or Trace around edge cuts.
I woke up pretty early on Saturday morning and walked around and almost hopped on a fire-engine tour. Always wanted to do that. Then I checked the radar, another thing missing in Nairobi, and a huge snowstorm was inbound. Snowstorms at this time in Chicago are atypical, but hey everyone stays in for the coference. By the time the conference finished and I headed home from the after-party everything was covered in snow.
The last day (Sunday) was spent taking an Uber Pool , a novelty for me, to a Vietnamese grocery and spending around 2 hours getting additional exotic food-supplies to bring back to Nairobi
I saw a Harvey milk tail fin and took to the skies back to hop across the Atlantic and Mediterrnean to Nairobi. Flying 40 hrs to conference for 48 hours and shop for 6 is a real pain. Will have to bring the KiCAD movement back home to Nairobi and pour more effort into the local hardware scene.
So long Chicago, see you next conference.

Saturday, March 18, 2017

Piezo Activated Drumlights - The PCB

I feel like once you have learnt one software tool in a particular domain to an intermediate level, you can pick up another in the same domain without much fuss. Only if you are too new or too entrenched with a tool do you feel the sunk-cost fallacy and have a higher barrier to switching to something new when circumstances change.

Nightly build I am currently using
I started my adventures in ECAD using Eagle and built up quite a bit of familiarity with it, I would like to say to an intermediate to advanced level. I also built up some assets i.e. libraries and projects. To unlock more features I spent a few hundred dollars on the maker edition. However as with all software, there were niggling bugs and gripes. One of them was lack of proper 3D support, another was lack of proper slots when exporting gerbers, well slots/mills that hackvana would accept. On the hackvana IRC channel KiCAD was mentioned often and I was encouraged to switch to it. The final straw was the acquisition of Eagle by Autodesk and subsequent switch to subscription based pricing.

Eeschema of Arduino Nano drumlights
So finally after much dithering, I decided to switch to KiCAD as my main ECAD tool in the beginning of February 2017. It has been a fun couple of month translating my Eagle knowledge to KiCAD and dealing with the vagaries of a rapidly evolving tool. So far I am loving it. The first PCB I designed using KiCAD was an Arduino Nano Shield using the template provided to work with my Drumlights project. I took the PCB design as an opportunity to add a battery charger and piezo charge amplifier using a TLV2771 opamp.

KiCost in action as a BOM tool
One of the Eagle features I miss is the forward-back annotation between the PCB and the schematic. In KiCAD the association between a schematic symbol and associated footprint and nets is done using a third tool. This way there is no need for duplicate footprints per device for commonly used pad patterns e.g. SOT-23 or TSSOP-16. All devices using this footprint can share a common PCB element and only differ in schematic element. However this also means that changes in the PCB and are not automatically propagated back to the schematic. The backward link will be coming soon according to a recent roadmap. So I am living nightly-to-nightly in anticipation.

PCBNew view of Arduino Nano Drumlights
The other feature I like about KiCAD is the seamless 3D support, especially in the recent builds.There is dual support for usual VRML for pretty rendering and associated STEP files for export to other CAD files particularly FreeCAD. I downloaded step files for parts not already in the library from Molex, JST of GrabCAD and populated them with some scaling and rotation onto the PCB. You can see the resulting internal KiCAD render below. Next came sending the boards to Fab, a lot of hackerfriendly fabs directly support Eagle .brd files, now there is increasing support for KiCAD as well.

KiCAD Ray trace render of Drumlights PCB
Oshpark can directly process KiCAD - kicad_pcb files to associated gerbers and board orders. This reduces the number of clicks to ordering a prototype and eliminates potential errors and filenaming issues when creating Gerbers, since KiCAD does not really have detailed DRC and CAM job settings like Eagle.
.kicad_pcb file directly imported in Oshpark
One of the valuable lessons I learnt which I have had issues with Eagle in the past as well (obviously I trusted community review of KiCAD libraries too much) was to always double check library footprints against the datasheet. The N-channel Mosfet schematic symbol was meant for a through hole part and when paired with a SOT-23 footprint things were not in the right place. So when testing I ended up with turned on mosfets being fed with 3.3V from the microcontroller from drain-to-source essentially shorting the output. Luckily no magic smoke escaped before I spotted it and pulled the power. You can see the picture here of my hack to salvage the erroneous PCB's using the SOT-23 at 45degrees. I have tested this board with LED strips and it works as expected.

Diagonal mosfets to correct for footprint mix-up
PCBs.io is another cheap option for getting good quality prototype PCB's if you are prepared to wait. However they do not support direct KiCAD upload. If you follow the Oshpark's Gerber generation guide to create gerbers and drill files they should work in PCBs.io as well. This is what I did when ordering my test boards, after a couple of revisions via Oshpark. Overall my experience with KiCAD has been very positive. The community is fun and responsive. There are some great ancillary tools like StepUp mentioned above and KiCost which I used to instantly generate BOM for my board and order all parts from Mouser in minutes.
KiCAD Gerbers rendered in PCBs.io

If you are interested in my KiCAD experience and general principle of piezo activated drumlights you can keep tabs of my hardware and software via github.