House of Hacks: Arduino
Showing posts with label Arduino. Show all posts
Showing posts with label Arduino. Show all posts

Saturday, December 17, 2022

Build Your Own Binary Clock: Design Changes and Electronics Review (part 2)

Description

Want to make an Arduino project a bit more complicated than blink? In today's episode of House of Hacks, Harley starts a project on how to make a binary clock. This project will use an Arduino and be presented in three parts. Today, the first part will be the overall design and software. In future videos, the second part will be building the circuit and getting it operational and the third part will be finishing it off with an enclosure.

Additional resources

If you want to build your own, here are the parts I used (all affiliate links):

If you just want a commercially made one like I have, they’re available on Amazon: https://amzn.to/3eGXFVD (Affiliate link)

Arduino Foundations book: https://amzn.to/37WMV3U (Affiliate link)

Music licenses

Music under Creative Commons License By Attribution 4.0 by Kevin MacLeod at http://incompetech.com.

Contents

Transcript

Introduction

Interested in making a binary clock inspired by this?

You're at the right place! This video is the next one in the series on how to make a binary clock.

Wow, it's really been a while since I've, started this project, and there are some good reasons for the delay, which I'll get into later. But in this video, I'll show the parts I've received since the last video and review the design with some changes I've thought of since then.

Imagine, Design, Build

When putting any project together there are three big stages: imagine, design and build.

Each stage is iterative and there's a bit of gray area, sometimes quite a bit, between where one stops and the next one begins. And sometimes you find problems in the stage you're working on that requires you to scrap it and go back to the previous stage. It's really just part of the creative process.

Well that happened to me on this project and I'll talk about that and some of the changes that I've made.

Welcome to the House of Hacks!

If we're just meeting, I'm Harley. Welcome to the House of Hacks where I make things out of different materials and show you how you can do that too. Around here any type of media is fair game, from things as basic as wood to as virtual as software.

In this project, I plan on using electronics, software, wood and some resin. But you know, plans change and when it's all said and done we'll see how things ultimately turn out.

Project review

This is the second in a series of videos about how to make a binary clock. I picked up this clock at a conference a number of years ago and thought it'd make a basis of a really cool project.

In a previous video I talked about the requirements, how to read it and the overall design. Since that last video, I ordered and received the electronics parts that will make up this project.

Arduino Micro specs

This is the Arduino I'm going to use. It's the micro version and has several things going for it. It doesn't have as many pins as the larger versions but it has more than enough for the purposes of this project. It's really compact and it's designed to be soldered into a project.

DS-1307 specs

And this is the clock module. It's a DS-1307. We can see here the battery holder and it's designed to keep accurate time. The way it works is you set the time and it will then tell you the time whenever you ask for it.

One of the nice things about this, besides the battery backup, is it outputs in BCD, so we don't have to do any conversion in our code.

This module actually has a number of features we're not going to be using such as tracking the date in addition to the time and a square wave generator. And it also has some memory that you can store small amounts of data in.

I2C bus overview

It communicates over what's called an I2C or I-squared-C bus. There are different ways of pronouncing this, none of which are really the "right" way.

route, route
data, data
neither, neither
gif, gif

But whatever it's called, this is a communication standard that allows multiple devices to communicate over just two wires.

It can be as simple as this project where there is one main controller, also called the master that initiates the communications, and one that responds to the controller, also called a slave. But it has a possibility to be something more complicated with multiple masters and multiple slaves.

In any case, regardless of how many exist, the masters always control the conversation and the slaves just respond.

74595 operation overview

These are the 74595 chips that we'll be using to light up the LEDs. Technically they're called 8-bit shift registers and use something called serial-in/parallel-out. That sounds a bit confusing but it's really not too hard if we break it down.

  • "8-bit" just means there are 8 outputs that are either on or off.
  • "Shift" means we put things in one end and they come out the other.

    Kind of like a line at the grocery store. You shift closer to the register as you move from the end of the line to the front.

  • "Register" means it remembers its value without having to do anything special.

    It gets written to and remembers that until it's written to again kind of like a check register if you're old enough to remember those things. It's really just a type of computer memory.

  • "Serial-in/parallel-out" means you put in one thing at a time and you get multiple things out.

    In this case, we put in one bit at a time and the output is eight bits at a time.

These chips connect to the Arduino with just three pins: that's the serial-in part. The three input pins are called the latch, data and clock.

First the latch pin says "get ready, we're about to make some changes." We set it whenever we want to change the contents of the register. We then use the data and clock pins to actually set values and then unset the latch when we're all done. When unset, the values put in on the data pin is transferred to the eight output pins.

The data pin says this is one value to display. It can be thought of as high or low, or on or off, or one or zero.

Finally, the clock pin says take the value off the data pin right now. This is because there can be a transition time when the data may not be fully on or fully off and we really want to make sure that the data value that we're using is the value we want to use before setting it on the chip.

One of the cool features of this chip is they can be daisy-chained together. If eight values are sent to a chip it fills up all the output pins. As more values are sent to it, each of the values at the end are sent to an overflow output pin. This overflow pin can be connected to the data pin of another shift register and the clock and latch lines connected to both. This means you could connect two of these chips together and clock in 16 data values or you could connect three and clock in 24 data values or however many groups of eight you want to put in. All through the same three pins on the Arduino.

Miscellaneous parts

And last of all, there are some miscellaneous things: the LEDs and resistors that will be used to actually display the time, the rotary encoder that will set the time and the project board that will connect everything together.

There may be some other things needed as this comes together but those are the major components.

Where I've been

I have some design changes to talk about but first let me say a bit about where I've been and why there haven't been as many videos in the past year as in previous years. Besides the whole dumpster fire that was 2020 in the world in general, there were several personal things that happened for me personally in 2020. One was really sad and the other is really pretty exciting. But both took time and emotional energy away from making videos.

The sad one was the passing of my Mom. It was quite unexpected and, as these things go, relatively quick.

One day she felt like she had the flu and was taking it easy. The next day the neighbor found her unconscious on the floor. Instead of the flu, she had a systemic infection that she just couldn't recover from. She never regained consciousness, which in the long term, I think is really probably for the best. There wasn't any long drawn-out painful period of decline as happens with some diseases. It was just, you know, one day she was herself and the next day she was gone.

But, we miss you Mom.

Arduino Foundations

And the one that's a bit more upbeat is I actually wrote a book called "Arduino Foundations." It's all about the things you need to know to start working with Arduinos. It's really kind of the pre-steps to your first project and it's broken down into three main sections.

The first section is about the hardware and electrical side of things. Answering questions like:

  • What is an Arduino and why would I use it?
  • How does it differ from other computers I'm familiar with?
  • What's voltage and amperage and watts and current?

    This section also talks about the tools needed to get started with an Arduino.

Next is a softer section going over what software is and the different things that make up a program particularly on an Arduino. All the basic commands are discussed and how memory is used.

And finally there's a setup and configuration section. In this section, I talk about how to set up a computer to work with an Arduino and how to select which model of Arduino to use from all the different options available.

If this sounds interesting to you, it's available on Amazon with a link down in the description.

Design changes

Now, let's revisit the design for this project for a minute.

In the first video, I talked about the need for 20 bits for all the output. Seven bits are needed for the seconds section, 7 bits for the minutes section and 6 bits for the hours section. In my prototype, I sent those in a single stream and that made for some messy code since the values weren't broken up into clean 8-bit values that are used by the 8-bit shift registers and internally in the memory of the Arduino. To clean up the code, I changed it to instead control each of the 595s individually, instead of chaining them together. This made the code much easier to read at the cost of using nine Arduino pins instead of just three.

After the video, as I thought about it some more, I realized that originally my idea to put all the unused bits at the end of the daisy chain was an unneeded constraint. There really was no reason for all the unused bits to be bunched up together. They could easily be spread out. This insight allows clean easy to read code and still daisy chain the shift registers together using only three pins on the Arduino. It's simply a matter of connecting the LEDs to the shift registers in a slightly different pattern.

This is a great example of the iterative nature of making things. Sometimes it's not our first or even second idea that sticks.

And this demonstrates the value of prototyping. By putting something together quickly, that's intended to be temporary, we can see the problems and work on better solutions without having a huge time or materials investment.

If you missed the first video in this series it can be seen up here and the next video will be down here when I get it released.

As always, go make something.

Perfection isn't required, fun is!

Friday, June 12, 2020

How to make a binary clock: design

Description

Want to make an Arduino project a bit more complicated than blink? In today's episode of House of Hacks, Harley starts a project on how to make a binary clock. This project will use an Arduino and be presented in multiple parts. Today, the first part will be the overall requirements and design. In future videos, the software, circuit and finishing it off with an enclosure will be covered.

Resources

  • All the information to make this project: https://www.house-of-hacks.com/p/arduino-project-binary-clock.html
  • If you just want to buy one: https://amzn.to/3eGXFVD (Amazon affiliate link)
  • Get a digital version of the new Arduino poster by signing up for the House of Hacks newsletter: https://list-optin.house-of-hacks.com/arduino
  • Or a printed copy of the poster can be bought on the House of Hacks store: http://store.house-of-hacks.com

Contents

  • 0:00 Project introduction
  • 0:59 Welcome and about House of Hacks
  • 1:19 Description of BCD
  • 2:14 BCD for binary clocks
  • 3:05 Project requirements
  • 4:02 Controlling the LEDs
  • 5:45 Tracking the time
  • 6:18 Adjusting the time
  • 7:23 Arduino selection

About

Here at House of Hacks we do tutorials, project overviews, tool reviews and more related to making things around the home and shop. Generally this involves wood and metal working, electronics, photography and other similar things. If this sounds interesting to you, you may subscribe here.

If you’re interested in learning more about the House of Hacks' values, here’s a playlist for you.

And here’s the most recent video.

For a written transcript, go to How to make a binary clock

Here's a list of the tools I use.

Music under Creative Commons License By Attribution 4.0 by Kevin MacLeod at http://incompetech.com.
Intro/Exit: "Hot Swing"

Transcript

A number of years ago, at a software conference, one of the evening activities as an outing to a hands-on science museum.

While there, I noticed and picked up this binary clock.

It uses something called BCD encoding and I thought it'd be kind of cool to make my own version of this as a project.

Technically, it could be done with some simple logic circuits and a timer.

But this would involve more hardware design and wiring than I wanted to be involved with and so I'm going to go the easy route and use an Arduino.

This is going to be done in four parts.

Part one today is the basic requirements and design.

Than as I'm waiting for parts to come in, I'll go over the software design and how to actually do some testing without having a complete circuit finished.

The third video I'll assemble all the circuits and get it running.

And then the fourth video will be creating an enclosure for it.

Welcome to the House of Hacks. If we’re just meeting, I’m Harley and I make stuff out a variety of materials.

For example, in this project, we're doing design discussions, and software and electronics and mixed media for the enclosure.

If making a things out of a variety of materials in the workshop is something that's your thing, consider subscribing and you won’t miss future episodes.

BCD is an acronym for Binary Coded Decimal and this was an encoding system that IBM came up with nearly a 100 years ago in the 1920s for use in their early mechanical devices.

As early computers came on the scene, they took this basic coding that they used and expanded upon it to use in the computers.

It was called EBCDIC at the time and was actually used until relatively recently.

Interestingly, early in my career, I had to write an ASCII to EBCDIC conversion routine for use by our business partners.

Before going to the whiteboard, a couple notes.

First, the code and schematics for this project, is available for free download off of GitHub.

And second, a commercial version of this clock, kind of like the one that I picked up at the conference, as well as all the materials I'm using in the project are available on Amazon. I’ll leave links for everything down in the description below.

In BCD, each column represents a decimal digit, coded in binary. The first column is the tens digit for the hours, the second is the units column for the hours. Next, we have the tens and units digits for the minutes and the tens and units digits for the seconds.

In decimal, we need four bits to cover the all digits 0-9 in binary. So all the units columns on the LEDs have four LEDs. Because on a clock, none of the tens digits go all the way to 9, we don’t need a full 4 bits for each of the tens columns. Hours for example only go to 2, so we only need 2 bits for a 24 hour clock. The minutes and seconds only go to five so we only need three bits for those.

So, to make this, what are our requirements?

For the LEDs, we have 3 groups of 4 and 2 groups of 3 for a total of 18 and another 2 for a total of 20 LEDs that we need to control.

Second, we need a way of keeping track of the time.

Third, we need a way to set the time.

I’ll talk about all these requirements in detail but first I’m excited to announce that I’m working on some Arduino training materials. I have an Arduino reference poster available now and am working on a book for people new to digital electronics and programming the Arduino. A digital version of the poster is available by just signing up to the House of Hacks mailing list where I’ll keep you updated on things happening here. I won’t bombard your email with a bunch of stuff. Just occasional updates when products are released and an occasional news item that I think you might find interesting related to making things. If you’re interested in this, there’s a link below in the description below.

Now, back to the design...

Looking at controlling the LEDs, my first inclination was to think about this as a single string of 20 bits where each digit in each group was put inline with the rest of the bits. The common way of working with large numbers of LEDs is to use a '595 based shift register. This only requires three pins on the Arduino but provides a number of digital outputs. This is so commonly used that there’s a shiftOut command built into the Arduino ecosystem. ‘595 chips typically only work with 8 bits (although there are variants that have more bits) but they can be daisy chained together so you can have an almost arbitrary number of digital outputs, all controlled by only three pins.

Since there’s 20 bits needed and each ‘595 provides 8 bits, I thought about using three shift registers, daisy chained together. This would give 8 times 3, or 24, bits. The first 20 bits would be used and the last 4 bits would be ignored.

I coded up a prototype sketch using this idea but it ended up being more messy than I really liked. All the code was one big blob with a bunch of dependencies spread throughout the whole thing. Some of that mess could be cleaned up with some refactoring, but it was still going to be more messy than I really liked.

Upon reflection, I realized each group of two numbers only needs at most 7 bits and I have three groups. For the purposes of this project, I could still use the three ‘595s but instead of daisy chaining them together, I could connect each one to the Arduino directly. This would help make the code cleaner. Each ‘595 needs three pins, so that’d be a total of 9 pins for the LEDs instead of 3. Let’s look at the rest of the requirements and see if there are enough pins.

To track time, the most reliable would be to use a clock module. A real time clock module, also called an RTC, is designed to interface with micro controllers and has it’s own battery backup. There are a number of different models. I selected to use a DS1307 because they can be had inexpensively and communicate with the Arduino using only three pins over the I2C bus.

It would also be possible to use the Arduino itself to track the time although I’m not to sure how accurate that would be. It would provide a software only solution though.

Finally, we need a way to set the time.

The commercial unit I have uses two buttons. One increases the hour each time it’s pressed. The other increases the minute each time it’s pressed and if they’re both pressed at the same time, the seconds are increased.

This could work, but I don’t have any good buttons that’d be appropriate for mounting in an enclosure and, in my spare parts bin, I have a rotary encoder.

Rotary encoders come in different styles. This particular one allows the user to spin it in either direction without any limits. It can also be pressed to indicate an event. The micro controller can detect which direction it’s turned and take appropriate action.

I think this would be easier to make accessible to the user in the enclosure, so I’m going to use it. It uses two pins to the Arduino to communicate the rotary action and one pin to communicate being pressed.

So, all in all, I’m looking at using 9 pins for the three ‘595s, 2 pins for the clock module and 3 pins for the rotary encoder. A total of 14 pins.

Since I want to keep this pretty compact, I’m going to select the Arduino Micro. It’s only about 2 inches long and about 3/4 inch wide and designed to go in breadboards and pre-made circuit boards with standard hole spacing. And it has 18 digital I/O pins. Four more than then 14 that we need.

I think it should work well.

So, I’ll go order the parts and, while waiting for them, I'll show you the software in this video.

If that video hasn’t been released yet, I’ll see you in this other video where I do an Arduino project simulating wind to make wind chimes sound indoors.

After watching that, go make something.

Perfection isn't required. Fun is!

Friday, March 28, 2014

How to make artificial wind


Description
For Arduino Day 2014, I show how I solved the problem of enjoying wind chimes when there's no wind. Using an Arduino of course.

For a written transcript, go to How to make artificial wind.

Music under Creative Commons License By Attribution 3.0.
Intro/Exit: "Hot Swing" by Kevin MacLeod at http://incompetech.com
Incidental: "Feelin Good" and "Cold Funk" by Kevin MacLeod at http://incompetech.com

Transcript

Today at the House of Hacks, I'm going to try to make some artificial wind.

Hi Makers, Builders and Do-it-yourselfers. Harley here.

Over the years we've been give a couple wind chimes that are really nice. They're tuned to specific chords to be really full and resonating. They've got some beautiful wood on them and they're just too good to put outside in the weather and get all beat up. So we have them hanging here in the corner of the living room. During the summer they work really well. We open the house up and the breeze comes through, particularly the evening breeze, they fill the house with nice chimes. During the winter we close everything up and we just don't get to enjoy them. We've tried using an oscillating fan and haven't really been able to get this to succeed very well. The fan itself is very loud and makes a lot of noise. And we haven't been able to get it adjusted so that it has the right amount of turbulence to ring the chimes in a way that sounds pleasant, it's either not enough or too much.

I've had an idea floating around in the back of my mind for awhile to do this electronically. I thought this was a good time to try to do this. March 29th is Arduino Day. It's hard to believe that Arduino's been around for 10 years, but this is its 10 year anniversary--10 year birthday. I thought this would be a good opportunity to do a project that featured an Arduino and also solved a problem that I have. So let's go down to the workshop and see what we can dream up.

The idea I've had floating around in the back of my mind now for awhile is to take an Arduino, connect it to a servo motor and on the servo motor attach a pulley. To the pulley attach some monofilament thread and connect the other end of that to the wind chimes. So, when the pulley turns, it pulls back the wind chimes and then it releases them and they can swing. The Arduino gives us the ability to add some randomness in there to pull it back different amounts, to release it at different speeds, things of that nature, to give us some randomness and hopefully give us a nice pleasing sound that we have some control over.

I think what I want to do is have a total of 12 inches that it pulls on the monofilament thread. And I want to do that in a quarter turn of the pulley. That means the pulley circumference needs to be 48 inches. To get the radius to make the pulley we have the 48 equals 2 pi R. We need the radius so we divide 48 by the 2 pi. Well pi is pretty close to 3 for round numbers and that gives us 48 divided by 6 which gives us a radius of 8 inches.

So let's go build this.

A thin strip of scrap wood fills the need perfectly for an ad hoc 8 inch compass.

I mark the boundaries of the center based on the outside dimensions of the cardboard.

The center of the circle needs to be inside these bounds.

And now just draw the circle.

I cut the cardboard freehand around the marks. I needed 3 disks in total.

Since this is just a prototype, proof-of-concept, scrap cardboard and some hot glue make fast and cheap building materials.

Mark the direction of the corrugations so when the disks are glued together they can be rotated 90 degrees to each other. This will give them some strength.

Three circles, one slightly smaller than the others will make a rough pulley.

I've found hot glue is a great tool for fast construction.

Now I need to find the center. If I'd been thinking I could have placed the other side up and had the hole from the compass already marking the center for me.

A dab of glue attaches a small servo.

The servo is mounted in a hole cut to its size.

A couple weights holds the cardboard tight to the motor mounts while some glue is applied.

A spare piece of Romex wire will work as a mounting bracket for the Arduino.

The wire just slides into the corrugations of the cardboard.

And holds the Arduino in place.

The circuit is simple. The servo connects to the breadboard. To connect the servo to the Arduino, the yellow data wire goes to pin 9, the brown ground wire goes to ground and the red power wire goes to 5 volts.

And it's ready to test.

Load the example servo to sweep a 180 degree arc and upload it to the Arduino.

Fail!! It worked a couple times and then stopped. Something broke. I had to help it get unstuck on one side.

So I needed to swap motors. The first one I tried had a 1.6 kg/cm torque rating and plastic gears. The replacement is rated for 3 kg/cm and has metal gears. It's also quite a bit more expensive.

So I used screws to mount it instead of glue.

I still used glue for the pulley though.

And this works much better. No manual intervention required.

A dollop of hot glue holds the monofilament string in place.

Another piece of bent Romex wire acts as a guide for the string.

Load a slightly modified version of the sweep example.

And a real test…

Yay!! It works!!

For a hacked together prototype, I'm pretty pleased with the way this turned out.

If you're interested in seeing this prototype turned into a finished project, let me know down in the comments below what it is you find fascinating about this project, what you'd like to see in a follow-up video, that type of thing.

Until next time, go make something. It doesn't have to be perfect, just have fun!


And finally "Thank you" if you've already subscribed. You can configure YouTube to notify you when new episodes are available. If you aren't subscribed and you want to get those notifications, be sure to subscribe. It's free and contains zero calories. Finally, if you're interested in this series, go ahead and hit the "like" button, that'll let me know there's interest in this.

Thanks for watching and until next time, go make something. It doesn't have to be perfect, just have fun.