Part I Introduction to a problem

We have used different modules for input of information to our robot so far - starting from simple IR remote to more complicated Grove Speech recognizer. What if we need to output the data somehow? Of course, since Bittle is a legged robot, we can (and in fact did) react to the data by executing movement commands. Also we used RGB LEDs available on BIttle mainboard. If we need to output longer strings of data though or just make our robot show lively expressions, we need another piece of equipment - a screen.

Part II Explaining the knowledge

How do OLED displays work?

Lesson 3 OLED screen - Displaying messages - 图2
OLEDs work in a similar way to conventional diodes and LEDs - these are made with two slabs of semiconductor material, one slightly rich in electrons (n-type) and one slightly poor in electrons(p-type).
When we allow the current flow in circuit electrons cross border between these two materials and release surplus energy, giving off a quick flash of light. All those flashes produce the dull, continuous glow. A simple OLED is made up of six different layers.
L8-A@4x.png
To make an OLED light up, we simply attach a voltage (potential difference) across the anode(positive terminal) and cathode(negative terminal). OLED screen is made of hundreds or thousands of individual OLEDs (128 x 64 = 8192) and by turning each of them individually we can draw pictures and output text in the way we see fit.

Lesson 3 OLED screen - Displaying messages - 图4
Obviously manual switching the individual OLEDs would be a nightmare. So, to help with that, there is an integrated circuit on OLED screen module that takes care of low-level, individual OLED control, together with software on our microcontroller. All of that allows us to simply type or draw pictures in Codecraft interface and then have them displayed on the screen without too much hassle.

Part III Solving a problem

Task 1: Display a word

Connect OLED display to Bittle mainboard Grove I2C socket.
Lesson 3 OLED screen - Displaying messages - 图5 For our first program using OLED screen we will output a short sentence on the screen, greeting users. You can find OLED screen related blocks in the bottom of Grove I2C category.

3-1.png

3-1

You will see the sentence displayed on the screen as in the picture below:
Lesson 3 OLED screen - Displaying messages - 图7

Task 2: Display gyroscope data

The best utilitarian application for OLED screen on robot is displaying data from sensors. For example we can display data from Bittle built-in gyroscope (which is used for automatic self-balancing). Gyroscope and accelerometer blocks can be found in System category.
3-2.png
3-2

The small delay value is necessary because otherwise the screen will be refreshing too often and the numbers would be hard to distinguish.
Lesson 3 OLED screen - Displaying messages - 图9

Task 3: Show expressions

The best utilitarian application for OLED screen on robot is displaying images. In the following example we will use Grove Speech Recognizer together with OLED display to listen to user command and render the appropriate image on the screen. Connect Grove Speech Recognizer to Grove Digital socket D6 and OLED screen to Grove I2C socket, as shown in the picture below:
Lesson 3 OLED screen - Displaying messages - 图10
Feel free to change commands and images as you see fit!
3-3.png
3-3

3-5效果展示,玉音放送.mp4 (20.84MB)One thing to remember is that if you want Speech recognizer listen for different commands, it is necessary first to obtain the recognition result, save it in a variable and then compare the result with command codes. Here we use Up and Down commands, which correspond to numbers 7 and 8. For full list of commands and their result codes, consult Lesson 2 of Bittle Sensor pack course.

Part IV Expanding the knowledge

Write program that would display current movement(for example, Trot or Walk) on OLED screen.