You must first complete Reading Sensor Data before viewing this Lesson

Displaying Sensor Data to OLED

Introduction

Since we already know how to take sensor reading, we can now do one of the most fun parts of interfacing the Little Python Brain.

Components Needed

  • Little Python Brain
  • A tablet/phone/laptop
Steps

1

Importing the screen library

We’ll start by grabbing the import screen block from the Libraries category. This is one of the few 

2

The screen.print_line() block

Taken from the Screen category, this is the most basic of the screen outputs. What it does is take the “string” that we typed  on the first space then displays it on the “line” of the screen that we indicate on the second space.

  • String – a data type that essentially means “text”. Most of the things that we’ve been printing to terminal in the past lessons are of this data type.
  • Line – the part of the screen where we print our text. Essentially, this is where we tell the Little Python Brain to print our text. It starts counting from 0.

3

Replacing the print() blocks

Remove the print blocks from the previous lesson. We will instead use the screen.print_line() blocks for our outputs.

4

An introduction to different data types

For most printing, we want to have a data type of string. This is especially true for the OLED screen. 

However, the two measurements that we have: the light level and the temperature are of two different types! The light level is an integer while the temperature is a float data type.

While the print() function we have used before can sometimes convert these data types automatically, we’ll have to convert these manually to a string type using the str() function. 

We’ll get more into data types in future lessons. For now, just copy the blocks shown and you’re ready to run the code!

The Complete Code

Note the 0 and 1 in the screen.print_line() blocks. Specifying the line to print on is very essential with the OLED as unlike printing to terminal, the OLED does not automatically put new prints in new lines. 

Back to: Beginner > Weather Station
© 2020 Little Python

CONTACT US

    Log in with your credentials

    or    

    Forgot your details?

    Create Account