CodeBot has a Breadboard!
I couldn't wait to get started with the new Breadboard expansion module. CodeBot brings out plenty of I/O capability on the expansion connectors to accommodate a virtually infinite array of external devices... where to begin!?
The Firia engineering team happened to be working on a health-thermometer project for COVID-19 screening, and I spied this nifty OLED display being tested. Perfect! These little displays are bright and crisp, AND readily available for under $10 from your favorite online sources.
Connecting the display to the Breadboard and jumpering to CodeBot's power and I2C lines couldn't have been easier. Wiring is as follows:
Now that the hardware work is done, it's time to write some Python code to make this thing do something!
Display Control Code
This type of display incorporates a very common controller chip, called the ssd1306. To speed things along even further there is already some MicroPython code written to talk to this chip over the I2C bus. I just grabbed the code from MicroPython's git repo. (Use the link below that points to the version that I tested with.)
Copy the contents of that file into a new file in CodeSpace, naming it ssd1306.py. Run the code on your CodeBot... and notice that nothing happens! That's because this is a module that doesn't have any application or test code to actually do something with the display. You'll need to create file to test this! Since you named the module with a ".py" extension, it will remain on your 'bot until you specifically delete it.
Hello, Display - your code here!
Now that the ssd1306 module is loaded on your 'bot, use File - Create New... and make a file with some code to test this out:
In the code above, notice that we're creating an I2C object with the pins for CodeBot's expansion connector SDA and SCL lines. Then we initialize the display as 128x64 pixels. Finally, the display.text() calls have an (x,y) pixel location for the position where the text string should be drawn. It's pretty basic, but this gives you the building blocks you need to create text-based logs or user-interfaces for your 'bot. Check out the ssd1306.py code for a few more calls that will come in handy in your own code.
It's amazing how bright and crisp these displays are. The picture below doesn't really do it justice!
Naturally, displaying text isn't the last word for a graphical display like this. You can of course implement pixel graphics! MicroPython includes a framebuffer object that the ssd1306.py module interfaces to. It lets you manipulate pixels, and even send image files to the display. See below for an example of that!
For more info on the framebuffer and another nice article on using this display from MicroPython check out the following: