Google Analytics

Sunday, December 31, 2017

An updated version of my Clock for Kids

Now that my daughter is 5 and is able to tell time, I wanted to make a new clock for my 3 year old son. Since my first prototype was green, I passed it down to my son and built a new pink clock for my daughter.  Just like v1, v2 does not change any of the functionality of the clock itself, it only adds an RGB LED.

Here is the link to my first version. It was powered by a Raspberry Pi Model B (not B+).  Now that the Pi Zero W is out and it fits perfectly inside of these clocks, I decided to use it for v2.  The clock is the same Walmart alarm clock as the first one.  Here are some of the photos from the build process:

Obligatory finished product image first.



The BOM is a clock, a Pi Zero W, MicroSD card, and a Shiftbrite.  
A Neopixel could be used instead but the Shiftbrite is far brighter.


The opening of the "light cone" needed to be enlarged to fit the new LED.  My Dremel to the rescue!


The wiring for the Shiftbrite and the 3.3v to power the clock's internals.






I used the 3.3V line of the Pi to power the clock. The Shiftbrite works on 5V, so I had to run a lot of different wires for everything.




The Pi Zero W fits in the clock perfectly.

A notch cut out of the back to power everything.



The final fitting.


Again, I used pretty much the exact same software from my GitHub repo. The only real difference between v1 and v2 is in the hardware. Instead of a 3.3V power supply crammed into the system, I used the voltage regulator on the Pi itself so it only needs power input and does not require external wires like v1.

I'll update this post with photos of the clock operating.  Also, I'll be posting soon on how to integrate everything with Google Home. It's very nice to be able to tell Google Assistant to tell the kids it's time for bed.



I'm happy to answer any questions that you might have.  If this has helped or inspired anyone, any donations will be very appreciated and will result in more cool stuff being built and posted here. Thanks for checking out my project!


Friday, December 9, 2016

DIY Ambilight version 3.1 (and 3.0)

Hey everyone!  I've updated my DIY Ambilight and wanted to share some of the details!




   

   


In 2011 I published my instructions for a DIY Ambilight.  This was a few months before Phillip Burgess published instructions on Adafruit's site.  So while I may have been one of the first to build this, others certainly did a MUCH better job than me.

I wanted to put instructions out for anyone that is is looking to build their first one or wanting to upgrade the one that they already have.  I'm really happy with the LED mount that I was able to put together and wanted to share that as well.  Now on to the tech!

I recently got a new TV which made it necessary to upgrade my DIY Ambilight. I had strand of 25 LEDs, but I added another 50 which necessitated a new build.  The display is 44.4" x 25.8" so I decided to make the LED mount roughly 40" x 23" to center on to the back of the display.  I used choice lumber from Lowe's for its finish and light weight.  The boards I used were 1x2s which are effectively 3/4" x 1 1/2".

Just like practically any other project like this, we start with an Arduino sketch.  I had some serious flickering issues with Adafruit's LEDStream sketch and started googling for a solution.  I tried changing the timing to a lot of different values with limited success.  Somewhere (and I cannot find it again) someone had posted a copy of the LEDStream sketch modified to use the FastLED library.  I found that it worked flawlessly.  If I track down the original author will will certainly give them credit.  You can find the modified file here: LEDStream with FastLED lib.

Once you have that loaded on your Arduino, you can hook up your LED strand and start pushing values.  I use boblight still and you can find an amazing Boblight Configuration Maker here.  If you are on Windows, I have a setup for a friend that works amazingly well using Prismatik.  You can find a 50 LED Prismatik configuration as well as my 75 LED boblight configuration in the same GitLab repo as the Arduino sketch.

Now to the really fun part - the LED mount. Please observe my first and terrible attempt at a 75 LED mount:

Version 3.0.  I'm not happy with this at all.

Pointing the LEDs straight at the wall "worked" but it could be a lot better.  I wanted the LEDs pointing out at a 30° angle from the back of the display. After a lot of experimentation, I found that building such a setup was not obvious.  I had a miter saw but not much experience with it.  Then I found that a miter saw calculator existed!  If I cut the boards with a blade angle of 37.8° and a miter angle of 26.6°, I could make exactly what I wanted.  The depth side of the frame boards came together at a 90° angle while the width of the boards is angled out at a 30°.  It's hard to explain, but here are some photos.
Then I needed 2 boards to attach to those angled boards in order to attach it to the VESA mounts on the display. This required building a 60° jig.






 Here's how everything fits together.






Additional components needed:
  • A 4+ Amp power supply.  I like the ones from uxcell like this
  • A relay to turn the LEDs off when the TV is off. I plug it in to the USB port on the TV and the TV powers the port down when you turn it off. You can go the homemade route or buy one.  The uxcell power supply whines when the DC power is cut off so I'm going to switch the relay from breaking the DC circuit to the LEDs to breaking the circuit on the AC line. Be sure your relay can handle the load you will put to it!
  • Hot glue.  I really like the Gorilla Glue hot glue sticks. They are perfect for attaching the LEDs without damaging them so you can repurpose your LEDs later. You could also drill 2 small holes on each side of the LED and attach them with zip ties.
  • A way to mount the components to the frame.  I like Command Strips with velcro. 
  • 4x metric bolts for the VESA holes in the TV
The final setup looks like this.






Thanks for checking out my project!  Please post any questions and I'll do everything I can to help.


Wednesday, October 26, 2016

Wish you bed had LEDs that turned on when you got up so you didn't stub your toes on your dresser?

Duh.



Here's how I did that.

A rough diagram explaining the components.

My bill of materials

  • Pi Zero (With USB Wifi dongle and MicroSD card)
  • 2 PIR sensors
  • 2 momentary push buttons 
  • 5v 5A power supply
  • Strip of Neopixels (150/5meters)

The premise is simple.  Detect motion, use math to figure out if it's dark outside, and if so, turn the lights on until there is no motion for about 5 minutes.  2 buttons have been added so you can turn it on and off on demand.  

You can find a the code and documentation here: Dhowdy on GitHub



And, of course, a video of the LEDs turning off


Please post any questions below!  Enjoy!

Monday, May 23, 2016

Update to VM_URL_Passer

Adding a simple bit of authentication to the VM URL Passer scripts.

Edit: Updated code can always be found on my github: https://github.com/dhowdy/VM-URL-Passer/


I got tired of network scans causing my script to open new Chrome windows, so I'm adding a bit of authentication.  Keep in mind that all of the data is still passed in cleartext, so this is not making it more secure to people wanting to force you to check out a website with a horrible photo but rather causing innocuous port scanners to not cause random popups.  

The updated client and server is as follows:

VM_URL_Passer_Server.pl

#!/usr/bin/perl
use IO::Socket::INET;

# auto-flush on socket
$| = 1;

# creating a listening socket
my $socket = new IO::Socket::INET (
    LocalHost => '0.0.0.0',
    LocalPort => '7777',
    Proto => 'tcp',
    Listen => 5,
    Reuse => 1
);
die "cannot create socket $!\n" unless $socket;
print "Running on port 7777\n";

while(1)
{
    # waiting for a new client connection
    my $client_socket = $socket->accept();

    # get information about a newly connected client
    my $client_address = $client_socket->peerhost();
    my $client_port = $client_socket->peerport();
    #print "connection from $client_address:$client_port\n";

    # read up to 1024 characters from the connected client
    my $data = ""; 
    $client_socket->recv($data, 4096);
    my @datastring = split('~~',$data);
    if ($datastring[0] eq "myweakasspassword"){
         print "received data: $datastring[1]\n";
         system("'/usr/bin/google-chrome' \"$datastring[1]\"");
    }else{
         print "Wrong password.";
    }   

    # write response data to the connected client
    $data = "ok";
    $client_socket->send($data);

    # notify client that response has been sent
    shutdown($client_socket, 1); 
}

$socket->close();

url_tcp_client.pl

#!/usr/bin/perl
use IO::Socket::INET;

# auto-flush on socket
$| = 1;

# create a connecting socket
my $socket = new IO::Socket::INET (
    PeerHost => '192.168.100.100',#IP of the host machine
    PeerPort => '7777',
    Proto => 'tcp',
);
die "cannot connect to the server $!\n" unless $socket;
print "connected to the server\n";

# data to send to a server
my $req = "$ARGV[0]";
my $pass = "myweakasspassword";
my $data = "$pass\~\~$req";
my $size = $socket->send($data);
#print "sent data of length $size\n";

# notify server that request has been sent
shutdown($socket, 1);

# receive a response of up to 1024 characters from server
#my $response = "";
#$socket->recv($response, 1024);
#print "received response: $response\n";


$socket->close();


The only real change is that the client now sends a "password" to the server separated by two tilde (~~).  The server splits the string into an array on "~~" and treats the first part as a password and the second as the actual data.  

Again: this isn't secure, but it doesn't really need to be.  Just a quick hack to make VMs a little bit more usable.

Wednesday, October 21, 2015

Opening a garage door from the Internet

Who wouldn't want to be able to control their garage door over the Internet?  No one, that's who.

I've recently mounted a 7" Android tablet in my wife's car to control navigation, music, realtime ODB II data, and various other tasks.  My wife then asked if she could control the garage door with the tablet.  "Well..... you can, but I have to build something to do that."  "Ok, then build it."

The requirements of the build are as follows:
  • It must give the status of the door (open/closed/unknown)
  • It must be able to toggle the status of the door
  • The WAF must be very high
  • It must work with at least Android, but all platforms would be ideal 
  • It must be secure since it's Internet facing
  • It must be reliable and therefore simple

The obvious place for me to start is with a Raspberry Pi - it's cheap, has network connectivity, runs Linux, and I have a spare sitting around the house waiting for a project.

It also seemed logical to make this as a web app instead of a native Android app so 0) it would be instantaneously up to date, 1) it wouldn't cause any battery drain from having to check the status every 30 seconds to stay up to date, and 2) for me, a web app is much easier to develop.

My garage door (like most) has a simple mechanism to trigger opening and closing the door.  Simply short two pins via a push button or, in this case, a relay.  The problem is that a Pi can't activate a relay directly with GPIO.  Well, not safely anyhow.  So we need to a very small amount of power to trigger an NPN transistor in order to trip the relay.  Since I'm using a 5V relay, I can safely pull that voltage from the 5V pin on the Pi.  The diode is there to prevent damage to the Pi when the field from the relay's coil collapses.

The electronics are pretty straightforward. A transistor activates a relay to open and close the door and 2 magnetic switches report the door's status back to the Pi.


The 10K resistors are there as pull up resistors.  Basically it makes GPIO pins 23 and 24 read as "high" unless the switch is activated.  Once the switch is activated the voltage goes to ground and the pin goes "low".

If you look at other projects on this page, you'll notice that I'm a big fan of using Cat5.  It's great: it's cheap, reliable, and able to carry signals over long distances without degrading.  In this case I ran 1 line of Cat5 to the garage and split 3 pairs off of it. The blue pair go to the garage door, the green pair go to the "opened" switch, and the orange pair go to the "closed" switch.

I decided to use 2 different switches instead of one because "not closed" or "not open" is not good enough for this project.  I wanted 2 switches to be in agreement as to the state of the door.  These are cheap door switches from Amazon - about $7 for a pack of 5 but they work great.


The activation circuit.  The blue and blue/white wires go to the garage door.


The switch to confirm that the door is opened

The switch to confirm that the door is closed

I simply soldered the resistors inline instead of bothering with another PCB.
Heatshrink tubing is awesome.
The finished hardware on a shelf in the basement (where no one can see it).
Now on to the software!

I used Inkscape to generate the SVG that I used to display the status of the door.  This project was largely an exercise for me to learn a little about CSS and SVGs.  This is the first thing like this that I've done from scratch and I know that there's room for improvement.  Please share ideas in the comments section if you have any constructive insight!

The idea is that the SVG will have either opaque or transparent doors depending on the status of the magnetic switches when the page loads.  When clicked, the SVG will have an animation of the doors either going up or down.  Once the animation is complete (which gives the door plenty of time to open or close) the page will refresh showing the status of the door as a confirmation. 



The code can be found on my GitHub account here: https://github.com/dhowdy/GarageDoor.

Security is accomplished via Apache with ModSSL and basic authentication.  The guys at DuckDNS and PortForward have everything that you need to access your Raspberry Pi from the Internet.  


Lastly, I have to say thank you to to Kevin Sangeelee for his great write-up on using a Pi's GPIO to activate a relay, Justin McCandless for patching jQuery's GLARING lack of SVG class support, and to Nate Krofft for giving me a huge hand with some of the CSS.  And, since I know that I'm going to get a lot of this... I know that I'm not the first person to do this; I simply wanted to share *my* way of doing this with everyone in case it can be helpful to someone else.

Thanks for reading!


Sunday, February 22, 2015

Building a clock to help kids tell time

My daughter is about 2 1/2.  She loves learning about colors, shapes, animals, dinosaurs, and all sorts of other things.  However, she's still too young to understand how to read a clock.  But now is a good time to start teaching her.

We wanted a clock that would change colors based on what it was time to do: play quietly, go to bed, get up and play, pick up toys, and so on.  Here is the result:



Alarm clock next to the baby monitors and entertainment center.



To start, I purchased a wife-approved, battery-driven clock from a local retailer for about $10.  This one was perfect for me: it has plenty of room inside, a nice, big face, some weight to it to hold it in place, and, to top it all off, it matched the wall.

OK, enough introduction, let's get down to it.  I've got a Pi running a baby monitor (another project, another write-up, but the LEDs in the lower left corner are a super bright infrared spotlight for night vision on the cameras), so I'll be driving it from that. And I've got some ShiftBrites leftover from version 1 of my DIY Ambilight (scroll down for more info on that project).  Perfect.  Let's build.

First, I needed a power supply.  Since we have an excess of USB ports, that's what we'll use.  I've already built a power supply based on the LM317T and it's been running for 7 or 8 years now.  Using this basic schematic, I built the power supply to take a 5V input:
(credit to http://kb.kaminskiengineering.com/ for the picture)




(I know, my workbench is cluttered.  I do a lot of work on it.)
This power supply is going to supply ~3V to the clock internals and 5V to the ShiftBrite.

Now we need software to test with.  After I could not get this tutorial to work, I found Hive13's project on GitHub.  After playing with it for a bit, I compiled the C program and was getting good tests.  However, I could not figure out a dead simple way to to just set certain colors and the program looped until interrupted - all of this is great for what Hive13 and likely most people want to do with a ShiftBrite on a Pi, but I needed something different.  I forked his GitHub repo and made a few changes, namely the ability to push red, green, blue, purple, yellow, and cyan from the command line and immediately exit.  I also added an "install script" as well as a "crazyclock" script to cycle through the colors.  It's all kind of hackish, but since the code was written for only my specific example, I don't care - but sharing that code back to the community is still the right thing to do.  

Essentially, I just added 6 command line arguments so instead of only having "-c [0-255]" emitting a white color with the given intensity, I've added the following code:

printf("  -R: Set to constant color Red\n");
printf("  -G: Set to constant color Green\n");
printf("  -B: Set to constant color Blue\n");
printf("  -P: Set to constant color Purple\n");
printf("  -Y: Set to constant color Yellow\n");
printf("  -C: Set to constant color Cyan\n");
.
.
.
} else if (opt->mode == RED && opt->constant_value_red >= 0) {
img[0] = opt->constant_value_red;
shiftbrite_refresh();
return 0;
} else if (opt->mode == GREEN && opt->constant_value_green >= 0) {
img[1] = opt->constant_value_green;
shiftbrite_refresh();
        return 0;
} else if (opt->mode == BLUE && opt->constant_value_blue >= 0) {
        img[2] = opt->constant_value_blue;
        shiftbrite_refresh();
        return 0;
} else if (opt->mode == YELLOW && opt->constant_value_yellow >= 0) {
        img[1] = opt->constant_value_yellow;
img[0] = opt->constant_value_yellow;
shiftbrite_refresh();
        return 0;
} else if (opt->mode == PURPLE && opt->constant_value_purple >= 0) {
        img[2] = opt->constant_value_purple;
        img[0] = opt->constant_value_purple;
        shiftbrite_refresh();
        return 0;
 } else if (opt->mode == CYAN && opt->constant_value_cyan >= 0) {
        img[2] = opt->constant_value_cyan;
        img[1] = opt->constant_value_cyan;
        shiftbrite_refresh();
        return 0;

All of this is on GitHub, but essentially calling the binary with "-R 255" will turn the LED red at full brightness and immediately exit.  Simple and straightforward.

It's also worth mentioning that since this box is secure and I didn't want to mess with the proper permissions to grant other users the ability to use SPI, I just changed the setuid attribute of the binary to always run as root.  Again, this would should never fly in a production environment but in this case it's nothing to worry about.  

SPI pins on the Pi.  
Next is the case mods.  There was not enough room to put the ShiftBrite, so my Dremel helped me make it fit. 

 
Essentially from here, I just hooked the Vout pin of the LM317T to the clock's battery terminal lines and attached the ShiftBrite directly to the 5V line coming off of the USB cable.  Then I crammed everything as neatly back in to the case as I could.  I had to cut some pins and use some hot glue to insulate some things, but it worked.


There is a USB cable running in to the back for the power supply and a piece of Cat5e running out the back for data from the Pi.
The clock installed next to the baby monitor cameras.


The last thing is setting the clock color automatically.  I found a nifty little project called Minicron. Essentially, it's a client/server setup that modifies your cron jobs and sends the output back to the server.  It's simple, straightforward to set up, and perfect for what I need (given my lack of web development skills).  I installed it on my web server and on this Pi.  Then I just configure what colors I want the clock to be and when.


Additionally, I've configured ConnectBot on my wife's phone to have different connections that will just log in using a public key and execute "/usr/local/bin/clock -G 255" for play time or "/usr/local/bin/clock -R 75" to turn the clock red at reduced brightness for nap.  The cron job will take care of almost everything, but she needed the ability to change it on demand.  

So, that's pretty much it.  I'll be happy to answer any questions below.  



UPDATE: I realize that I forgot to mention that it is important to keep the clock and Pi synchronized.  Since I use Raspbian on the Pi, here's how I ensure it has correct time by using a Stratum 1 time server in my home town.

apt-get install ntpdate
service ntp stop
update-rc.d ntp disable
echo -e '#!/bin/sh \n/usr/sbin/ntpdate 0.ntp.mst.edu' > /etc/cron.daily/ntpdate
chmod +x /etc/cron.daily/ntpdate
service cron restart

This will get the Pi to update its time every day.  If you notice a skew over the course of a day (since the Pis lack a realtime clock) then you can just move this script to the /etc/cron.hourly folder.  If you do so, please us a different time server than this one.