• DIY Arcade Cabinet Using A Raspberry Pi


    [vc_row][vc_column width=”2/3″][vc_separator][venera_framed_image content_type=”video” css_animation=”appear” frame_type=”browser” slider_engine=”flexslider” video_link=”https://www.youtube.com/watch?v=LssEe_xx3eI” browser_url=”https://www.youtube.com/watch?v=LssEe_xx3eI”][vc_separator][/vc_column][vc_column width=”1/3″][/vc_column][/vc_row][vc_row][vc_column width=”2/3″][vc_tabs][vc_tab title=”About This Project” tab_id=”1402713028-1-39e9a4-2f888a6d-d37d76d3-94ce”][vc_column_text]

    The $35 Raspberry Pi has proven to be a hit amongst hardware hackers and DIYers. It’s very small, easy to set up, and very versatile. This tutorial walks you through the steps of creating and setting up an Arcade cabinet using a Raspberry Pi as the core.

     

    [/vc_column_text][/vc_tab][vc_tab title=”Parts and Downloads” tab_id=”1402713028-2-39e9a4-2f888a6d-d37d76d3-94ce”][vc_column_text]

    Parts List

    The prices really depend on what you would like to purchase. Depending on what you already have available, it’s possible that you may not have to spend over $50.

    Raspberry Pi Arcade

    Part name Price
    Raspberry Pi $35
    Wifi Adapter $17
    Ethernet Cable $3
    SD Card $6
    Powered USB Hub $4
    USB Mouse $6
    USB Keyboard $5
    Monitor (may also need an adapter) $120
    USB Joystick and Buttons (optional) $27
    Arcade Cabinet Kit (optional) $200-$500

    [/vc_column_text][/vc_tab][vc_tab title=”Assembly” tab_id=”1402753910272-3-88a6d-d37d76d3-94ce”][vc_column_text]

    Raspberry Pi Setup

    Installing the Operating System

    There are several different options when it comes to emulators on the Raspberry Pi, but in order to make the Pi function as an Arcade, one stands out amongst the rest. It’s an opensource program called AdvMame and what makes it unique is that it can be used in conjunction AdvMenu to automatically boot to your game directory. The only issue is that it requires a lot of editing and tweaks to get everything to work. Luckily the folks at blog.sheasilverman.com have compiled a version of AdvMame with all the tweaks and edits so that it works specifically for the Pi. It’s called PiMame and can be downloaded and burned to an SD card.

    Win32DiskImager

    Windows

    To install PiMame on an SD card in Windows, you need to download an image burner such as Win32 Disk Imager. After you have PiMame downloaded, you should be able to extract it to view the PiMame.img file. Launch Win32 Disk Imager and under “Image File”, select the PiMame image. For “Device”, select the drive letter for your SD card. Then click “write” to burn the image to the SD card.

     

    Mac

    For Mac computers you do not need any extra software. Just download the PiMame zip file and extract it. Insert your SD card and open up a terminal prompt. Type in

    df -h
    

    Record all of the “disk” entries that are listed (ex. disks1). Go into your Disk Utility settings and find your SD card and unmount it (not eject). Then go back to your terminal prompt and type df -h again to see which disk is no longer there. The missing one is the disk ID of your SD card. With that in mind, type in this command

    sudo dd bs=1m if=~/PATH TO PIMAME/pimame-0.5.img of=/dev/DISK#
    

    where PATH TO PIMAME is the path to where you downloaded the PiMame image and where disk# is set to your SD cards disk number (ex. disks1 = disk1). Executing this command will burn the image to your SD card. When it’s done, you can type

    sudo diskutil eject /dev/DISK#
    

    This will eject your SD card.

    First Run

    Gridlee game splash screen

    Once PiMame is installed on your SD card, it’s time to boot up your Raspberry Pi. Make sure that you have a monitor plugged into it as well as the powered USB hub with your USB wireless card, keyboard, and mouse plugged into it. As a pro tip, you can also plug the Raspberry Pi itself into the USB hub since the hub can provide enough juice to power the Pi. The only reason you would need the network cable is in the event that the wireless adapter doesn’t work and you need to download updates in order to get it working.

    With the SD card in the Raspberry Pi, turn it on and you should see it boot to the AdvMenu where you will see a game called Gridlee already installed. You can use your keyboard’s number pad and enter key to select the game and play it.

    Setting up wireless

    The most optimal way for the Arcade cabinet to connect through the internet would be through wireless. But in order to tweak the AdvMame and AdvMenu setup, we need to first get to the command line console. If you are in a game, you can hit Esc on your keyboard and select Exit. This will take you back to the game menu. Then hit Esc again to exit the menu and bring up the command prompt. The newest version of PiMame includes Raspbian, which provides a Graphical User Interface (GUI) that has an easy to use wireless program.

    Raspbian Wireless Interface

    Making sure that your USB Wifi card is plugged in, type this in to access the Raspbian GUI:

    startx
    

    This will launch the user interface in which the mouse will be enabled and can be used. Double click on the Wifi Config icon, which should be on the desktop. This will launch an interface. Click on the Manage Networks tab and select the Enabled radio button to enable wireless. Then you should be able to click scan to scan your area for wireless networks. Find your wireless network, double-click on it and enter in your wireless password. When you have successfully connected, you can logout of the Raspbian GUI session. At this point you can unplug your network cable and your mouse as they will no longer be needed.

    Connecting via SSH

    With the wifi enabled, the easiest way to work with the Pi is through SSH, which is essentially a way to remote connect to the Pi and run commands on it. Connecting via SSH requires finding the IP address of your Pi. The easiest way to do this is by typing

    ifconfig
    

    This brings up your internet connection settings with eth0 being your ethernet connection and wlan0 being your wireless connection. Immediately under your wlan0 connection, you should see the IP address assigned to it (ex. 192.168.1.5). Once you have your IP address, you can connect via SSH.

    Tweaking The Software

    Adding Joystick Input

    If you would like to be able to use joysticks and buttons with your arcade machine, then you will first need to purchase USB enabled joysticks and buttons. Depending on what you get and where you purchase them, the price can range from $25 to hundreds of dollars. When using them, make sure that you have them plugged directly into the powered USB hub, as joysticks sometimes require more power than the Pi alone can provide.

    Once you have the joysticks and buttons hooked up and plugged in, we need to enable them within the software, because AdvMame has it turned off by default. So make sure you are at a command prompt and type

    sudo nano .advance/advmenu.rc
    

    This will open up the AdvMenu settings as an editable file. Within this file, you want to find the line that says:

    device_joystick none
    

    and edit it so that is says

    device_joystick auto
    

    Now hit Ctrl X on your keyboard and it will ask you if you want to overwrite the file, hit y for yes and then hit enter to save. You should now be back at the command prompt. At this point, you could restart your Pi by typing:

    sudo reboot
    

    It will reboot back into the game menu where you can start the game and see if the joystick functionality works.

    Arcade Cabinet Setup

    Monitors

    When it comes to monitors, just about any will do as long as you have the right adapter. Here you can find an HDMI to VGA and a HDMI to DVI adapter. Those two adapters should account for most monitor connections (including older CRT monitors). The main thing that you need to take into account is the size of the monitor and how it will fit into your arcade cabinet.

     

    [/vc_column_text][/vc_tab][vc_tab title=”Important Links” tab_id=”1402753981900-3-108a6d-d37d76d3-94ce”][vc_column_text]

    Help support my channel:

    1. Donate To My Patreon
    2. Follw Me On Google +
    3. Like Me On Facebook
    4. Follow Me On Twitter

    [/vc_column_text][/vc_tab][/vc_tabs][/vc_column][vc_column width=”1/3″][/vc_column][/vc_row]

  • Try Out The New Firefox OS!!!


    [vc_row][vc_column width=”2/3″][vc_separator][venera_framed_image content_type=”video” css_animation=”appear” frame_type=”browser” slider_engine=”flexslider” video_link=”https://www.youtube.com/watch?v=_8lgpqn4Tw8″ browser_url=”https://www.youtube.com/watch?v=_8lgpqn4Tw8″][vc_separator][/vc_column][vc_column width=”1/3″][/vc_column][/vc_row][vc_row][vc_column width=”2/3″][vc_tabs][vc_tab title=”About This Project” tab_id=”1402713028-1-395270-7c72d1f3-23ee”][vc_column_text]

    Mozilla (the creators of Firefox) has been working on a new Mobile Operating System called “Gecko”. This video will show you how you can install it on your computer to test it out.

    [/vc_column_text][/vc_tab][vc_tab title=”Installation” tab_id=”1402713028-2-395270-7c72d1f3-23ee”][vc_column_text]

    How To Install

    Mac/Linux

    The Firefox dev platform is made to run on Mac and Linux, so it’ll be easier to install. You can find a simple guide here. But basically the process is as follows:

    Firefox Mobile OS

    1. Download the latest B2G isntaller] for your Operating system (you can find nightly builds here).
    2. Use Git to download a Gaia profile for the Firefox OS to use.
    	
    git clone git://github.com/mozilla-b2g/gaia
    
    1. Use GCC to actually compile the profile
    make -C gaia profile
    
    1. On Linux, use the command below to launch the program, where /path/to/b2g is the actual path to the desktop build on your machine
    /path/to/b2g -profile gaia/profile
    
    1. On a Mac, use the command below to launch the program, where <your username> is your Mac username
    /Applications/B2G.app/Contents/MacOS/b2g -profile /Users/<your username>/gaia/profile
    

    Windows

    Since windows doesn’t have a build in option to “make” the profile, we kind of have to use a workaround. Otherwise, it’s essentially the same.

    1. Download the latest B2G isntaller] for your Operating system and unzip it to your computer (you can find nightly builds here).
    2. Instead of installing “git”, I’ve uploaded a gaia-profile to my website that you can download.
    3. Unzip the gaia-profile to your b2g folder that you downloaded
    4. Also, in your b2g folder, right-click on b2g.exe and choose “create shortcut”
    5. In the “target” textbox, add -profile “C:\<path to your b2g folder>\gaia-profile”. Essentially it will look something like this:
    C:\Users\<your username>\Desktop\b2g\b2g.exe -profile "C:\Users\<your username>\Desktop\b2g\gaia-profile"
    
    1. Double click on the shortcut and it should load the interface

    A Word Of Warning

    This release is not meant to be an entirely functional version. If you’re not a curious early adopter, there’s no really reason to download and try this. It’s only for those that want to see what Firefox is up to.

     

    [/vc_column_text][/vc_tab][vc_tab title=”Important Links” tab_id=”1402713403419-2-15270-7c72d1f3-23ee”][vc_column_text]

    Help support my channel:

    1. Donate To Patreon!
    2. Follow Me On Google +
    3. Like Me On Facebook
    4. Follow Me On Twitter!

    [/vc_column_text][/vc_tab][/vc_tabs][/vc_column][vc_column width=”1/3″][/vc_column][/vc_row]

  • Install A Counter-Strike Server On Android


    [vc_row][vc_column width=”2/3″][vc_separator][venera_framed_image content_type=”video” css_animation=”appear” frame_type=”browser” slider_engine=”flexslider” video_link=”https://www.youtube.com/watch?v=3-0atIGgsXE” browser_url=”https://www.youtube.com/watch?v=3-0atIGgsXE”][vc_separator][/vc_column][vc_column width=”1/3″][/vc_column][/vc_row][vc_row][vc_column width=”2/3″][vc_tabs][vc_tab title=”About This Project” tab_id=”1402713028-1-395270-7c72″][vc_column_text]

    My favorite first-person shooter game growing up was Counter-Strike. Now this nostalgic game has been portablized. So in this episode, I show you how to install a Counter-strike server on an Android device.

    [/vc_column_text][/vc_tab][vc_tab title=”Installation” tab_id=”1402713028-2-395270-7c72″][vc_column_text]

    How To Install

    The portable Counter-Strike initiative isn’t backed by the original distributors of the game, so it isn’t supported by Valve or the original Counter-Strike creators. So to grab the unsupported portable version of the game, you need to go to CS-portable.com. Across the top of the menu, you’ll see links to download the portable version, or to even play online. Keep in mind, though, that the online version can’t network with the portable versions.

    Counter-Strike Logo

    iOS Devices

    Installing CS portable on iOS devices is considerably more difficult than Android devices because of Apple’s strict App approval procedures. But here’s the basic procedure:

    1. Download a jailbreaking tool such as GreenPoison that matches the iOS version that you have installed (current version is 5.1.1).
    2. Jailbreak your iOS device and install cydia using these steps.
    3. Inside of Cydia, you need to install Installous. Here’s a nice guide to help you do that.
    4. Now you can use Installous to download and install CS portable. Here are a couple of guides to help out with that: [Guide 1] [Guide 2]

    Android Devices

    For Android devices, the process is much simpler.

    1. In the settings of your android device, make sure that your applications are set to allow unknown sources.
    2. Now you can download the CS-portable APK file for android to your computer and use a method, such as Dropbox to transfer it to your device.
    3. Using a file browser/explorer, find and open up the CS-portable APK file

    Now you should just be able to open it up like a regular App and start playing!

     

    [/vc_column_text][/vc_tab][vc_tab title=”Important Links” tab_id=”1402713403419-2-15270-7c72″][vc_column_text]

    Help support my channel: http://www.patreon.com/tinkernut Follow Tinkernut! Google + Facebook Twitter

    [/vc_column_text][/vc_tab][/vc_tabs][/vc_column][vc_column width=”1/3″][/vc_column][/vc_row]

  • How To Make A Raspberry Pi Web Server


    [vc_row][vc_column width=”2/3″][vc_separator][venera_framed_image content_type=”video” css_animation=”appear” frame_type=”browser” slider_engine=”flexslider” video_link=”https://www.youtube.com/watch?v=WgcNBjIJNYs” browser_url=”https://www.youtube.com/watch?v=WgcNBjIJNYs”][vc_separator][/vc_column][vc_column width=”1/3″][/vc_column][/vc_row][vc_row][vc_column width=”2/3″][vc_tabs][vc_tab title=”About This Project” tab_id=”1402713028-1-39e9a4-2f88123b-77946048-9294ef23-7cf7″][vc_column_text]

    The Raspberry Pi is an amazing $35 mini-computer. And in this video, I’ll show you how to set it up as a fully functioning web server.

    [/vc_column_text][/vc_tab][vc_tab title=”Code” tab_id=”1402753910272-3-8123b-77946048-9294ef23-7cf7″][vc_column_text]

    What is a Raspberry Pi

    The Raspberry Pi is a revolutionary mini-computing system that is super cheap. It’s based on the ARM processor, and can be powered through USB (5v) and has all of the standard functionality of regular computers.

    Raspberry Pi

    There are two types of Raspberry Pi Models: Model A ($25) and Model B ($35). Both models have 256mb of RAM, HDMI and Composite video connections, audio connections, USB power input, USB port output, and SD card input. Model B adds an ethernet port (for network connections) and an extra USB port, which is what makes it more expensive.

    Since the Raspberry Pi is in such high demand, attaining one is kind of difficult. At the time of writing this wiki, you can only sign up to be notified when more Raspberry Pi devices are available. You can sign up at Alliedelec (North America only), RS-Online (everyone), or Element14 (everyone).

     

    How To Set Up A Raspberry Pi

    Raspberry Pi Box

    When you first receive a Raspberry Pi, it’s basically just a circuit board in a box. Obviously to run it as a computer, you need some necessary hardware peripherals first. Here’s the list of parts you will need to run it for the first time:

    1. A USB keyboard
    2. An HDMI or Composite cable
    3. A TV or Monitor that is HDMI or Composite capable
    4. A micro-usb power cable
    5. A 2gb or larger SD card (by default, the operating system can only access 2GB)
    6. A network cable (if you want to connect to the network)

    Installing the Operating System

    Before you can use the Raspberry pi, you have to install the Raspberry Pi Operating System on to the SD card. Don’t worry, it’s not as difficult as it sounds. If you have Windows (you can find Linux and Mac instructions here, there are only 2 things you need to download

    Win32DiskImager

    1. The Raspberry Pi Operating System (I chose the “Debian Squeeze” version)
    2. Win32DiskImager (The binary version)

    Unzip the Debian Squeeze file that you downloaded. It should produce an ISO file. Now insert your SD card into the computer that you downloaded the files to. Open up Win32DiskImager and for the Device, choose the drive letter of you your SD card. Then click on the folder icon to browser to the Debian Squeeze ISO file that you downloaded. Lastly, click “Write” to write the image file to your SD card. It can take a few minutes to write the files.

    Running For the First Time

    Once the SD card has been prepped, stick it into your Raspberry Pi. Now you can start plugging in all of your other hardware peripherals, making sure to plug in the micro-usb cable last, since it provides the power.

    Raspberry Pi Connections

    Once power has been provided, you should start seeing the loading screen for the Raspberry Pi OS on your monitor. The first time, it will take a few minutes to completely load. All other times, it should load pretty fast. You’ll know when it’s through loading because you will see a line that says “raspberry pi login:”. The defaul login name is pi. And the default password is raspberry.

    You should now be at a line that says pi@raspberrypi:~$. This means you can start entering in commands. For those of you that are used to a desktop environment, I know this isn’t what you had in mind. So if you prefer a desktop environment, you can type

    startx
    

    This will load the desktop environment. From here you can plug in a mouse and use it like you would a normal computer GUI.

     

    Initial Software Setup

    It’s good practice to update the software and software repositories when you first set up your Raspberry Pi. It’s also important to update the system clock via the internet, since the Raspberry Pi does not have real-time clock. So here’s a list of initial commands to get your system updated:

    Configure Time

    sudo dpkg-reconfigure tzdata
    

    Update software packages

    sudo apt-get update
    

    Update Debian

    sudo apt-get upgrade
    

    Updating Firmware

    NOTE: If you are running the latest Raspbian hard float release, this update tool will prevent your pi from booting. Only use this if you have Debian squeeze
    To keep the Raspberry Pi firmware up-to-date, you have to install a program called Hexxeh’s RPI update tool through Git-hub. Here’s the process

    Install certificate authority certificates

    sudo apt-get install ca-certificates
    

    Install Git (required to run Hexxeh)

    sudo apt-get install git-core
    

    Download Hexxeh’s RPI update tool

    sudo wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update && chmod +x /usr/bin/rpi-update
    

    Update the firmware

    sudo rpi-update
    

    Reboot

    sudo shutdown -r now
    

     

    Setting Up SSH and Remote Connections

    You will not have to do this step if you have downloaded Raspbian or Debian Wheezy – SSH should be enabled by default. If it is not enabled, follow these instructions:

    To start out, type this then hit enter:

    sudo raspi-config
    

    You will now see a screen with a few options. Use the arrows keys to navigate to the SSH option. This will take you to another screen that asks you “Would you like the SSH server enabled or disabled?” Choose the <Enable> option with your arrow keys and hit enter. Select okay, and hit enter. Now, back at the raspi-config screen, navigate to <Finish> and hit enter. You should now be able to use SSH with your Pi!

    An ideal setup of Raspberry Pi would be to control it remotely. This can be done through an SSH connection, but by default SSH connections are disabled. Before we enable it, the screen should have the IP address of the Raspberry Pi listed (ex. 192.168.2.37). Write down that IP address as we will need it for the SSH connection. Ok, To enable SSH, simply run this command:

    sudo mv /boot/boot_enable_ssh.rc /boot/boot.rc
    
    sudo shutdown -r now
    

    Once the Raspberry Pi reboots, you can now unplug the keyboard and the monitor connections from the Raspberry Pi, as we will no longer need them for the rest of this tutorial.

    Putty Window

    On a remote Windows machine, in order to connect to the Raspberry Pi, you will need to download Putty, a Windows SSH client. Once it’s downloaded, start it up and type in the Raspberry Pi’s IP address that you wrote down earlier in the Host Name (or IP address) field. Then just click “open”. If it’s your first time connecting, Putty will ask you to store a key authentication, so click “Yes”. Now you should see a login screen where you can log in using your Raspberry Pi login credentials.

    Changing the Password

    For obvious security reasons, it’s recommended to change the default password to a secure password of your own. After you have logged into your pi account, to change the password, type:

    sudo passwd pi
    

    Now you should be prompted to enter in a new password. Once you’ve typed in your password and hit enter, you’ll then be prompted to repeat your password. After typing it in again and hitting enter, you will have successfully changed your password.

    Installing the Server

    In order to use the Raspberry Pi as a web server, you have to install all the necessary server software components. If you just want a simple HTML server, you can just install that server software (Apache or Cherokee). If you want MySQL and PHP support on your server, you have to install those components separately as well.

    Apache Server

    Apache server software is the most widely used server software. However, it is a little bit more bloated than the Cherokee server software. If you want a more traditional experience, you can install Apache. Otherwise, you can skip to the Cherokee Server section and install Cherokee. Here’s how to install Apache:

    Install Apache with PHP

    sudo apt-get install apache2 php5 libapache2-mod-php5
    

    When it asks if you want to continue, press y

    Resolve installation error

    sudo groupadd www-data
    
    sudo usermod -g www-data www-data
    

    Restart Apache

    sudo service apache2 restart
    

    Now if you open up a web browser and type in your Raspberry Pi’s IP address, you should be pull up a the test page for your server!

    Cherokee Server

    If you want a lighter web server, then Cherokee is better than Apache. And considering the limited resources of the Raspberry Pi, lighter is better. Here’s how to install it:

    Prevent install errors

    sudo addgroup www-data
    

    Install Cherokee

    sudo apt-get install cherokee
    

    Install PHP

    sudo apt-get install php5-cgi
    

    Edit the PHP config file

    sudo nano /etc/php5/cgi/php.ini
    

    Hit ctrl+W and search for cgi.fix_pathinfo=1, remove the ; form the front of the line
    Hit ctrl+X to exit, y to save and enter to confirm

    Restart Cherokee

    /etc/init.d/cherokee restart
    

    Now if you open up a web browser and type in your Raspberry Pi’s IP address, you should be pull up a the test page for your server!

    Installing MySQL

    Installing MySQL is pretty simple. You basically just install these packages:

    sudo apt-get install mysql-server mysql-client php5-mysql
    

    When it asks if you want to continue, press y

    It will eventually prompt you for a new root user password, so create a strong password and continue until the installation is through.

    Installing FTP

    FTP is not only a great way to remotely add/change files on your website, but it’s also a great way to transfer files to your Raspberry Pi. This is important for installing PHP MyAdmin in the next step. These instructions are for the Apache server install.

    Take ownership of the WWW Apache folder

    sudo chown -R pi /var/www
    

    Install VSFTP

    sudo apt-get install vsftpd
    

    Edit the FTP configuration file

    sudo nano /etc/vsftpd.conf
    

    Hit ctrl+W and search for anonymous_enable=YES, and change it to anonymous_enable=NO
    Remove the # from in front of local_enable=YES
    Remove the # from in front of write_enable=YES
    Skip to the bottom of the file and add force_dot_files=YES
    Hit ctrl+X to exit, y to save and enter to confirm

    Restart VSFTP

    sudo service vsftpd restart
    

    Change the root users password

    sudo passwd root
    

    Create a new password and then exit out of Putty

    exit
    

    Restart Putty and log in as root with the new password
    Edit the password configuration file

    sudo nano /etc/passwd
    

    Find the line pi:x;1000:1000:Raspberry Pi User,,,:home/pi:/bin/bash and add a # sign to the beginning of it.
    Hit ctrl+X to exit, y to save and enter to confirm
    Add the pi user as a mod and exit out of the Putty

    sudo usermod -d /var/www pi
    
    exit
    

    Restart Putty and log in as pi
    Give mod rights to root and exit

    sudo usermod -L root
    
    exit
    

    Now your FTP server should be up and running. You can test it out by logging into it with any FTP client such as FileZilla or WinSCP. Use the IP address from your Raspberry Pi that you wrote down earlier, port 22, your Raspberry Pi username (pi), and your password.

    Installing PHP MyAdmin

    To better manage MySQL databases, it’s often preferred to use the PHP MyAdmin program. So here’s how you can install it:

    1. Download PHP MyAdmin
    2. Extract the zip file to a folder
    3. Using your FTP client upload the extracted PHP MyAdmin files to your web server.

    To access PHP MyAdmin, in a web browser type in your Raspberry Pi’s IP address and then add /admin to the end of it (ex. 192.168.2.37/admin). Then you can log in using the root username and password that you created for your MySQL installation.

     

    [/vc_column_text][/vc_tab][vc_tab title=”Important Links” tab_id=”1402753981900-3-10123b-77946048-9294ef23-7cf7″][vc_column_text]

    Raspberry Pi – http://www.raspberrypi.org
    Raspberry Pi Disk Image – http://www.raspberrypi.org/downloads
    Win32DiskImager – https://launchpad.net/win32-image-writer
    Putty – http://www.chiark.greenend.org.uk/~sgtatham/putty/

    Website Tutorials – http://www.youtube.com/playlist?list=PL6291918FE7103470
    Port Forwarding Tutorial – http://www.youtube.com/watch?v=1DSDbvtVIaA

    Help support my channel: http://www.patreon.com/tinkernut Follow Tinkernut! Google + Facebook Twitter

    [/vc_column_text][/vc_tab][/vc_tabs][/vc_column][vc_column width=”1/3″][/vc_column][/vc_row]

  • Learn How To Use An Arduino


    [vc_row][vc_column width=”2/3″][vc_separator][venera_framed_image content_type=”video” css_animation=”appear” frame_type=”browser” slider_engine=”flexslider” video_link=”https://www.youtube.com/watch?v=PWKYYJu4yVw” browser_url=”https://www.youtube.com/watch?v=PWKYYJu4yVw”][vc_separator][/vc_column][vc_column width=”1/3″][/vc_column][/vc_row][vc_row][vc_column width=”2/3″][vc_tabs][vc_tab title=”About This Project” tab_id=”1402713028-1-39e9a4-2f88123b-77946048-92948c2b-0e6b”][vc_column_text]

    The easiest way to make and control your own electronics is through a device called an “Arduino”. This video shows you the basics of getting started with it.

    [/vc_column_text][/vc_tab][vc_tab title=”Parts and Code” tab_id=”1402753910272-3-8123b-77946048-92948c2b-0e6b”][vc_button title=”Download The Arduino Software” target=”_blank” icon=”none” size=”btn-huge” href=”http://arduino.cc/en/Main/Software”][vc_column_text]

    Obtaining An Arduino

    Arduino’s can be purchased online at varying prices. Amazon or Ebay will vary greatly in prices. The price also depends on the version of Arduino that you purchase. The current version is the Uno and the older version is the Duemilanove. Other types of Arduino exist as well, such as an Arduino that you can build yourself, Arduino Nano, Lilypad, Arduino BT and a lot more.

    Version Price
    Arduino Uno $29.96

    Installing the Software

    You can download the Arduino software from here. It’s available for Windows, Mac and Linux. It downloads in a zip file, so you will need archiving software such as 7-zip to unzip it. Then you will need to just click on the “Arduino” program icon to launch the program.

    Arduino Uno board

    The first thing you want to do is check to make sure the program is set to match the Arduino board that you are using. You can find out the type of board you have by looking on either the top or the bottom of the board. Then go to Tools>Boards from the menu and select your board.

    Also you need to make sure the correct serial port is selected. This section is also accessed from the Tools menu. If the option is greyed out, then that means your Arduino board is not connected properly. You can find some common troubleshooting techniques below. For most new computers that only have one Arduino connected to them, there will most likely only be one serial port to select.

    Creating A Program

    The Arduino uses C/C++ programming language, so if you’re familiar with those languages you’re already way ahead of the curve. The Arduino program basically allows you to write a program, upload it to your Arduino device and save it for later use. The programs tell the Arduino what to do, how to control things, what information to retrieve, etc. You can find lots of sample programs by going to File > Examples. The sample program used in the video can also be found at File > Examples > 01.Basics > Blink. The final code can be seen here:

    int led = 13;
    
    void setup() {
      pinMode(led, OUTPUT);     
    }
    
    void loop() {
      digitalWrite(led, HIGH);
      delay(1000);
      digitalWrite(led, LOW);
      delay(1000);
    }
    

    As you become more advanced with creating programs and adding devices, you will need to start using different Arduino libraries. The make is easy to extend the functionality of the Arduino in amazing ways.

    Connecting Devices to the Arduino

    The sky is the limit when it comes to what can be connected to the Arduino. But you must know how to connect them. There are lots of input/output ports on the Arduino. Some are analog and some are digital. Please refer to the online documentation to know which pins are best for your project.

    Powering the Arduino

    The Arduino runs off of 5 volts, so whenever it’s connected to your computer via USB, it can power itself. If you wanted to run it separately from your computer, then you would need to supply it with 5 volts via a battery pack or by wiring 5 volts of current through the Arduino’s power pins.

    Troubleshooting

    Serial Port option is greyed out

    This generally means that your Arduino board either is not connected properly or not installed properly. Check your USB cord and the connection to make sure that it is connected properly. On Windows 7 and some Vista machines, you will need to install the drivers for the Arduino before it works. To do this, open up your Device Manager (Start>Search>”Device Manager”) and look for any device that has an exclamation point or question mark beside it. Right click on that device and choose “Update Driver”. Then browse to the “drivers” folder in your Arduino installation folder. After clicking next, it should install the drivers.

    Program does not upload to Arduino

    There three main reasons this will happen:

    1. The board is not connected.
    2. The board is not installed correctly (see above).
    3. The board you are using is different from the board selected in Tools > Boards.

    The LED does not blink

    Please check the previous troubleshooting questions to see if they resolve this problem before continuing. If it still is not working, then the LED is not connected properly. Make sure the positive leg (the longer LED leg) is connected to port 13 and the negative leg (on the same side as the flat part of the LED) is connected to GND. It will not work in any other ports due to port 13 being the only one that has a built-in resistor.

    [/vc_column_text][/vc_tab][vc_tab title=”Important Links” tab_id=”1402753981900-3-10123b-77946048-92948c2b-0e6b”][vc_column_text] Help support my channel: http://www.patreon.com/tinkernut Follow Tinkernut! Google + Facebook Twitter [/vc_column_text][/vc_tab][/vc_tabs][/vc_column][vc_column width=”1/3″][/vc_column][/vc_row]

  • Candle Powered Phone Charger


    [vc_row][vc_column width=”2/3″][vc_separator][venera_framed_image content_type=”video” css_animation=”appear” frame_type=”browser” slider_engine=”flexslider” video_link=”https://www.youtube.com/watch?v=17VU2FkfDOM” browser_url=”https://www.youtube.com/watch?v=17VU2FkfDOM”][vc_separator][/vc_column][vc_column width=”1/3″][/vc_column][/vc_row][vc_row][vc_column width=”2/3″][vc_tabs][vc_tab title=”About This Project” tab_id=”1402713028-1-39e9a4-2f888a6d-d37d835b-230e”][vc_column_text]

    According to the first law of thermodynamics, heat that flows from a hot object to a cold object is energy. An invention called a Peltier Device takes this energy and converts it to a form of electricity. Peltier devices can be found inside USB drink chiller/heaters. Using these principals, we can create a device that charges a cell phone using the heat from a flame lit lamp.

    [/vc_column_text][/vc_tab][vc_tab title=”Parts and Downloads” tab_id=”1402713028-2-39e9a4-2f888a6d-d37d835b-230e”][vc_column_text]

    Parts List

    Here’s a main list of parts and approximate prices:

    Part name Price
    USB drink chiller $10-$20
    Sterno Cooking Fuel $10-$20
    Single AA Emergency Phone Charger $10-$20

    If you want to create a metal stand like I did in the video, here are the parts I used that I found at a local hardware store:

    Part name Quantity
    1/4 Inch Hex Nuts 8
    1/4 Inch Threaded Metal Rod (7-8 inches) 4
    Electrical box face plates 2
    1/4 Inch washers 4
    1/4 Lock washers 4

    Although it’s not required, it’s helpful to have a Multimeter so that you can read what voltage is being output.

    [/vc_column_text][/vc_tab][vc_tab title=”Assembly” tab_id=”1402753910272-3-88a6d-d37d835b-230e”][vc_column_text]

    Obtaining the Peltier Device

    Peltier Devices

    Inside of the USB drink chiller is a peltier device. In it’s current state, it will take electrical impulses and cool down one side of the device while the other side of the device heats up. This is what cools down the drink that is sitting on top of it. But we’ll be using it for the exact opposite of this: we’ll be heating up one side of the peltier device and cooling down the other so that it outputs electricity.

    To remove the Peltier device, just unscrew the bottom of the USB drink chiller. You will probably see a bunch of wires and a heat sink. Unscrew the heat sink, if necessary, and underneath it you will find the Peltier device. You should see a black wire and a red wire coming from the Peltier device. Cut these wires being sure to leave at least a few inches attached to the Peltier device.

    Constructing the stand

    The metal stand serves multiple purposes. Not only does it provide a nice platform for the Peltier device to sit above the fire, but it helps distribute the heat more evenly across the Peltier device.

    Metal Stand Parts

    I used two metal electrical box faceplates to increase the thickness and heat distribution. Most faceplates have 4 holes or notches so that you can easily attach screws, or in our case, metal rods. On each threaded metal rod, place one nut and one lock washer. Adjust the nut and lock washer so that they’re about 4-5 inches from the bottom of the metal rod. Then slide the rods through each of the holes on the faceplates so that the faceplates rest on the lockwashers. The faceplates should now be standing on the metal rods about 4-5 inches above the surface of the table. Lastly, place one washer and one nut over the top of each metal rod and screw them down to secure and stabalize the faceplates.

    Completed Metal Stand

    The Set Up

    The set up is pretty simple. With your stand, place the Peltier device on top of the faceplates with the wires safely hanging over the side. Place a lit flame underneath the faceplates so that it starts heating up the Peltier device. For best results, place a heat sink directly on top of the Peltier device to help keep the opposite side cool.

    If you have a multimeter, connect it to the two wires of the Peltier device to get a voltage reading.

    Adding the Voltage Boost

    Since it’s hard to get the Peltier device to output more than 1.5 – 2 volts, we need to use a voltage booster to jump it up to 5 volts, which is the standard voltage required to charge most cell phones. The necessary voltage booster can be found in an Emergency Phone Charger that uses only one AA battery. For mine, it was very simple to unscrew the Emergency Charger and remove the component that boosts the voltage.

    Noticing which part of the AA battery (plus or minus) touches which part of the voltage booster will allow you to determine which side is positive and which side is negative. Once that is determined, you can use alligator clips, or soldering equipment to attach the negative wire of the Peltier device to the negative terminal of the voltage booster. Do the same for the positive wire and the positive terminal.

    Go ahead and plug your phone into the voltage booster. Once the voltage of the Peltier device reaches 1.5 volts, the phone should start charging.

     

    [/vc_column_text][/vc_tab][vc_tab title=”Important Links” tab_id=”1402753981900-3-108a6d-d37d835b-230e”][vc_column_text]

    Help support my channel:

    1. http://www.patreon.com/tinkernut
    2. Follow Tinkernut! Google +
    3. Facebook
    4. Twitter

    [/vc_column_text][/vc_tab][/vc_tabs][/vc_column][vc_column width=”1/3″][/vc_column][/vc_row]

  • Make A Simple Responsive Website


    [vc_row][vc_column width=”2/3″][vc_separator][venera_framed_image content_type=”video” css_animation=”appear” frame_type=”browser” slider_engine=”flexslider” video_link=”https://www.youtube.com/watch?v=RSoWg29wPVc” browser_url=”https://www.youtube.com/watch?v=RSoWg29wPVc”][vc_separator][/vc_column][vc_column width=”1/3″][/vc_column][/vc_row][vc_row][vc_column width=”2/3″][vc_tabs][vc_tab title=”About This Project” tab_id=”1402713028-1-39e9a4-2f88123b-77946048-92947b1b-34c3″][vc_column_text]

    A responsive website is a website that changes it’s size and shape so that it can be viewed properly on any device. This is a tutorial that shows you the steps on how to make your own responsive website. Before jumping in, it’s best to watch my beginners guide to HTML and CSS at the links below.

    [/vc_column_text][/vc_tab][vc_tab title=”Code” tab_id=”1402753910272-3-8123b-77946048-92947b1b-34c3″][vc_button title=”View sample Site” target=”_blank” icon=”none” size=”btn-huge” href=”http://tinkernut.com/demos/315_responsive/index_responsive.html”][vc_column_text]

    How Does A Responsive Website Work?

    A new addition to CSS3 is an element called a Media query, so if you haven’t already, take a look at my CSS tutorial before continuing. A media query allows CSS code to be executed only when certain constraints are met. For instance, you can set the media query to turn the background color of the webpage blue only when the browser size is 480px. So using media queries, you can have several different sets of CSS for your website that can be activated for many different devices or any browser sizes.

     

    How To Create Media Queries

    Media Queries are elements of CSS3, so they go in the CSS portion of your webpage. Normally the CSS is located in the header using style tags. To create a media query, just add the code below to your CSS:

    <style>
    @media {
    }
    </style>
    

    Then after the @media declaration, you can set the parameters you want to target, such as browser size or device size. For browsers, you can use the max-width attribute. For devices, you can use the max-device-width attribute. To set the media parameters in between a maximum value and a minimum value, you can use both the max-width and min-width attributes within the same parameter.

    <style>
    @media screen and (max-width:480px){
    }
    </style>
    

    This is an example of a max and min parameter:

    <style>
    @media screen and (max-width:800px) and (min-width: 480px){
    }
    </style>
    

    The only thing left to do now is to add your own custom CSS code in between the curly brackets. The CSS can be minimal changes, or you can completely change the design and makeup of the entire site. How much or how little is completely up to you.

    <style>
    @media screen and (max-width:480px) {
         div.main{
    	width:300px;
         }
         div.row2col1{
    	font-size:0.5em;
         }
         img{
    	width: 250px;
         }
         p.welcome {
    	font-size:0.8em;
         }
         p.content {
    	font-size:0.7em;
         }
    					
    }
    </style>
    

     

     

    Sample Website Code

    Below is a finished copy of the webpage code used in the video:

    <html>
    	<head>
    		<title>My Data</title>
    		<style>
    			b{
    			color:#000000;
    			}
    			a{
    			text-decoration:none;
    			color:grey;
    			}
    			img{
    			display:block;
    			margin:auto;
    			}
    			p.welcome {
    				text-align:center;
    				font-family: “verdana”;
    				font-size:1.875em;
    				color:white;
    				font-style:bold;				
    			}
    			p.content {
    				font-family: “verdana”;
    				font-size:1em;
    				color:white;
    				font-style:italic;				
    			}
    			div.main{
    				width:50%;
    				margin:auto;
    				background:#251111;
    			}
    			div.row1{
    			width:100%;
    			}
    			div.row2{
    			width:100%;
    			}
    			div.row2col1{
    				float:left;
    				margin:0;
    				padding:1em;
    				color:white;
    			}
    			div.row2col2{
    				margin-left:25%;
    				background-color:#0A1616;
    				padding:1em;
    				border:15px solid #251111;
    			}
    			body{
    				background-color:#393635;
    				color:white;
    			}
    			@media screen and (max-width:480px) {
    					div.main{
    						width:300px;
    					}
    					div.row2col1{
    						font-size:0.5em;
    					}
    					img{
    						width: 250px;
    					}
    					p.welcome {
    						font-size:0.8em;
    					}
    					p.content {
    						font-size:0.7em;
    					}
    					
    			}
    			@media screen and (max-width:800px) and (min-width: 480px) {
    					div.main{
    						width:600px;
    					}
    					div.row2col1{
    						font-size:0.7em;
    					}
    					img{
    						width: 400px;
    					}
    					p.welcome {
    						font-size:1em;
    					}
    					p.content {
    						font-size:0.8em;
    					}
    					
    			}
    		</style>
    	</head>
    	<body>		
    		<div class="main">
    			<div class="row1">
    				<img src="logo.jpg"/>
    			</div>
    			<div class="row2">
    				<div class="row2col1">
    					Navigation
    					<hr align="left" width=75%>						
    						<ul>
    							<li><a href="about.html">About Me</a></li>
    							<li><a href="http://www.google.com">Google</a></li>
    						</ul>
    				</div>
    				<div class="row2col2"><p class="welcome" >Welcome to my data page!</p><p class="content" >This page is a work in progress that will eventually show places for data input, as well as data recall. Check back here for updates and more information! Thanks for visiting!</p>
    				</div>
    			</div>
    
    		</div>
    		
    	</body>
    </html>
    
    
    

     

    [/vc_column_text][/vc_tab][vc_tab title=”Important Links” tab_id=”1402753981900-3-10123b-77946048-92947b1b-34c3″][vc_column_text]

    Important Links:

    Help support my channel:

    [/vc_column_text][/vc_tab][/vc_tabs][/vc_column][vc_column width=”1/3″][/vc_column][/vc_row]

  • Website Basics 6 – MySQL


    [vc_row][vc_column width=”2/3″][vc_separator][venera_framed_image content_type=”video” css_animation=”appear” frame_type=”browser” slider_engine=”flexslider” video_link=”https://www.youtube.com/watch?v=WKw_Q3wUX0Q” browser_url=”https://www.youtube.com/watch?v=WKw_Q3wUX0Q”][vc_separator][/vc_column][vc_column width=”1/3″][/vc_column][/vc_row][vc_row][vc_column width=”2/3″][vc_tabs][vc_tab title=”About This Project” tab_id=”1402713028-1-39e9a4-2f88123b-77946048-929441a5-bb59″][vc_column_text]

    Many people on the internet aren’t familiar with how to make a decent website on the internet. In an effort to remedy that, this episode kicks off the first of a five part series explaining the different aspects of building a good looking, database driven website from scratch.

     

    In the final part 6 of this series, we will look at the connecting our website to our MySQL database.

    Here’s a list of the other tutorials in the series:

    [/vc_column_text][/vc_tab][vc_tab title=”Code” tab_id=”1402753910272-3-8123b-77946048-929441a5-bb59″][vc_button title=”Download Code Sample” target=”_blank” icon=”none” size=”btn-huge” href=”http://www.tinkernut.com/demos/309_mysql/309_mysql.zip”][vc_column_text]

    What is a database?

    A database is an organized means of storing data and information. There are several different database software programs out there for creating database, but when it comes to websites, MySQL software is most widely used. In the MySQL software, databases are the top level of organization. You can have dozens of different databases depending on your computers storage capacity. Databases classify data into very broad subjects, such as “Financial Database” and “Office Database”. Within each database is a table. Tables are used to classify the data into common groups. For instance, in the “Office Database”, you could have a table for “Coworkers” and a table for “Shifts”. In each table are columns. Columns divide up the data into much more specific groups. Taking the “Coworkers” table from the “Office Database”, you can have columns for “ID”, “First Name”, “Last Name”, “Phone Number”, and “Address”. Within each column is a row or record of data. This is where the actual data goes.

     

    OFFICE DATABASE

    Coworkers
    ID First Name Last Name Phone Number Address
    14 Bob Dole 999-999-9999 1 Google Drive

     

    Creating A MySQL Database

    MySQL is a popular database for websites. Back in our episode of setting up a WAMP server, MySQL, along with PHP, was automatically installed on our server. There are two main ways of creating databases in MySQL. The first is through using PHPMyAdmin. This is the most common interface for web hosting providers. If you were to purchase hosting space from someone, PHPMyAdmin would most likely be your database interface. The second method is through the MySQL command line. Although the command line may seem intimidating, it’s actually a much easier and faster method of setting up a database.

    Setting up a database through the command line means knowing about database queries. A query is an action request for a database. Some examples of database actions are CREATE, SELECT, and INSERT. Click the query link above for a large list of common database queries. When you open up a the command line interface, it will prompt you for a password. By default there is no password, so hitting enter will bypass this prompt. But for security reasons, we should go ahead and create a password. The default account for the database is called “root”, so this is the account that we will need to make a password for. To set a password, you can use this SET query:

    SET PASSWORD FOR 'root'@'localhost' = PASSWORD('abc123');
    

    It’s important to note how each query ends in a semi-colin (;). The capitalization of the letters (the case) is not important. In this instance, it just shows the difference between queries and custom information. Now that we have secured our database with a password, we can view what databases already exist. By default, the MySQL installation comes with a few sample database. To view them, you can use the SHOW query:

    SHOW DATABASES;
    

    This returns a list of existing databases. So now let’s add our own database to the list. Creating a new database is simple. Just use the CREATE DATABASE query followed by a name that you have chosen for your database. Here’s an example:

    CREATE DATABASE my_data;
    

    Before we can add stuff to our new database, we have to actually select it. So to do that, we will use the USE query:

    USE my_data;
    

    This selects our database and any queries from here on will be executed within our database. So the next step is to create a table within our database. Your database can have several different tables, but for now we will just create one. Using the CREATE query again, we can create a table with a name of our choice:

    CREATE TABLE users;
    

    But to make things simpler, we can use CREATE TABLE query and go ahead and attach our column query onto it. When creating columns, you have to include character specifications for each column so that the database knows which characters are and are not allowed. There’s four core types to choose from: numbers signified by the type INT (for integer), text and numbers signified by the type VARCHAR, text signified by the type TEXT, and date formats signified by the type DATE. For TEXT and VARCHAR types, you can also specify the number of characters allowed for each column. For instance, most first names are generally less than 20 characters long (the name “gigafide” is 8 characters long). So you can set the character limit for those types by adding it in parenthesis, such as VARCHAR(20). Keep in mind that if the characters are longer than that number, only 20 characters will be stored in the database.

    CREATE TABLE users(id int, username varchar(20), password varchar(100));
    

    For records, it’s good practice to have a column that stores a unique value that can be used to differentiate between all of the different records. This is why most tables have an ID column. This column of unique values is called a Primary Key. So that we don’t have to constantly enter a unique value manually when adding a new record, we can set it to automatically increment with each new addition. To do this, add the AUTO_INCREMENT query to the id column. Also, we need to make this column required so that it is never accidently left blank. So we can add the NOT NULL query to it as well. To wrap it all up, after all the columns are listed, add a PRIMARY KEY query and set it to the column that you want to use as the primary key. In this case, it’s the id column. Here is what the final CREATE TABLE query will look like:

    CREATE TABLE users(id int NOT NULL AUTO_INCREMENT, username varchar(20), password varchar(100), PRIMARY KEY (id));
    

    Now we have our database, table, and columns. All that’s left to do is add data to the columns. For inserting data, we will be using the INSERT INTO query. Then we just add the table name that we want, the columns that we will be inserting values into, and then the values themselves.

    INSERT INTO users(username,password) values('gigafide','abc123');
    

    Finally, to view what you’ve just created, you can use the SELECT query followed by an asterisk (*), which says to select all values.

    SELECT * FROM users;
    

    Encryption

    When dealing with passwords, it’s a good precaution to encrypt password values before they are inserted into the database. There are tons of different available encryptions out there, but the most common one when dealing with MySQL is called Md5. Encrypting a value using the Md5 encryption method is really simple. All you have to do is enclose the value that you want to encrypt with parenthesis and add md5 to the beginning of it. Below is an example where the password value has been encrypted.

    INSERT INTO users(username,password) values('gigafide',md5('abc123'));
    

    Be aware that if you want to compare any values to the encrypted database value, the compared value will need to be encrypted as well or else it will not match up with what is in the database.

    Connecting a webpage to your database

    If you want to use the data in our database with your webpage, you will need to create a script that connects it to your database. The most common language used for interfacing a website with a database is PHP. This is because PHP has a lot of built in functions that makes it easy to get information from databases. For example, to log into a database, you can use a function called mysql_connect and it takes the parameters of your server location, you server username, and your server password. If you are running a WAMP server, your server location will be localhost. Otherwise, it will probably be an IP address or URL of some sort.

    mysql_connect("localhost","root","abc123");
    

    To test connectivity, you will need to set this function equal to a PHP variable and then add it to an IF statement to see if there are any errors upon connection. If there are, you can have it return any errors using the mysql_error() function. Otherwise, you can select the database you want to use. This can be done using the mysql_select_db function using your database name and the mysql_connect variable. The full final connection script should look something like this.

    <?php
    	$db_con = mysql_connect("localhost","root","abc123");
    	if (!$db_con)
    	  {
    		die('Could not connect: ' . mysql_error());
    	  }
    	  mysql_select_db("my_data", $db_con);
    ?>
    

    This code can be added directly to the webpage, or it can be added to a page of it’s own. As an example, you can save this script to a page called config.php and then link to this page from any other webpage using the include PHP script:

    <?php
         include('config.php');
    ?>
    

    Verifying User Credentials With A Database

    One primary use of a database is to store user information and then use that information to verify a user when they log in to your website. In the previous PHP tutorial, we created a form that asked for log in credentials and then passed those credentials to a page that verified them and then logged the user into the website if the credentials were correct. We can use this same method to validate the user using the database, but we have to change a few things first. Here is the original verification code:

    <?php
    $mypass = “abc123”;
    $passcheck = $_POST[“password”];
    if ($passcheck == $mypass){
    echo “Welcome, ” . $_POST[“username”] . “! You are now logged in.
    “;
    $_SESSION[‘user’]= $_POST[“username”];
    $_SESSION[‘pass’]= $passcheck;
    }
    else
    echo “Sorry, wrong password.
    “;

    ?>

    The variables store the valid password and the password sent from the form. Since the valid password is now in the database, we can remove the the $mypass variable and replace it with a $usercheck variable that stores the username sent from the form.

    $usercheck = $_POST["username"];
    

    Next we need to create a database query that checks to see if the submitted username is actually in the database. We can use the PHP mysql_query function along with the SELECT * FROM query. Then we set the select parameters WHERE the username is equal to the usercheck variable from the form. Then you can set that entire query equal to a variable.

    $db_query = mysql_query("SELECT * FROM users WHERE username = '" . $usercheck  . "'");
    

    After that, before checking the password, you need to actually run the query and see if it returns any results. So you can use an IF statement to see if it returns a row. If it does, then you can run the password verification script. If not, then you can echo a result saying that the password is wrong.

    if (mysql_num_rows($db_query) == 1){
         ....PASSWORD SCRIPT....
    }
    else
         echo "Sorry, wrong username. <br/>";
    

    In order to check the submitted password variable with the password from the database, we need to assign the row that was found to an array variable using the mysql_fetch_array function.

    $record = mysql_fetch_array($db_query);
    

    This will allow us to select any column from that record. So the column that we want is the password column. To access it, you just type the $record variable followed by the column in question.

    $record['password']
    

    With that in mind, and remembering to encrypt the submitted password, our new password check if statement should look like this:

    if (md5($passcheck) == $record['password']){
    

    The final script in it’s entirety looks like this:

    <?php
    if (mysql_num_rows($db_query) == 1){
         $record = mysql_fetch_array($db_query);
         if (md5($passcheck) == $record['password']){
    	echo "Welcome, " . $usercheck . "! You are now logged in. <br/>";
    	$_SESSION['user']= $usercheck;
    	$_SESSION['pass']= $passcheck;
         }
          else
    	echo "Sorry, wrong password. <br/>";
    }
    else
         echo "Sorry, wrong username. <br/>";
    ?>
    

    Adding Form Data To A Database

    Retrieving information from a database is only half of the database functionality. With PHP, you can also add values and records to a database. A common reason to do this is to store data from a form, such as adding a user to a website. So, you will need to start out with a typical PHP form, that points to a page that can add the data to the database. We’ll call this page “add_user.php”. Here’s a typical form:

    <form action='add_user.php' method='post'>
    Name:<input type='text' name='addusername'/>
    Password:<input type='password' name='addpassword'/>
    <input type='submit' value='Add'/>
    </form>
    

    Notice that the password type is set to password. This will make it so that the form field shows only dots instead of revealing the actual password. This form stores the form fields as addusername and addpassword variables and then passes those variables to the add_user.php page that will then insert the values into the database. For the add_user page, you want to make sure you start the session and that you include the config.php page first so that we connect to the database:

    <?php session_start(); 
    include('config.php');
    ?>
    

    Then you can add your page theme or template. For the content, you want to run an INSERT query using the variables sent from the form. Before adding the password, however, make sure that it is first encrypted using md5. Then assing this query to a variable, and run it through an IF statement to execute it. If it fails, then display the error. If it succeeds then you can echo “User Added”.

    <?php
         $db_query="INSERT INTO users (username, password) VALUES ('$_POST[addusername]',md5('$_POST[addpassword]'))";
         if (!mysql_query($db_query)){
              die('Error: ' . mysql_error());
         }
         echo "User Added";
    ?>
    

    Inserting Database Data Into HTML Tables

    A good way to show data from a database on a webpage is by displaying it in an HTML table. The first step in this process is to create a SQL query variable that selects the table or data that you want to display.

    <?php
         $db_query= mysql_query("SELECT * FROM users");
    ?>	
    

    The next step is to use PHP to echo an HTML table with one row and two columns: One for User ID and one for Username.

    <?php
         $db_query= mysql_query("SELECT * FROM users");
         echo "<center><h1> User List:</h1><table border='1'>
         <tr>
         <td><b>User ID</b></td>
         <td><b>Username</b></td>
         </tr>
         </table>
         </center>";
    ?>
    

    We want to add more rows, but we want the rows to be equal to the amount of data records returned from the query. The most effective way to do this is to put the row HTML within a while loop so that it loops a new row for each record until there are no more records. Then display the results in the columns using record array.

    <?php
         $db_query= mysql_query("SELECT * FROM users");
         echo "<center><h1> User List:</h1><table border='1'>
         <tr>
         <td><b>User ID</b></td>
         <td><b>Username</b></td>
         </tr>";
         while($record = mysql_fetch_array($db_query)){
              echo "<tr>";
              echo"<td>" . $record['id'] . "</td>";
              echo"<td>" . $record['username'] . "</td>";
              echo"</tr>";
         }
         echo"</table></center>";
    ?>
    

    Pay close attention to the echo statements and how you have to make sure the PHP code is not enclosed within an echo statement. Each line of the new row within the while loop as it’s own echo statement.

    Final Code

    Here is the final code for the pages used in this tutorial. You can combine these with pages from other tutorials that are not included here.

    config.php

    <?php
         $db_con = mysql_connect("localhost","root","abc123");
         if (!$db_con){
              die('Could not connect: ' . mysql_error());
         }
         mysql_select_db("my_data", $db_con);
    ?>
    

    add_user.php

    <?php session_start(); 
    include('config.php');
    ?>
    <html>
    <head>
    <title>My Data</title>
    		<link rel="stylesheet" type="text/css" href="style.css" />
    </head>
    <body>
    
    <?php include("header.php"); ?>
    <p class="welcome" id="greeting">
    <?php
      $db_query="INSERT INTO users (username, password) VALUES ('$_POST[addusername]',md5('$_POST[addpassword]'))";
    
    if (!mysql_query($db_query))
      {
      die('Error: ' . mysql_error());
      }
    echo "User Added";
    ?>
    </p>
    <a href="index.php">Click here</a> to return to the main page.
    <?php include("footer.php"); ?>
    
    	</body>
    </html>
    

    welcome.php

    <?php session_start(); 
    include('config.php');
    ?>
    <html>
    <head>
    <title>My Data</title>
    		<link rel="stylesheet" type="text/css" href="style.css" />
    </head>
    <body>
    
    <?php include("header.php"); ?>
    <p class="welcome" id="greeting">
    <?php
    	$usercheck = $_POST["username"];
    	$passcheck = $_POST["password"];
    	$db_query = mysql_query("SELECT * FROM users WHERE username = '" . $usercheck  . "'");
    	if (mysql_num_rows($db_query) == 1){
    		$record = mysql_fetch_array($db_query);
    		if (md5($passcheck) == $record['password']){
    			echo "Welcome, " . $usercheck . "! You are now logged in. <br/>";
    			$_SESSION['user']= $usercheck;
    			$_SESSION['pass']= $passcheck;
    			}
    		else
    			echo "Sorry, wrong password. <br/>";
    	}
    	else
    		echo "Sorry, wrong username. <br/>";
    
    ?>
    <a href="index.php">Click here</a> to return to the main page.
    
    <?php include("footer.php"); ?>
    
    	</body>
    </html>
    

    Index.php

    <?php session_start(); 
    include('config.php');
    ?>
    <html>
    	<head>
    		<title>My Data</title>
    		<link rel="stylesheet" type="text/css" href="style.css" />
    		<script>
    			function clicked(){
    			var x;
    			var y;
    			x = document.getElementById('nameCheck').value;
    			y = document.getElementById('password').value;
    			if(x !="" && y !=""){
    				return true;
    				}
    				else if(y ==""){
    					document.getElementById('errorPass').innerHTML='<font color="red">(required) Password:</font>';
    					return false;
    					}
    				else if(x ==""){
    					document.getElementById('errorMsg').innerHTML='<font color="red">(required) Name:</font>';
    					return false;
    				}
    				
    				
    			}
    		</script>
    	</head>
    	<body>		
    <?php include("header.php"); ?>
    					<?php
    					if (isset($_SESSION['user'])){
    					$db_query= mysql_query("SELECT * FROM users");				
    						echo "<center><h1> User List:</h1><table border='1'>
    							<tr>
    							<td><b>User ID</b></td>
    							<td><b>Username</b></td>
    							</tr>";
    							
    						while($record = mysql_fetch_array($db_query)){
    							echo "<tr>";
    							echo"<td>" . $record['id'] . "</td>";
    							echo"<td>" . $record['username'] . "</td>";
    							echo"</tr>";
    							}
    						echo"</table>
    						</center>";
    							}
    					else 
    						echo "<p class ='welcome' id='greeting'> Please Login:</p>
    								<form action='welcome.php' method='post' onSubmit='return clicked();'>
    									<b id='errorMsg'>Name:</b>
    									<input type='text' id='nameCheck' name='username'/>
    									<b id='errorPass'>Password:</b> <input type='password' id='password' name='password'/>
    									<input type='submit' value='Click Me'onClick='clicked()'/>
    								</form>";
    					
    					?>
    					<?php
    					if (isset($_SESSION['user']) && $_SESSION['user']=="gigafide")
    					echo "<p class ='welcome' id='greeting'> Add User:</p>
    								<form action='add_user.php' method='post' onSubmit='return clicked();'>
    									<b id='errorMsg'>Name:</b>
    									<input type='text' id='nameCheck' name='addusername'/>
    									<b id='errorPass'>Password:</b> <input type='password' id='password' name='addpassword'/>
    									<input type='submit' value='Add'/>
    								</form>";
    								?>
    				<p class="content" >This page is a work in progress that will eventually show places for data input, as well as data recall. Check back here for updates and more information! Thanks for visiting!</p>				
    <?php include("footer.php"); ?>
    	</body>
    </html>
    
    
    

     

    [/vc_column_text][/vc_tab][vc_tab title=”Important Links” tab_id=”1402753981900-3-10123b-77946048-929441a5-bb59″][vc_column_text] Help support my channel: http://www.patreon.com/tinkernut Follow Tinkernut! Google + Facebook Twitter [/vc_column_text][/vc_tab][/vc_tabs][/vc_column][vc_column width=”1/3″][/vc_column][/vc_row]

  • Website Basics 5 – PHP


    [vc_row][vc_column width=”2/3″][vc_separator][venera_framed_image content_type=”video” css_animation=”appear” frame_type=”browser” slider_engine=”flexslider” video_link=”https://www.youtube.com/watch?v=j-2Rz3nL2HU” browser_url=”https://www.youtube.com/watch?v=j-2Rz3nL2HU”][vc_separator][/vc_column][vc_column width=”1/3″][/vc_column][/vc_row][vc_row][vc_column width=”2/3″][vc_tabs][vc_tab title=”About This Project” tab_id=”1402713028-1-39e9a4-2f88123b-77946048-92949565-beb2″][vc_column_text]

    Many people on the internet aren’t familiar with how to make a decent website on the internet. In an effort to remedy that, this episode kicks off the first of a five part series explaining the different aspects of building a good looking, database driven website from scratch.
    In part 5 of this series, we will look at the basics of using PHP and adding its functionality to our site.

    Here’s a list of the other tutorials in the series:

    [/vc_column_text][/vc_tab][vc_tab title=”Code” tab_id=”1402753910272-3-8123b-77946048-92949565-beb2″][vc_button title=”Download Code Sample” target=”_blank” icon=”none” size=”btn-huge” href=”http://www.tinkernut.com/demos/308_php/308_php.zip”][vc_column_text]

    Basic PHP Syntax

    There are several requirements before your PHP page will become functional. The first requirement is to make sure that you have a server with PHP installed. If not, you can learn how by watching the create a server tutorial. Your website files must reside on the server. Next, any file that has executable PHP code must be saved as a PHP file. For example, if your index.html page has PHP code in it, it must be saved as index.php before the code can be executed. Lastly, in order for the browser to process PHP, it has to be declared using the following tag structure:

    <?php
         PHP CODE GOES HERE
    ?>
    

    Anything in between those declaration tags will be processed as PHP code. PHP tags can go anywhere in a webpages HTML structure, but is generally found in the body of the HTML code or above the HTML code (before the opening <HTML> tag). To display text or HTML on a webpage using PHP, you want to use the “echo” command. The “echo” command followed by the text or HTML code in quotes will tell it the web browser to process that text or code as regular HTML. Here is an example:

    <?php
         echo "It's PHP!";
    ?>
    

    Notice how the “echo” command is terminated by a semi-colon. Apart from conditional statements, all PHP code should end with a semi-colon. If an echo statement contains HTML code that has quotation marks (“), you will need to replace them with apostrophes (‘). This prevents confusion when processing the PHP code.

    <?php
         echo "<p class ='welcome' id='greeting'> Hi! Welcome to my site!</p>";
    ?>
    

     

    Variables

    A variable is an object within programming code that can change it’s value as the program is executed. It’s similar to mathmatics were variables are used in equations to represent unknown values i.e. 2 + x = 4. Variables are used very frequently in Javascript because their value can be set to whatever you need it to. To create a variable in PHP, you want to come up with a name for your variable, and then precede it with a dollar ($) sign. Then you can set it equal to the value you desire. To recall the variable at any point in your code, simple type the name of the full name of the variable including the $ sign.

    <?php
         $username = "gigafide";
         echo $username;
    ?>
    

    When returning a variable value, sometimes you may want the variable to appear in the middle of a string of other text, such as a sentence. This is called concatenation As opposed to Javascript where a plus (+) sign is used to concatenate strings together, PHP uses a period (.) to concatenate.

    <?php
         $username = "gigafide";
         echo "<p class ='welcome' id='greeting'> Hi, " . $username . "! Welcome to my site!</p>";
    ?>
    

    Conditional Statements

    A conditional statement is a section of code whose output is dependent on certain conditions. In PHP, this is charactarized by an “if” statement. An “if” statement will output a result if certain conditions are met. The syntax of an “if” statement starts with if followed by the conditions in a set of parenthesis. Immediately following this, you will put the line of code to be executed if the conditions are met. If you have more than one condition to be executed, you can enclose the code to be executed within curly brackets. If the conditions are not met, you can add an “else” statement after the “if” statement. The else statement can contain code to be executed if the conditions are not met.

    <?php
         if($username == "gigafide"){
              echo "<p class ='welcome' id='greeting'> Hi, " . $username . "! Welcome to my site!</p>";
              echo "Thanks for visiting!";
         }else 
              echo "Hi! Welcome to my site!";
    ?>
    

    Include

    A great benefit that PHP offers is the ability to import HTML or PHP code into your page from a separate file. This is through a function called the include command. Include is often used when creating website templates. [WordPress] is a common platform that makes regular use of the include function for its templates. Here is how it works. Create a seperate page (both html and php pages will work) and put a section of HTML code in it. Then, on your main webpage, place the PHP include function with the seperate pages name wherever you want it to appear on the main webpage.

    <?php
         include("header.php");
    ?>
    

    This is a good method of keeping a website organized. If you have a section of your website (such as a navigation menu) that stays static throughout your website, you can use it as an include webpage instead. This will shorten the websites code significantly, as well as allow you to only have to modify one page.

    Think of it this way: if you have 100 pages on your website,and they all had a common menu, it would be a tedious task to edit 100 menus. With PHP, you can include one menu in 100 pages, and edit one menu to complete the task.

    Passing Information Between Pages

    Forms

    Method:GET

    Method:POST

    Storing User Information

    If you’re going to create a website that requires a user to enter information, it’s almost a necessity to store that information somewhere so that the user doesn’t have to enter it again and so that it can be recalled later and used elsewhere in the site. In PHP, there are two methods of storing a users information. One is Cookies and the Other is Sessions.

    Cookies

    Cookies are a means of storing a user’s information so that the user doesn’t have to enter in the same information again. For instance, websites commonly store a cookie of your username and password so that you don’t have to keep logging in to the website everytime you visit. Cookies store the information on the client’s computer as a small file. If the website needs to recall that information later, it can open up the cookie and read the information stored there. Let’s say you want store information from a form to a cookie. First you need to create a cookie using “setcookie” parameter, then give it a name, the value you want to store, and the time before it expires.

    <?php
         setcookie("user", $_POST["username"], time()+3600);
    ?>
    

    Then if you want to recall that value later on, you can use this code

    <?php
         echo $_COOKIE["user"];
    ?>
    

    Or if you wanted to return the entire contents of a cookie, you can use this code

    <?php
         print_r($_COOKIE);
    ?>
    

    To use the cookie information in a conditional statement, you want to use the ISSET command to check and see if there is information stored in the cookie. If there is information stored in it, you can execute one set of commands. IF there is not information stored in it, you can execute another set of commands.

    <?php
         if (isset($_COOKIE["user"]))
           echo "Hi, " . $_COOKIE["user"] . "Welcome to my site!<br />";
    ?>
    

    Finally, if you want to delete the cookie information (such as to create a “log out” page), essentially you just set the cookie expiration date to a negative value.

    <?php
         setcookie("user", "", time()-3600);
    ?>
    

    Sessions

    Sessions are another means of storing users information. Except, unlike Cookies, they store information on the server as opposed to the clients computer. To start a session, you have to put a session_start script at the beginning of every webpage that uses session information (above the opening HTML tag).

    <?php session_start(); ?>
    

    Session information can then be stored to $_SESSION variables the same way you would store any other variable. Then you can recall the session information by simply using the variable name you created. Here’s an example.

    <?php
         $_SESSION['user']="gigafide;
         echo "Hi, ". $_SESSION['user'];
    ?>
    

    Similar to the cookie example above, you can use Session information in an if statement by adding the ISSET command.

    <?php
         if(isset($_SESSION['user']))
           echo "Hi," . $_SESSION['user'] . "!";
    ?>
    

    And then finally, to stop storing information for a session (and to forget the stored information), you can add a session_destroy command underneath the session_start command for your logout page.

    <?php
    session_start(); 
    session_destroy();
    ?>
    

    Final Code

    After completeing the tutorial, you should have something similar to the code below. Please use this code for reference and correction.

    header.php

    <div class="main">
    	<div class="row1">
    		<img src="logo.jpg"/>
    	</div>
    	<div class="row2">
    		<div class="row2col1">
    			Navigation
    			<hr align="left" width=75%>						
    				<ul>
    					<li><a href="about.html">About Me</a></li>
    					<li><a href="http://www.google.com">Google</a></li>
    				</ul>
    		</div>
    		<div class="row2col2">
    

    footer.php

              </div>
         </div>
     </div>
    

    logout.php

    <?php
    session_start(); 
    session_destroy();
    ?>
    <html>
    <head>
    <title>My Data</title>
    		<link rel="stylesheet" type="text/css" href="style.css" />
    </head>
    <body>
    
    <?php include("header.php"); ?>
    <p class="welcome" id="greeting">
    You are now logged out
    </p>
    
    	</body>
    </html>
    

    welcome.php

    <?php session_start(); ?>
    <html>
    <head>
    <title>My Data</title>
    		<link rel="stylesheet" type="text/css" href="style.css" />
    </head>
    <body>
    <?php include("header.php"); ?>
    <p class="welcome" id="greeting">
    <?php
    	$mypass = "abc123";
    	$passcheck = $_POST["password"];
    	if ($passcheck == $mypass){
    		echo "Welcome, " . $_POST["username"] . "! You are now logged in. <br/>";
    		$_SESSION['user']= $_POST["username"];
    		$_SESSION['pass']= $passcheck;
    		}
    	else
    		echo "Sorry, wrong password. <br/>";
    ?>
    <a href="index.php">Click here</a> to return to the main page.
    <?php include("footer.php"); ?>
    	</body>
    </html>
    

    Index.php

    <?php session_start(); ?>
    <html>
    	<head>
    		<title>My Data</title>
    		<link rel="stylesheet" type="text/css" href="style.css" />
    		<script>
    			function clicked(){
    			var x;
    			var y;
    			x = document.getElementById('nameCheck').value;
    			y = document.getElementById('password').value;
    			if(x !="" && y !=""){
    				return true;
    				}
    				else if(y ==""){
    					document.getElementById('errorPass').innerHTML='<font color="red">(required) Password:</font>';
    					return false;
    					}
    				else if(x ==""){
    					document.getElementById('errorMsg').innerHTML='<font color="red">(required) Name:</font>';
    					return false;
    				}
    				
    				
    			}
    		</script>
    	</head>
    	<body>		
    		<?php include("header.php"); ?>
    			<?php
    			
    			if (isset($_SESSION['user']))
    				echo "<p class ='welcome' id='greeting'> Hi, " . $_SESSION['user'] . "! Welcome to my site!</p>";
    			else 
    				echo "<p class ='welcome' id='greeting'> Please Login:</p>
    						<form action='welcome.php' method='post' onSubmit='return clicked();'>
    							<b id='errorMsg'>Name:</b>
    							<input type='text' id='nameCheck' name='username'/>
    							<b id='errorPass'>Password:</b> <input type='text' id='password' name='password'/>
    							<input type='submit' value='Click Me'onClick='clicked()'/>
    						</form>";
    			
    			?>
    			<?php
    			if (isset($_SESSION['user']))
    				echo "<center><h1> User List:</h1>
    					<table border='1'>
    					<tr>
    					<td><b>User</b></td>
    					<td><b>Login password</b></td>
    					</tr>
    					<tr>
    					<td>" . $_SESSION['user'] . "</td>
    					<td>" . $_SESSION['pass'] . "</td>
    					</tr>
    					</table>
    					</center>";
    			?>
    			<?php if (isset($_SESSION['user']))
    				echo "<center><a href='logout.php'>Logout</a></center>";?>
    			<p class="content" >This page is a work in progress that will eventually show places for data input, as well as data recall. Check back here for updates and more information! Thanks for visiting!</p>
    				
    		<?php include("footer.php"); ?>
    	</body>
    </html>
    

     

    [/vc_column_text][/vc_tab][vc_tab title=”Important Links” tab_id=”1402753981900-3-10123b-77946048-92949565-beb2″][vc_column_text] Help support my channel: http://www.patreon.com/tinkernut Follow Tinkernut! Google + Facebook Twitter [/vc_column_text][/vc_tab][/vc_tabs][/vc_column][vc_column width=”1/3″][/vc_column][/vc_row]

  • Make A Complete Website From Scratch – Part 4:Server


    [vc_row][vc_column width=”2/3″][vc_separator][venera_framed_image content_type=”video” css_animation=”appear” frame_type=”browser” slider_engine=”flexslider” video_link=”https://www.youtube.com/watch?v=cUMYcuOjfns” browser_url=”https://www.youtube.com/watch?v=cUMYcuOjfns”][vc_separator][/vc_column][vc_column width=”1/3″][/vc_column][/vc_row][vc_row][vc_column width=”2/3″][vc_tabs][vc_tab title=”About This Project” tab_id=”1402713028-1-39e9a4-2f88123b-77946048-9294f5dc-5b7c”][vc_column_text]

    Many people on the internet aren’t familiar with how to make a decent website on the internet. In an effort to remedy that, this episode kicks off the first of a five part series explaining the different aspects of building a good looking, database driven website from scratch.

     

    In part 4 of this series, we will look at the basics of creating a MySQL database that will store the content for our website.

    Here’s a list of the other tutorials in the series:

    [/vc_column_text][/vc_tab][vc_tab title=”Important Links” tab_id=”1402753981900-3-10123b-77946048-9294f5dc-5b7c”][vc_column_text]

    Links used in the video:

    1. http://www.wampserver.com
    2. http://www.thegeekstuff.com/2008/09/how-to-install-or-upgrade-lamp-apache-mysql-and-php-stack-on-linux-using-yum
    3. http://www.mamp.info/en/index.html
    4. http://www.cmyip.com
    5. http://www.no-ip.com

     

    Help support my channel: http://www.patreon.com/tinkernut Follow Tinkernut!

    1. Google +
    2. Facebook
    3. Twitter

    [/vc_column_text][/vc_tab][/vc_tabs][/vc_column][vc_column width=”1/3″][/vc_column][/vc_row]