Posted on Leave a comment

Python and AutoHotKeys Scripts – The Old Job

At my previous job, I declared war on all possible boring processes and automated them as much as I could. Anytime I was caught up, I immediately started coding away our problems. Here are a few.

Text Macros
I noticed I was repeating the same sentence 5 times a day. I used AutoHotKeys so I could paste the sentence with a shortcut. That eventually expanded to about 30 different automated text Macros.

Drill File Correction
Our NC drill files from Gerbers had damaged headers when exporting from our Gerber editor software (Fab3000). I wrote a Python script to correct those headers and used AutoHotKeys to run the Python script instantly.

AutoHotKeys GUI
I had to create a GUI in AutoHotKeys to run our macros since no one could remember them all.

EBOM Analyzer
We ran into a problem where our system required the manufacturer name to be 100% identical to the manufacturer name in our parts database or it took about a minute of work to correct it per MPN. Bla! I created a spreadsheet of “good” manufacturer names. I used Right Click > Send To in Windows to run my Python script that compared the manufacturer names to my “good” manufacturer names spreadsheet. This one script paid for itself 10,000x.

Over time, we found dozens of features to add to the EBOM Analyzer.

  • Certain keywords in the parts description indicating additional labor was required ( “screw”, “conformal coating”, etc. ). Finding these keywords saved the company a tremendous number of problems.
  • Reference designators were sometimes duplicated. This can’t happen, but it did. The EBOM Analyzer would catch that before it was too late.
  • Sometimes reference designators weren’t compatible with our platform. Example. ( ref des C1-3. Does that mean that ref C1, C2, and C3 are required or does it mean that the reference designator is literally “C1-3”? We had to catch that and address it. The EBOM Analyzer made that easy.

Platform Analyzer
Once I gained access to our platform API, I was able to apply the same types of checks used in the EBOM Analyzer to the platform itself.

  • Is the stackup of the PCB symmetrical? If not, it’ll probably warp. We checked for that.
  • Are there overhanging parts but all 4 sides are v-score? This script checked for that.

The script checked for over 50 things. It was incredible how much time was saved with this script. The number of things that can go wrong on a PCB is truly staggering and this helped catch a ton of them.

Altium Placement To XYRS Conversion
We frequently received placement data from Altium in .txt format. Altium’s placement data is extremely consistent in terms of formatting. It was very easy to identify a placement data file from Altium. Using a single shortcut key, we could convert the Altium placement data to the spreadsheet our system required instantly. A huge time saver!

Enterprise Level? Sharing With My Team
Not quite! When my team expanded from me to 4 of me, I had to adapt all scripts to work on more than just my computer. I started using Github. I created config files so that my team could set the Macros they wanted, use their own API keys, etc.

I learned that Mexico Microsoft Windows has quirks that US Microsoft Windows does not have, particularly with the timing of pasting text using AutoHotKeys. I learned that Microsoft Windows in Missouri has quirks that Windows in Atlanta doesn’t have. I was able to work out these bugs within AutoHotKeys and Python, but working on software for a variety of individuals was a whole new set of problems.

Auto Sorting PCB Files
Part of the job was sorting a customer’s incoming Gerbers, drills, ODB++, EBOM, fab drawing, assembly drawing, nonsense, family photos, napkin drawings, and 50-page lawyer agreements into folders we could make use of. We had to create a folder for the original files and we needed a folder for the edited versions that were cleaned up for our system. It was mind-numbing creating so many folders.

I tried a method were I created the folder structure on my desktop and then just copy and pasted it to the folder of interest. It became confusing. The empty folders seemed to indicate a file was missing. (Missing files can’t happen.) So I scrapped that approach.

I wrote a script where I could use Right Click > Send To and it would create the necessary folder, move the file there, and then create the second folder for edits and make a copy of the file there with a new naming scheme. This saved what feels like decades of pain.

EBOM Spreadsheet – to Spreadsheet Conversion
Someone decided that additional information needed for Row 1 of a spreadsheet would look nicer on Row 2. This violates every law of computer science, basic Microsoft Excel usage, and common decency. Each row is a supposed to be a unique entity and all the information for that row should on that row. Sometimes, Rows 2 through 10 added information to Row 1. It was just madness.

If we had a spreadsheet BOM with 100 unique MPNs, we’d need to manually copy and paste the additional information in Row 2 through Row 10 to the actual row it belonged on. The most common example of this was alternate MPNs.

Manual copy and pasting is time-consuming and dangerous. Humans make mistakes, particularly with mindless, repetitive actions.

I wrote a script that would move the alternates on the “extra” rows up to the row they actually belonged to. This was dangerous. I added numerous fail-safes to be sure that a row wasn’t accidentally moved up to the next row. The row had to be 100% blank except for the information moving up. The same # of blank columns had to exist on every “bad” row before being moved up, etc. This one took real thought.

In the end, I figure this script saved us a few hundred hours of tedious, unpleasant manual work and who knows how many RMAs were avoided.

Auto Creation of Fab3000 Files
Originally, our system often required us to download Gerbers from our platform, make edits, inspection, corrections, and DRC in Fab3000 and then upload the new versions to our platform. This required assigning every Gerber layer (although Fab3000 got better at detecting these….not perfect…but better) but I could not stand setting the blind and buried via settings. It was tedious and nasty….and we already had the information in our platform.

So I went to work generating a script that downloaded all Gerbers and drills along with their specific settings for all blind and buried vias and embedded that into a file that Fab3000 could open. No configuration needed. This saved hours and hours of time and pain over the years.

Posted on Leave a comment

Idiot Christmas Light Controller

There are 3 types of people at Christmas time. People that put up:

  • A reasonable amount of Christmas lights
  • No Christmas Lights at all
  • An ungodly horrendous amount of Christmas lights.

I’m the third type.

I decided the world needed a box with 8 outlets that could be controlled from a master in my house. I wanted the ability to dim the lights, blink the lights, control the lights with DMX down the road ( never did that one ), but ultimately decided all I really needed was to blink them in the most chaotic way possible. Random was good as long as half the lights were on at any given time. Completely random blinking meant that half the lights were off about half the time. About 25% of the time only 25% of the lights were on. I didn’t like that.

Oh, and I made 8 boxes. So that’s 64 outlets total.

Too keep the current consumption reasonable, I decided that not only was 4 outlets the minimum number outlets, it’s the perfect amount of lights that should be on. It’s totally random which 4 outlets are on for each box, but it is only four.

Running power all over the yard was made simpler by allowing 110VAC input and output on every box.

This project consisted of:

  • A TRIAC power board x8
  • A Receiver board x8
  • 3D printed customer enclosure x8
  • A control board

ESP32

My weapon of choice whenever wireless or wi-fi is being used is the ESP32. I have many of the cheapo Ali Express Dev boards, but I spun my own boards for this one. Wireless range was a concern, but the ESP-NOW library allowed me to build up a mesh network so that each ESP32 board could talk to the other one. The library does all the heavy lifting, but range has been no problem at all even though my control board is down in a basement.

TRIAC Board

TRIAC Board

I guess you can call this a mixed signal board. It’s not EXACTLY a digital signal, but there is some 110VAC power here….at least by my standards. Each outlet is rated for 1A (20 strands of lights), but I’ve never came close to that number. The board itself is rated at 4A total, but I need to check my old notes to see how I came up with that.

The bottom pick is missing the slots where the Christmas Lights plug into. It makes much more sense with that correction. I took a chance on this approach. This 3D model does not show the enclosure the outlets must slip through before soldering. Luckily, this approach has been bulletproof for 5 years and allowed me to avoid wires. Life doesn’t get much better than avoiding wires.

Receiver Board

This receiver board is super simple. +5V input. The ESP32 talks to the Sender via ESP-NOW (more or less wi-fi, kinda). It talks to the TRIAC board via the IDC connector. I originally designed this using a press fit connector instead of the IDC connector. Lesson learned. See “Mistake” below.

Mistakes

Press Fit Connectors Without Serious Jig = Bla!

I experimented with a ribbon connector to mate the TRIAC board with the receiver board within each box. I found some new connectors where you just smash the ribbon with these jaws-of-life teeth. These are probably great if you have a jig to correctly smash them. (I later learned all about press fit connectors at work.) My “jig” was completely inadequate and some of the connections were bad. I lost one or two outlets on each box right away and had to redo the press fit process over and over to get it right. Even then, the connection was unrliable.

I could have used standard 2×5 IDC 2.54mm cables. I always have dozens on hand. I guess my need to experiment bit me that time.

The press fit style connector can not be taken off and this made troubleshooting difficult at times. Lesson learned.

If I redesigned this, I’d use a board-to-board connector…probably just standard 2.54mm headers.

Strengths

PETG Works Great For Enclosures!

PETG enclosures have been very durable. I left 2 of these boxes outside. They are covered to keep the rain out, but nothing else. In a bad storm, they’ll get wet. They’ve been outside since October 2021. They still work very well.

Modern LED Christmas Lights Use Little Power

I’m not sure I believe it, but a 25ft strand of the LED Christmas Lights I purchased only consumes 50mA….and they are really too bright. I’ve considered knocking the brightness down in the code by shortening the TRIAC “duty cycle”. I don’t that’s the term when dealing with TRIACS but this project was 5 years ago and it is the term for PWM and the concept is mostly the same.

Enclosure Ventilation Is Good

Everyone says that water and electronics don’t mix. That’s super true if you’ve got an electrolyte in your water. What they don’t tell you is humidity is everywhere ( not a shock ) and no matter how well you seal up your enclosure, water vapor is getting in. In December in Missouri the temperatures will get down to 0F sometimes and as high as 70F with a typical temperature at any given time being around 32F. That’s a recipe for condensation.

So even if you think you completely sealed your enclosure, water vapor is getting in and that moisture is going to experience condensation. Then you have water….not jus t the vapor in your enclosure. If you think you sealed the water out, you’ve now just sealed the water in. OUCH! That part isn’t intuitive.

I took ventilation seriously and it’s paid off tremendously.

Posted on Leave a comment

YM3812 Synthesizer

Believe it or not this is a fully functional music synthesizer with fully every possible parameter tweakable and can save presets. The synth sound horrible, but that was by design.

The YM3812 chip is from an old Soundblaster card from back in the Reagan days. This thing sounds like bad dog stuff. It’s so bad it’s fun. I fell in love with this little SPI chip. Designing a full blown synthesizer with hardware interface ended up being a fairly atrocious amount of work, but I was graduated and unemployed. The intention was to take what started out as an Arduino project and move into a legit project.

I ran into problems with this one on the mechanical side. I needed a way for buttons to feel “good” and I needed a user interface that felt sturdy….like I could throw it down the stairs and it not break. Of all theory of magnetic fields and high speed signal propagation I have studied, I had no background in making a product tough. So this is a fully functional synthesizer that worked in prototype mode, but by the time of V2 I was bogged down by the mechanical end and working a full time job. Eventually, it was out of sight and out of mind. I would love to go back now and slaughter this one.

Microcontroller: STM32 Blue Pill

I was really into these STM32 Blue Pills in 2020. They provided tons of bang for the buck, got me into Cortex M3 32-bit land, and were a big step up from the Atmega328p microcontrollers in the Arduino clones I had laying around. The price was basically the same. I ended up ditching the Cortex M3 because when it came time to design PCBs without modules, the MPN: STM32F103C8T6 was very expensive and had a lead time of a billion years due to the supply chain nasties that didn’t really go away until 2023 or so.

2020 = Mechanically Awful!

When I got my job at Macrofab as a “circuit board analyzer”, I had not studied many products for how to “do it”. I was coming from 4 years of aggressive Arduino hobbyist work followed by 4 years of hell in school and trying to put it all together. You can see that here. I just used a 3/4″ wooden box with butt joints as my “enclosure”. It’s one way to do it, but it’s a dumb way.

You can see from this rear view how much empty space I was working with. Granted, for this phase of the prototype it didn’t matter. I was experimenting with board-to-board connections using 2.54mm which was definitely the right track.

Looking at the front with the pretty cover removed, you could see I had 2 PCBs for the switches. This strikes me as expensive at the moment, but I say that about air, too. These front panel PCBs contained the switches but also contained the LEDs that were used to indicate the level/intensity/setting of every possible parameter on the synths.

It makes more sense if you look at what I had planned for the front panel. This would have been a 3U rack, if I remember correctly. My gut says this is a $1,000 product when I look at it. I had temptations to do all of this GUI stuff on a $70 tablet and call it a day. Talk to the main microcontroller through UART / bluetooth / wifi / whatever. That approach would have been radically cheaper.

Below is the money shot.

On the far left breadboards you can see old-school MIDI inputs. Just to the right of that is the actual YM3812 audio circuit. I’m trying to remember if I had 2 of these. I believe I did so that I could have more voices. You could argue the point using a primitive junk 80’s chip is to be limited, but my brain doesn’t work that way. I wanted the brain to be awesome. With more voices, I could detune one chip slightly and that allows for all kinds of big, nasty sounds one may hear in supersaw dance land.

Below the 2 YM2812 synth boards is an encoder PCB. It has 4 encoders but I was only using one or two of them. I had built that as a development tool back in the day and got plenty of use out of it on the breadboard.

To the right you can see the PCBs with 16 switches each. These, too, were prototype tools I developed. I need to look up the chip. I used a SPI expander so that I could have a ton of buttons with only only the CS, MOSI, MISO traces.

To the left of that was the TM1640 LED drivers. I need to look up how I drove these LEDs. Now I don’t remember and I’d like to pick my brain. I may have put real thought into this and came up with an interesting solution. I bet I came up with a matrix array thing. I’m not sure how I’d have enough IO otherwise.

On the far right, you can see the blue LEDs that were used to indicate level.

Posted on Leave a comment

Big Girl Audio – Audio Power Amplifier

I became intrigued with the 200W+ audio amplifiers on Amazon for $80 or so on Amazon. I did a little digging and found that some were based on a TI TPA3255 chip. I picked up a few MPN: TPA3255DDV and went to town. I basically lifted this schematic directly from the datasheet so it wasn’t like I had to get super creative, but it was fun dealing with power levels that I’m not used to.

This one worked on the first try, so you know something went very wrong. The difference is this time I don’t know what it was. Maybe that’s the definition of success.

Posted on Leave a comment

POWER INVERTER IN DQ REFERENCE FRAME

The task: Take a DC boost converter controlled with with a PID loop. Input a 60Hz sine wave as the setpoint. This creates a 60Hz sine wave with a DC offset. Make another identical DC boost converter and slam them together across a resistive load. (See schematic). The end result is the DC voltage is cancelled out and the AC voltage is multiplied by 2.

I don’t like talking about this one. I was sprinting full speed for months. The goal: Get my electronics project in a peer-reviewed journal before I graduated from engineering school. I was on a mission and it was going to work. I had managed to take a 5V DC signal and crank it up to 41VAC RMS. The goal was 120VAC.

I had problems with a massive inductive spike on startup that confused the heck out of the PID loop to the point that I could never get the thing to start correctly. Damn causal systems! I created a massive capacitor bank to counter the massive inductive spike.

Then that stupid pandemic thing happened in 2020. I lost access to the university’s high end power supply needed to get this bird off the ground. In addition to a full load of senior engineering classes I was now spending 6 hours a day trying to convince a GRUMPY GRUMPY GRUMPY first grader to do his homework with me. (At-home learning works well….WHEN DONE CORRECTLY…but not for the little ones.)

I bought a 48V DC Meanwell PSU like you see for servers and such. I tried getting this to work at home. Working 18 hours a day pre-Pandemic was possible. My role as a father (and now first grade teacher) was not compatible. I chose to be a good dad. It stung. While comedians all over the world were endlessly ranting about their Netflix binges and ping pong table purchases, I was working myself beyond the absolute maximum and it wasn’t enough.