Posted on Leave a comment

Use Python To List All Files In A Directory

I needed a lengthy list of files for a massive 3D printing project I’m starting and I didn’t want to have to copy and paste each file one at a time.  Brandon’s Rule #232:  If you are faced with a 2 minute task that bores the hell out of you, invest 15 minutes into automating it.

Everyone should have Sublime Text installed on their machine and have just enough competence in Python to Google the living crap out of any problem that arises.

This Python code simply lists all the files in the directory containing this file.


from os import listdir
from os.path import isfile, join

mypath = '.'
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]

for x in range(len(onlyfiles)):
print(onlyfiles[x])
Posted on Leave a comment

My Saga With PLCs – Part1

I didn’t learn PLCs in school.  My gig was Engineering Physics and if the homework didn’t use Calculus to think about the atomic level, I didn’t learn it.  Granted, I didn’t learn to use Calculus to think about the atomic level, either, but that’s another rant.  So, I’m learning PLCs.  Here are some thoughts for others entering this domain.

  1. There must be no money in PLCs anymore. (joke)  Allen and Bradley made some truly cutting edge software at the tail end of the Reagan administration and then halted all progress.  This, in and of itself, ain’t a big deal.  The big deal is that 3 decades of progress have radically reduced the time wasted on clunky software.  If you use a modern IDE to program anything, you’ll be frustrated by RSLogix.  If you use Notepad to program anything, you’ll still be frustrated by RSLogix.
  2. The story goes that Ladder Logic was designed to be simple enough for non-programmers to use it.  I’m not a “programmer”, but I’ve done a fair chunk of it.  The need for visualization adds an extra layer to the mix.  Instead of remembering the XIC is “examine if closed”, we also have to remember what the schematic symbol looks like and where we can find it and how to get it into our schematic.  It would have just been much more efficient to type “XIC”.   A GUI needs to hit a critical mass of usefulness in order to displace text-based tools.  The GUI in Notepad++ is pretty straight-forward.  We all know how to manipulate text.  Finding the menu with XOR in it is not so clear.  Hopefully, getting adapted to RSLogix won’t be so bad after I force myself through the blatant inefficiency.
  3. I started down the PLC thing months ago.  It’s taken me months of working here and there to get a working hardware setup.  (4 switches, 4 lights, and connected to the PC.)  I spent nearly a week working on the ethernet connection.  I found an authority online who said, “Absolutely do not use Ethernet! on a MicroLogix PL1100”.  I bit the bullet and bought the $25 Serial cable. It worked immediately.  It’s my understanding that the ethernet on the MicroLogix1100 is of the primitive variety….whatever that means.  If a person has to use ethernet, the recommendation seems to be to use a “crossover cable” ($6 on Ebay) to allow plugging it straight into a computer somehow.
  4. The $25 Serial cable was a total waste of money.  It works, but I have $2 FTDI chips all over the place.  (FTDI converts USB to serial and vice versa for use as COM ports in Windows or equivalent.)  I only needed power and 2 wires.   The MicroLogix PL1100 uses a fairly goofy connector that I don’t have.  So, I basically paid $25 for a connector.  Oh well.
  5. The $25 Serial cable was actually a knockoff from Amazon.  The Allen and Bradley cable is a whopping $50.  To me, this is a $2 board from Ebay.   You see ridiculous pricing all over the place in PLC land.  The most notable example is the PLC Trainer.  They often come with 4 switches and 4 lights and cost $150+.  Since no one with sense is driving 100kW systems while TRAINING, there’s no point for these to be high-power, industrial powerhouses.  Switches rated for 125V on Digikey start at $1 a pop.  The lighting is even more grotesque.  Industrial-grade indicator lights are expensive because they are built like tanks.  As cool as tanks are, you don’t want a tank in your basement.  An LED and a resistor, believe it or not, is capable of acting as a perfectly viable indicator-via-photon tool.  This does lead to opportunity, but I have to admit I get nervous when prices are obscenely inflated and no one seems to question it.  I’m sure questioning it.  Look for an Electron Injection PLC trainer soon.
  6. It seems obvious to me to use an LED and resistor for indicator lights.  They’ve been the absolute standard since they were invented.  The LED is the default tool to use for such a job.  I can’t see how any engineer or technician learning PLCs wouldn’t immediately think to grab a 680 ohm resistor and a red LED out of the cabinet.  A person has to go through a minefield of rationalizations to arrive at the hyper-expensive alternative for the same reason you don’t book a flight in a B2 bomber to go Cancun.
  7. The worst part about learning PLCs this far is the lack of projects.  It’s well understood that the best way to learn Arduino (or anything in life) is to have a big problem you plan to solve with it and jump in.  Let’s say we want a robot that can plant seeds.  When you finish such a project, you end up with a seed planter.  Cool!  The problem with PLCs is they cost about 100x what microcontrollers generally cost.  (Give or take.)  It doesn’t make sense to jump into such “hobbyist” projects with industrial tools.  So what are you supposed to do?  Start your own beer factory in your basement?  (Don’t tempt me!)  Even then, it’s not exactly clear why I’d use a PLC when I could just program a $5 microcontroller.  Maybe that will be revealed down the road.
  8. I learned pretty quickly that the emulator for the Allen and Bradley PLCs was omitting quite a bit of the “PLC Experience”.   Here’s a metaphor.  Your can emulate changing the oil in your car, but it will never drip oil in your face.  There’s some nastiness that needs to be addressed with the real thing that gets lost in the emulators even though I REALLY wanted the emulator to work out.
  9. Get ready for some work.  I decided that I hated the user interface.  Again, this is common when doing anything new.  I was hoping for a shortcut by jumping straight into the code.  WRONG!  Here’s the code for my tiny little “program”.

     BST XIC I:0.0/0 NXB XIC I:0.0/1 BND BST XIC I:0.0/2 NXB XIC I:0.0/3 BND OTE O:0.0/1 

    Look at the end first.  We have an OTE to energize the output at 0.0/1 whenever the rest is true.

    As for the rest, I’ll show you the C version.

    if (   (BIT0  OR BIT1)  AND  (BIT2 OR BIT3)  ) {

           Output  = 1;

    }

    I’m reminded of how lucky I am to have the C language.  This is only an illustration to show that if a person had some hardcore coding to do on a PLC, the GUI is where it’s at.  The code behind PLCs reminds me a bit of Assembly and no one wants to go there. 

Conclusion

My earliest days with PLCs have been less than ideal.  It’s not PLCs fault that I can’t economically use them for stupid, little projects.  That takes most of the fun away.  However, I’ve made myself a list of assignments…..easy stuff like “Push a momentary switch and turn an LED on for 8 seconds”.  By stacking up enough of these little hurdles, I think I can begin to get a feel for this thing.

PLCs are a radically different culture than I’ve experienced with programming microcontrollers or playing with Python or even HTML.  The terminology is different.   They often make things much more complicated than they need to be.  The above C vs PLC code above is a great illustration of that.    They will often say things that are either incorrect or could easily be made to be incorrect.  For example, the whole idea of XIC is “examine if closed”.  In real life, they are asking if an input is at a HIGH level and is so, do something else.    Well, I can create either HIGH or LOW levels with either a closed or open switch using pullup resistors on a microcontroller.   Why do they assume the switch is closed?  It’s okay that they have, but it would have been nice to have this explained to me.  In my mind, reacting to HIGH and LOW conditions is just as simple and not so presumptuous.  There are REALLY good reasons why you may want to utilize active HIGH or active LOW (see the NC vs NO debate with CNC machines limit switches, for example).  This is just one example.  Maybe I’m making it too complicated…..

Making these simple generally makes them more complicated.  PLCs seem to fall into this category over and over for me.  Again, when I finally adapt to Ronald Reagan’s RSLogix, I suspect things will get easier.  The quirks are all over the place.  With that said, if a person was diving into bare metal C on a microcontroller, they would probably see even more quirks.  Too bad.  I’m generally used to those so they don’t count.  (smilie)

Posted on Leave a comment

Trials and Tribulations With Protoneer V3.51 CNC Shield

I recently purchased a Protoneer V3.51 board for my CNC as I wanted to control the speed of my spindle in Fusion 360. My CNC came with a potentiometer which made it impossible to save my speeds and feeds. Speeds and feeds are the name of the game with CNC. There is an ideal amount of scraping you do with your end mills for any given material. Spin too fast and you generate heat. This will burn wood and melt acrylic and even some aluminum. Spin too slowly and you’ll be slamming your end mill into your material at a speed it can’t keep up with. The details as to what the ideal speeds and feeds are elude me currently as I’ve never had any method to set them to a repeatable number. That’s the purpose of this board swap.

My goal was to use Fusion 360 to control the spindle speed. Even if that didn’t work out, I can at least set the PWM % in bCNC and write that number down in my notes. That will achieve the same thing, more or less. I can’t speak for all CNC sofware, but bCNC allows you to set the minimum and maximum speeds of the spindle and adapt the PWM for that. In other words, I can set an RPM of 5000 in bCNC and it will handle the rest. Cool.

It turns out that I didn’t have to buy a new board for this as I have the HQ-LB60-12A spindle controller. I could have easily set up a microcontroller with a DAC to send 0-5V to my spindle controller and it would have figured out the correct PWM. Oh well, this is a problem with under-documented parts……or wrongly-assumed-underdocumented parts. It turned out that I found the documentation after the fact. https://www.mantech.co.za/Datasheets/Products/HQ-LB60-12A-V1-180191_SGT.pdf

So, it was not necessary for me to upgrade from the Protoneer V3 to the V3.51. The PWM functionality was already there.

End Stops
My end stops were not working for either axis. It turns out that the (-) pin for all three flow through a jumper before going to ground. The purpose is to give the user the option of normally high or normally low limit switches.  The reasons for choosing NO or NC switches are beyond the scope of this blog post.   Just keep in mind that the Protoneer V3.51 requires setting the jumper or the return from the switches or they will be floating (not connected to anything).  If the limit switches aren’t connected to anything, they will not work.

Posted on Leave a comment

Is Engineering School A Total Waste of Time and Money?

I graduated with a degree in Engineering Physics from Southeast Missouri State University three weeks ago.  I turned 40 three weeks ago.  My situation is a bit unique.  I’ve been trying to put into words what school is dozens and dozens of times.  This attempt is the only one I’m happy with.  Here goes.

What Is Engineering School?

1) Engineering school speeds by at a pace that only about 10% of students can handle. The odds are you won’t keep up.  I mean that if you scored a 30 on your ACT, you have a 10% of keeping up.   Instead of absorbing knowledge like a sponge, most people cringe, roll themselves up in a ball, and just barely get by until the semester is over. For this group of  90%, learning efficiency is reduced to approximately 10%.  I want to make it clear that it was very rarely that I kept up despite my best efforts.

2) Engineering school is ideally suited for people with a practical background in any given class. If you’ve built circuits before, doing a little calculus on a diode has a bit of value. If you haven’t worked with circuits before, you will be asking, “What the hell is a diode?”. You won’t be ready to stack up pn-junction theory.

The theory stuff doesn’t mean much without the context of holding a diode in your hand and maybe burning a few up.  All the usual who? what? when? where? why? and how? questions pop up when dealing with a new widget.   Engineering school does not answer any of these questions.

The approach I received in pretty much every class goes like this.
1) Here is the math.
2) Here is the procedure for solving for alpha, beta, zeta, etc in the homework problems.

That’s it.

I can’t count the number of times I asked, “What is this?” at the end of class. Professors are sometimes startled by the question. In many cases, the material is so abstract that they have to take a second to switch back to reality to explain it in English.

Having an abstract method for solving for X is a blessing.  It means we can solve for X.  That’s good to know.  Unfortunately, the process is almost always emphasized over actually conveying what X actually is and developing the intuition to use X.

3) I have no background in teaching people, but I know from my own background that if I can’t answer the who? what? when? where? why? and how? questions, I have no clue what is going on.

4) There were a few hands-on classes. I gained rudimentary skills in Python, AutoCAD, and C programming for microcontrollers.  I touched MATLAB a bit.  I think we use Quartus II for programming FPGAs but I can’t remember.  (Not a good sign!)  I learned a bit about electronics, but I had been studying electronics hard for years on my own time.   These are basically the only hands-on skills I can remember learning.

5) The school isn’t serious about a class unless it has a lab.  That’s an idea I’ve played with for some time.   Without a lab, a class is a theory-only. Without application to reality, little appreciable learning takes place. The shelf life for theory is about 3 days in my experience. (Maybe you can remember theory for 3 weeks. You are a rare individual.)  I had very useful labs for Physics 1, Physics 2, digital design, electronic circuits, microcontrollers, Python, and Autocad.  The huge majority of classes were pure theory and I retained very little.  This was mostly the case with upper-level engineering classes.  When starting with physics, we can all imagine a tennis ball accelerating.  We can even imagine an atom.  In the upper-level courses, it’s often very difficult to imagine the topic in the first place and building upon the unimaginable is often futile.

6) A person who is passionate about Python can learn the equivalent of a college Python class in about 2-3 aggressive weekends. This assumes zero programming experience. Continuing with that logic, a passionate person taking a $10 online class can be twice as good at Python as a college engineering student in a month.  This isn’t necessarily a slam on college.  The intent of an undergrad Engineering Physics degree is not to make you a master in Python.  You’d need to major in Python for that to make sense.

7) The complete course of an engineering degree covers a wide, comprehensive base. As #6 states, a person could easily find online classes for $10-$50 per class and surpass the college degree. Because of #1, a student taking the $10 online classes can learn much more than an engineering student at school.  Because of this, there’s no reason to assume that an engineering graduate can outperform a passionate, high school drop out at any given task.

8) A person leaves engineering school knowing very little. If a person were trying to design anything of value solely from what they learned in school, they are in for a very difficult time. With that said, I think it’s fair to say that engineering school does provide a skeleton of rope bridges (like in Indiana Jones).  Having a skeleton of rope is infinitely more valuable than having nothing when encountering X new challenge.  The passionate Python programmer may run into trouble with kinematic models.  I’ve not done inverse kinematics yet – robot motion – but from the videos I’ve watched, it appears I’ve done them 10,000 times.  It appears to be trig calculated a few thousand times a second.  Yup, I’ve definitely done that 10,000 times.

9) Engineering school is mostly about handling extreme workloads, tight deadlines, and high stress.  You can’t get that from a $10 online class.   I’m not sure why you’d want to.   They aren’t trying to make you a master at anything. The rope bridges they are building in #8 could easily be achieved using Google and free stuff. This is particularly so if you factor in #1 that most students will only retain 10% if they are lucky. You won’t leave engineering school a badass.  The question is why don’t people look at the curriculum at a 4-year university’s engineering program and simply ala cart those at Udemy or equivalent?  The answers are accreditation and status.

10) You’ll leave engineering school with a confidence problem. Everyone enters engineering school with a certain bit of ego and confidence. School destroys all of that for 90% of students. You’ll also learn that you can survive in a state of absolute fear, misery, and anxiety for 4 years straight (minus a few short breaks here and there) and not die.  You’ll learn that you are tough.  You can use that in the future. Most people don’t know how tough they are.  You’ll have a better idea.

11) The students that can handle the pace often have photographic memories. We’ll say they are solid-state hard drives. The rest of us are the old-time platter hard drives. They are quicker at doing the math and procedures, but in no way is this an indication of work ethic, leadership, problem-solving, or integrity.  It doesn’t mean they’ll be better engineers, either.   In short, school does not in any way test the skills that generally matter in real situations.  You can look around in any given classroom and pick your team your for tech startup.  The grades will probably not be a huge factor in choosing your team.

12)  Sometimes the class theory “closes the loop”.  I mean that sometimes the theory learned in class reaches critical mass and becomes useful in real-life engineering circumstances.  A majority of the time, however,  the theory never reaches critical mass.  The loop isn’t closed and you forget everything.  These are the worst classes as the information starts out abstract, stays that way, you fight to the death to learn it, and then end up with very little.

It’s hard to imagine how most of the theory would be used unless you working in extremely niche areas. Then again, some of the theory pops up in real life. You never really know what you’ll encounter, I guess.  The jury is still out on that one

The Hardest Part of Engineering School

The hardest part of engineering school was that I needed 28 hours per day to get the maximum benefit from it and I didn’t have 28 hours in a day.  That was compromise #1.   I had to give up practically everything I enjoyed, every hobby, and almost all free time to dedicate to learning. That’s not the end of the world, but it does put a person in a burn-out mode by week #2 or so.  Trying to learn while in burn-out mode is inefficient.   The amount I gained is tiny compared to what I put into it. As I’ve stated, I would have gained so much more by working at my own pace, but this is not the way of the formal education system.

Realistic Expectations

If you look at an undergrad in engineering as a good way to take at kid at his high-school prom to being a productive 22-year old, it does an okay job. If you look at college as the pinnacle of education for learning how to design mechanical and electrical products, the system is highly flawed.  It’s barely acceptable.  It’s not entirely clear what a university is trying to do.  They don’t even know.  In Coddling Of The American Mind, they thought the purpose of college was the pursuit of truth.  Others say social justice is the purpose.  I was hoping to be a monster at designing electronic devices that didn’t kill people.  Nothing anywhere close to that happened.

It may be beneficial to look at graduation day as the starting line and not the finish line. Then you can attack what you truly love with full force. If you run into math, it won’t scare you.  You’ll know enough physics to know a con artist from the innovator. I learned that I can build a jet engine in my garage in thermodynamics. That’s about the only thing I remember from that class. That may be the only lesson I need to remember.

Is Engineering School A Total Waste of Time and Money?

If I had to do it all over again, I’m not sure I could. 4 years of sadness is too damn long. Granted, it’s only been  3 weeks since graduation and I’m still licking some deep wounds. Because of the COVID mess, the job outlook is pretty grim. So, I’m back to being Mr. Independent. I’m designing a synth that I may sell 8 of. I could have done all of this without school although it’s highly likely that I’ll use my schooling for a project this year. If I had slipped right into a decent paying engineering job out of school that can only be gotten with the degree, then I could say at least a made a few bucks last week specifically because of my education. I can’t say that.   So is engineering school a total waste of time and money?  No.  It’s not a total waste, but there is certainly a TON of waste.  The direct benefits of my education are a little hard to see at this point, but I certainly got something out of the deal.

 

Most Jobs Want 1-2 Years of Experience

If you scan the web, you’ll see job offer after job offer of employers looking for engineerings with 1-2 years of experience.  This is for a reason.  You can graduate with an engineering degree and not know what a screwdriver or a soldering iron is.  Some engineering graduates have zero skills.  Schools are supposed to weed these people out, but I never saw school weed out anyone.  I saw multitudes of people weed themselves out.  School is so miserable that anyone with a pulse will find something else to do.   I’m not entirely sure this is a valid approach.  Some good people were made so miserable they changed majors.  Some people without a pulse weren’t aware enough to quit.

If a person is going to bother with the engineering degree, they should already be building things themselves.  95% of my resume is stuff I’ve done on my own.  Without a background of building things, most of engineering school will go in one ear and out the other.

Conclusion

If you are looking for a rite of passage, have a significant background in building things, have a high tolerance for the abstract, and don’t mind being worked to the point of sadness of 4 years, engineering school is a great way to get a basic understanding of everything from photons bouncing around in a laser to why electric motors spin.  You’ll be a master of none, but you’ll know the basics of quite a bit.  Granted, you’ll only retain a small percentage of what you put in.  If you are relying on engineering school to make you a wicked product designer, forget about it.  That’s not the intent.  The idea is to give you a broad background that you can use for the next step.

Posted on Leave a comment

Solved: G28 Causing CNC Crashing From Fusion 360 Generated GCode

For some time I struggled with the default Gcode generated by Fusion 360 on my CNC machine. The G28 command was causing the tool to go straight to the top edge of my project and scrape the living crap out of it. My temporary solution in a pinch was to remove the G28 commands from the Gcode manually. This was a hassle and it turns out that the solution is hyper quick and robo easy.

As far as I can tell, G28 is saved in EEPROM. This means that the G28 setting is still there even after I kill the power to my CNC machine and restart. (My CNC was a kit that came with an Arduino Uno and the cheapo red CNC board).

Solution:

  1. Put the CNC tool thing in a safe position. (Crank the Z-axis pretty much to the top. Put the x and y somewhere close to where you generally put your project.)
  2. Enter: G28.1 in the command line of your software.

That’s it.  This saves a new G28 point.  It’s an absolute position that the CNC should remember.

It turned out that G28 was previously set with a Z value that happened to be atrociously close to where I usually did my grinding and engraving. Fusion 360 has the G28 Z0 setting there as a safety measure. Unfortunately, that only works if G28 is set to a safe point. If it’s set to a dangerous point, the problem is only made worse.

Brandon