Search This Blog

Sunday, January 1, 2017

How to set up the Waveshare Relay Board for Raspberry Pi

Just get a new relay board from Waveshare for your Raspberry Pi? Waveshare does a great job of posting all the resources that you'll need, but if you're a noob like me, with little experience working in the terminal, you might need a little more information, like I did.
I also discovered that with my Raspberry Pi 3, already updated with the most current version of Pixel, some of the steps on the Waveshare wiki were erroneous.

Below is a step-by-step on how to set up your relay board for use:

1) Start by running an update on your Pi:
  • Open the terminal window
  • Type in sudo apt-get update then hit enter to run
  • When updates are done type in sudo apt-get upgrade and hit enter to run
  • Install the python-dev package by typing sudo apt-get install python-dev in the terminal and the RPi.GPIO library by typing sudo python install in the terminal 
***The Waveshare site prompts you to install these packages that allow you to control the GPIO pins on your Pi, however Raspberry Pi already runs Python out of the box, so likely you don't need to run this install, especially if you have a RPi 2 or 3 with an up-to-date Raspian OS installed... unsure? Run the install and the terminal will spit out a note that lets you know if anything new was installed or if you already have all the updated packages installed.)
  • Install the library smbus to set up the I2C interface functions using sudo apt-get install python-smbus
  • Install the library serial using sudo apt-get install python-serial
2) Install the bmc2835 libraries
  • Go to (great directions here, but if you need more, keep reading)
  • In the terminal window on your RPi, type in wget 
    • (On McCauley's site you are prompted to replace XX in each step with the number version of the bcm2835 library that you want to download... it took me a long time searching around the web to figure out which version is the most current... as of this week, v50 was the newest I found)
  • Before moving forward, you'll want to make sure that the bcm2835 files are saved to your Pi's drive. Open the "downloads" folder on your Raspberry Pi and make sure that the folder, if it downloaded there, is moved out of "downloads" and into "home/pi"
  • Type tar zxvf bcm2835-1.50.tar.gz into the terminal to unzip the files
  • Now, change to the directory that we'll be installing by typing cd bcm2835-1.XX in the terminal (50 instead of the XX since that's the version we downloaded above)
  • On the next line type in ./configure and hit enter
  • Type make on the terminal line
  • Then sudo make check
  • Then sudo make install
3) Install the WiringPi libraries

  • Go to and follow the directions for downloading and installing using the terminal
    • (Step 2 prompts you to update your RPi, but we did that above so you do not need to do it again)

4) Configure the interfaces
  • Enable interfaces by going to Menu --> Preferences --> Raspberry Pi Configuration (enable SPI, I2C, Serial)
  • Update the configuration file by typing sudo nano /etc/modules in the terminal 
    • Make sure the following two lines are typed in the configuration file:
      • i2c-bcm2708
4) Restart Raspberry Pi to make sure all updates are enabled

5) Download demo codes for the relay board

  • Go to and scroll to the very bottom of the page
  • Click on "demo code" then click on the RPi_Relay_Board.tar.gz link at the top of the page to download the demo files
  • Go to "downloads" folder on your RPi and open the demo codes folder. Double click on the Python file to open it and run the code to test the relay board.

Waveshare documentation for the relay board--

1 comment: