Wedding Projecting with the Raspberry Pi pt.2

Parts 1 | 2

So, at the end of part 1, we had a mostly set up Pi for day to day use. Being that this Pi, specifically, is going to be for a very particular day’s use, we need to make some changes.

  • Issue ‘sudo raspi-config’ and navigate to ‘Boot Options’
    • Select ‘Desktop/CLI’ then ‘Console Autologin’

Excellent! Now we don’t have to worry about anything ever again. We did it, guys!

I have chosen to go with the wonderful servo control baked into PiGPIO and the author[s] of that deserve a MASSIVE shoutout!

PiGPIO is an absolute MONSTER of a timesaver when it comes to controlling servos (and many other types of electronics) because it handles timing and math for us, and it integrates beautifully into python, which we will be using for both reading our keypad and all logic associated with locking/unlocking.

With that said, lets go about getting it installed.

Installing PiGPIO

From a terminal of your choice, in my case SSH, issue the following commands:

  • rm pigpio.zip
  • sudo rm -rf PIGPIO
  • wget abyz.co.uk/rpi/pigpio/pigpio.zip
  • unzip pigpio.zip
  • cd PIGPIO
  • make
  • sudo make install

Be patient with the install process. According to the creator, the initial part of the make will take 100 seconds+ on older Pis

Once that is said and done, ensure the PiGPIO daemon is set to start on boot:

  • find the location of the PiGPIO daemon by issuing ‘whereis pigpiod’
  • issue ‘sudo crontab -e’ to edit the root crontab
    • If you haven’t selected a preferred editor, do so now. I prefer nano.
  • add the following at the bottom of the file:
  • @reboot    /usr/local/bin/pigpiod
  • CTRL+o -> Enter to save changes
  • CRTL+x to exit
  • issue ‘sudo reboot’ to reboot and test everything
  • After reboot, issue ‘ps -ef | grep pigpiod’ to make sure it started on reboot
    • Yay!

Coming in part 3:

Utilizing PiGPIO and Python to control Servos for profit and success!

Re-Using Raspberry Pi Formatted Memory Cards

This solution is specifically for Windows, because I’m a conformist.

  1. Launch CMD as an administrator
    1. Start -> Type in CMD -> Right Click -> Run as Administrator
  2. Enter DISKPART into CMD and hit Enter
  3. Enter LIST DISK and hit Enter
    1. Find your memory card in the list and not whatever disk number was assigned to it
  4. Enter SELECT DISK # where # is the number of your disk and hit Enter
  5. Enter LIST PART and hit Enter
    1. These are all of the partitions, one of which Windows can see and one that it can’t.
  6. Enter DELETE PART # where # is one of the partitions you want to delete and hit enter
    1. Repeat for all the partitions you want gone
  7. Enter CREATE PART and hit enter

The memory card should now be ready for you to format however you choose (one easy way is through right clicking it in Explorer) and to use however you choose.

Yaaaaay Pi!

Wedding Projecting with the Raspberry Pi pt.1

Parts: 1 | 2

It’s finally time to get some work done on a project I’ve been thinking about for a while. Keeping with the theme of Nerd-Wedding, and paying attention to how important our friends are to us, I will be making a box that requires the best man, and the maid of honor, to input a 4-digit code of their own choosing before it opens to reveal the rings we will exchange during the ceremony. Below are the requirements:

  1. Come up with a cool name. Current project code name is ConsentBox v2.0
  2. Not look fucking ugly.
  3. Battery operated (Raspberry Pi)
  4. Get maid of honor / best man PINs from text files, recognize whether either was entered
  5. (decide if they both need to be entered for one box to open or if each opens a different compartment) – Need some input from the love on this one. If ONLY there was SOME WAY for her to see this and comment on it…
  6. Write Python to reflect the above. This is the easiest step as I will be reusing code I made for a different project.
  7.  Build / repurpose box to open automagically. I will be making an interference fit “lock” (or two) that is/are operated by servo[s]. Also springs will be involved.
  8. Python for Servos? Currently looking at using servomaster or pigpio

Aaaand that’s about all that comes to mind. Below will be an account of today’s successes and failures in terms of setup and getting back on the horse with my favorite kind of pi and most hated kind of programming!

Getting the Raspberry Pi up and stable:

Decide if you need a GUI. In this case I don’t, and I want this to be as small and streamlined as possible (we will be using some VERY inefficient code, I know, I wrote it) so we will be securing the latest Raspian Lite from the Raspberry Pi Foundation. https://www.raspberrypi.org/downloads/raspbian/

Choose what you’ll be using to burn your image to card. I will be using win32diskimager, which I have found to be wonderfully fast and reliable at reading and writing images to or from SD Cards. https://sourceforge.net/projects/win32diskimager/

Unzip the image you downloaded and burn that bad boy!

Get your fresh Pi off the windowsill, hook it up to a monitor, and get going! Default user: pi default password: raspberry

  • Change your password by issuing ‘passwd’
  • use ‘sudo raspi-config’ to expand the storage to use the whole card, set your keyboard, time, and wifi country values in localization options. Bonus points for setting your hostname to something other than the default.
  • Exit raspi-config, but don’t reboot yet.
  • enable ssh by typing ‘sudo touch /boot/ssh’
  • reboot by issuing ‘sudo reboot’
  • Login again! with your new password! Look at you go!
  • Configure WiFi. Issue ‘sudo nano /etc/wpa_supplicant/wpa_supplicant.conf’
  • Add a block like this to the end of your file:

network={
ssid=”youNetwork”
psk=”yourPassword”
}

  • Save your changes using Ctrl+o and hitting enter at the suggested filename (hint, it’s just the current filename) and then exit using Ctrl+x
  • reboot again
  • pray
  • Yay! it worked.

This is where our steps will probably diverge. I have a NAS at home that proves it’s use over and over, and this is no exception. Because I’m not a fucking masochist, I’ll be using Atom to edit the python files I’ll be writing for this project, those will be saved onto my NAS, and the pi will execute them from there. So now we get to start mapping (in Linux its called ‘mounting’….heh….heh…) shares! Prerequisite to the below is that you have a user already set up for you Pi’s on the share. I do, and you should too. You would be amazed how handy it is to be able to grab any file you want from anywhere in your home.

  • Create a directory that you will use as your mount point. I call mine ‘General’ because that is the name of the share that it will be using on my NAS. I prefer to do this in /home/pi ‘mkdir /home/pi/General’
  • Make sure you are in /home/pi ‘cd /home/pi’
  • Verify that everything is working by mounting the share once ‘sudo mount -t cifs -o username=pi@nasName,password=password //nasNameOrIP/General ~/General’
  • Verify that it is indeed mounted by either ‘cd’ing to it or just use ‘df -h’
  • It’s there you say? Sweet!
  • Set it mount every time you start by issuing ‘sudo nano /etc/fstab’
  • At the bottom of your fstab, add the following: ‘//nasNameOrIP/General /home/pi/General cifs username=pi@nasName,password=password 0 0’
  • Save and exit as before
  • reboot as before
  • verify it auto-mounted!

Now we have the framework for not wanting to chop our dicks off every time we need to create or modify code for this to run. In a future post I’ll go through how everything is setup and some of the code. Fun Fun!