Noise Maker – Ring in the New Year!

As I mention in my Kitchen Towel Rack post: I printed the Party Noise Maker by Works by Solo on my Prusa i3 MK2 at 240%. I first saw this Party Noise Maker on a youtube video by Joel Telling.

Well I should play the lottery! Check this out!

I knew I was going to be cutting it close because the filament roll was getting low, but wow! I can’t believe I lucked out! I don’t have a filament sensor, so it would have been a failed print. I was in bed and using the Printoid app to view the print and I saw some orange behind the extruder, so I thought… ugh a failed print!?!? So I threw on my pajamas and ran down stairs to my surprise! hahaha I’m seriously going to buy a few lottery tickets today! haha

If you want to see all of the photos and timelapse video click this link: https://photos.app.goo.gl/5rSxSfz2vPbDiil92

Once I get showered and dressed, I’ll go outside and test out the noise maker!

 

Kitchen Towel Rack

So we used to have two kitchen towel racks, but one broke a while back. I took the old one and measured it out and then sketched it on a piece of paper with the dimensions. Then I opened up Fusion 360, and created a couple sketches and here is what I came up with:

Once I’m done printing the 240% Party Noise Maker by Works by Solo on my Prusa i3 MK2, I’ll print this out and and upload a photo of the final results. I first saw this Party Noise Maker on a youtube video by Joel Telling.

Handling signal TERM in Python

I had an issue with the lights staying on after stopping the python script using start-stop-daemon, because I wasn’t handling the terminate signal that it passes to the script.

By default, when you call start-stop-daemon with –stop argument it sends a signal TERM (terminate). To handle this signal I created a class that registers a callback method for signal.SIGTERM. That method then sets a flag. So when start-stop-daemon is called with the –stop argument it will call the method and set the flag. In my main while loop I now check that flag and if it is set then I quit the code and clear the GPIO pins.

class CancellationToken:
    cancel_now = False
    def __init__(self):
        signal.signal(signal.SIGINT, self.exit_gracefully)
        signal.signal(signal.SIGTERM, self.exit_gracefully)

    def exit_gracefully(self,signum, frame):
        self.cancel_now = True
...



while not request.cancel_now:
    #do stuff here... and stop once the service receives
    # a TERM signal

Turning a python script into a service

So now that I have my build lights I want the python script that controls the lights to be setup to run as soon as the RPi is turned on. So I needed to find a way to setup the python script as a service. I found a REALLY good blog post by Stephen Phillips on how to do this pretty easily.

It worked great! I only noticed one issue that I still need to investigate. If I stop the service the GPIO channels are not closed properly, so the lights will stay on.

Here are some things I’d like to do next:

  • I need to incorporate the code for the TeamCity Provider, so it will query a TeamCity build server (instead of the current test code).
  • Since, I don’t have a TeamCity build server currently I’ll need to make a synthetic or stub service that provides sample output from a TeamCity Build box.
  • Then I would like to build out other providers beyond TeamCity, so it could work with CC.NET or VSTS continuous build servers.
  • Once I create those, create a Python Service Locator, so based on configuration it will choose the correct provider.

Build Lights

A few years back I created some build lights for our Continuous Integration (CI) server. You maybe asking “What are build lights?”. Well in a continuous integration server every time a developer checks in code to a source control repository it triggers an event on the CI server. The CI server will typically download the latest code from the repository build it and run all the unit tests. If all the test pass then it will typically copy the latest code to your development environment. If it fails people want to know ASAP, so they can fix whatever broke the build.

Build lights are the physical signal of whether or not all the unit tests have passed or they have failed.

When I built this project 3+ years ago I used a RPi to query our TeamCity CI Server using their XML REST based API. I wrote a script in python that polls the status every N seconds. If ANY of the unit tests fail a red LED would light up! This was the signal to the developers AND the project manager something was wrong. The best part was seeing how the other developers reacted. We had a number of unit tests that were failing for weeks and no one was fixing them, within 2 hours after I setup my RPi with the build lights the developers on the team had fixed ALL of unit tests that were having issues! 🙂

After that it was like a challenge to see who would fix the issue when the light would go red. In fact, the project manager would even jump in and ask why is the light red? It was amazing to see the effect it had on the team!

The reason I bring this up today and I’m blogging about it is… I’ve finally got around to hooking up the RPi to a stop signal that I bought on Amazon. To hook up a RPi to mains voltage I used a SainSmart 4-channel 5V relay.

Check out the video! 

Updated: Motion Detection

Over 3 years ago I augmented my home security system with a Passive Infrared Motion (PIR) sensor and placed it at the front door. I quickly put together a Python script that runs on a Raspberry Pi (RPi) computer.  Basically it sends and email and triggers a IFTTT event whenever there is movement (detected by the RPi GPIO library) by the front door.

Side note: If you haven’t checked out IFTTT I highly recommend you check it out, there are a LOT of really cool things you can do with it.

There has been an issue with the sensor sending multiple text messages per “event”. This is due to how I wrote the code to handle the event detection with a callback. This would allow for multiple events / threads to be fired per movement in rapid succession. There are many ways I could handle this issue.

  • I could do some low level locks around the global variable
    • pro: control the date variable that’s being used by each thread
    • pro: very granular level of control
    • cons: more difficult to code
    • cons: more prone to errors
  • I could add all events into a global in-memory and loop on the main thread over the queue
    • assumption: there is a thread safe in-memory queuing library in Python
    • pro: easy to code
    • pro: could add extra functionality easy per event (e.g. logging messages)
    • con: need to find a thread safe queuing system
    • con: might be overkill
  • I could listen to different events that don’t run on a seperate threads
    • pro: after looking over the RPi GPIO (General Purpose Input Output) documentation again. It seems there are other events that might be more suited to the task.
    • cons: the events I’m looking out would likely miss the extra events that are triggered, but who cares! 🙂

I’m leaning towards the last option. I’ll start with that one tomorrow and see how it goes, and update the blog soon.

 

Update:

Okay, so updated the code. Haven’t checked it into GitHub yet and it is working well. I’m not getting the multiple notifications within the same second. However, I’m still get false positives on occasion. So since this is hardware, I thought maybe something is up with the voltage. Especially, since my RPi is about 40+ feet from the PIR sensor. I got the multimeter out and it was reading a constant 3.2V, so I think that’s fine. What I did notice was the connections were pretty loose, so I tightened those up a bit and we’ll have to wait and see if I still get those false positives.

https://photos.app.goo.gl/Kt5yd05WI6UQSVlE3

 

Linear advance

If you have a Prusa i3 MK2 or later, since April this year the latest drivers/firmware were released that allowed for linear advance. What does this mean? It’s an algorithm that allows you print faster with the same and/or better quality that slower prints. Okay, that’s a bit overly simplified, but if you’d like to read more I’d go to this article by Matt Harrison.

Here is an example below. I printed this at 90mm/s and this was before I cleaned up the supports. This is Ziro Marble PLA I purchased from Amazon for $22 for a 1kg spool. Pretty good price and the print turned out great!