Using an External Data Feed in Your Projects

This blog post on working with external data feeds is an excerpt from Lesson C-15 of our Intro to Robotics program. Level C is the third level in Intro to Robotics and covers working with complex electrical components (including audio-visual elements), writing advanced-level code commands in Python, and using a Raspberry Pi to control your electronics projects with the code you write. It contains 600 pages with 18 lessons and 54 projects and activities. Sample lessons and a full scope and sequence for Level C can be found here.

 

In Lesson C-15 you learn about a few of the different web page formats that are used to display data on the internet as well as how to pull a specific value from these types of pages. This data can then be used to trigger behavior in your Python program based on the content you pulled from the web page.

There are many ways that you can gather data from the internet, and a couple of the more popular options are parsing data, using an API, or database-type web pages:

  • Parsing Data: Parsing data refers to breaking the data up into different parts so you can find the value that you need. This method is both a little complicated and fragile. It's fragile because this method relies on finding very specific characters in a specific order within the page content. If this web page is provided by a third-party, they could easily make changes to the page that would make the data incompatible with your program.
  • API Data Access: An API is a set of commands that a website is programmed to respond to in certain ways. The commands and responses available within the API are decided by the designers of the website. API access is very powerful as it cannot only be used to request information from a site, but some allow website changes to be made using the API.
  • Database-Style Web Page Content: More and more web pages are being used to convey information that needs to be processed by other systems. New data formats called XML and JSON have emerged as good ways of formatting the data on a web page into something that can be more easily processed by other systems. This data will look more like computer code than a web page, because it's very similar to the dictionaries and nested lists that you worked with in Lesson C-8.

 

Cheerlights

Cheerlights in an example of an API data feed. The Cheerlights project publishes information about a color whenever someone uses Twitter to send a tweet to @cheerlights. The tweet must include one of the color names listed below:

red
green
blue
cyan
white
oldlace / warmwhite
purple
magenta
yellow
orange
pink

These tweets will update multiple Cheerlights feeds to display the new color value. Homemade projects capable of displaying multiple colors can then periodically check the Cheerlights value and change appearance to match the current color. These devices may be as simple as a color changing LED, strings of many LEDs, or anything else that can display multiple colors and has an internet connection capable of accessing the Cheerlights feed.

The Cheerlights project has many different feeds available and information about them can be found here:

https://cheerlights.com/cheerlights-api/

Some feeds only contain the most recent color, while other feeds have a historical record of the last 100 colors that were displayed. The feeds are also available in txt, xml, and json file formats. Which feed and file type you might choose would depend entirely upon the needs of the project that you're building.

In the activities section of Lesson C-15 we guide you through:

  • Building a circuit with a RGB LED and an OLED screen capable of displaying text
  • Writing a Python program to change the color of the RGB LED based on the color name published on a web page on the internet
  • Writing a Python program to display the name of the current color from the Cheerlights feed on your circuit's OLED screen

Breadboard circuit containing OLED screen displaying data from Cheerlights feed 

This blog post on working with external data feeds is an excerpt from Lesson C-15 of our Intro to Robotics program. Level C is the third level in Intro to Robotics and covers working with complex electrical components (including audio-visual elements), writing advanced-level code commands in Python, and using a Raspberry Pi to control your electronics projects with the code you write. It contains 600 pages with 18 lessons and 54 projects and activities. Sample lessons and a full scope and sequence for Level C can be found here.

Older Post
Newer Post
Close (esc)

Popup

Use this popup to embed a mailing list sign up form. Alternatively use it as a simple call to action with a link to a product or a page.

Age verification

By clicking enter you are verifying that you are old enough to consume alcohol.

Search

Your cart is currently empty.
Shop now