Control an LED from your Browser + Giveaway Winners

Published on: June 1, 2019

Ready to put everything we've learned to use? 

Today's tutorial is just the end result of everything we've learned so far. I don't get into the nitty gritty of installing all the software in this tutorial, instead, I show you what I implemented and a brief look into how I implemented it. I would highly recommend going through the following six tutorials for more in-depth details on everything I've implemented. Feel free to skip anything you feel you don't need:

  1. Headless Raspberry Pi
  2. Using the RPi.GPIO library to turn on an LED
  3. Run Apache on your Pi
  4. Running a Flask App on your Pi
  5. Run Flask behind Apache
  6. Simple AJAX with jQuery/JavaScript

A few more things to know about this video is that we are using GPIO Pin number 18 as we've done in the second tutorial listed. And we will only be dealing with HTTP GET requests. 

The above tutorials will teach you the very basics of what is involved in this tutorial. Once you are caught up, watch the video below or head over to the Github repo which contains the UI and backend Flask app here: Raspberry Pi - Browser LED Control

In the above tutorials, we don't combine RPi.GPIO and Flask. But in this video, they are both essential and it's necessary to run them from a virtual environment. The one issue that you will run into is that your virtual environment will NOT have access to the globally installed RPi.GPIO package on your Raspberry Pi. To get around this, after you've installed and activated your virtual environment, run the following command to install RPi.GPIO locally in your venv:

pip3 install RPi.GPIO

Without this, your Flask app will fail. 

If all goes well, you should be able to make an HTTP GET request for http://{{ip_addr}}/led?status=on or http://{{ip_addr}}/led?status=on and trigger your LED.

If that works, then congratulations! You can now control your LED over your browser. For a better user experience, you can hit the index.html page on your Pi and trigger the lights. This adds a quick and dirty User Interface for you to use. 

You can apply what you've learned in endless ways. In the future, I will show you how to use this tactic to control relays and transistors, and in turn control LED strips (both regular and RGB led strips). So do subscribe and stay tuned!

I am planning on moving over the summer so I will be packing away most of my equipment for now. I will be on hiatus from making videos over the summer but I will be active online! Feel free to continue to ask me questions and send me requests for videos. I will answer your questions and add your video requests to my backlog. 

Contest Info:

Thanks to all who entered the fourth Raspberry Pi giveaway! These two will make the 13th and 14th Pi that I'm giving away. Although this is the last giveaway of the summer, I plan on returning with more after my hiatus!

Congratulations to the two winners below. Winners were picked using the Winner Picker script. 

The winners are:

  • sage vibe
  • David L.

Thank you all again! If you  have any questions, please ask below!

 

Remember to checkout the Resources section below for associated downloadable content, JSFiddle links, and other resources. Watch the video and follow along!

Resources:

Get everything in the Github repo here: Raspberry Pi - Browser LED Control



Comments: