Using a Raspberry Pi Zero W to display Order Count

My wife has a shopify account where she takes orders for her online business (MyPaperdot.com). Because sometimes she’s knee deep into work, kids, etc, there are times where she won’t see an order come in until an hour or so after it comes in.

I decided to create a simple order counter that updates itself periodically. By using the Shopify API and a raspberry pi zero I got to working.

Materials

I used a generic pcb, a couple of resistors (330 ohm, I believe), a raspberry pi zero and case as well as a 3 digit 7 segment display.

20180401_220021

Connections

There are 7 connectors for the digits (that’s where the name 7-segment display) comes from. Each of the connectors needs to be connected to a GPIO pin on the Pi through a resistor.

There are also 3 other leads that will be connected directly to a GPIO pin (no resistor). Whichever is activated will make that digit turn on.

This is what the connectors look like:

You can choose any pin to connect the leads to so long as it is a GPIO pin. For reference, you can look here: https://pinout.xyz/

I have terrible soldering skills, but I tried my best to make it as tidy as possible. I used a proto-pcb and soldered the leads so that they would align to the GPIO pins when mated to the Pi.

This is how I test fitted the connections:

I then proceeded to solder the cables and resistors on the back (between the Pi and the PCB.

The next step was to put the Pi in the case, connect the PCB and finish soldering the connections.

The Code

Here is the code: https://github.com/robtrevino/piOrderCounter/blob/master/alerting.py

The Pi needs to know where you connected each of the leads of the display. You can see those in lines 18 and 27.

You also need to specify which segments are on and which are off for each number. You can see that being setup in lines 33 through 43

Shopify provides a very simple Restful API to read orders. I used the Requests package to make calls to the API, parse the results and then light up the proper segments to show the number. You can see these calls on lines 63 through 65.

Once we know what number we want to display, we need to tell the Pi to:

  1. Turn on those segments
  2. Turn it on only for that digit

The second part is tricky, because, for example, if you need to display the number 15, you need to turn on two digits, and you need to have different segments for each. The trick is to use something called persistence of vision to our advantage.

What this means in the code is that we will turn on and off each digit really fast. I found that 4 milliseconds gives a really good result (i.e. no flickering). You can see this being done in lines 53 through 59.

Conclusion

I hope you enjoy this project as much as I did and can find other cool useful ideas for the display!

How to turn your PiHole on and off with Alexa

I’ve used PiHole for a while now and if you’ve not used it before, I highly recommend you give it a try.

The only one issue with it is that when I do want an ad to display, I have to login to the interface and disable it. It makes it a pain. Especially because sometimes I like to browse deal sites that require referrer links that change often.

Enter my solution, create a smart home skill with Alexa that allows you to turn it on and off at will with your voice! It’s so simple! In reality, it’s a bit more confusing to create it, so I will use my experience creating a smart home skill for music box to create one for pihole.

Create Amazon account and Amazon Developer account

First, you need to create an Amazon account AND an Amazon developer account. The former is because smart home skills require you to do Oauth. Using “Login with Amazon” is the easiest, and since this going to be for your own personal use, you won’t have any issues with this approach. The latter is so you can create your smart home skill.

Create the lambda function and skill

Once you’ve created both accounts, follow this guide: HOWTO: Add OAUTH To Your Alexa Smart Home Skill In 10 Minutes. It goes through how to link your new skill (and create a blank lambda function, which we will modify later) to Amazon OAuth. By the end of it you should have an empty lambda function. Make sure the lambda function you create is Python 3.6

Modify the lambda function.

Download my source code then login to your AWS account and go to the lambda section where you will find the lambda function you created during the previous step.

Upload the zip file you downloaded. After it finishes uploading, you should be able to select “Modify Inline”.

Now you will see the code for the lambda function you imported. Modify line 4. and put in the IP address and port to your raspberry pi. This address has to be accessible over the internet. I use a DNS provider and forward the port using my router. You should be able to do the same. Also, keep in mind that you should really secure it with https so your token is not being sent out in plain text. It is out of scope of this write up, though.

Click Save.

Discover your devices

Now the fun part. Tell Alexa: “Alexa, discover my devices”.

You should now see the device under smart home devices on your Alexa app.

Control PiHole

Here are the commands you can tell Alexa to control your pi:

  • Alexa, turn on pihole
  • Alexa, turn off pihole

 

That’s it! enjoy simple turning on and off of your ads!

Integrating Musicbox Into Old Speakers

I had recently posted how to control music box on the raspberry pi with Alexa. I decided it would be fun to integrate the raspberry pi zero w into an old pair of speakers. That way, I could get the whole package and move it around the house.

I had these old creative portable speakers laying around. Luckily they are powered by 5V, so no need to step up or down for the pi. I took it apart to see what it had inside.

The speakers have a little cubby on the bottom that houses the batteries. I thought I would get rid of that since running the pi on battery is also not the best experience. I thought of grinding it down with my dremel later on.

First test fit. It seems to be fitting fine.

The raspberry pi zero does not come with a DAC. So I bought a $1 cheap one from China. I figured that if it was very bad I would upgrade it.

I took it out of its casing and sodered the 3.5mm leads together.

I then sodered the USB leads from the DAC to the USB pads on the raspberry and turned it on to try it out.

Test fit again.

The speakers come with a switch that is activated when you swivel the speakers into the base. It’s originally meant so that when you’re transporting them, they don’t get damaged. I decided to hook into this switch and pause/play when you swivel. So I soldered the lead into the pi’s GPIO.

I then dremeled out the battery cubby. It looks ugly without the battery cover, but no one is going to see it.

Success!

Adding an all-in-one water cooler to my PC

I recently built a new PC and wanted to add some water cooling to the CPU. When water cooling started on PCs (a long time ago) setting it up was complicated and required a lot of time and effort. Recently, the all-in-one (AiO) solutions have been very popular as an entry point for water cooling.

I decided to go with the Arctic 120 as it had good reviews.

The first thing you want to do is make sure your motherboard comes with a CPU backplate, this is the metal part behind the CPU. If it does not, you either have to purchase one or get one from the cooler manufacturer. Since my CPU uses the AM4 socket, and it is part of the spec, all AM4 motherboards come with a backplate.

Now the fun part begins, your cooler will likely look like such:

Put the case on its side and remove the screws that are holding the cpu/heatsink in place. Then make sure to wipe off any thermal paste with a dry paper towel.

Carefully add the standoffs to the backplate through the motherboard. These should have come with your cooler.

Make sure you have all the parts for your cooler.

Attach the first fan to it. This will be the inner most fan, not the one that will be in direct contact with your case.

Place the cold plate (the part that goes in your CPU) on the CPU after you’ve applied a pea-sized amount of thermal paste. Screw it into place. Take note of the orientation of the hoses as it may interfere with the placement of the radiator.

Now place the radiator where you want it to be on your case with the other fan in between the case and the radiator. Use the provided screws to screw it into place.

Do some cable management and admire your work!

PC Specs:

  • Ryzen 7 1700 @ 3.9Ghz
  • 32GB Ram
  • GTX 1080ti
  • Intel 600p NVME SSD
  • MSI x370 PRO Carbon Motherboard

Modifying My Daughter’s Power Wheels

So we got this power wheels as a hand-me-down. When my daughter tried it out it was OK, but I noticed it would slow down significantly when she went on the grass. My engineering self thought: “It needs more torque”.

Now, you could go on and see if the motor / plastic transmission can handle more torque if more amperage is supplied, but whatever, it’s a cheap piece of machinery anyway.

A while back I had bought a battery for the atv because when we got the atv it didn’t have the charger and, on ebay, it was cheaper to buy it as a bundle.

My plan was to wire the two batteries in parallel so the motor could get more current if it needed it. The circuitry is extremely simple. All it is is a motor wired to a battery with a switch in the middle. The obvious risk is that this thing can overheat and it will catch fire, but she never uses it alone, so I’m there, and honestly these are the same motors that are used in larger vehicles, so they’re over-sized for this application, so it’s unlikely this will happen. That being said, don’t do everything that you read on the internet.

 

The little atv holds everything under the seat.

It is a simple circuit with only a battery hooked up to a motor with a button/switch in between.

Test fitting the second battery, we can see how it fits neatly within the space. Now all we need to do is work on the wiring.

First order of business is to cut the connector from the original battery so we can splice into it. We will need to do this because we need to be able to take out both batteries at once for charging. The charger, by the way, is a simple trickle charger.

We add the connectors.

Then we just connect everything back up and close it! Now we get a lot more torque out of the small atv.

Pi MusicBox controlled by Alexa

For the longest time I’ve wanted Google Music support on Alexa. Being that Google and Amazon are mortal enemies, this is likely not going to happen any time soon.

A few days ago I saw the release for Pi MusicBox and decided to give it a try. I had never heard of this piece of software before, but the support for Google Music is what caught my eye. I set it up according to their documentation and I was up and running in no time. I love it!

The web interface is great, but I still wanted to be able to do some basic controlling through Alexa. Things like pause, stop, next, etc.

After going through the documentation for the smart home skills, it seemed like that was the solution.

Creating skills for Alexa can be confusing, so I’ll try to make it as easy as I can because I had a hard time figuring out myself.

Create Amazon account and Amazon Developer account

First, you need to create an Amazon account AND an Amazon developer account. The former is because smart home skills require you to do Oauth. Using “Login with Amazon” is the easiest, and since this going to be for your own personal use, you won’t have any issues with this approach. The latter is so you can create your smart home skill.

Create the lambda function and skill

Once you’ve created both accounts, follow this guide: HOWTO: Add OAUTH To Your Alexa Smart Home Skill In 10 Minutes. It goes through how to link your new skill (and create a blank lambda function, which we will modify later) to Amazon OAuth. By the end of it you should have an empty lambda function. Make sure the lambda function you create is Python 3.6

Modify the lambda function.

Download my source code then login to your AWS account and go to the lambda section where you will find the lambda function you created during the previous step.

Upload the zip file you downloaded. After it finishes uploading, you should be able to select “Modify Inline”.

Now you will see the code for the lambda function you imported. Modify line 4. and put in the IP address and port to your raspberry pi. This address has to be accessible over the internet. I use a DNS provider and forward the port using my router. You should be able to do the same.

Click Save.

Discover your devices

Now the fun part. Tell Alexa: “Alexa, discover my devices”.

You should now see the device under smart home devices on your Alexa app.

Control MusicBox

Here are the commands you can tell Alexa to control your pi:

  • Alexa, resume musicbox
  • Alexa, pause musicbox
  • Alexa, next song on musicbox
  • Alexa, previous song on musicbox
  • Alexa, stop musicbox
  • Alexa, fast forward musicbox
  • Alexa, rewind musicbox
  • Alexa, start over musicbox
  • Alexa, mute/unmute musicbox
  • Alexa, set volume on musicbox to <0~100>
  • Alexa, increase/decrease volume on musicbox <by 0~100>

This is one of the first skills I’ve ever created. I hope you guys find it useful.