×

SparkFun will be closed on Tuesday, December 24th, and Wednesday, December 25th, in observance of the Christmas holiday. Any orders qualifying for same day shipping placed after 2:00 p.m. (MST) on Monday, December 23rd, will be processed on Thursday, December 26th, when we return to regular business hours. Wishing you a safe and happy holiday from all of us at SparkFun!

Please note - we will not be available for Local Pick up orders from December 24th-December 27th. If you place an order for Local Pick-Up we will have those ready on Monday, December 30th.

Getting Started with Python on the Raspberry Pi

A new tutorial to help beginners control hardware with Python.

Favorited Favorite 3

"Hey, I heard that the Raspberry Pi will teach you to program!"

"I bought a Raspberry Pi because it's cheap...now what do I do with it?"

These are the two most common phrases I hear when people are trying to figure out what to do with the Raspberry Pi. Certainly, the Pi is a great piece of inexpensive hardware that functions as a complete Linux (or other operating system) computer.

In response to the "Raspberry Pi will teach you to program" comment, I usually tell people, "Not any more than your current computer." The Pi can't magically upload programming knowledge to your brain (yet).

alt text

That being said, the Raspberry Pi can be a fun learning environment for individuals and schools thanks to several factors:

  • It's affordable
  • If you break something in software, it's easy to flash a new image
  • GPIO pins are broken out, which allows you to control hardware devices

Python has been gaining in popularity as a beginner-friendly-yet-still-powerful programming language over the past few years (according to several indexes like TIOBE and PYPL). Many schools are switching to Python to teach students as their first language. It's approachable due to its script-like nature, but it can be used to teach more advanced concepts like polymorphism.

As a result, the Raspberry Pi can be a perfect platform for learning Python. There are plenty of books, websites and videos out there that can help you learn Python. However, we find there is something special about controlling a piece of hardware (spinning a motor, lighting an LED, taking a temperature reading) through programming. So, we've put together a guide to help you get started controlling hardware with Python on the Raspberry Pi:

Python Programming Tutorial: Getting Started with the Raspberry Pi

June 27, 2018

This guide will show you how to write programs on your Raspberry Pi using Python to control hardware.

The raspberry-gpio-python module thankfully makes controlling pins super easy. Once you have the basics down (toggling pins, reading pin states, UART, SPI, I2C), you can control a whole suite of hardware, and the fun begins there. Robotics, IoT sensors, home automation projects, etc. become attainable.

What other combination of Python, Raspberry Pi and hardware projects/concepts would you like to see? Let us know in the comments!

 

 


Comments 5 comments

  • Member #335572 / about 7 years ago / 1

    I would like to see how you can interact with raspberry pi from a web based interface, effectively controlling it remotely.

  • Member #1051571 / about 7 years ago / 1

    https://xkcd.com/1987/ Anyway the first post is very good, you are one of the few guy that start telling which python version are you using.

  • Member #134773 / about 7 years ago / 1

    Hi Shawn!

    As usual, a great blog post. I haven't had time to read through the tutorial in detail, but glancing through it, it looks good.

    My one comment is that there's a really big advantage to learning coding with a Raspberry Pi as opposed to an Arduino, and that is that the RPi has access to many debuggers. IM[NS]HO, using a debugger to single-step through a program, especially one with loops, and watch the variables change, is by far the best (and fastest) way to learn about that sort of thing. (My "standard rant" about the Arduino IDE is the absense of any sort of a debugger -- something which appeared in IDEs in the late 1970s, when I'd only been programming for about a decade.)

    Another advantage of RPi is that it (normally) runs Linux, and is a great way to learn about this OS. While M$ Windows is "easier" for the raw beginner with computers (think "elderly aunt"), once you get beyond the stage of using (or I would claim "being abused by") the canned programming (e.g., "social[sic] media", web surfing, e-mail, Skype), Linux can be much more friendly. BTW, I've been using Unix and Unix-like systems since the mid-70s, and been abused by Window$ since W 3.1.

  • Member #1397223 / about 7 years ago / 1

    I'd like to see some articles on C programming on the Raspberry Pi. Python is all well and good, but to get more performance, C is hard to beat. Not only that, but introducing people to working with a compiled language like C opens up new areas of interest too.

Related Posts

Recent Posts

Tags


All Tags