|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "f3918b49-9476-4415-a7e9-68539c202181", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "# Project 4 - Circuit 4A: OLED \"Hello, World!\"\n", |
| 9 | + "\n", |
| 10 | + "Printing “Hello, world!” is usually the first thing that programming tutorials will have you do in a new language. This guide starts by blinking an LED, but now we’re going to print out real text using an \"organic light-emitting diode\" (OLED) display.\n", |
| 11 | + " \n", |
| 12 | + "TODO: Update the LCD display with an OLED display.\n", |
| 13 | + "TODO: Update the jumper wires with a Qwiic connector.\n", |
| 14 | + "\n", |
| 15 | + "\n", |
| 16 | + "## New Components\n", |
| 17 | + "\n", |
| 18 | + "### Organic Light-Emitting Diode (OLED) Screens\n", |
| 19 | + "\n", |
| 20 | + "An [OLED Display](https://en.wikipedia.org/wiki/OLED) is a component that allows us to visualize information from our program in the real world. It contains a layer that emits light in response to an electric current. The [SparkFun 1.3\" OLED display](https://www.sparkfun.com/sparkfun-qwiic-oled-1-3in-128x64.html) provided in the SIK is a \"monochrome\" OLED meaning that it can only show two colors: white and black. Each pixel of the display can be set individually to white or black allowing us to display anything from text to lines to shapes!\n", |
| 21 | + "\n", |
| 22 | + "\n", |
| 23 | + "\n", |
| 24 | + "### Qwiic Cable\n", |
| 25 | + "\n", |
| 26 | + "Do you want a break from sticking jumper wires into your breadboard? Then this project is for you. SparkFun's [Qwiic Connect System](https://www.sparkfun.com/qwiic) saves you the trouble of manually running jumpers between your RedBoard and your other components. Qwiic cables combine 4 jumpers into a single cable with a handy \"clicking\" connector at the end. SparkFun builds this connector into many of their sensors so that they can be used out-of-the-box without any breadboard set up needed.\n", |
| 27 | + "\n", |
| 28 | + "\n", |
| 29 | + "\n", |
| 30 | + "## New Concepts\n", |
| 31 | + "\n", |
| 32 | + "### I2C Communication\n", |
| 33 | + "The 4 jumper wires that are combined in a qwiic cable are power, ground, and the 2 necessary signals (SDA and SCL) that make up the (I2C Communication protocol)[https://learn.sparkfun.com/tutorials/i2c]. In electronics, a [communication protocol](https://en.wikipedia.org/wiki/Serial_communication) is just a way that devices can talk to each other by sending ones and zeros to each other. They do this by setting signals high (1) and low (0) just like we've been doing in all of our projects. By setting the signals high and low very quickly and in a known kind of pattern, the devices can talk to each other! You can think of it kind of like [Morse Code](https://en.wikipedia.org/wiki/Morse_code) where entire words can be sent between people by just sending a series of dots and dashes. I2C is a very common communication protocol where one device puts ones and zeros on two different wires to talk to another device (or multiple devices). Many SparkFun devices speak in this \"language\" and that is why the Qwiic Connnector was created to easily connect together devices that communicate with I2C.\n", |
| 34 | + "\n", |
| 35 | + "TODO: Maybe replace this with our own similar image that has serial/peripheral instead of master/slave.\n", |
| 36 | + "\n", |
| 37 | + "\n", |
| 38 | + "### Qwiic Driver Modules\n", |
| 39 | + "Since so many components of SparkFun hardware use the Qwiic Connect system and I2C to communicate, there are also [many MicroPython software modules](https://github.com/topics/sparkfun-python) that have been developed. These modules eliminate the need to know the ins and outs of the complicated I2C protocol and to deeply study the datasheet of each new device. They provide us functions we can use directly to talk to I2C devices. We will be using one of these, the [qwiic_oled_py](https://github.com/sparkfun/qwiic_oled_base_py) module in order to talk to our OLED. The RedBoard RP2350 ships with these drivers already installed, so you can directly `import` them in your code.\n", |
| 40 | + "\n", |
| 41 | + "Ready to start hooking everything up? Check out the Hardware Hookup section below to see how everything is connected.\n", |
| 42 | + "\n", |
| 43 | + "## Hardware Hookup\n", |
| 44 | + "\n", |
| 45 | + "Take a deep breath, this circuit has no circuit diagram, schematic, or hookup table! Just plug one end of the Qwiic cable into the Qwiic connector of your OLED and the other end of the Qwiic cable into the OLED like pictured below. Just like that you're ready to use the OLED. \n", |
| 46 | + "\n", |
| 47 | + "TODO: Get a nice picture of the backside of the oled with a qwiic cable attached. Possibly draw an arrow or similar in the direction that it should be plugged in. Do the same for the RedBoard RP2350.\n" |
| 48 | + ] |
| 49 | + }, |
| 50 | + { |
| 51 | + "cell_type": "markdown", |
| 52 | + "id": "1bd52930-d783-460a-923b-41a3c37d2f2b", |
| 53 | + "metadata": {}, |
| 54 | + "source": [ |
| 55 | + "## Using the OLED.\n", |
| 56 | + "\n", |
| 57 | + "Now that your circuit is built, it's time to write to the OLED. This is done using MicroPython, which is running on the RedBoard.\n", |
| 58 | + "\n", |
| 59 | + "The first step is to connect your RedBoard to a USB port on this computer.\n", |
| 60 | + "\n", |
| 61 | + "Select the \"Connect\" button at the bottom right of this screen and a panel is displayed\n", |
| 62 | + "\n", |
| 63 | + "Select the \"Connect Device\" Button, and when the selection dialog appears, select the port with that displays ***Board in FS mode (...)*** or *TBD*\n", |
| 64 | + "\n", |
| 65 | + "\n", |
| 66 | + "\n", |
| 67 | + "With the RedBoard connected, use the following MicroPython commands to write to the OLED. \n", |
| 68 | + "\n", |
| 69 | + "### Using MicroPython\n", |
| 70 | + "\n", |
| 71 | + "The following MicroPython commands are entered to write to the OLED. \n", |
| 72 | + "\n", |
| 73 | + "**REMEMBER** To enter a MicroPython command, hold down either the Control (on Windows) or Command (on Mac) key when pressing *Enter*\n", |
| 74 | + "\n", |
| 75 | + "#### Step 1 - Setup\n", |
| 76 | + "\n", |
| 77 | + "Lets start by importing any of the libaries we plan on using and setting up our pins." |
| 78 | + ] |
| 79 | + }, |
| 80 | + { |
| 81 | + "cell_type": "code", |
| 82 | + "execution_count": null, |
| 83 | + "id": "4494b462-505b-4a23-8ebc-28b54152bd88", |
| 84 | + "metadata": {}, |
| 85 | + "outputs": [], |
| 86 | + "source": [ |
| 87 | + "# The qwiic_oled driver module allows for control of SparkFun OLEDs.\n", |
| 88 | + "# The QwiicLargeOled class is for the Large 1.3\" OLED display in our SIK\n", |
| 89 | + "from qwiic_oled import QwiicLargeOled\n", |
| 90 | + "\n", |
| 91 | + "# Define the OLED object that we will use\n", |
| 92 | + "# Note how we don't have to provide the pins, the driver automatically selects the pins for the qwiic connector\n", |
| 93 | + "myOLED = QwiicLargeOled()" |
| 94 | + ] |
| 95 | + }, |
| 96 | + { |
| 97 | + "cell_type": "markdown", |
| 98 | + "id": "2d94be96-a8c9-4932-8111-58d10a8622a9", |
| 99 | + "metadata": {}, |
| 100 | + "source": [ |
| 101 | + "#### Step 2 - Displaying To the OLED\n", |
| 102 | + "Now let's write \"Hello World!\" out to the OLED! We will use the `begin()`, `clear()`, `print()` and `display()` functions from the qwiic_oled module. For a full list of the functions that this module provides, check out the [driver documentation](https://docs.sparkfun.com/qwiic_oled_base_py/classqwiic__oled_1_1qwiic__oled__base_1_1_qwiic_oled_base.html)." |
| 103 | + ] |
| 104 | + }, |
| 105 | + { |
| 106 | + "cell_type": "code", |
| 107 | + "execution_count": null, |
| 108 | + "id": "04884e2e", |
| 109 | + "metadata": {}, |
| 110 | + "outputs": [], |
| 111 | + "source": [ |
| 112 | + "myOLED.begin() # Initialize the OLED\n", |
| 113 | + "\n", |
| 114 | + "# Clear the OLED\n", |
| 115 | + "myOLED.clear(myOLED.ALL) # Clear OLED graphic memory.\n", |
| 116 | + "myOLED.clear(myOLED.PAGE) # Clear the processor's display buffer.\n", |
| 117 | + "\n", |
| 118 | + "myOLED.print(\"Hello World!\") # Print a message to the OLED\n", |
| 119 | + "myOLED.display() # Display the message on the OLED (this function must be called to actually show the text)" |
| 120 | + ] |
| 121 | + }, |
| 122 | + { |
| 123 | + "cell_type": "markdown", |
| 124 | + "id": "10d5c3fe-852f-42f7-8378-85dc8c8c7c3e", |
| 125 | + "metadata": {}, |
| 126 | + "source": [ |
| 127 | + "## What You Should See\n", |
| 128 | + "When you run the cell above, you should see the text \"Hello World!\" show up on the OLED display.\n", |
| 129 | + "\n", |
| 130 | + "## You've Completed Circuit 4A!\n", |
| 131 | + "\n", |
| 132 | + "Continue to circuit 4B to build your very own digital temperature sensor.\n", |
| 133 | + "\n", |
| 134 | + "" |
| 135 | + ] |
| 136 | + } |
| 137 | + ], |
| 138 | + "metadata": { |
| 139 | + "kernelspec": { |
| 140 | + "display_name": "MicroPython upydevice kernel", |
| 141 | + "language": "python", |
| 142 | + "name": "micropython-upydevice" |
| 143 | + }, |
| 144 | + "language_info": { |
| 145 | + "codemirror_mode": "python", |
| 146 | + "file_extension": ".py", |
| 147 | + "mimetype": "text/x-python", |
| 148 | + "name": "python", |
| 149 | + "pygments_lexer": "python" |
| 150 | + } |
| 151 | + }, |
| 152 | + "nbformat": 4, |
| 153 | + "nbformat_minor": 5 |
| 154 | +} |
0 commit comments