Thursday, May 30, 2019

Raspberry Pi Garage Door opener

I wanted to repurpose my raspberry pi to be a garage door opener.  I tried several different methods to make this work, but wasn’t happy with how it was coming out, so I came up with more-or-less my own easy custom solution that I wanted to share.

Of course, you have to start by setting up Raspian on the Pi.

Then, enable VNC, SSH, and the camera in the settings.

VNC makes it a heck of a lot easier to log in once you've put the pi in the garage.

There were three things I needed to add to my Pi:
A camera
A relay switch
and a reed switch


Next, there are 4 pieces of software to install:

1. Apache (will allow you to create a web page to control the pi from a phone)
https://www.raspberrypi.org/documentation/remote-access/web-server/apache.md

2. Webcam (so you can look and see what state the garage door is in, as a visual check)
https://www.raspberrypi.org/documentation/usage/webcams/

3.Node.js (allows for the algorithms to be written in javascript, my language of choice)
https://www.instructables.com/id/Install-Nodejs-and-Npm-on-Raspberry-Pi/
This one is a little tricky!  You have to follow the directions to get the exact right copy of the file for your Pi.  The full listing of available zip files is here https://nodejs.org/dist/v10.16.0/

Note: You may also have to install sudo apt-get install npm and sudo npm install

4. OnOff (this is the javascript tool that allows you to check the GPIO pin conditions)
https://www.npmjs.com/package/onoff


And then comes the wiring.  Your Pi has 40 GPIO pins to control external devices.


In short, you are going to use Java to look at the pins and either turn them on and off, or to evaluate whether the circuit is complete.

First the relay.  I pinned it to GPIO4, Ground, and a 5V

Pi Pin .  Relay input
2            VCC
 6            GND
7             IN2

(Note: in a previous version of this post, I noted the ground as pin 4; the picture was correct. I made a typo)






Then, I created a javascript that looks like this:
'use strict';

const Gpio = require('../onoff').Gpio; // Gpio class
const led = new Gpio(4, 'out');       // Export GPIO4 as an output

led.writeSync(1);
led.writeSync(0);

// Turn off after 3 seconds
setTimeout(_ => {
led.writeSync(1);
  led.unexport();    // Unexport GPIO and free resources
}, 3000);

Save it, and call it whatever you want - by running node yourfilename.js you will cause the relay to turn on and then off again 3 seconds later.

On the relay end, you want to attach two wires, which will open a circuit when the relay comes on.  The other ends of the wire attach to the opener itself, in my case to the left most screws.  When the circuit opens, the connection is shorted and the door opens or closes.  




Cool right?


For the reed switch, I pinned it to GPIO17 and a 3.3v



Note: I connected the wires to longer wires so I could run it across my garage.  Doesn't matter which is which on this end.


Then, I created a javascript that looks like this:
'use strict';

const Gpio = require('../onoff').Gpio; // Gpio class
const led = new Gpio(17, 'out');       // Export GPIO17 as an output

console.log (led.readSync());
if (led.readSync()==0) { console.log ("open")};
if (led.readSync()==1) { console.log ("closed")};

Save it, and call it whatever you want - by running node yourfilename2.js you will to see if the reed switch is closed or not - closed would indicate the door is closed.

And that is 99% of the work.

Next up is the html so that it will look like you want it to, and allow for "remote control"


Sunday, March 31, 2019

Classic kid reaction at the science center

Last year, we visited the franklin institute in Philadelphia. Fun and interactive place.

We watch a demo by a museum worker about liquid nitrogen. The kids were enthused and the persons patter was good.

One young boy (maybe about 10) was more thrilled than the rest. He was excited by it and kept shouting things back when she'd talk.

Toward the end she told everyone she had something we could all take home. The kid yells out "she's giving us liquid nitrogen!" And I can hear him telling his friends that he was planning to have fun at home.

The show ends and she tells us that we are going to take home nitrogen - and before she can finish he gives her a "see I told you!"

...and then she tells us to take a deep breath. We now have nitrogen in our lungs that we take home.

The kid stands up, points, and, at the top of his lungs, yells "she lied!"

Silence for a moment and then laughter among the adults.

I talked with the experimenter and had a good laugh. She has a good story to tell!

Saturday, March 30, 2019

My silly Starbucks story

I got an offer that if I made a purchase using my rewards account, I would get a free drink to use within 7 days.

I made the purchase ... but never got the drink. So I contacted customer support.

They advised me that I did get it, but that it wouldn't appear under rewards in the app, but rather on the card. I follow the directions and find it. Great.

Now I also get an instruction that the cashier has to enter a code at the time of purchase. Fine.

I go to use the award, tell the cashier, and....she redeems stars that I have on my account.

Well, it is what it is. I still have the other award. But I decide to reach out to customer service to let them know that it's hard to find and harder to use.

The person I contacted was very nice and apologized, and returned the stars. And I still had the award. Sweet.

I go to use the award again today. I explain it to the cashier, and she nods and says she's got this. And...proceeds to remove stars.

Ugh. I'm like "wait..." but it's too late. Stars are gone. So I explain it again, she apologizes and calls over who I assume is the manager. He tells me it was a mistake, and proceeds to refund me the cost of the drink to my card, which is more or less the equivalent of the stars, I guess.

Then he starts a new order and manages to enter the code and it works! Yay. He then tells the barista to only make one of them, not two.

But she's already made the first one, and thus only sees one and proceeds to make it.

So on this trip I have two drinks. They tell me to keep the other one, which isn't a bad play.

And in all, my free drink based on purchase resulted in 3 drinks and 125 stars converting to $5 in cash on my account.

So uhhhh. Yeah. #winning I guess.

Tuesday, March 12, 2019

Dumb comment of the day

Trump (or one of surrogates) said that we need to teach "both sides of science" in school.

Huh?

I'm pretty sure there's only one side. The other point of view is called bull shit.

Thursday, March 7, 2019

NYTimes: One More Time, With Big Data: Measles Vaccine Doesn’t Cause Autism

If there was any doubt whatsoever. 

A 10-year look at more than 600,000 children comes at a time when anti-vaccine suspicion is on the rise again.


Short. Sweet. To the point. That's the beauty Dave's iPhone.