At this point, we have a basic idea about how to build our project, and we also have all the software required for our project. In this section, we will go through a number of iterations until we reach the final goal of using a remote device to control the lamp.
We will do this in three steps:
During development, it's inefficient to always boot the Raspberry Pi using, for example, an HDMI connection to a TV that also requires a separate mouse and keyboard to control the Pi. Using HDMI, we will not be able to track the early boot procedure either. For this project, we also want to be able to troubleshoot the Raspberry Pi without the need to place it close to a TV. For our project, we will either use SSH or a serial connection to reduce turnaround time during development.
The first method is to use a serial connection to the Raspberry Pi. The easiest way to achieve this is to use a USB-to-serial cable. Connect the USB to the your host machine. Then, connect the four wire cables to the correct GPIO pins on the Raspberry Pi, as showed in the following figure:
The following table will give a more detailed explanation of how the GPIO wires should be connected. Also check the GPIO header diagram in Chapter 8 , Diving into the Raspberry Pis Peripherals and Yocto Recipes. to review the purpose of all the pins in the GPIO header.
Red |
5V |
Black |
GND |
White |
GPIO 14 (TXD) |
Green |
GPIO 15 (RXD) |
Once the physical connection has been set up, we can continue with preparing our host environment. In this example, we will use the screen
package to set up our console connection.
To set up screen
on Ubuntu, use this command:
$ sudo apt-get install screen
Use this one to set it up on Fedora:
$ sudo yum install screen
Next, we must ensure that we have plugged in the USB cable to our Raspberry Pi (remember that no additional power supply is needed). After that, we can open a terminal window and type the following command, which will connect us to the Raspberry Pi console:
$ sudo screen /dev/ttyUSB0 115200 <snip> [ 2.017380] [vc_sm_connected_init]: end - returning 0 [ 2.023899] uart-pl011 3f201000.uart: no DMA platform data [ 2.034527] EXT4-fs (mmcblk0p2): INFO: recovery required on readonly filesystem [ 2.041844] EXT4-fs (mmcblk0p2): write access will be enabled during recovery [ 2.093584] EXT4-fs (mmcblk0p2): recovery complete [ 2.103945] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null) [ 2.112154] VFS: Mounted root (ext4 filesystem) readonly on device 179:2. [ 2.122995] devtmpfs: mounted . . . Starting syslogd/klogd: done Poky (Yocto Project Reference Distro) 2.0+snapshot-20160229 raspberrypi2 /dev/ttyAMA0 raspberrypi2 login: [ 17.906610] random: nonblocking pool is initialized Poky (Yocto Project Reference Distro) 2.0+snapshot-20160229 raspberrypi2 /dev/ttyAMA0 raspberrypi2 login:
If we have connected a network cable to the Raspberry Pi, we can use this method to grab the IP address of our board:
root@raspberrypi2:~# ifconfig eth0 | grep "inet addr" inet addr:192.168.1.13 Bcast:192.168.1.255 Mask:255.255.255.0
The other method to gain quick access to the Raspberry Pi without using any external equipment (such as a mouse, keyboard, or TV) are using SSH. If you have an SSH daemon running on your Raspberry Pi and it's connected to the network, you can access it through SSH using your host machine, with a command similar to this:
$ ssh [email protected] root@raspberrypi2:~#
Now we are ready to get going with connecting the relay and lamp to our Raspberry Pi.
18.222.120.133