Gullible?

We are in the midst of a series of critical repairs at the Cox home. The pandemic forced us to postpone many of them, but slowly they are starting back up.  This last week involved the removal and upgrade of our failing main electrical breaker box panel.  Of course, that meant an extended power outage and the hourly “When will power be back on?” questions from my girls.  I must say, we all gained a greater appreciation for our ancestors who navigated the 1800s with gas lights, candles and no air conditioning.

Speaking of appreciating our 21st century lifestyle, I love using Apple Pay!  With the team of contractors working hard in the heat to get our power back on, I decided to make a run to our local grocery store to pick up some bottled water, Gatorade and snacks for them.  As is my custom, I paid with my Apple watch.  The customer behind me was shocked and struck up a conversation.  

I grew up in the Midwest where you expected friendly conversations with random fellow human travelers all the time.  However, that’s typically not how we do things in California.  Here, everyone tends to be more focused on their own business, mostly without even making eye contact.  But I find I still revert to my Midwest roots on occasion, much to the embarrassment of my kids, especially when there happens to be a cute baby in line with us.  I just can’t help myself.  Babies are irresistible.  In any case, I happened to run into this concerned citizen in line with me at the grocery store who was seriously worried about my Apple watch.   The conversation was really quite fun.

“Hey, aren’t you worried someone is going to steal all your information with that thing?”  I responded, “Actually, it uses an encrypted token, not my info, to complete the transaction.”   

“Like whatever, encrypted nothing, they got you!  That’s dangerous!  Can’t someone just decrypt it?”  I really wanted to start drawing a diagram to explain how it worked, but I knew the rest of the customers in line were not interested in an extended lecture.  I still switched into professor mode, “Sure, but just keep in mind, this isn’t my information directly, it is just a token identifier.”  

“Man, you really are gullible.”   I wasn’t making any progress.  He shook his head but then proceeded to pull out his credit card in plain sight.  I was able to clearly read his name, card number and expiration date printed on the front.  No, I didn’t try to memorize it but was struck by the irony.  He swiped his card with his in-clear-text magnetic stripe, also showing the CVV.  Sigh.  Yes, I guess I’m gullible.

I appreciate my friend’s paranoia, despite his negligence in protecting his own identity.  No system is 100% secure.  We know that.  Several years ago, I had the privilege of teaching a cybersecurity class at USC where we explored the anatomy of an attack.  One particular study was the 2013 Target breach. We examined all the points of vulnerability that existed in the system at that time.  It began with a phishing scheme that equipped the attackers with a contractor’s credentials to log in to the energy management system for the stores.  That led the attackers to a vulnerable Windows PC that just so happened to bridge the HVAC network with the global store network. That network was home to all the point of sale systems for all their stores.  The card readers on those systems only accepted plain text magnetic stripe data. The hackers installed BlackPOS, a malware opensource package that intercepts track data.  It began reading all of that data, sending it off to a server hosted in Russia.  They managed to extract 40 million credit cards before they were discovered.  A year later, the nearly exact same attack occurred at Home Depot, but for 56 million credit cards.

Vigilance is needed.  Reliability engineering is not just about system performance or uptime, it is also about running secure systems.  As we help design, build and run systems, this is a great reminder that we can all help safeguard our customers’ and company’s data.  Have you found a vulnerability?  Are you concerned about some missing measures or designs that should be modernized or addressed?  If so, don’t wait, raise those issues.  Speak up and act.  You can make a difference.  Let’s continue to help make our systems more secure for the good of the kingdom, our guests, businesses and fellow employees.

Automate, Accelerate, Optimize, but first, Delete

“I think it’s very important to have a feedback loop, where you’re constantly thinking about what you’ve done and how you could be doing it better. I think that’s the single best piece of advice: constantly think about how you could be doing things better and questioning yourself.” – Elon Musk

The Tesla Model 3 production line was too slow. Demand was high but delivery was low.  The entire line was being delayed by one particular step in the battery production line.  Specifically, it was a step where a fiberglass mat was added between the battery pack and the floor pan.  Elon Musk talks about the focus that was suddenly placed on this choke point.  In an interview he gave, he says he was basically living on that production line until they could get it fixed.

Automate, Accelerate, Optimize. To address the constraint in the system that was choking the throughput, Elon goes on to explain how they focused on the automation.  To make the robot better, they adjusted the programming.  They increased the speed from 20% to 100%, optimized the paths it would take, increased the torque, removed unnecessary motion and reduced the amount of product needed.  Instead of spackling glue on the entire mat, they programmed it to deliver dabs of glue that were just enough to hold it in place, sandwiching it between the battery pack and floor.  These all added up to some minor time savings.

After investing a lot of time into the efficiency improvements, it occurred to Elon that he didn’t even know the reason for these mats.  He asked the battery safety team, “Are these mats for fire protection?”  They answered, “No, they are for noise and vibration.”  He then went to the noise vibration analysis team and asked them, “Are these mats for noise reduction?”  They answered, “No, they are for fire safety.”  

“I’m trapped in something like a Kafkaesque or Dilbert cartoon!”  Elon discovered the mats had no reason to be included.  After verifying with testing, they eliminated the unneeded parts that were choking the Model 3 production line.  Production throughput increased.

How many times have you optimized a bit of code, a process or a system only to finally realize that the best optimization was to simply delete it?  Before we take on some new work, a new project or even an improvement effort, ask yourself and others, “Do we even need this?”  We all have limited time and resources.  Some upfront investment in validating the real need can pay material dividends.  Seek to eliminate waste.  Instead of focusing on improving unneeded processes, let’s focus our efforts on things that deliver real value and outcomes.  

Before automating, ask yourself if the time investment will deliver more value than we put in.  Before accelerating, ask yourself if the haste will actually eliminate waste.  And before improving something, ask yourself if we should just delete it instead.  Challenge assumptions so we can ultimately deliver bold results that matter.

Eureka! Eureka!

“Eureka!  Eureka!” –  Archimedes

The famous Greek mathematician, physicist and astronomer, Archimedes had been given the task to verify that the king’s crown was made of pure gold.  The king suspected the goldsmith had somehow cheated him, perhaps by mixing in a cheaper metal like silver.  But he had no way of proving that so he asked Archimedes to figure it out. One day Archimedes was contemplating this problem while taking a bath. He happened to notice how the water was being displaced as he stepped into the full tub, spilling out all over the floor.  He remembered that silver weighs less than gold by volume.  It suddenly dawned on him that if he were to take the same amount of pure gold by weight as the crown, and put it into water, it should displace (spill) the same amount as the crown.  Archimedes was so thrilled with this discovery that he immediately hopped out of the bath and ran to tell the king, exclaiming “Eureka!” which means, “I found it!”.   In case you are curious, when Archimedes tested the crown, he discovered that it displaced more water than gold, indicating it was less dense (not pure gold).  So, indeed the king had been cheated by the goldsmith. You can probably guess what happened to the goldsmith!

Learning is hard.  There really isn’t a way around it.  If you want to learn something, it’s going to take effort.  I often use the excuse that the human brain is optimized to save energy.  We build models and synaptic connections to do things “without conscious thinking.”  We process huge amount of sensory data every day.  We are faced with a plethora of problems we need to solve. It would be overwhelming if it wasn’t for these optimized unconscious neural pathways that allow us to sort, react and perform our tasks without much thought.  

Learning builds more capability.  At some point in our past, we learned something new and, Eureka!  That learning was forged in our brains.  It allowed us to perform our duties while we engage our higher brain functions for more important tasks like daydreaming, pondering the next season of Loki, or wondering what’s for dinner.  Ok, so maybe those aren’t more important tasks, but you get the idea.  By leveraging our learning, we expand our capacity to respond well to incoming tasks, difficult challenges, complex changes and even enjoyable exercises. 

Learning builds on learning.  I know that sounds a bit meta, but if you examine your own experience, you know that learning builds pathways to future learning. I remember the first time I learned to program a computer.  It was hard!  I was 12 years old and wanted to make my new computer display a Christmas tree for the holidays.  Somewhere in the midst of typing in some code from a Dr. Dobbs Journal article, a Eureka moment hit and I understood the procedural flow that was happening.  I had looked at more advanced programming techniques but they were out of reach for me, at least until I hit that Eureka moment.  Suddenly that complexity was unlocked.  That eventually led me down the path to discover microprocessor design, compiler construction and operating system development.

I recently purchased some dev kits, including a LIDAR kit.  This past weekend I decided to learn how to use it to image my room as a stepping stone to my larger robotics navigation project.  The funny thing about learning is that it often takes you on roads you didn’t expect to go.  LIDARs are basically spinning measuring devices that use a laser to measure distance and send back angle and distance data.  I wanted to visualize what the LIDAR was reading but the kit didn’t provide any imaging tools.  So, I decided to learn OpenGL to render the output on my Mac. That became an exercise in itself but by the end of the weekend, I had a working project (see https://github.com/jasonacox/OpenGL-LIDAR-Display).  It was challenging and frustrating at times.  But as with any good learning effort, I had a Eureka moment that unlocked excitement and plans for future learning.  I’m looking forward to the next phase!

What are you learning?  When was the last time you had a Eureka moment?  If you haven’t already, make plans this week to tackle something new to learn.   Keep learning!

Keep Learning

“The illiterate of the 21st century will not be those who cannot read and write but those who cannot learn, unlearn, and relearn.” – Alvin Toffler

As a kid, I was inspired by movies like TRON to explore computers.  I caught the bug as soon as I saw how easily software could be used to shape reality and improve things.  I spent 6 years skipping around between computer science, mathematics, physics, electrical and civil engineering.  I even invested a year working toward a masters in divinity until I realized Koine Greek wasn’t a new computer language.  

My dad was a civil engineer with crazy mad RPN calculator skills. He could crank out and tabulate thousands of calculations per day.  But one day I wrote a bit of software and suddenly a week’s worth of tedious error prone work was done in minutes.  He immediately hired me to “computerize” the rest of his business.  With my educational background, I thought I was set… I could change the world (or at least my corner of it), one program at a time… but I still had a lot to learn. I soon discovered I didn’t know enough about statics and dynamics for the structural engineering work I needed to do.  I also needed to dive deeper into 3D geometry and computer graphics for modeling complex systems.  I went back to school.

There is a thought that education is just a box you need to check to begin your career.  You may get certified, degreed or licensed and now you are done, right?  Nope! Those are all great, but they are just visible footprints on the stairway of continual learning.  Learning expands the mind and prepares us for more learning.  Each step along the way reveals new vistas of knowledge to explore, new puzzles to solve and new mastery to obtain.  We are forever on this learning adventure, growing and thriving on the food of knowledge, discovery and experimentation.  Every new cognitive challenged unlocked is like an awakening.  It is the physics of life.  Each discovery expands who we are and carries us to a new level.  We are alive and growing when we are learning.

Learning can be fun, but it isn’t easy.  It takes work.  It can be exhausting and even frustrating at times.  Because of that, there is a temptation to become comfortable with our current state.  We may find we can get by with what we already know, often for years without having to learn something new.  But we aren’t growing.  We become stale.  Our capacity to move ourselves, our teams and our organization forward, withers.  Like physical exercise, mental exercise is required to stay healthy, vibrant and alive.  Just as we should plan to exercise our physical bodies to stay healthy, we should plan to exercise our minds as well. 

What are you learning?  May I suggest, if you aren’t learning anything new right now, pick something new and start learning it today?  I know it isn’t easy, but embrace the constructive discomfort and expand your knowledge and skill.  Tackle it.  Imagine yourself thriving and growing.  Don’t limit yourself. Set a goal to upgrade your knowledge every week.  Study, grow and keep learning!

A Sonic Revolution

“We knew it could become big but could have never imagined it would be a revolution.” – Lou Ottens

Magnetic tape was genius!  A ferric oxide placed on a thin plastic film allowed the world to record, store and playback audio.  It revolutionized broadcasting, radio and especially, music.  In 1960, the portability of that music was still captured in a clumsy 7-inch reel.  It wasn’t easy to play. You needed a hefty machine the size of a small suitcase.  Lou wasn’t happy with that.  

Lou loved technology.  He was ever the engineer and loved solving problems.  As a teenager during World War II, Lou made a radio for his family so they could listen to programs like Radio Oranje.  To avoid the Nazi jammers, he even constructed a primitive directional antenna.  Just as he had made those freedom broadcasts accessible to his family, he now turned his attention to democratizing music.

The 7-inch music reel was too bulky and awkward for the general population.  He wanted music to be portable and accessible.  He thought a lot about what it should be like.  Trying to envision something that didn’t yet exist, he began shaping it into a small wooden block.  It needed to be small enough to easily fit in your hand and more importantly, fit in your pocket.  His “compact cassette” tape came to life in 1963 and quickly became a must-have sensation across the world.  It unleashed a multi-billion dollar industry but also taught us how to use our own voice.  The cassette became an audio canvas for the masses to self-create their own albums or compile their own mixtapes to share with others.  For those of you who don’t have as many candles on your cake as I do, mixtapes were basically the playlists of the 1980s.

The cassette tape was a raging success, but Lou wasn’t happy with it.  He complained about the noise and distortion that would eventually plague the aging tapes. In his mission for higher fidelity, he worked with his company, Philips and Sony to co-develop the digital optical storage system, the compact disk (CD).  As he had done with the cassette tape, Lou championed a portable disk size that could be easily held and used.

Lou Ottens passed away earlier this month, at the age of 94.  He sparked a worldwide sonic revolution, but humbly dismissed his role as nothing special, instead crediting other engineers and designers for bringing his ideas to life.  Lou reminds us that making science and technology accessible is just as important as the discovery itself.  

Do we make our complex technical inventions and solutions accessible?  When technology is done well, the technology itself fades to the background and becomes “indistinguishable from magic”.  That is to say, it provides a human experience and value and doesn’t get in the way.  My challenge to us this week is to examine the solutions we deliver and ask ourselves, can we make them more accessible and magical?  

As Lou taught us, the genius of a great idea is not just in the science, it is making that technology portable and accessible.

See Problems

“Failure isn’t fatal, but failure to change might be.” – John Wooden

On June 4, 1942, the Japanese Navy arrived at the island of Midway to battle the United States Navy.  They had twice the number of pilots, planes and firepower.  Clearly with this much difference between these two forces, the Japanese should have won.  But that’s not what happened. In a surprising turn of events that became lore and even feature length movies, the United States won the Battle of Midway and that catastrophic defeat devastated the Japanese Navy.  It led to their inability to wage war in the Pacific for the remainder of the Second World War. 

Dr. Steven Spear from MIT, tells this story and asks the question, “When do you suppose the Japanese lost the Battle of Midway?”  Books have been written on the exact details of each maneuver during the battle to try to determine the exact moment that spelled the loss for Japan.  Prepare for a surprise.  The Battle of Midway was lost in 1929, not 1942.  Over a decade before!  Here’s the deal, by 1929 the Japanese Admiralty had locked in their assumption on how wars would be fought and won on the sea.  Everything was built upon the assumption that the entire fleet of one nation would face the entire fleet of the other head on. That doctrine dictated how they designed their aircraft, their carriers, their procedures and tactics.  They scripted the entire battle plan for Midway and conducted war games to rehearse it.

During the war game they set up a huge table with the layout of the two sides.  The Japanese Admirals sat on one side of the table and brought in junior officers to play the side of the US.  Both sides used sticks to push the wooden ships around the map.  After a few back and forth moves, a referee blew a whistle and accused the junior officer of not playing according to the battle plan.  He was kicked out and another junior officer was recruited.  This officer did the same thing as the former one, he looked down the table, realizing he was significantly outmatched, he too deviated from the battle plan and began to win against the Japanese side.  Once again, he was accused of not understanding the battle plan and dismissed.  This same thing happened until they went through all the junior officers, then petty officers and even brought in noodle vendors off the street.  Each time the US side won and the Japanese Admirals were frustrated that nobody was playing by the battle plan.  Instead of seeing the problem that these exercises were showing, they fixated on pathologically rehearsing their failed plan.  That is how the battle was lost.

The lesson here is powerful.  We often believe we know the best way to solve problems.  We can go to great lengths and details in defining and prescribing the solution.  But if the solution is not tested or we are unwilling to observe and build ways to see problems and learn, we can suffer catastrophic failures similar to the Japanese Admiralty.  We should design and test our systems in such a way that we can clearly detect problems, learn from them and alter course when discovery is made.  Avoiding that is effectively setting a course for failure.

A growth mindset seizes upon unexpected events or failures as golden moments of learning.  I believe this applies to all of life, not just our engineering efforts.  We all make plans, sometimes elaborate plans, and yet how do we react when those plans are thwarted?  Do we dismiss the opponent and try to get back to plan, or do we learn and alter our course?  I know this is a growth area for me.  I often want to push ahead with full force to get something done.  This pandemic has thwarted and change a lot of our plans.  But do we surrender or do we embrace the discovery as new opportunity?  Don’t become discouraged, fatigued or apathetic.  Convert problems into energy and redirect it towards a positive direction.  The secret power of successful businesses, teams and individuals is the ability to quickly learn and adjust to discovery. 

Are you struggling with your own plan failures?  Don’t give up!  Look at those failures as opportunities for learning and adopt the change.  The battle is not lost.  Glean the learning and become better.  You can do this.  Keep learning!

Road Construction Ahead

“We believe that people with passion can change the world for the better… and those people that are crazy enough to think that they CAN change the world, are the ones that actually do.” – Steve Jobs

Road work ahead!  For the past two weeks we have had road construction in our neighborhood.  Like a marching band, the big equipment moved in with all the familiar drumming, scraping, cutting, dumping and rolling sounds.  In the past, I doubt I would have given it much thought as I commuted to and from the train to get to work.  But this time I have the pleasure of soaking it all in.  On our morning walks I get to see it all up close, greeting the workers moving about in some sort of construction choreography, adorned with branded masks and new coronavirus safety rules.  Watching this work, I’m reminded of the incredible value of building and maintaining this vital infrastructure for our society.  Roads, bridges, utilities, vehicles and buildings all create a platform for our communities, country and world to live, connect, conduct business and shape new ideas into reality.  Infrastructure propels us forward. 

I love technology.  Right out of college, my dad convinced me to join his civil engineering firm to help him, as he called it, “computerize the business.”  I didn’t know anything about civil engineering, but leaned into my science background and learned the complexities of land surveying, hydrology, material science, logistics and structural engineering.  I was amazed at the work that was done manually calculating, planning, drawing, erasing and drafting again.  I introduced the staff to AutoCAD and the coordinate geometry tools I had built to help accelerate their work.  But I was about to learn a big lesson in change management. 

“You’re crazy!”  The engineers were adamant that they didn’t want those “darn computers” (and other colorful adjectives) anywhere near their projects.  I couldn’t understand why everyone wouldn’t want to embrace new technology.  Instead of giving up, I pivoted and took on a housing development project myself.  Working with a skeptical but supportive colleague, we loaded all the elevation data to build contour maps and went to work planning streets, utilities, houses and storm systems.  The client loved the initial plans but after a review by the city, a major rework was required to expand the housing lots and add a park.  This is where the magic happened.  In the past, that would have been a start over scenario, but by having the entire project in the computer we only needed to make a few modifications to the model and the entire set of plans were ready to be released for construction.  The skeptics were blown away with the turnaround.  All the initial resistance gave way to aggressive adoption as they all saw how the computer had chewed away the toil, tedium and time to deliver plans. 

Technology amplifies human ability.  We leverage information technology to connect, to accelerate and displace manual steps, to elevate our capabilities and extend our horizon.   As technologists, we have an incredible opportunity to build a better world.  Through our trade, we can construct next generation digital infrastructure, better connect people to people, people to ideas, and ideas to reality. 

Technology builds upon technology.  Prior generations of tools stack to scaffold us up to the next level, which becomes the platform for the next.  Despite the entire world being in time out for COVID-19, people are still working, business is still being conducted, things are still moving forward, because of technology put into place by people like you. 

As technologists, we can make a difference.  Our human family is counting on us to help keep the information roadways maintained and improved.  Our companies are counting on us to use our expertise to power our businesses, to ship value better, faster, safer and happier. 

What crazy ambitious ideas do you have to help change the world?  What can we do to better help each other through technology?  I challenge you this week to give that some thought.  Let’s be some of the crazy ones who want to change the world.  Who knows, we might actually do it!

Digital Scale for 3D Printer Filament

This project is to add a load cell to the filament spool holder of a Creality Ender 3 Pro 3D-printer to measure and display weight of spool. Using the tare function of the scale on an empty spool, the user can determine the amount of filament (in grams) remaining on a spool.

This project uses an Arduino or ATtiny85 microcontroller with the HX711 load cell module for weight measurement and a TM1637 4-digit LED display. Project GitHub Link

Components

  • ATiny85 Microcontroller (DigiKey)
  • TM1637 4 Digit Segment LED Display (Amazon)
  • Load Cell with HX711 Load Cell Amplifier (Amazon)
  • 100uF Electrolytic Capacitor
  • 5V Power Supply – Micro USB to DIP 5-Pin Pinboard (Amazon)

Schematic

Schematic

How to Build

The filament scale mounts on top of the Ender 3 top rail where the filament spool is located. You will need to print the load cell mount and the LED display box. This is available on Thingiverse or Tinkercad. See example build pictures below.

Setup & Calibration

Download the Arduino code here: https://github.com/jasonacox/Ender3-Filament-Digital-Scale

This sketch requires that you calibrate the load cell. This involves the following steps:

  1. Run the sketch with DEBUG true (using a Arduino Uno or other microcontroller with serial)
  2. Record the “HX711 reading” values with NO load on the scale – this is your “CAL_OFFSET
  3. Use an trusted scale and weigh an object (grams or kg) – record this value as your “KNOWN-VALUE
  4. Place the object on the load cell and record the “HX711 reading” – this is “CAL_VALUE
  5. Compute the CAL_RATIO = (CAL_VALUECAL_OFFSET) / KNOWN-VALUE
  6. Edit the #defines in the code
    CAL_OFFSET  = -148550
    KNOWN_VALUE =  382.7186 g
    CAL_VALUE   = -107150
    CAL_RATIO   = (CAL_VALUE - CAL_OFFSET) / KNOWN_VALUE
    CAL_RATIO   = ((-107150) - (-148550 )) / (382.7186)
    CAL_RATIO   = 108.17

Programming Notes

The TARE button uses PB0. If you use the Tiny AVR Programmer from Sparkfun it drives an LED on PB0 and once the sketch is uploaded, the ATTiny will read PB0 as LOW and assume you wish to TARE the scale. You will need to remove the the chip from the programmer after uploading to get it to work correctly in the circuit.

Tare Function

On start the circuit will read the last TARE value from EEPROM and display the the current weight. Press and hold the TARE button and the current weight value will be recorded in EEPROM and subtracted from the current reading to “Zero” out the scale.

Assembly

The 3D model for the case and load cell mount is on Tinkercad and available for download on Thingiverse. The case is open-back for simplicity and it has mounting holes that use the existing spool bolts and fasteners.

I used a small 20mm wide project circuit board to mount the ATtiny85 socket, resistor, electrolytic capacitor and microswitch. The microswitch is located on the bottom and will face the hole on the front of case. A circular 3D printed button will fit in the hole and press against the microswitch to activate the TARE function.

The case is designed to hold a USB plugin board, the TM1637 display, the controller board and the HX711 load cell module. The HX711 slides in with a hole on the side to feed the load cell wires.

You will need M5 bolts to mount the load cell onto the 3D printed case bracket (see pictures below) with bolts going up into the threaded load cell holes. The filament spool holder that came with the Ender 3 Pro will attach to the “load” end of the load cell (the end marked with the down arrow and max weight). A 3D printed shim adapter will go between the filament holder and the load cell. An M4 bolt will go down and tighten into the load cell. The other M4 bolt will need a M4 nut under the shim.

Attach the scale and filament holder back on to the top of the Ender 3 Pro using the two M5 bolts and M5 T-nuts that came with the printer.

Plug in the scale and put an empty filament spool on the holder. Press the TARE button to zero out the weight (it records this TARE value in EEPROM memory so it remembers it on power cycle – you shouldn’t have to use TARE again). Now replace the empty spool with one with filament. It will now show you the estimated amount of filament remaining. it has been surprising accurate for my project. Notice the example below shows a slightly used 1kg spool is reading 992 grams.

Optional Roller Addition

I immediately noticed that when printing, as the extruder stepper pulls the filament, the weight will change, reflecting the dynamic force of the pull and the sliding friction resistance of the static spool holder rod.

I decided to addd a real roller to the spool holder so I printed this model that uses two bearings to remove friction: https://www.thingiverse.com/thing:3209211

References

ATtiny85 Weather Station

Weather Station

This project will show you how to build an ATtiny85 based mini Weather Station that displays temperature, humidity and pressure using four easy to read 7-segment LEDs.

Requirements

This sketch requires a version of the Wire library that is compatible with the ATtiny85 for the I2C communication to work with the BME-280 sensor. I used the ATTinyCore arduino core by Spence Konde which has a version of the Wire library that works with the ATtiny85. I was able to use the standard Adafruit_BME280 library to pull data from the BME-280. You can install ATTinyCore by putting the board manager URL in the Arduino IDE preferences:

http://drazzy.com/package_drazzy.com_index.json

Set the board to the ATtiny85 chip at 1Mhz (internal).

Circuit

Components:

  • ATiny85 Microcontroller (DigiKey)
  • BME-280 Sensor (Temperature, Pressure, Humidity) (Amazon)
  • 74HC595 8-bit Shift Register (Qty 4) (DigiKey)

Sensors

  • 7-Segment LED Display (Qty 4) (DigiKey)
  • 0.1uF Ceramic Capacitor (Qty 2)
  • 100uF Electrolytic Capacitor
  • 5V Power Supply (Alternatively you can use a 5V Solar cell, 3.7V lithium ion battery and a TP4056 constant-current/constant-voltage linear charger to charge the battery during the day).

Schematic

Circuit Board

ATtiny85 Microcontroller

Circuit Board

Programming Notes:

Code for this project is located on Github: https://github.com/jasonacox/ATtiny85-Weather-Station

I2C communication with BME-280 uses pins PB0/SDA and PB2/SCL. If you use the Tiny AVR Programmer from Sparkfun or something similar, keep in mind that it drives an LED on PB0 which will interfere with I2C communication. You will need to remove the chip from the programmer after uploading to get it to work in the circuit.

Memory Warning

This sketch uses nearly all of the ATtiny85 program storage space (8K) so you may get an overflow error if the libraries change or you add any code. To address this, I created a minimized BME280 library to reduce the PROGMEM space required. You will need to download and install the Tiny_BME280_Library library in:

~/Documents/Arduino/libraries/ directory and restart the Arduino IDE.

Display

  [ 70'] - Temperature in degree F 
  [ 24r] - Relative Humidity %
  [_970] - Pressure in hPa with rising/falling animation
  [ 21c] - Temperature in degree C 

Construction

I used two circuit boards: Display and Logic board. The Display board holds the four 7-segment LEDs with the array of resistors. On the back are header pins that plug in to the logic board. The Logic board holds the 4 register chips and the ATtiny85. On the back are headers for the Display board to plug in.

Logic and Display boards: 

Both boards together and running: 

I printed a simple cylinder case (Thingiverse) to mount the weather station and have it on the back patio: 

Power Supply

The circuit will run on 5V or 3.3V. I used an existing solar panel, battery and TP4056 charger circuit to power this project with a 3.3V regulator.

Solar Power Option

  • 1 x 2.5W 5V/500mAh Solar Cell – Amazon
  • 1 x 5V Micro USB 1A TP4056 Lithium Battery Charging Board with Protection Charger Module Amazon
  • 1 x 3.7V 3000mAh 755068 Battery Rechargeable Lithium Polymer ion Battery Pack – Amazon
  • 1 x 3.3V Linear Regulator 250MA MCP1700-3302E/TO – DigiKey

ATtiny85 Ultrasonic Distance Measurement for Parking Help

After discovering the tiny but mighty ATtiny85 microcontroller, I decided to put it to use to help me park my car in the garage. Sure, I could continue to use the softball hung from the ceiling to let me know when I have the car pulled in far enough, but why not take advantage of some tech and have it show me instead? Alternatively, for these times, it is also a fun way to clearly demonstrate 6ft social distancing. 😉

ATiny85 Microcontroller

The ATtiny85 has 5 GPIO easily usable pins (technically you can even use Reset pin as a 6th GPIO but that makes it much more difficulty to reprogram). For information about how to program the ATtiny85, see my previous blog post here.

The tiny but mighty ATtiny85 Microcontroller Pinout

For my “Parking Helper” project I decided to use the low cost entry level ultrasonic distance sensor, the HC-SR04 and two 7-Segment LEDs to show the distance between the device and the front of the car.

HC-SR04 Ultrasonic Sensor

The HC-SR04 has 4 pins: VCC, Trig, Echo and Gnd. The Trig and Echo lines will be driven by the Attiny85.

HC-SR04 Ultrasonic Distance Sensor

The HC-SR04 measures distances by sending (TRIG) an sound pulse and measuring the time it takes for the ECHO. Sound travels through air at 332 meters per second at 20 °C (68 °F). Using this the unit provides a duration pulse back to the controller that can be used to determine the distance.

The speed of sound is: 343m/s = 0.0343 cm/uS = 1/29.1 cm/uS

I found a great project here where the author uses the HC-SR04 as an ultrasonic rule. Using the ATtiny85 to trigger and receive the duration pulse we can determine the distance to the parked car.

// Send TRIG HIGH for 10 microseconds 
// to trigger the HC-SR04 to send a sound pulse
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

// Read the ECHO duration
  duration = pulseIn(echoPin, HIGH);

// convert the duration to cm
  distance = (duration / 2) / 29.1; 

LED Display (2 Segment)

Driving the display with two 7-segment LEDs is a bit more complicated. Each segment has 7 LEDs to form the numbers plus one LED for the decimal point. That would require 8 GPIO ports for each LED Display or a total of 16 GPIOs! The ATtiny85 has only 5 available for use so we need another way. Thankfully, we can use two low cost 8-bit shift registers (74HC585) and get by with using only 3 GPIO and still drive the 16 LEDs on the two displays.

74HC595 8-bit Shift Register to Drive 7-Segment LED Display

Here is how it works… The ATtiny85 sends the binary data for the the numbers to a first 74HC595 8-bit register using its “Data Input,” “Clock” and “Latch” lines. Once the register receives a total of 8 bits (1 byte), it will overflow the data out through its “Output” line which can be connected to the “Data Input” of another register.

We toggle the “Clock” to signal to the registers to record the value of the data line (1 or 0). We do that for each of the bits of the two bytes we need sent for each display. Finally, we have the ATtiny85 toggle the “Latch” to let the registers know when the transmission is complete. They then lock the 8 output lines (QA to QH) to high or low depending on what they recorded. These lines are connected to the individual LEDs on the 7-segment LED displays.

I found a great example of using the 74HC595 to drive multiple LED Displays here. I used that code to send the data as well as the byte arrays used to form the numbers on the LEDs. Since that project was using a common anode LED and my project uses a common cathode LED I had to flip the bits. In the code below, a one (1) value would drive the LED high (on) and a zero (0) would drive it low (off).

/* Set up 7-segment LED Binary Data

     |--A--|
     F     B
     |--G--|
     E     C
     |--D--|   H - Decimal

     0b00000000
       ABCDEFGH
  */  
  numArray[0] = 0b11111100; // 0 - Zero
  numArray[1] = 0b01100000; // 1 - One
  numArray[2] = 0b11011010; // 2 - Two
  numArray[3] = 0b11110010; // 3 - Three
  numArray[4] = 0b01100110; // 4 - Four
  numArray[5] = 0b10110110; // 5 - Five
  numArray[6] = 0b10111110; // 6 - Six
  numArray[7] = 0b11100000; // 7 - Seven
  numArray[8] = 0b11111110; // 8 - Eight
  numArray[9] = 0b11110110; // 9 - Nine
  numArray[10]= 0b00000000; // All Off

Circuit Schematic

Pulling it all together, here is a schematic I put together that combines the ATtiny85 with the two 74HC595 registers, two LED displays and the HC-SR04 ultrasonic sensor.

A Kicad schematic is included in this project and the schematic export is sown above. The circuit is powered with a steady 5V DC supply (e.g. USB adapter). The HC-SR04 is an entry level sensor and does suffer from some fluctuation. Logic in the code attempts to stabilize the measurement by making multiple readings.

List of Materials

  • 1 x ATiny85 Microcontroller (DigiKey)
  • 2 x 74HC595 8-bit Shift Register (DigiKey)
  • 1 x HC-SR04 Ultrasonic Distance Sensor (DigiKey)
  • 2 x 7-Segement LED Display CC (DigiKey)
  • 16 x 220 Ohm Resistor
  • 1 x 100uF Electrolytic Capacitor (DigiKey)
  • 1 x 0.1uF Ceramic Capactior – (Amazon)

Code

The code for the project can be found on GitHub: https://github.com/jasonacox/UltrasonicDistanceDisplay

Imperial and SI Units

In Imperial unit mode, the code is written to display distances in inches (1 to 11) for distances less than 1 foot. Once the distance reaches 1 foot, it will show feet in decimal (1.0 to 9.9) until the distance reaches 10 feet when it will display in feet only (e.g. 10).

In SI unit mode, it will show centimeters for distances less than 1 meter (1 to 99, then it will show meters with decimal (1.0 to 9.9) until the distance reaches 10 meters and will continue to show meters only.

To toggle Units: Hold the distance to 4 (either unit) for ~4 seconds and it will toggle between units. Imperial mode will flash “in” and SI mode will flash “c”.

Sleep Feature

Sleep Mode: The code includes logic to turn off the display when there is no movement and power back on when movement is detected.

Prototype

Prototype Model without Box