Internet of Things Laboratory Manual
Internet of Things Laboratory Manual
INTERNET OF THINGS
LABORATORY MANUAL
ROLL NO :………………………………………………………………
BRANCH:……………………………..SECTION:……………………
YEAR: …………………………SEMESTER:………………………..
1
INTERNET OF THINGS LAB for 2021-2022 SVIT
III Year BTech II Sem L T/P/D C
003 1.5
Program Objectives:
Course Objectives
2. To introduce the Python Scripting Language which is used in many IoT devices
List of Experiments:
Flashing the OS on to the device into a stable functional state by porting desktop environment with
necessary packages.
Making use of available laptop/desktop displays as a display for the device using SSH client & X11
display server.
3. GPIO Programming
Programming of available GPIO pins of the corresponding device using native programming language.
Interfacing of I/O devices like LED/Switch etc., and testing the functionality.
2
Chronos device is a programmable texas instruments watch which can be used for multiple purposes
like PPT control, Mouse operations etc., Exploit the features of the device by interfacing with devices.
Using the light sensors, monitor the surrounding light intensity & automatically turn ON/OFF the high
Monitor the voltage level of the battery and indicating the same using multiple LED's (for ex: for 3V
battery and 3 led's, turn on 3 led's for 2-3V, 2 led's for 1-2V, 1 led for 0.1-1V & turn off all for 0V)
Instead of using the conventional dice, generate a random value similar to dice value and display the
same using a 16X2 LCD. A possible extension could be to provide the user with option of selecting
Displaying the RSS news feed headlines on a LCD display connected to device. This can be adapted
to other websites like twitter or other information websites. Python can be used to acquire data from the
internet.
Attempt to use the device while connecting to a wifi network using a USB dongle and at the same time
3
Building and hosting a simple website(static/dynamic) on the device and make it accessible online.
There is a need to install server(eg: Apache) and thereby host the website.
Interfacing the regular usb webcam with the device and turn it into fully functional IP webcam & test the
functionality.
12. FM Transmission
Transforming the device into a regular fm transmitter capable of transmitting audio at desired frequency
4
Text Books:
1. Internet of Things - A Hands-on Approach, Arshdeep Bahga and Vijay Madisetti, Universities
Press, 2015, ISBN: 9788173719547
2. Getting Started with Raspberry Pi, Matt Richardson & Shawn Wallace, O'Reilly (SPD), 2014,
ISBN: 9789350239759
Program Outcomes:
1. Interpret the impact and challenges posed by IoT networks leading to new architectural
models.
2. Compare and contrast the deployment of smart objects and the technologies to connect
them
to network.
3. Appraise the role of IoT protocols for efficient network communication.
4. Elaborate the need for Data Analytics and Security in IoT.
5. Illustrate different sensor technologies for sensing real world entities and identify the
applications of IoT in Industry
5
INTERNET OF THINGS LAB for 2021-2022 SVIT
CONTENTS
5 ON/OFF Control Based On Light Intensity Using the light sensors, monitor the 17
surrounding light intensity & automatically turn ON/OFF the high intensity
LED's by taking some pre-defined threshold light intensity value.
6 Dice Game Simulation Instead of using the conventional dice, generate a random value 18
similar to dice value and display the same using a 16X2 LCD. A possible extension
could be to provide the user with option of selecting single or double dice game
7 Displaying RSS News Feed On Display Interface Displaying the RSS news feed 22
headlines on a LCD display connected to device. This can be adapted to other websites
like twitter or other information websites. Python can be used to acquire data from the
internet.
8 25
Porting Openwrt To the Device Attempt to use the device while connecting to a
wifi network using a USB dongle and at the same time providing a wireless
access point to the dongle.
9 36
Hosting a website on Board Building and hosting a simple
website(static/dynamic) on the device and make it accessible online.There is a
need to install server(eg: Apache) and thereby host the website.
10 Webcam Server Interfacing the regular usb webcam with the device and turn it into 40
fully functional IP webcam & test the functionality.
11 FM Transmission Transforming the device into a regular fm transmitter capable of 45
transmitting audio at desired frequency (generally 88-108 Mhz)
6
Raspberry Pi and its components.
The Raspberry Pi Components
The Raspberry Pi device looks like a motherboard, with the mounted chips and ports exposed
(something you'd expect to see only if you opened up your computer and looked at its internal boards),
but it has all the components you need to connect input, output, and storage devices and start
computing.
You'll encounter two models of the device: Model A and Model B. The only real differences are the
addition of Ethernet and an extra USB port on the more expensive Model B.
• ARM CPU/GPU -- This is a Broadcom BCM2835 System on a Chip (SoC) that's made up of an ARM central
processing unit (CPU) and a Videocore 4 graphics processing unit (GPU). The CPU handles all the
computations that make a computer work (taking input, doing calculations and producing output), and the
GPU handles graphics output.
• GPIO -- These are exposed general-purpose input/output connection points that will allow the real
hardware hobbyists the opportunity to tinker.
• RCA -- An RCA jack allows connection of analog TVs and other similar output devices.
• Audio out -- This is a standard 3.55-millimeter jack for connection of audio output devices such as
headphones or speakers. There is no audio in.
• LEDs -- Light-emitting diodes, for all of your indicator light needs.
• USB -- This is a common connection port for peripheral devices of all types (including your mouse and
keyboard). Model A has one, and Model B has two. You can use a USB hub to expand the number of ports
or plug your mouse into your keyboard if it has its own USB port.
• HDMI -- This connector allows you to hook up a high-definition television or other compatible device using
an HDMI cable.
• Power -- This is a 5v Micro USB power connector into which you can plug your compatible power supply.
• SD cardslot -- This is a full-sized SD card slot. An SD card with an operating system (OS) installed is
required for booting the device. They are available for purchase from the manufacturers, but you can also
download an OS and save it to the card yourself if you have a Linux machine and the wherewithal.
• Ethernet -- This connector allows for wired network access and is only available on the Model B.
7
Many of the features that are missing, such as WiFi and audio in, can be added using the USB port(s) or a
USB hub as needed. Next: More details on the device itself and its compatible operating systems.
8
1.Flashing the OS on to the device into a stable functional state by porting desktop environment
with necessary packages.
How to Install Raspbian on Raspberry Pi
The Raspberry Pi is the most popular single-board computer of all time. It can be used for various
purposes such as desktop PC, home media center, smart WiFi router, automation system, and game
server. The use cases are endless.
If your Raspberry Pi comes without an SD card preloaded with NOOBS, you will need to install an operating system
on your SD card manually. You can run many different operating systems on Raspberry Pi, including various Linux
distributions such as Arch Linux , Windows 10 IoT, and FreeBSD.
Raspbian is the recommended OS by the Raspberry Pi Foundation. It is based on Debian, built specifically
for the Raspberry Pi boards. Raspbian comes pre-installed with a plethora of software for development,
education, and multimedia, making it the best general-purpose OS for Raspberry Pi users.
Installing Raspbian is as simple as writing the OS image file to the SD card. This tutorial will show you
how to format the SD card, flash the Raspbian image, and boot up the Raspberry Pi.
If you want to use Raspberry Pi as a desktop PC, download one of the Raspbian desktop images.
Otherwise, if you intend to use Raspberry Pi as a media center or anything else that doesn’t require a GUI,
download the Raspbian Lite image.
Before flashing the image to the micro SD card, first you need to format it to the FAT32 file system.
The Raspberry Pi’s bootloader supports reading only from FAT file systems. If your SD card is 64GB or
larger, make sure it is formatted as FAT32, not as exFAT.
Note that formatting is a destructive process, and it will erase all the existing data. If you have data on
the SD card, first back it up.
Windows
Windows users can format the card using the standard Disk Management.
2. In the Windows search box, type “Disk” and select “Create and format hard disk partitions” from the results
box.
3. Right-click on the card’s unallocated space and start the Wizard by clicking on “New Simple Volume”. Click
“Next”.
4. Next, you will be asked the volume size. Leave the default maximum disk space. Click “Next”.
9
5. You will be prompted to specify the mount path. Click “Next”.
6. On the next window, select FAT32 as a File system. Click “Next” and then “Finish” to complete the creation
of the partition. If the card is 64GB or larger, the FAT32 option will not be available. Select exFAT and
complete the process. To format the SD card as FAT32, visit the FAT32 Format download page, and
download the tool. Double-click on the exe file, select a drive to format, and click “Start”. The card will be
formatted to FAT32 in a few seconds.
There are several different applications available for free use, which allows you to flash ISO images to SD
cards. In this tutorial, we will use Etcher.
Etcher is a free and open-source utility for flashing images to SD cards & USB drives and supports
Windows, macOS, and Linux.
Head over to the Etcher downloads page , download the most recent Etcher for your operating system,
and install the application.
1. Insert the SD card into your SD card drive and Launch Etcher.
2. Click on the Select image button and locate the Raspbian zip file. If you downloaded the file using
a web browser, then it should be stored in the Downloads folder located in your user account.
Etcher will autoselect the SD card if only one drive is present. Otherwise, if more than one SD card
or USB stick are attached, make sure you have selected the correct drive before flashing the
image.
3. Click on the “Flash” button, and the flashing process will start. Etcher will show a progress bar and
ETA while flashing the image. The process may take several minutes, depending on the size of the
ISO file and the card speed.
On Raspbian, the SSH server is disabled by default. For headless Raspbian setup, you can enable SSH by
placing a file named ssh without any extension onto the boot partition. Simply open the SD card in your
File Manager and create the file.
Put the SD card into your Raspberry Pi board, plug in the monitor, keyboard, and power source, and you’re
ready to go.
10
If you enabled SSH and want to use Raspberry Pi as a headless server, connect the board with a network
cable with your router. Once booted, you can find the board IP address in your router’s DHCP lease table
and login to your Raspbian via ssh:
sudo raspi-configCopy
From here, you can change the pi user password, set up the WiFi, and expand the filesystem.
Conclusion
Installing Raspbian on Raspberry Pi is a pretty straightforward process. Basically, all you need to do is to
write the image to the SD card and boot up the Raspberry Pi.
11
2. Exporting Display On To Other Systems Making use of available laptop/desktop displays
as a display for the device using SSH client & X11 display server
You can access the command line of a Raspberry Pi remotely from another computer or device on the
same network using SSH.
The Raspberry Pi will act as a remote device: you can connect to it using a client on another machine.
You only have access to the command line, not the full desktop environment. For a full remote desktop,
see VNC.
Make sure your Raspberry Pi is properly set up and connected. If you are using wireless networking, this
can be enabled via the desktop's user interface, or using the command line.
If you are not using wireless connectivity, plug your Raspberry Pi directly into the router.
You will need to note down the IP address of your Pi in order to connect to it later. Using
the ifconfig command will display information about the current network status, including the IP
address, or you can use hostname -I to display the IP addresses associated with the device.
2. Enable SSH
As of the November 2016 release, Raspberry Pi OS has the SSH server disabled by default. It can be
enabled manually from the desktop:
12
1. Launch Raspberry Pi Configuration from the Preferences menu
2. Navigate to the Interfaces tab
3. Select Enabled next to SSH
4. Click OK
When enabling SSH on a Pi that may be connected to the internet, you should change its default
password to ensure that it remains secure. See the Security page for more details.
For headless setup, SSH can be enabled by placing a file named ssh , without any extension, onto the
boot partition of the SD card from another computer. When the Pi boots, it looks for the ssh file. If it is
found, SSH is enabled and the file is deleted. The content of the file does not matter; it could contain text,
or nothing at all.
If you have loaded Raspberry Pi OS onto a blank SD card, you will have two partitions. The first one,
which is the smaller one, is the boot partition. Place the file into this one.
SSH is built into Linux distributions and Mac OS, and is an optional feature in Windows 10. For older
Windows versions and mobile devices, third-party SSH clients are available. See the following guides for
using SSH with the OS on your computer or device:
13
• Linux & Mac OS
• Windows 10
• Windows
• iOS
• Android
14
3.GPIO Programming Programming of available GPIO pins of the corresponding device
using native programming language. Interfacing of I/O devices like LED/Switch etc., and
testing the functionality
Note
If you have used the same pin in several scripts at the same time, you will see a warning when the code is running. Use the
following command to disable this alert: GPIO.setmode(GPIO.BCM)
Examples
LED
Circuit
Connect a LED to GPIO17 pin using a resistance.
15
code
Turn On and OFF LED w/ Gpiozero
red = LED(17)
while True:
red.on() #turn led on
sleep(1) #delay for 1 second
red.off() #turn led off
sleep(1):
16
5. ON/OFF Control Based On Light Intensity Using the light sensors, monitor the surrounding
light intensity & automatically turn ON/OFF the high intensity LED's by taking some pre-defined
threshold light intensity value.
import RPi.GPIO as GPIO
from time import sleep
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
while True:
GPIO.output(17, True)
sleep(1)
GPIO.output(17, False)
sleep(1)
17
7. Dice Game Simulation Instead of using the conventional dice, generate a random value
similar to dice value and display the same using a 16X2 LCD. A possible extension could be to
provide the user with option of selecting single or double dice game.
18
19
20
21
8. Displaying RSS News Feed On Display Interface Displaying the RSS news feed headlines
on a LCD display connected to device. This can be adapted to other websites like twitter or
other information websites. Python can be used to acquire data from the internet
Here’s a Raspberry Pi project that will use Python code to read an RSS feed, the Tom’s Hardware feed for
example, and display the top five headlines on an LCD screen.
To build this project you will need:
• Any model of Raspberry Pi with Raspberry Pi OS and GPIO Pins
• An I2C LCD screen such as this one
• 4 x Female to female jumper wires
1. Install Python libraries to use LCD screens and work with RSS feeds by entering the following
commands:
sudo pip3 install rpi-lcd feedparser
2. Enable the I2C interface via Preferences >> Raspberry Pi Configuration
22
(Image credit: Tom's Hardware)
4. Launch Thonny. You can find it on the start menu under Programming.
5. In a new file import libraries of Python code to use the LCD screen, control the pace of the project, read
the RSS feed and finally manipulate text into chunks.
from rpi_lcd import LCD
from time import sleep
import feedparser
import textwrap
6. Create an object, called “tom” which will store the RSS feed data from Tom’s Hardware.
tom = feedparser.parse("https://www.tomshardware.com/uk/feeds/all")
7. Create a connection to the LCD and then pause the code for 1 second.
lcd = LCD()
sleep(1)
8. Use a for loop to repeat code five times. If you want more than 5 headlines, change the (5) to a higher
number.
for i in range(5):
9. Print the entries from the Tom’s Hardware RSS feed. The value of i is incremented each time the for
loop goes round, to a maximum of five.
print(tom['entries'][i]['title'])
10. Create an object called split and use that to save 16 character chunks of the RSS feed. The chunk size is
set by the 16 character screen size of the LCD.
split = textwrap.wrap(text, 16)
11. Create an object called split and use that to save 16 character chunks of the RSS feed. The chunk size is
set by the 16 character screen size of the LCD.
split = textwrap.wrap(text, 16)
12. Print “Tom’s Hardware” (or the name of your news source) to the first line of the LCD screen.
lcd.text("Tom's Hardware", 1)
13. Create another for loop to print the contents of the split object to the LCD screen.
for i in range(len(split)):
lcd.text(split[i], 2)
sleep(0.5)
14. Add a one second pause before clearing the LCD screen.
sleep(1)
lcd.clear()
15. Save the code as TomsRSSFeed.py
16. Check your code against our complete code listing.
from rpi_lcd import LCD
from time import sleep
import feedparser
import textwrap
tom = feedparser.parse("https://www.tomshardware.com/uk/feeds/all")
23
lcd = LCD()
sleep(5)
for i in range(5):
print(tom['entries'][i]['title'])
text = tom['entries'][i]['title']
split = textwrap.wrap(text, 16)
lcd.text("Tom's Hardware", 1)
for i in range(len(split)):
lcd.text(split[i], 2)
sleep(0.5)
sleep(1)
lcd.clear()
17. Click on Run to start the code.
24
9. Porting Openwrt To the Device Attempt to use the device while connecting to a wifi network
using a USB dongle and at the same time providing a wireless access point to the dongle.
Setting up WiFi on Raspberry Pi 2 is different from setting up on Raspberry Pi 3 as Raspberry Pi 2 or earlier models
doesn’t have on board WiFi Adapter like Raspberry Pi 3 does. Hence, in order to access WiFi using Raspberry Pi 2, we
need to use an external adapter like a WiFi Dongle.
In previous tutorial, I’ve explained how to connect Raspberry Pi 3 to a WiFi Network using the on – board WiFi Adapter.
In this tutorial, I’ll show you how to setup WiFi on Raspberry Pi 2 using a WiFi Dongle and get connected to a WiFi
network.
We have already seen how to setup a Raspberry Pi Computer in headless fashion i.e. without using monitor and
keyboard. We have also seen how to enable and configure the WiFi in Raspberry Pi 3.
In order to connect a Raspberry Pi 2 or older devices (which doesn’t have on – board WiFi Adapter), we need to use an
USB type WiFi Dongle.
The WiFi Dongle used in this project is a Tenda W311MI USB Adapter. This particular adapter supports IEEE 802.11b/g/n
protocols with speeds up to 150Mbps.
25
We will now see how to configure the Raspberry Pi 2 to access a WiFi network. The following steps are common whether
your Raspberry Pi is connected to a Monitor and Keyboard or it is accessed using a remote SSH Client like Putty in a
headless fashion.
Outline
• Connect the Hardware
• Check for USB WiFi Dongle Hardware
• Edit the Network Interfaces File
• Edit the WPA Supplicant File
• Reboot the Raspberry Pi
• Troubleshooting
Also connect an Ethernet cable (optional, if you are using monitor and keyboard) to the Raspberry Pi and have a
computer (with internet connection) ready. Now you can turn on the Raspberry Pi and wait till it boots up.
26
If you are using Putty (headless setup), login to Raspberry Pi using the username and password. If you are using a
monitor, open the Terminal from the desktop.
To check whether the Raspberry Pi detected the WiFi Dongle hardware that is plugged in to the USB port, type the
following command in the terminal and hit enter.
dmesg | more
Hit space bar multiple times to jump to next page of the list. If you scroll down, you can see few lines related to the WiFi
Dongle, something similar to the following.
[ 1.872459] usb 1-1.2: new high-speed USB device number 4 using dwc_otg
[ 1.992997] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
27
This means that the Raspbian OS has detected the USB WiFi Dongle. But the Dongle doesn’t work yet as we need to
configure it.
auto lo
auto wlan0
allow-hotplug wlan0
28
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
Press CTRL+X to exit the editor. It will ask you whether to save changes to the file or not. Type y and hit enter. You will
go back to the terminal. We are done with editing the Network Interfaces File.
We need to edit this file and add the details of your personal WiFi network. In order to open the WPA Supplicant File,
type the following command and hit enter.
29
network={
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP TKIP
group=CCMP TKIP
30
Replace Name of WiFi Network with the actual name of your WiFi Network. In our case, it is SLNP. Similarly, enter the
password of the WiFi network corresponding to psk.
In order to exit and save the file with the same name, press CTRL+X and then Y and finally hit enter.
sudo poweroff
After the Raspberry Pi is shut down, switch of the power supply and disconnect the Ethernet cable. Now, boot the
Raspberry Pi and scan for the IP Address. If the WiFi is configured correctly, you should get the IP Address associated
with the WiFi Dongle connected to the Raspberry Pi.
Using this new IP Address, you can login in to the Raspberry Pi with the help of SSH Client Putty.
31
To test the WiFi connection, we can use different commands. First, you can use the following command to get details of
all the network connections.
ifconfig
This will return the IP Address, Transmitted bytes, Received bytes etc.
32
Another command is iwconfig. It is similar to ifconfig but it is associated only with wireless networks.
iwconfig
33
This command will return details like SSID, frequency, bit rate, power, link quality etc. If the Link Quality option reads
0/70 (0/Maximum), then the WiFi adapter didn’t get connected to the WiFi Network properly.
Another way to test the connection is using Ping command. Use the following command and see if you get any reply.
34
To come out of the Ping, press CTRL+C.
Troubleshooting
If you are facing any trouble connecting to WiFi using the USB WiFi Dongle check for the following. These might be the
problem (but not limited to these).
• Power: WiFi Adapters might require more power and if your power supply cannot provide enough power to it, it
might not function properly.
• Compatibility: Check for the list of compatible external WiFi adapters and buy one.
• USB Adapter: Check if the Dongle is perfectly fitted in to the USB Port.
• WiFi Network: Check if your WiFi network is up and running.
• Network Interfaces and WPA Supplicant Files: Make sure that you have entered the correct commands in the
corresponding files.
• Power Down and Reboot: Power down the Raspberry Pi and reboot again.
35
10. Hosting a website on Board Building and hosting a simple website(static/dynamic) on the
device and make it accessible online. There is a need to install server(eg: Apache) and thereby
host the website.
A Raspberry Pi makes excellent sense as an inexpensive and power-efficient way to host websites and web applications over
a local network.
It’s a great testbed or development environment where you have full access right up to the metal. You won’t have to worry
about bandwidth charges or acceptable use policies while you’re robustly testing it either.
It’s also an excellent way to host something like a wiki on the local intranet for a small or medium business. Just be sure to
automate backups.
You may be using your Pi to prototype an IoT device that features some kind of web interface or dashboard. Installing a web
server is the only real way to do this.
Finally, one of the very best reasons to install a web server on a Raspberry Pi is just to start learning about web servers.
By far, the two most popular web servers are Apache and Nginx (pronounced Engine-X). These are both open source projects
you can install and use freely.
Apache, first released in 1995, is nearly as old as the web itself and is still the most popular web server on the internet.
It has its own modules to serve dynamic content such as PHP, and its ubiquity means that it’s incredibly well documented. It’s
a robust all-rounder that makes it easy to give individual directories their own configuration. These things make it a great place
to get started.
36
Nginx was written to address Apache’s limitations with handling many concurrent users. It excels at serving static content but
requires an external processor for dynamic content.
In this guide, we’ll install Apache. Nginx’s advantages are real but aren’t that important to the typical use cases of a Raspberry
Pi. But if you are using your Pi to prototype something that might scale, think about learning Nginx as well.
It’s, in fact, not all that unusual to see both used together, with Nginx on the front end, serving static resources and Apache in
the back, rendering dynamic content.
Other web servers of interest include:
• Node.js is installed on your Raspberry Pi already. It’s not a traditional web server, but a runtime environment for Javascript. It
can handle many connections at once, which makes it very handy for large web applications, though you would normally use
something like Apache or Nginx as a front end.
• Also already on your Raspberry Pi is Python’s http.server module. It’s good for testing and development, but it’s especially
convenient for those things. If you’re writing a web application in Python, you can set up a simple web server in a few lines of
code.
• Lighttpd makes very efficient use of system resources, which should interest anyone developing embedded systems and IoT
devices.
This guide is written for Raspberry Pi OS Buster, but if you’re using an earlier version of Raspbian, this won’t be very different;
Apache is very mature software.
You will need internet connectivity to install these packages.
Get on to the terminal and update your operating system by typing:
sudo apt update && sudo apt upgrade -y
When the updates are complete, install Apache with this command:
sudo apt install apache2 -y
You can now test that Apache has installed properly by browsing to your Raspberry Pi. If you’re using the Pi’s web browser,
type http://localhost.com/ into the address bar.
From elsewhere on your local network, you will need to use the IP address. If you don’t know this already, you can get it with
this command:
hostname -I
37
Your browser will load a page that looks like this.
Static websites are lightning-fast and simple to maintain and offer a lot to explore. For a simple blog, business website, or
information website, this might be all you need. Just deploy your website to the directory /var/www/html/, and Apache will
serve it.
Instead of just displaying the same thing every time, you might want to serve dynamic content – pages the server generates
by executing code.
This might be so that users can edit or add to pages or to add new pages of their own – perhaps for a wiki, a forum, or a
comments section on a blog.
38
It might also be so that your device can display data on a dashboard, whether that’s collected from an online service, a
database, or from something connected to the GPIO pins.
There are many scripting languages you can use to build dynamic websites, such as Java, Perl, PHP, Python or Ruby. You
can even use compiled binaries written in Go, C++ or C.
PHP is a good starting point since the most popular open-source CMS platforms like WordPress, Joomla! and Drupal are built
on it. Together, these platforms easily form a majority of all websites.
Installing PHP
39
11. Webcam Server Interfacing the regular usb webcam with the device and turn it into fully
functional IP webcam & test the functionality.
Rather than using the Raspberry Pi camera module, you can use a standard USB webcam to take pictures
and video on the Raspberry Pi.
Note that the quality and configurability of the camera module is highly superior to a standard USB
webcam.
Install fswebcam
40
If you are not using the default pi user account, you need to add your username to the video group,
otherwise you will see 'permission denied' errors.
To check that the user has been added to the group correctly, use the groups command.
Basic usage
Enter the command fswebcam followed by a filename and a picture will be taken using the webcam, and
saved to the filename specified:
fswebcam image.jpg
41
Note the small default resolution used, and the presence of a banner showing the timestamp.
Specify resolution
The webcam used in this example has a resolution of 1280 x 720 so to specify the resolution I want
the image to be taken at, use the -r flag:
42
Picture now taken at the full resolution of the webcam, with the banner present.
Specify no banner
43
Now the picture is taken at full resolution with no banner.
44
12. FM Transmission Transforming the device into a regular fm transmitter capable of
transmitting audio at desired frequency (generally 88-108 Mhz)
You’ll need to get Raspbian, the Linux-based operating system for the Raspberry Pi.
Get your tracks set and copy them over to the Raspberry Pi. If you’re using the base PiFM software,
you’ll need 16-bit .wav files. Make Magazine’s code supports broader file support, though.
4. Add an antenna
Plug a strip of wire into the GPIO4 pin on your Raspberry Pi (the fourth pin down on the left side on most
Pi hardware). You’ll want something at least eight inches long, although closer to 25 inches is
recommended for better range. Depending on your setup and surrounding environment, the Pi can
broadcast between about a foot to roughly 300 feet away.
5. Broadcast
Run the PiFM code. You’ll do that by running a command like “sudo ./pifm awesomejams.wav 100.0”,
where that “100.0” is the frequency in MHz on which you’re broadcasting.
Get your FM radio of choice, tune to your broadcast station, and enjoy!
45
46
47
48