PiConnect [Concept]

I recently moved to a new house, and with a new house, there is a new system to adapt to. The two biggest changes that affect me the most are the new wifi and the sound setup.

First the sound.

The previous owners of the house put in this great speaker system that is wired for the whole house:

Bose Speakers

The main problem of this, however, is that the whole system is controlled from a rather old pre-amp:

House Preamp

Because of its age, we physically have to go and plug our devices into it in order to listen to music around the whole house (because plugging things in is so last decade.)

This isn’t that big of a problem, however, I feel the whole experience can be streamlined by making the whole system wireless, which will not only allow for us to play music as well as use our phones at the same time, but then my parents can’t make me get up from the sofa to plug in their phones.

Second, the WiFi.

I love this new wifi. I’m getting a 8ms ping, and 80 mbps both download and upload. However, with the new house, we need to have 2 wifi networks to cover the whole area (I tried to get my dad to just go with a booster, but he didn’t want to do that for some reason.) These two networks are fine with me, but the network that has access to all of the printers and other devices is just out of reach from my room, which forces me to go downstairs whenever I want to print something, which is rather annoying, considering I’m a student, and I make roughly 2-3 print trips per night.

My solution is to make the Raspberry Pi into a print server so I can print from my room. You might be asking, how will you be able to print if you can’t access the network that the Pi is on? I will be using Hamachi, which has worked great for me with the PiRoom and the PiVPN. That way, as long as I have some type of wireless connection, I can print to my printers at home.

Both of these projects should be fairly small, I’ve already done the research to do them. However, the Pi I currently plan on using for these projects is giving me problems, so I don’t really know when I can start with this project.

I’ll be posting all of my progress, so stay tuned.

PiVPN [Conclusion]

I finally got my OpenVPN system to start working, however, I was still having the problem that I didn’t want to connect to my VPN inside of my house in order to connect to my Pis.

My friend told me about LogMeIn Hamachi, which he used for making mini servers in Minecraft. After doing some research about it, I found out that Hamachi allows the computer to have access to the local as well as the VPN network at the same time, which is exactly what I wanted it to do.

I had to jump through a couple of loops, however, I got both my PiVPN and my PiRoom part of the Hamachi VPN network, and it works beautifully. This is how my system looks right now:

Hamachi Setup

If you notice, PiVPN isn’t there right now, it is actually experiencing some difficulties. Nevertheless, I can access my PiRoom from all of my devices and even get solid work done outside of my home network. Even though this wasn’t my original idea, I’m still going to mark this off as a success.

3D Printed Headphone Stand [Design Update]

I was looking at a couple of videos form LinusTechTips, and I stumbled upon his headphone design contest. One of the designs has a nice angle forward that gave it a very streamlined look.

Obviously, I wanted that.

I added a 45 degree cut to the end, and I’m really satisfied with the product:

Headphone Stand V3

I was a bit concerned that the printer wouldn’t print the angle, but my teacher told me it should be fine.

I plan to print this today, pretty excited!

All of my code is available at my github.

3D Printed Headphone Stand [Design]

I recently moved in to a new home, I decided that it would be a good time to finally have a place to put my headphones. I wanted to have a pretty basic headphone stand, at least for the moment; so I designed it on the bus.

I wanted to have something that would accomplish the following goals:

  • Hold my headphones (duh)
  • Make sure that the padding in the headphones doesn’t get compromised
  • Look fairly decent

For the basic concept, I thought that a half-log like structure would do pretty well to achieve the tasks. However, I also wanted to have a stand that would be rigid.

I decided on a design that would be placed on top of my desk, and screwed in. The main benefits of this design are that, although a bottom mounted stand would look A LOT nicer, all of stress would be on the screws that are holding the stand to the desk. Instead, I’m going with a top-mounted stand, in which 25% of the stand will rest on the stand, and there will be a little plate that gets screwed into the desk. This will make the stress more distributed and result in less of a chance of the whole structure breaking.

I got cracking, and made a basic sketch (This was done in OpenScad, if you are wondering):

Stand V1

My friend then pointed out that over time, the structure will end up bending, or from some impact to the stand, and the headphones have a potential to fall off (shoutout to @JonathanJalajas). To account for this, I added a little nub at the end so the headphones won’t fall off:

Headphone Stand V2

The way I programmed this, all of the values are variables, so the design will change very easily. I simply plugged in the numbers that I wanted (in mm), and hit the render button:

Headphone Stand Variables

The code for the model above can be found at my github:

https://github.com/agupta231/Static-Headphone-Stand

G.A.L.E. Concept and Idea

It has always been my dream to make a system such as J.A.R.V.I.S. Tonight, I decided to make that dream into a reality. I settled on G.A.L.E (Gupta Artifical Language Encoder) for the name of my system.

First, I’m just going to let this run in unison with my PiRoom project (this is the voice control aspect of it), however, if I have the time, I might be able to make it something more than that..

Stay tuned for more, I just decided on the name, and in the rush of excitement, decided to make this post :D.

Sleep / Unlock Keyboard Button Using AppleScript

As I mentioned before, I use the Microsoft Ergonomic Keyboard 4000 for my daily keyboard. I initially remapped three of the keys to control my Spotify, but I got intrigued by the power of AppleScript, and I tried to see what else I could do with it.

As I’m a huge fan of only using the keyboard, not a mouse (funny, because I’m using a Mac), I thought it would be cool to have an unlock button as well as a put to sleep button. After a little bit of research, this is what I came up with:

Sleep button:

on run {input, parameters}
	
	tell application "Finder" to sleep
	
	return input
end run

Unlock Button:

on run {input, parameters}
	tell application "System Events"
		keystroke "My Password!"
		delay 0.25
		key code 36
	end tell
	return input
end run

A side note, I changed my actual computer password with a placeholder (for obvious reasons). Although these programs may not seem impressive, they are not meant to be the next AI, but they are meant to serve a specific task, and they do it well.

You might also be thinking that having a button on your keyboard to unlock your computer is pretty risky, but the way I see it, my laptop is only connected to my keyboard in my house, and I don’t have anything on my laptop that I don’t mind anybody in my house seeing.

Controlling Spotify with Microsoft Ergonomic Keyboard 4000

This was done nearly a year ago, but I didn’t have this website then, so I’m just quickly rewriting my process over here. This whole project took roughly 30 minutes (5 minutes programming, 25 minutes on reading up how Applescript works.)

For my daily keyboard, I use the Microsoft Ergonomic Keyboard 4000:Microsoft Ergonomic Keyboard 4000

I like this keyboard in particular due to its shape: it enables me to type faster and more accurately for longer periods of time. However, the default hotkeys on the top are only meant to work with iTunes, and I use Spotify. I decided to change this by making three small Applescript programs to control my next track, previous track, and pause/play functions in Spotify.

The code for the following three is below:

Spotify Previous Track:


on run {input, parameters}
tell application "System Events" to get name of every process

if the result does not contain "Spotify" then
tell application "Spotify" to launch
repeat until application "Spotify" is running
delay 0.25
end repeat
delay 5
end if

tell application "Spotify" to next track
return input
end run

Spotify Play Pause:

on run {input, parameters}
tell application "System Events" to get name of every process

if the result does not contain "Spotify" then
tell application "Spotify" to launch
repeat until application "Spotify" is running
delay 0.25
end repeat
delay 5
end if

tell application "Spotify" to playpause
return input
end run

Spotify Next Track:

on run {input, parameters}
tell application "System Events" to get name of every process

if the result does not contain "Spotify" then
tell application "Spotify" to launch
repeat until application "Spotify" is running
delay 0.25
end repeat
delay 5
end if

tell application "Spotify" to next track
return input
end run

As I said before, these programs are extremely small, and they are meant to run quickly at a moment’s notice. I simply mapped this programs to my keyboard hotkeys, and I can now control spotify via my keyboard!

Building the Websocket Server

I was doing a basic outline of what I wanted this application to do, and I realized that I wanted a hardware switch for the lights as well as well as the software interface.

If there are two different interfaces, that means there will be a discordance with the hardware values compared to the web values for the lights. The only way then, to make sure everything is a-ok, is to make sure that the clients are always synced to the server, so the hardware values change the values on the clients’s webpages.

One easy and obvious solution is to simply refresh the webpage every x seconds with JavaScript, but that wouldn’t give realtime feedback, which kind of ruins the whole “home of the future” experience for me. I then looked into sending AJAX requests every x seconds, but realized that if I have more than 5 or so client webpages open at the same time, my pi would literally go on fire.

I could go around that by using a service such as pusher, which basically outsources the request to an off-site server, but I would rather buy a server than pay for a service such as pusher (huge fan of not buying things :D)

After a little more research, I found that the websockets are the way to go. They basically open a tunnel between the server and the client, where both the client and the server can communicate with each other in realtime. An easy application for this would be a simple chat application.

Since, my Pi is already built with Apache, I decided to use PHP to run my websocket server (plus PHP is the language I’m best at).

I used a library for the basic websocket functionality, which can be found here.

After that, I realized that I needed to run the PHP locally, not every time a client connects to the server. I then added another class and a small amount of code which can be run from the command line:

require_once 'WebSockets.php';

class Server extends WebSocketServer {

protected function process ($user, $message) {
$this->send($user,$message);
}
protected function connected ($user) { }
protected function closed ($user) { }
}

$server = new Server("localhost", "1738");

try {
$server->run();
}
catch (Exception $e) {
$server->stdout($e->getMessage());
}

I opened up the Pi and ran this file, which gave me the following output:

Output from Websocket Server

So far, it looks like the server is running smoothly. Now, I need to connect my client with my server and get them synchronous.

If you are thinking that this is overkill for a simple application such as this, that I don’t really need a hardware interface, I would have to tell you that a websocket is a lot more integral to the whole project than it initially appears. If there are multiple tabs open with the server control panel, and there isn’t a websocket set up, then the tabs would never be updated, which would be very confusing to the user. In this case, a websocket not only provides basic functionality, but also increases the expandability of the project exponentially.

Cosine Law Calculator

In my precalculus class, we had just gotten into the Law of Cosines and the Law of Sines. Granted this is an easy subject, but the pure amount of tedious work that goes into it is absolutely time-sucking. Instead I came up with a program which takes in 4 parameters, the sides of the triangle and one angle.

Since with the cosine law, you always know three of the four before mentioned parameters, you just plug 0 in for the parameter that you want to solve for. After that, the program will automatically rearrange the Cosine law and give you your answer. This is the source code for the program:

Prompt A
Prompt B
Prompt C
Prompt θ

If A≤0
Then
Disp "A:"
Disp √(B²+C²-2*(B)*(C)*cos(θ))

Else
Disp "θ:"
Disp cos((A²-B²-C²)/(­2*B*C))

End

A side note: I never use this on a test, as I always have to do work. I just prefer to use this on homework and word problems, as I already know the material, and want to sleep at a reasonable time :D.

Custom LED Lighting: Circuit Design

I still don’t have access to my Pi(s), but I decided to work on the electronics a bit so that I could hit the ground running when I do get access.

I’m thinking about using PWM (pulse width modulation) the LEDs from my Pi. I really don’t know how the stability will be affected with the pins running PWM for hours at a time, but I guess I’m going to find out.

Quick tangent about PWM. PWM basically turns the pins on and off really quickly to output a signal that isn’t 0% or 100% power. I will most likely be using the WiringPi or the pigpio libraries to pull this off with the Pi. However, the Pi only outputs 3.3v with it’s GPIO pins (not the 5v rails), which is not nearly enough to power the LED strip.

I decided to use 3 transistors, this allows me to still use the Pi’s PWM, and also let it deal with higher voltages. I could have gone with solid state relays, but I’m not really pushing that much current to justify the choice. I’m also aware of the added “lag” when using more parts, especially transistors, but I seriously doubt that this “lag” will affect the LED’s performance, or affect enough that the human eye can sense that something is wrong.

With all of this in mind, my current idea for the LED light controller is as follows:

RGB Controller Layout

I’m trying to do some research on whether or not I will have to cool the transistors, as they should theoretically be getting very hot. Also, it should be noted that the protoboard will be cut to be smaller than shown, I just didn’t know the size before hand. Hopefully I can get the parts ASAP and start building soon!