SparkFun Forums 

Where electronics enthusiasts find answers.

Hardware or product specific questions are best asked here.
User avatar
By MassiveDMG
#217044
Hi all!

First time poster here, so I hope I'm ok posting this question.

TLDR:
How to wire and drive two uniquely addressable SSD1306 OLED displays from the Artemis Redboard Nano?

I am trying my hands on creating a fully functional PipBoy from Fallout, and wanted to use the Artemis Nano board for the main brains behind the bells & whistles. You can see my Hackaday.io project here.

I've had some experience programming iPad apps in Objective-C, and I know my way around an IDE.
Dabbling in Code + Electronics is a new venture for me!

I purchased some tiny OLED displays on AliExpress that seem to be of the SSD1306 variety.
I managed to get one of them work on an Arduino Uno with the example sketches for that board (ssd1306_128x32_i2c from Adafruit), however I'm having a hard time figuring out how to hook up these OLED displays to the Artemis Nano board. I know I've got to look at I2C ports, and that there's some IOMasters at play, but I have no idea how I would go about doing that on the Artemis Nano.

If someone who is more adept at the Artemis Nano could help me with the wiring of those two OLEDs and get that sketch to work that would be awesome! I found the I2C Qwiic breakout boards, but that would make the fitting difficult for the PipBoy case, so ideally I'd just wire them up to the Nano board, unless the Qwiic makes handling them easier/more efficient.

The sketch starts with:
Code: Select all
 This is an example for our Monochrome OLEDs based on SSD1306 drivers

 Pick one up today in the adafruit shop!
 ------> http://www.adafruit.com/category/63_98

 This example is for a 128x32 pixel display using I2C to communicate
 3 pins are required to interface (two I2C and one reset).

 Adafruit invests time and resources providing this open
 source code, please support Adafruit and open-source
 hardware by purchasing products from Adafruit!

 Written by Limor Fried/Ladyada for Adafruit Industries,
 with contributions from the open source community.
 BSD license, check license.txt for more information
 All text above, and the splash screen below must be
 included in any redistribution.
 **************************************************************************/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
When I run the sketch with the Nano board selected, it errors out:
Code: Select all
Arduino\libraries\Adafruit_SSD1306\Adafruit_SSD1306.cpp:492:44: error: 'digitalPinToPort' was not declared in this scope
     dcPort = (PortReg *)portOutputRegister(digitalPinToPort(dcPin));
                                          
Arduino\libraries\Adafruit_SSD1306\Adafruit_SSD1306.cpp:492:44: note: suggested alternative: 'digitalPinToInterrupt'
     dcPort = (PortReg *)portOutputRegister(digitalPinToPort(dcPin));

Arduino\libraries\Adafruit_SSD1306\Adafruit_SSD1306.cpp:492:25: error: 'portOutputRegister' was not declared in this scope
     dcPort = (PortReg *)portOutputRegister(digitalPinToPort(dcPin));

Arduino\libraries\Adafruit_SSD1306\Adafruit_SSD1306.cpp:493:17: error: 'digitalPinToBitMask' was not declared in this scope
     dcPinMask = digitalPinToBitMask(dcPin);
Arduino\libraries\Adafruit_SSD1306\Adafruit_SSD1306.cpp:493:17: note: suggested alternative: 'digitalPinToInterrupt'
     dcPinMask = digitalPinToBitMask(dcPin);

exit status 1
Error compiling for board SparkFun RedBoard Artemis Nano.
User avatar
By liquid.soulder
#217076
Hi! Cool project - it would be awesome to see it when it is done.

Seems like the Adafruit library depends partially on microcontroller specific code (aka it goes beyond the standardized Arduino API and therefore won't just magically work across many platforms).

This line:
dcPort = (PortReg *)portOutputRegister(digitalPinToPort(dcPin));
uses some kind of type definition (PortReg) which just doesn't exist in the Apollo3 Arduino core. However you should still be able to identify the functionality (what does it do? Is it meant to toggle a pin?) and recreate it using either the normal Arduino API (digitalWrite) or Apollo3 functionality (using the AmbiqSuite SDK HAL functions or even going in for direct register manipulation - for speed).

You also mentioned something about I2C ports... do you expect to need to use more than one? Here's a recent (long-ish) post about I2C ports and IOMs on our boards.
viewtopic.php?f=169&t=51004&p=216097
User avatar
By MassiveDMG
#217118
Hi there, thanks for the reply! I'll have a read through that topic, thanks for pointing me in the right direction!
I've got half a mind to wire those Sparkfun 4-pin Qwiic breakout boards to the OLED screens so they fit flush with them and I can daisy chain them in the casing without (hopefully) too much trouble. Through-pin won't work, as it will no longer fit the case, but if I rotate them and wire them up, it might do the job just fine.
That way I can just use the SDA0 and SCL0 (I assume) from the Qwiic port on the Nano and use the address headers on the OLED to address them individually without having to sacrifice pins.

As for the sketch, I'll just try and find a way to reverse engineer/port this to the Apollo 3 Arduino core, the SSD1306 seem like a common enough part that there's bound to be some code out there that would work on the Apollo3 core.

EDIT:

I found another library at https://github.com/olikraus/u8g2, and this seems to work just fine! I jerry rigged the SDA3 and SCL3 wires with some dupont male/female shenanigans (don't want to solder just yet!) and I got most of the test sketch to draw on the screen from the Artemis! Next step is to have it render the Date and Time in a format that matches the PipBoy, and maybe even whip up some animation so it looks like one of those old mechanical cassette tape roller counters. Thanks for the help so far!
User avatar
By drbrodie
#218505
I was trying to use the SSD1309 library to which you provided link but had a number of problems:
1. The first line of the Example9999_Testing.ino is - #include "HyperDisplay_UG2856KLBAG01_I2C.h" which isn't in the SRC folder and which I cannot otherwise find
2. I tried changing that to: #include "HyperDisplay_SSD1309.h" which did not compile
3. First, it said that hyperdisplay.h was missing which I did find and install in the Libraries
4. It still does not compile with an error message: 'UG2856KLBAG01_I2C' does not name a type; did you mean 'UG2856KLBAG01_SPI_MODE'?
5. If I change that to the suggestion it still does not compile stating 'myTOLED' was not declared in this scope
It seems like I'm on the completely wrong track here. I'm just trying to run an SSD1306 128X32 on an Artemis. Please help!
 Topic permissions

You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum