Software Development Timesaver #6

Another timesaver for Git!

git checkout -

The command lets you checkout the previous branch you were on. Perhaps you are perusing the feature/102-description-of-feature branch, and decide to checkout to master. You can simply use the git checkout - to get back.

Reupholstering a Retro Armchair DIY

A few months back we moved into a new place. Everything was new and crisp, with white walls and white stained wood flooring. To add some character to the place we decided to decorate with fairly colorful furniture. The first thing we bought for the living room was a blue couch. We then wanted a simple armchair of sorts to complement the couch. Not long after, the chair had to be yellow and have velour chair cushions. And, used furniture are pretty popular nowadays. So yep, a simple retro yellow armchair. How hard can that be to find…

Turns out, pretty hard. Yellow velour fabric on retro armchairs are not that common, actually. The idea of doing some DIY upholstery had been brewing in my mind for some time, and this seemed to be the perfect opportunity.

In all, the project took around a week. Most evenings on work days and the weekend were spent working on the chair.

Armchair in it's new coat


Materials and Tools

Item Quantity Cost
Used armchair 1 $86
Staple gun 1 $11
Staples 8mm A shit ton $3
Yellow velour fabric 3 m $50
Yellow velour buttons 2 $5
Upholstery foam 3 m $25
Cotton batting 3 m $15
Upholstery nails 3 m $3
Denim sewing thread 1 $4
Curved upholstery needle 1 $3
Total   $205

These are the items bought specifically for the project. All materials were bought at Stoff og Stil, a sewing supply store in Norway. In addition to the items listed above, the project required some basic tools. A round nose plier, side-cutting plier, hammer, scissors and a screwdriver. I also used some wood glue and a wood cleaner/wax remover product. The tools all depend on what chair you’re working on, and what you have laying around.

Finding a Suitable Chair

We looked around online and in different used furniture stores. We finally found a chair at NMS Gjenbruk, a local thrift store, for around 700 NOK. Not that cheap, but it looked exactly like what we wanted. A simple Scandinavian style armchair. It did not have any upholstered fabric on the armrests, only the chair pad and back, which is good when you’ve never done anything fabric related before. The chair pad and back is challenge enough. So, go for something simple, if you want to attempt a similar project.

Used and tired armchair

Buying Supplies and Fabric

This step turned out to be hard to do in one go, even though I tried. I had to go back a couple of times for things I suddenly realized that I needed.

Materials

Dismantling the Chair

If you plan to do a similar project, remember this: Take a lot of pictures while dismantling the chair. As you can see from the pictures below, be meticulous in recording how the original upholstery work was done, in order for you to replicate it later. It will also serve as a way to determine the order of how the new fabric pieces should be attached. For instance, in my case the chair pad fabric should be attached after the back support fabric.

Photos taken to document upholstery work

Unscrewing base Underside of chair Removing fasteners from underside Knocking bolts out The chair is pretty old, which meant that the bolts holding the chair and the base together were hard to get out. I had to apply some force to a hex key positioned at the tip of the bolt, to get them out. Once out, I cleaned the brass bolts and fasteners in a water salt and vinegar solution. Later, I applied some grease on the bolts and fasteners.

Product label Found this underneath the chair. Product number 2383 and made by P.I Langlo factories. Nothing about what year it was produced, which I am a bit curious about.

Base and chair separated


Remove the Original Upholstery

Again, take a lot of pictures! In addition, remove the old fabric without destroying it, because you can use the original fabric as a template when measuring up the new fabric, batting and foam later.

Old fabric Removing back fabric A plate, that had a cardboard feel to it, was found underneath the fabric on the back. I managed to reuse it by carefully removing all the staples that attached it to the wood frame.

How it looks underneath back fabric Removing staples A lot of staples. Some of the staples were quite hard to get out. In order to get them out, I first split the staple in two with side-cutting pliers, and dragged each part out with the round nose plier.

Loosen staples from back plate Taking off back plate After having removed the cardboard covering, the interior could finally be seen. As you can see from the picture above, the buttons on the back support are secured by string and pieces of electrical wire. Which made me wonder if someone had reupholstered this chair before, maybe.

Removing buttons Removing staples from chair pad All staples removed from underside Uh oh! Another layer of fabric, which meant even more staples to pull out. This was also the point where I realized I maybe needed a layer of cotton batting, underneath the yellow velour fabric. This helped me secure the foam cushions, and can give the surface a more even finish.

How back support and chair pad fabric is attached at the back Shows how the fabric from the back support and chair pad is attached to the wood frame.

Back support side A lot of staples

Lost brick domino that’s where all the missing domino pieces go! Found it inside the frame of the armchair.

Stripped armchair First layer removed. Another layer to go! My hands were getting sore at this point from pulling out so many staples.

Furniture stuffing At this point I got my first glimpse of what furniture stuffing had been used. Something similar to needled wool felt.

Straws and hay as well It was much more surprising to find hay beneath the needled wool felt. Apparently, it is common to use straw as a base layer in furniture filling. I had no idea!

In the end I decided to replace the needled wool felt, since it smelled somewhat old. The straw, however, I decided to keep just because it looked very hard to remove. And it didn’t smell all that much, either.

Another look at the underside Details from under fabric Took a picture at this point to remember to staple around the hole where the bolts go. It seemed important.

Removing under fabric 1 Removing under fabric 2 Removing under fabric 3 Removing under fabric 4

Pulling out all those staples left a lot of small holes in the wood frame. I ended up applying some wood glue to fill them up. Not sure if that was necessary, but it sure felt good.

Cutting Foam and Attaching the Cotton Batting

Unfortunately, from this point forward I became a bit carried away, and did not take as many pictures as I should. Hopefully, there are enough to show how the new upholstery was added.

Foam fitting Here, I used the previous furniture filling to get an idea of how to cut the foam. I measured up the foam, drew lines with a sharpie, and did a rough cut of the foam. Afterwards, I put the foam on the chair and made some finer adjustments to it, as you can see in the picture above.

Foam 2  Batting After I was satified with the foam, I began working on the cotton batting.

 Rough cutting batting As you can see, I simply reused the old upholstery to get some rough measurements. I cut two large pieces of batting with scissors, that were more than enough to cover the back and pad. Any excess material I cut away after attaching it to the chair. It also helps having a large margin or seam allowance because the batting has a tendency to tear apart quite easily, and you want to pull very firmly on it when attaching it to the wood frame.

 Attaching batting on seat  Stapling batting Having an extra person to pull the fabric does not hurt, here. At least until you can properly attach one side. I started stapling from the middle of one side, pulling, holding, and stapling. I continued this process towards each corner, but would stop around 10 cm from each corner. Then, I switch to the opposite site, doing exactly the same. From the middle, towards each corner. I repeated this for the final two sides, as well. Finally, I secured the corners in a similar manner, pulling and stapling.

 Hammering loose staples Some of the staples did not go all the way in. So, I used a hammer…

 Batting seat seen from front side  Batting seat seen from back side The foam on the back support is extra long, since it wraps around the top edge of the wood frame.

 Putting batting on the back support Again, I pull firmly on the batting before stapling, starting from the center of each side, and work myself towards the corners. In the picture above you see me kind of, trying to, demonstrate it on a completed corner.

 Putting batting on the back support, side view  Putting batting on the back support, side view 2  The back before cutting batting As you can see, a lot of wasted cotton batting.

 After cutting cotton batting And finally, after having secured the batting to the wood frame, I simply cut away the excess.

 Cotton batting step completed

Cutting the Fabric

Basically repeat what you did with the cotton batting, but with much more accuracy. As you can see below, I utilized the previous fabric to measure up and cut the new fabric. I did leave a slightly larger seam allowance, just in case.  New yellow fabric and original fabric  During cutting There is not that much magic to it.


Attaching the Fabric with Staples.

Testing fit Testing the fit.

 New upholstery Or maybe there is a bit of magic to it. I managed to rip the fabric while attaching it to the frame, which meant I got to take the curved needle for a spin. The fabric had already been stapled to the wood frame, so it was a bit awkward sewing the rip.

 New upholstery  New upholstery  New upholstery  New upholstery The process here is exactly the same as for the cotton batting. From the middle, towards each side. Corners last. The only difference is that inaccuracies are now visible, so pull harder!

 New upholstery  New upholstery As you can see in the pictures above, I tried to fold the corners in a consistent manner.

 New upholstery I did end up having to cut some excess fabric. Especially from the corners.

 New upholstery  New upholstery I threaded some string on a needle, and poked holes in the fabric at around the same spots of the previous buttons. I did utilize a level and measuring tape to get the buttons on a pretty straight line.

 New upholstery To use pieces of electrical wire to secure the buttons was actually a pretty smart idea. Had to copy that.

 New upholstery You can now start to see some flaws in the upholstery work. Either I did not pull hard enough when securing the bottom side of fabric on the chair support, or I might have put too little stuffing in. Not sure why. There are also some issues on the bottom front of the chair pad.

 New upholstery  New upholstery The next step, was to reattach the cardboard plate. As you hopefully can kind of see (sorry, for the lack of pictures!), is that the fabric is wrapped around the plate, except for at the bottom. the fabric and plate were secured to the chair frame by staples and upholstery nails.

 New upholstery


Assembling the Chair Back Together

 Assembing chair  Assembing chair Basically, I glued the base of the chair, and screwed the base and chair together in one go. I let the glue dry overnight.

 Assembing chair

Final Polish

 Final polish Each corner has two prominent folds, that almost create hidden pockets. As a final polish I sewed these shut with yellow denim thread.

 Final polish

And with that, the living room became one yellow velour chair richer. It was a fun project to do, and it resulted in something unique. The chair took around a week to do, has some blemishes, but looks pretty good considering it is the work of a complete novice.

Thanks for reading!

Making a Bluetooth Numpad. Part 3: Enclosure

First, electronics, then software, and now woodworking. No wonder making a custom keyboard can be this exciting. In this part you will find mostly pictures of the process, including some remarks. Then, I’ll do a small conclusion of what worked and areas that can be improved upon.


Procuring Materials and Equipment

Not done much woodworking before, so I had to buy most of the tools and materials. I did manage to borrow a table saw and a miter saw. Below I’ll list everything:

Tools

Materials


Cutting the Frame

Unfortunately I lost the photos taken during the frame cutting. Basically, I scribbled some measurements on paper based on length and width of the metal plate. I adjusted the measurements to allow the plate to be inserted in a 2-3 mm groove in the frame.

The thickness of the oak plank will also influence these measurements. I only managed to find an oak plank that was 1,8 cm deep.

Finally I had to decide how deep the box should be. I ended up with 3 cm, which left some room for the lid.

Enclosure planning

As you can see from the scribbles, I’m not that good at planning. Had to do some improvisation along the way.

I used the table saw to cut apart a 3cm piece from the oak plank. Then, I cut a 0.9 cm groove along an edge with the table saw. This will allow the lid to be flush with the frame.

Frame pieces

With the measurements tweaked and finalized, I cut the fairly long piece of wood with the miter saw on a 45 degree angle.

This was not easy to get right. The wood was hard to cut, and I got a lot of tearout. I added some electrical tape to reduce this.

Frame

To create the lid I cut a really thin 0.4 cm piece from the oak plank. This piece was then parted into fitting lengths. Later these thin pieces were glued together, forming the lid.

Lid


Metal plate groove

This is the reason why I bought a dremel and a router attachement. I needed some extra precision to carve out the grooves.

I tested the router attachment first on a discarded piece of oak to get a feel of the device, and how to use it.

Test of router

Router attachment

Test groove

Unfortunately, I forgot to buy proper router bits for the dremel so I went over the wood in several passes with a bit that looked router-y. I clamped down the remainder of the oak plank and a discarded frame piece to my kitchen dinner table to keep the frame pieces from moving when cutting the groove. Luckily, it worked out well!

Finished grooves

This allowed me to test the fit of the frame. Not a perfect fit, but good enough.

Testing fit


Drilling holes for the USB and Switches

In one of the frame pieces I had to droill three holes. Two for the switches and one for the USB. The frame is pretty thick, so this meant a lot of carving and drilling. This was also a bit nerve wracking, since any errors would most likely be very visible, and could result in me having to cut a new piece.

First, I marked the spot where I would drill a 10 mm hole about halfway in. I used a nail with some tape to ensure I would not drill to far in.

Nail with tape

Testing depth with nail

Drilled switch holes

Then I switched from a 10 mm bit to a 6 mm bit and drilled all the way through. The neck of the switches is threaded and can be secured with a small fastener.

Drilling through the frame piece

Backside of piece showing 6 mm hole

Testing fit of switches

As you can see in the picture above, the threaded neck was not long enought to fasten on the other side. This meant I had to carve out an area from the inside of the wood piece. In the picture below a 10 mm hole for the USB connector has also been drilled. The router attachment came in handy here as well.

Cutting out an area to reduce the depth of the frame

Finally I did a lot a sanding of all the pieces, including the lid. Sanding

Sanding lid

I also added some electrical tape to separate the hand-wiring from the MCU.

Layer between matrix and MCU


Gluing the Mess Together

First, I glued a small piece of wood to close of the hole in the metal plate.

Hole in metal plate

The lid had to be glued together. Gluing lid

I, of course (did not almost forget), to test that the numpad still worked before gluing the frame to it. Testing numpad by connecting it to a computer and verified that all keys still worked using keyboardTester.com. The F13 and up keys were tested at this site.

Testing numpad one final time

The switches and the USB was fastnened to the top piece. Hot glue was used for the USB connector.

Switch and connector

Top piece with components

Hot gluing

Testing usb connector

Then, a final test of the frame. It fit, but not perfectly. Some gaps. Might have appeared because I sanded all the 45 degree surfaces. I probably should have avoided that.

Testing frame

Applied wood glue to all 45 degree angled surfaces. Should have used tape here to avoid glue squeeze out. But forgot, of course.

Applying glue

Clamps

After glue had dried


Finishing Touches

I noticed that the frame had pretty large gaps after the glue had dried overnight. I made some wood filler by mixed some of the sawdust with glue, and tried to fill in the gaps.

Gap

Wood filler

Dried wood filler

I glued the metal plate to the frame with hot glue. Hot gluing to metal plate to frame

Coated the frame and lid with hardwax oil. Did that twice. Coating wood enclosure with oil


Securing the Lid

After gluing and coating the frame and lid, the final thing left to do was securing the lid to the bottom of the frame.

After second coat

I drilled 3mm pilot holes in the lid and down into the frame. Done to prevent wood from cracking, and since the screws are really close to the edge of the lid and the frame.

Drilling holes for lid screws

brass screw

Furthermore, I had to sand away a bigger diameter around the holes to make the screw heads flush with the lid surface.

Lid secured

Found some adhesive rubber feet lying around, so I applied them to the bottom of the numpad. The device is finished. In it’s final form. The only thing missing now is adding some key caps to it.

Rubber feet

The key caps came in the mail a week after. Ordered them from AliExpress. Key caps

Key caps Key caps Key caps

A short video of the device in action, can be found here.

Conclusion

In conclusion, I would say the numpad is functional. It works. However, there are a lot of things that could have been improved.

  • First, the software is a bit unfinished. For instance, handling a press-and-hold of a key. I might do that in the future. Or somehow use existing keyboard software ported to Arduino.

  • The frame is also a bit wide for my taste. Originally, I aimed at an 1 cm wide frame, but had to later adjust since I did not find any oak material with that thickness.

  • Not sand the angled surfaces, or be more careful when doing that.

  • Adding a blue led to indicate if the numpad is in USB or Bluetooth mode would have been nice to have.

  • I could also have removed the switch that switch between USB and Bluetooth. This could have been done with a special numpad key combo that I could include in the software.

Including the tools and material bought to do this project, it is one expensive numpad! However, can’t set a price on having fun. Plus, productivity in Excel will go through the roof with this device!

Making a Bluetooth Numpad. Part 2: Software

This is part two of the build log. Now we turn to the software, which are gonna make this thing act as a numpad when connected to a computer. The code that runs the numpad can be found at this repo.

image of computer and numpad


Configuring the Arduino IDE

To load the software onto the Adafruit Feather 32u4, you’ll need the Arduino IDE. Out of the box the IDE does not support the Feather, so follow the setup guide to install the Adafruit board manager.

After you’ve installed everything, you can test the board with some of the example scripts to check that the board is working.


Simple Numpad Scanner Script

I implemented my own matrix scanner. First, to get a deeper understanding of how the matrix works, but I ended up later converting it to a library, that the main sketch utilizes to scan the numpad.

The scanner code was shown in the previous post (and can be found on GitHub, here). Note that I mixed up row and column. For instance, the activateOneRow should have been called activateOneCol. This mix-up was fixed in the library code, so please look at that if this code is confusing.

The code snippet has been left there to illustrate how I progressed from an empty sketch to a working HID numpad.


Converting a Script to a Library

Putting all the numpad code, in addition to the Bluetooth and USB code in one sketch would quickly turn messy and unmanageable. However, I had no prior experience with C and C++, so writing the library was challenging. I used this Arduino guide as a reference to write it.

I’ve mostly spent my time in languages such as JavaScript, Python and C#, so writing C++ was interesting. Below is a list of issues I had. I spent quite a bit of time on some of them.

  • Pointers.
  • Returning arrays from a method was not that straightforward, because of the point above.
  • Memory management felt a bit foreign.
  • Worrying about running out of memory.
  • Serial object not initialized before setup(), so calling print does not work, and using Serial to determine if board is connected to USB did not work.

However, I did create a library of some sort. If you want to use it, remember to put it into the /Documents/Arduino/libraries folder to use it in the Arduino IDE. In the section below, you can find a tip related to that.

Below I’ll quickly explain the public methods:

  • scan() - Scans matrix and records pressed keys.
  • getPressedKeys(int i) - Returns one of the pressed hexadecimal integer key code.
  • getNumberPressed() - Number of keys that have been pressed.

The methods above are defined in the Numpad.h header file. The header file also defines a matrix of hexadecimal integers that represent HID key codes. A table of all available USB HID codes can be found here.

I also tried implementing some sort of delay between the first and second character press, but here I failed. Instead, when you press and hold, only one character is sent. You will have to release and press again to send another character to your computer. This alternative approach works well enough for a numpad.


Arduino unfortunately likes to have all its libraries in /Documents/Arduino/libraries. This is a bit inconvenient when developing a library. In the beginning I did a copy and paste of the library from the code base into the libraries folder, whenever I did a code change. Did not take long before I got tired of doing that, and found a better way.

The solution is to create a symbolic link. Arduino will then always use the up to date library code from the code base.

How to creating a symbolic link:

  • Open cmd.exe in administrator mode.
  • Create a symbolic link by: mklink /D "C:\Users\equalpasta\Documents\Arduino\libraries\Numpad" "C:\Users\equalpasta\Documents\git\arduino-bluetooth-numpad\Numpad"


Power Switch and Battery

Since I will connect a battery to the board, I soldered on an on/off switch. This is done by connecting the ENABLE pin to GROUND through a switch. If the circuit is closed, the device does not operate. See here for more information.

switch


Bluetooth and USB Connectivity

The HID keycodes are either sent over Bluetooth or USB.

Bluetooth

  • Utilized example code that can be found on the board’s website. The HIDKeyboard example shows how to set up the board as a HID device, set the broadcast name, and how to send key codes.
  • I created a small wrapper for the Bluetooth code.
  • Basically, you use ble.print to send AT+BLEKEYBOARDCODE=00-00-00-00-00-00-00-00 commands. The latter 6 groups of number specify up to 6 simultaneous key presses.
  • After each of these you need to “release” the keys by sending an additional AT+BLEKEYBOARDCODE=00-00 command.

USB

  • As specified in the Arduino reference, 32u4 based boards can become a HID device. It also mentions NicoHood’s HID library that implements different HID devices.
  • I used the Improved Keyboard HID library.
  • Add Keyboard.begin() at the top. Sending codes are done by: Keyboard.write(KeyboardKeycode(numpad.getPressedKeys(i)));. getPressedKeys returns hexadecimal integers.


An Additional Switch for Bluetooth/USB

Originally, I planned to switch between Bluetooth and USB connectivity based on whether the USB/Serial was connected. This turned out to not be as easy as I thought:

  • Checking if Serial is initialized or not can work. Unfortunately, this check cannot be done in setup since Serial is not necessarily instantiated before setup is run.
  • No easy way to detect USB/Serial disconnect event.
  • You might want to charge board, while sending keystrokes over Bluetooth. So, you need to determine that the board is connected to a computer.

Basically, I ended up soldering on an additional switch, that controls how the numpad sends pressed keys. In each iteration of the loop method, switch is checked and the pressed keys are either sent over Bluetooth or USB:

int pressed = numpad.getNumberPressed();
  if (pressed > 0) {

    int mode = digitalRead(CONNECTIVITY_MODE);
    if (mode == BLUETOOTH_MODE) {
      sendKeysBLE(pressed);
      blueBoard.resetKeys();
    }
    else {
      sendKeysUSB(pressed);
    }
  }

switch

That’s it! And here is a video of the numpad working as a USB HID device.

All that remains is to get some nice keycaps and create a pretty enclosure. That will happen in the next post!