Introduction: Getting Started With Raspberry Pi

I created a three-part video series with SparkFun Electronics on getting started with the Raspberry Pi. The videos will walk you through downloading and creating a Raspbian (Debian) Linux image, configuring the Pi, connecting to the Internet, reading a sensor, and posting to Twitter using Python.

The Raspberry Pi is an inexpensive Single Board Computer (SBC) created by the Raspberry Pi Foundation, which is a group of people in the UK dedicated to bringing cheap computing to the classroom. The Pi was released in early 2012 and saw immediate success, selling over 2.5 million units in the first two years. Hobbyists and educators gravitated toward the tiny computer due to its low price, ease of use, and large community support. Instructables even has an entire section devoted to the Raspberry Pi.

If you are following along with the videos, I recommend the Raspberry Pi Model B, although the Model A will work (you just might need to make some changes to the code). The videos and accompanying descriptions will provide a list of which additional items you will need.

Step 1: Introduction

The first video is a tutorial on preparing and configuring the Raspberry Pi. I show you how to download a Raspbian Linux image, copy it to an SD Card, configure the Raspberry Pi, and create a simple blinky LED sketch with Python. You will need the following components:

The code for the blinky program is attached and copied below.

import time
import RPi.GPIO as GPIO

LED = 22

GPIO.setmode(GPIO.BOARD)
GPIO.setup(LED, GPIO.OUT)
GPIO.output(LED, GPIO.LOW)

while True:
	GPIO.output(LED, GPIO.HIGH)
	time.sleep(0.5)
	GPIO.output(LED, GPIO.LOW)
	time.sleep(0.5)

Step 2: WiFi and Python and Twitter Oh My!

In the second episode, I cover how to connect the Raspberry Pi to a WiFi network and post something on Twitter using the Twython package.

From the first episode, you will need the following equipment:

Additionally, you will need:

The hello_tweet Python program is attached and copied below.

from twython import Twython

APP_KEY=''
APP_SECRET=''
OAUTH_TOKEN=''
OAUTH_TOKEN_SECRET=''

twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
twitter.update_status(status='Roads? Where we\'re going, we don\'t need roads.')

Step 3: Tweeting Weather Station

In the final episode, we tie everything together to read temperature and humidity from a sensor and post the data to Twitter on a regular basis. From the first and second episodes, we need the following:

You will also need:

The code shown in the episode can be found below.

from twython import Twython
from smbus import SMBus
import time

# Twitter authentication
APP_KEY=''
APP_SECRET=''
OAUTH_TOKEN=''
OAUTH_TOKEN_SECRET=''

# Twython object
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)

# I2C globals
ADDR = 0x27
bus = SMBus(1)

# Special characters
deg = u'\N{DEGREE SIGN}'

# Main loop
while True:

	# Get the current system date and time
	datetime = time.strftime('%m/%d/%Y %H:%M:%S')

	# Read data from sensor
	bus.write_byte(ADDR, 0x00)
	ans = bus.read_i2c_block_data(ADDR, 0x00, 4)

	# Convert to human readable humidity
	humd = ((ans[0] & 0x3f) << 8) + ans[1]
	humd = humd * float('6.10e-3')
	humd = '{:.0f}'.format(humd)

	# Convert temperature to Celsius
	temp = (ans[2] << 8) + ans[3]
	temp = temp >> 2
	temp = (temp * float('1.007e-2')) - 40.0
	temp = '{:.1f}'.format(temp)

	# Print date, time, temperature, and humidity
	print datetime
	print 'Temperature: ' + str(temp) + deg + 'C'
	print 'Humidity: ' + str(humd) + '%'
	print ''

	# Post to Twitter!
	msg = 'Weatherbot here! It is ' + datetime + \
		'. The temperature is ' + str(temp) + \
		deg + 'C, and the humidity is ' + \
		str(humd) + '%.'
	twitter.update_status(status=msg)

	# Delay (in seconds) before next reading
	time.sleep(60)

Comments

author
SathyaK6 (author)2016-09-21

Hello Sir..Great Project

My doubt is: Do you have an inbuilt browser with Raspberry Pi. How do you copy the twitter.com data to the tweet.py program??

author
craftclarity (author)2014-06-02

Looks like fun....!

About This Instructable

5,868views

166favorites

License:

More by ShawnHymel:Getting Started With Raspberry PiimpBoot: Remotely Turn on a Desktop ComputerCylon Pumpkin 2012
Add instructable to: