Wednesday, January 10, 2018

Party Button 2018 Edition - Python controlled Relay, Momentary Push Button with Key Lockout

Asked for a launch button for Christmas. Thought it would be a cool thing to add to some projects, a silly way to kick something off. The first project I went for was the Party Button 2018 Edition. I made one back in 2016 with an Amazon Dash Button hack: Party Button 2016. Man can't believe that has been almost 2 years.

Santa brought this launch button from Amazon: Launch Button. Taking it apart to review the wiring I quickly realized I had an issue. The green button has an LED in it, but also has a fuse. This light will not come on unless you provide 220V of power...uh...there is no way I am lighting this cheap chinese plastic box up with 220 volts of power to light up a silly LED.

So I stripped down the button and the guts, removing the fuse, feeding some wires through the switch and up to a cheap LED I had laying around. I wired this to the Raspberry Pi GPIO. Then I hooked up the key to another GPIO pin. So I read the pin on the key and if it has power than i turn on the LED.



I snagged a 3V relay for some other ESP8266 project I was working on and headed over to Home Depot to grab an outlet. I used some 3M tape to adhere the relay to an outlet box and juiced up both outlets to the relay. I'd like to control both outlets separately but I hosed up when I ordered the relay and only ordered a 1 Channel Relay.


With most of the hardware components wired up I started on the software side. After several rounds of testing I came up with the python script that would read to see if the Key was in the on position, if so then light up the LED. If you press the Green button it will then fire up the relay and then pick a random song from the folder. If the key is not in the on position then pushing the green button will do nothing and the LED will not light up.


Key and Green Button Code



So finally I needed a way to quickly kill all this. I decided the Red Mushroom button would be the party kill switch. I turn off the LED, turn off the relay and also kill the VLC and Launch Button python script. This will shut the party down hard. I made this a separate script that will listen on a 3rd GPIO port to see when I push the kill switch button.



Pretty happy with how it turned out. Took about 4 days of tinkering to get it right. Here is a Youtube Video of the button in action:




Monday, December 18, 2017

AIY Google Assistant Kit Start on Boot

I picked up the AIY Google Assistant kit from MicroCenter the other day. Man it is a cool project. All the instructions you need to get up and rolling are in the box. The MicroCenter deal came with the Raspberry Pi 3 included and only cost 35$, essentially you get the kit for free.

After the build I wanted a way to start the Google Voice Python script on startup. The AIY project site has great instructions that I will summarize here.


  1. Create a new file in /home/pi called voice_assistant.service using the command: sudo nano /home/pi/voice_assistant.service
  2. Enter the following text into the file

    Description=My awesome assistant app
    [Service]
    ExecStart=/bin/bash -c '/home/pi/AIY-voice-kit-python/env/bin/python3 -u src/assistant_library_demo.py'
    WorkingDirectory=/home/pi/AIY-voice-kit-python
    Restart=always
    User=pi

    [Install]
    WantedBy=multi-user.target

  3. Move the file to the correct folder using this command: sudo mv voice_assistant.service /lib/systemd/system
  4. Enable your service: sudo systemctl enable voice_assistant.service
  5. Start your service: sudo service voice_assistant start
  6. Reboot the pi: reboot
  7. After reboot check the status of the service: sudo service voice_assistant status
  8. The status should be started and you should be able to say "Okay Google"



Friday, December 1, 2017

ESP8266 Servo Control from Website

I wanted a way to host a web site on the ESP8266 and control a Servo from that website. I had to search around for a bit and piece together a few bits of code, but it was pretty simple once I found the right combo.

The code is pretty straight forward. Enter your SSIS and your password. Set the int servoPin = to whatever pin you connected the servo data line to. Update the webPage line to style the web page like you want. I am going to mess around with some mobile frameworks to see if I can get it to build a good mobile looking site for me.

You can see where we are moving the servo if you find the Servo1.write() lines. You can tweak the angles to meet your needs. If you want to add a button just copy and paste the section that starts with server.on

Paste your new section above the line that says server.begin(). You will also need to add the button in your webpage+= line to add the new button: <a href=\"socket1On\"><button>UP</button> Make sure the ahref matches whatever you call the new button in the server on section.

Upload the script to the ESP and you should be rockin and rollin.

If you open the Serial Monitor you will see the IP address assigned to the ESP.


The main reason I wanted this servo functionality is because I saw the Paper Signals Google project. The voice thing is cool, but I just wanted a simple way to do the Arrow up and down. So I am going to print out the paper molds and try to assemble it this weekend.

The goal being I can have a web enabled Up Down arrow. When someone walks by my cube and gives me some lame idea I will click the down arrow. If they say something funny I will click the up arrow. The cool part is if this works well I can attach whatever symbol I want to it and move it around with the web enabled servo.

UPDATE:

Remote Boss Thumbs UP/DOWN

While planning the Paper Signals build I decided to make a remote Thumbs UP/DOWN for my boss. Now from his desk he can give me a Thumbs up or Thumbs down by hitting a web site from anywhere in the office.







I also baked in the Bootstrap Mobile framework into the web site hosted on the ESP, however Blogger was having a hard time displaying the code since it had several <script> tags. I have included the .INO file below that you can load up in Arduino IDE.


Tuesday, November 28, 2017

Raspberry Pi Relay Control from Android and Internet

This turned out to be drop dead simple. Once you have your outlets wired up to your relays and everything working good this is so easy. See my other post on how to setup the relays and such here.

I wanted to create my own, low dollar, solution for Home Automation and such. Jason Findlay does all of the software heavy lifting for you. Assuming you have a Relay hooked up to your Raspberry Pi, follow along.

  1. Install Wiring PI
    1. git clone git://git.drogon.net/wiringPi
    2. cd into the directory: cd wiringPi
    3. Run this: sudo git pull original
    4. then run: ./build
  2. Install Apache and PHP
    1. Run this command: sudo apt-get install apache2 -y
    2. Run this command: sudo apt-get install php7.0 libapache2-mod-php7.0 -y
  3. Create the PHP script
    1. Run this command: sudo nano /var/www/html/gpio.php
    2. Paste this code
    3. Save the page. You should now have a gpio.php file. This will drive the calls from the Android app.
  4. Download and Configure Android APP
    1. Search the Play Store for PiRelay and download the app: https://play.google.com/store/apps/details?id=com.jasonfindlay.pirelaypro
    2. Fire up the app and click on the Hamburger Icon in the top left to show the config sections.
    3. Click on the Pi URL Addresses option
    4. Enter the address to your Pi Example: http://192.168.1.200 (or whatever the IP on your Pi is. Run an ifconfig to see the IP)
    5. Click the Hamburger Icon in the top right corner again and Click Number of Relays
    6. Enter the number of Relays you will configure
    7. Click Hamburger Icon in the top right corner again and Click Setup Relays
    8. Click Relay 1
      1. Enter a name for the relay
      2. Choose the WiringPI Pin #. Use this as a guide
      3. Select a Relay Icon
      4. Choose the appropriate Relay type. The Relays I used were Active Low. Just play around with it until it works
      5. Then click the back arrow.
      6. You should now be able to toggle the relay and turn whatever you have plugged in on and off.

This may seem like a lot of instructions, but honestly it was very easy to setup and get rolling. If you have troubles head over to https://pirelay.jasonfindlay.com for help. You can also use the gpio.php page you built above to control the relays without using the Android app.

http://{your pi IP address}.gpio.php/?pin=1&status=0
http://{your pi IP address}.gpio.php/?pin=1&status=1

Use the Pin look up image I pasted above to specify the correct Pin number, this is the WiringPi pin, not the GPIO or Raspberry PI pin numbers.










Monday, October 16, 2017

Post to Web Service using ESP8266

I want to park this here before I lose the code. Simple HTTP POST to a web service using ESP8266.


This just logs some data to a SQL Server table for me. I am cooking up some push button stuff to act as a data logger using WIFI.

Simple Insert Procedure

Then I created a table to store the data.
And Finally the web service code is as follows:

Monday, September 18, 2017

Arduino Presence using PIR Motion

I cooked up a low tech presence project using an Arduino and PIR motion sensor in my cube at work. That way my colleagues can see if I am at my cube before walking down the hall. There are other more sophisticated ways to detect human presence with different sensors but this cheap PIR method works pretty well.

I  used a delay in the code to make it more usable. The out of the box PIR code will just constantly check for motion on the PIR. I inserted a delay so if it sees motion, wait 1 minute and then start checking again. Every once in a while I am real still and the sensor does not pick up but again we are talking low-tech easy solution here.

Materials

  • Arduino UNO
  • 2 - LEDs
  • PIR Motion Sensor
  • Jumper Cables


Code



Pics





Buddy said I should add a mood feature to display the mood. I have an RGB LED laying around so I may implement that next.

Thursday, August 10, 2017

Python Windows Toast Notifications

Started working with Microsoft Life Cycle Services recently deploying some cloud hosted environments. Wanted a way to get notified when an environment was finished deploying. I am sure there are better ways, but I wanted something quick and easy.

Double bonus is that you can use this for other Python projects where you want a Windows Toaster notification. Windows Toaster notifications are those little pop ups that appear in the bottom right corner of your screen.



I fired up Fiddler hoping to find that LCS would give me some sweet JSON action. At first I was a little bummed because the return application type showed javascript instead of JSON



When I clicked JSON view the response looked like JSON, but when I tried to load it into Python as JSON I kept receiving the "is not JSON serializable error".



After some searching I stumbled on some stack overflow articles mentioning this was JSONP not normal JSON. I finally landed at this article that gave me a really simple solution.  Here is my final script to generate the Toast Messages for the LCS deployment status.


You can see where I convert the JSONP to JSON by just removing the first and last character (Line 16) of the response. It is really that simple, just remove the ( and the ) and we now have valid JSON we can feed in.

We loop every 5 minutes checking status and pop up a toast notification giving the status. Here is a screen shot showing the result (I stopped all my environments for some maintenance thus all are Stopped status).

One thing to keep in mind is you are limited on height of the toast message. So your message will be cut off if your message cannot fit in the toast notification window size.




Friday, August 4, 2017

Raspberry Pi Sound Board

I have wanted to create a sound board for some time. I finally got around to getting it done. This project took way longer than I wanted mostly because I did not make time to work on it. I created a really simple wood structure to mount the arcade buttons to.

I wanted a solderless solution so I ordered some female spade connectors so I could just crimp the wires instead of soldering. Turned out pretty good.

Supplies

  • Raspberry Pi 3
  • Female Spade Connectors 2.8mm width. Make sure you get the size that matches your arcade buttons.
    https://www.amazon.com/gp/product/B01962MW2G/ref=oh_aui_detailpage_o03_s00?ie=UTF8&psc=1
  • 10 x 30mm arcade buttons
    https://www.amazon.com/EG-Starts-Buttons-Multicade-Accessories/dp/B01N5DVINY/ref=pd_sbs_21_4?_encoding=UTF8&pd_rd_i=B01N5DVINY&pd_rd_r=4AG8PN4FQKRH00AGR4XN&pd_rd_w=1gW6J&pd_rd_wg=Iv7vh&psc=1&refRID=4AG8PN4FQKRH00AGR4XN
  • Jumper Wires
  • Bore Bit to cut your holes for arcade buttons

My first mistake was buying a bore bit that was too small. My buttons were 30mm and my bore bit was 28mm. Not sure where I got 28mm from but the holes were too small. I was able to use a Dremel to make the holes bigger but it sure wasn't as pretty as clean 30mm holes. 

I used common ground lines for the buttons so I had 4 buttons one one and 5 buttons on the other. I used a wire nut to ground them and attached them to two separate ground ports on the Raspberry Pi. 

Code 

I spent way too long trying to figure out the Python code to detect a button push. Finally found the right combo. Here is my code.


So the jist is to wait for a button to be pushed then call the Command line version of VLC to play the MP3 specified. Not that elegant but works great. You will see here that this version of the sound board is my Dr. Phil quotes soundboard. Good times. You can SCP to copy the files you need to the Pi or use a USB stick as pictured in my pics below. I didn't really plan my project well so I had to run the jumper cables out to the side of box so I could plug stuff into the pi. It works fine and gives the project that hacker feel.

This of course can be used for anything really. You can launch python scripts to do whatever you want. 





Friday, March 10, 2017

Arduino LED Sign

Finally finished version 1 of my Arduino LED sign. Using the awesome tutorial and code from this fella: https://wp.josh.com/2016/05/20/huge-scrolling-arduino-led-sign/. I went with 60 LED 1 meter long strips. Man they are bright!!!

Here are some pics of the build.





Parts List

Everything is driven by the awesome Arduino Software that Josh from the link above built. Once you get everything plugged in and ready to go it just works.




Wednesday, February 15, 2017

Google Traffic API using Python or PowerShell

UPDATE: 2/16/2017 - small tweak needed to the scripts. I changed the JSON element to duration_in_traffic. This will show the duration plus traffic. Duration will just show how long it should take with no traffic.

I have visited this area a few times. I needed a clean solution to get drive times for my commute home. Fortunately Google Maps Distance Matrix has an easy to use API. Of course you will need to enable the API in your Google Dev Console and get your API key to use the traffic feature.

Once your have your key its a cinch. 
  1. Grab your origination and destination LAT, LONG coordinates. Just go to google maps, find your location, right click on the map and select What's Here from the menu. You will see your coordinates.

  2. Plug these into the script 
  3. You can tweak the model if you want. Distance Matrix has 3 traffic models, best-guess, pesimistic, and optimistic.
  4. Run the script

Powershell


Python

In order to get the Python Script to work we have to bypass the SSL verification. Probably not the best idea for production type implementations but it is a workaround.


You can find more information about the Distance Matrix API here: https://developers.google.com/maps/documentation/distance-matrix/