0

Writing simple text to OLED 128x64 via SPI using Trinket
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Writing simple text to OLED 128x64 via SPI using Trinket

by nataku on Sun Jun 08, 2014 9:57 am

Hi,
I am trying to simply write Hellow World from Trinket using SPI to OLED 128x64.
I started with Adafruit example program and remove most of the stuff about displaying graphics.

I use the Adafruit_Arduino_IDE version 1.0.5 (via you download link).
I selected Arduinio Trinket 8MHz as the board type and USBTinyISP as the programmer per your tutorial.

Is this possible? I search this forum and on the internet but found no example. There is one or two guys in this forum that says they were able to do it but never did post enough detail on schematic and their code.



Here is my program

Code: Select all | TOGGLE FULL SIZE
#include <SPI.h>
#include <TinyWireM.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

// If using software SPI (the default case):
#define OLED_MOSI   9
#define OLED_CLK   10
#define OLED_DC    11
#define OLED_CS    12
#define OLED_RESET 13
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

/* Uncomment this block to use hardware SPI
#define OLED_DC     6
#define OLED_CS     7
#define OLED_RESET  8
Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS);
*/

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2

#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16
static const unsigned char PROGMEM logo16_glcd_bmp[] =
{ B00000000, B11000000,
  B00000001, B11000000,
  B00000001, B11000000,
  B00000011, B11100000,
  B11110011, B11100000,
  B11111110, B11111000,
  B01111110, B11111111,
  B00110011, B10011111,
  B00011111, B11111100,
  B00001101, B01110000,
  B00011011, B10100000,
  B00111111, B11100000,
  B00111111, B11110000,
  B01111100, B11110000,
  B01110000, B01110000,
  B00000000, B00110000 };

#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

void setup()   {               
  //Serial.begin(9600);
 
  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  display.begin(SSD1306_SWITCHCAPVCC);
  // init done
 
  display.display(); // show splashscreen
  delay(2000);
  display.clearDisplay();   // clears the screen and buffer
 
  // text display tests
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("Hello, world!");
  display.setTextColor(BLACK, WHITE); // 'inverted' text
  display.println(3.141592);
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.print("0x"); display.println(0xDEADBEEF, HEX);
  display.display();
  delay(2000);

}


void loop() {
}

Here is the error compilling. I do not have anything connected to the USB yet when I compile.

In file included from MyTrinket_ssd1306_128x64_spi_text_only.ino:19:
/Users/am/Documents/Arduino/Adafruit Trinket Arduino 1.0.5.app/Contents/Resources/Java/libraries/SPI/SPI.h: In static member function 'static byte SPIClass::transfer(byte)':
/Users/am/Documents/Arduino/Adafruit Trinket Arduino 1.0.5.app/Contents/Resources/Java/libraries/SPI/SPI.h:56: error: 'SPDR' was not declared in this scope
/Users/am/Documents/Arduino/Adafruit Trinket Arduino 1.0.5.app/Contents/Resources/Java/libraries/SPI/SPI.h:57: error: 'SPSR' was not declared in this scope
/Users/am/Documents/Arduino/Adafruit Trinket Arduino 1.0.5.app/Contents/Resources/Java/libraries/SPI/SPI.h:57: error: 'SPIF' was not declared in this scope
/Users/am/Documents/Arduino/Adafruit Trinket Arduino 1.0.5.app/Contents/Resources/Java/libraries/SPI/SPI.h: In static member function 'static void SPIClass::attachInterrupt()':
/Users/am/Documents/Arduino/Adafruit Trinket Arduino 1.0.5.app/Contents/Resources/Java/libraries/SPI/SPI.h:63: error: 'SPCR' was not declared in this scope
/Users/am/Documents/Arduino/Adafruit Trinket Arduino 1.0.5.app/Contents/Resources/Java/libraries/SPI/SPI.h:63: error: 'SPIE' was not declared in this scope
/Users/am/Documents/Arduino/Adafruit Trinket Arduino 1.0.5.app/Contents/Resources/Java/libraries/SPI/SPI.h: In static member function 'static void SPIClass::detachInterrupt()':
/Users/am/Documents/Arduino/Adafruit Trinket Arduino 1.0.5.app/Contents/Resources/Java/libraries/SPI/SPI.h:67: error: 'SPCR' was not declared in this scope
/Users/am/Documents/Arduino/Adafruit Trinket Arduino 1.0.5.app/Contents/Resources/Java/libraries/SPI/SPI.h:67: error: 'SPIE' was not declared in this scope
Last edited by adafruit_support_bill on Sun Jun 08, 2014 10:29 am, edited 1 time in total.
Reason: please use the </> button when submitting code. press </>, then paste your code between the [code] [/code] tags.

nataku
 
Posts: 36
Joined: Sun Feb 17, 2013 12:09 am

Re: Writing simple text to OLED 128x64 via SPI using Trinket

by adafruit_support_bill on Sun Jun 08, 2014 10:31 am

You won't be able to drive that display from a Trinket. It requires 1K of SRAM for the display buffer, and the Trinket only has 512 bytes.

adafruit_support_bill
 
Posts: 66820
Joined: Sat Feb 07, 2009 10:11 am

Re: Writing simple text to OLED 128x64 via SPI using Trinket

by nataku on Mon Jun 09, 2014 11:07 pm

It seems that it will be useful to provide a smaller version of the Adafruit_GFX and Adafruit_SSD1306.h that is smaller in size that simply write text so that these smaller display and smaller microcontroller platform will work together.

I just tried running the same OLED using SPI on YUN using standard example included by Adafruit and it works obviously because Yun has more memory.
However, when I try to combine the temboo-Yun example (to check local weather) and display the weather on the OLED it does not work again. This time it compiles but give me the following warning and the OLED does not even display anything and the Yun does not connect to the internet. It will work independently.

Here is the compile error and

Sketch uses 15,200 bytes (53%) of program storage space. Maximum is 28,672 bytes.
Global variables use 873 bytes (34%) of dynamic memory, leaving 1,687 bytes for local variables. Maximum is 2,560 bytes.


here is the code of the sketch. There is a tembooaccount.h related to this that I do not include.

Code: Select all | TOGGLE FULL SIZE
/*
GetYahooWeatherReport

Demonstrates making a request to the Yahoo! Weather API using the Temboo Arduino Yun SDK.

This example code is in the public domain.
*/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// If using software SPI (the default case):
#define OLED_MOSI 9
#define OLED_CLK 10
#define OLED_DC 11
#define OLED_CS 12
#define OLED_RESET 13
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif


#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information

// the address for which a weather forecast will be retrieved
String ADDRESS_FOR_FORECAST = "104 Franklin St., New York NY 10013";

int numRuns = 1; // execution count, so that this doesn't run forever
int maxRuns = 10; // max number of times the Yahoo WeatherByAddress Choreo should be run


void setup() {
Serial.begin(9600);
display.begin (SSD1306_SWITCHCAPVCC);

// for debugging, wait until a serial console is connected
delay(4000);
while(!Serial);
Bridge.begin();

}

void loop()
{
// while we haven't reached the max number of runs...
if (numRuns <= maxRuns) {

// print status
Serial.println("Running GetWeatherByAddress - Run #" + String(numRuns++) + "...");

// create a TembooChoreo object to send a Choreo request to Temboo
TembooChoreo GetWeatherByAddressChoreo;

// invoke the Temboo client
GetWeatherByAddressChoreo.begin();

// add your temboo account info
GetWeatherByAddressChoreo.setAccountName(TEMBOO_ACCOUNT);
GetWeatherByAddressChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
GetWeatherByAddressChoreo.setAppKey(TEMBOO_APP_KEY);

// set the name of the choreo we want to run
GetWeatherByAddressChoreo.setChoreo("/Library/Yahoo/Weather/GetWeatherByAddress");

// set choreo inputs; in this case, the address for which to retrieve weather data
// the Temboo client provides standardized calls to 100+ cloud APIs
GetWeatherByAddressChoreo.addInput("Address", ADDRESS_FOR_FORECAST);

// add an output filter to extract the name of the city.
GetWeatherByAddressChoreo.addOutputFilter("city", "/rss/channel/yweather:location/@city", "Response");

// add an output filter to extract the current temperature
GetWeatherByAddressChoreo.addOutputFilter("temperature", "/rss/channel/item/yweather:condition/@temp", "Response");

// add an output filter to extract the date and time of the last report.
GetWeatherByAddressChoreo.addOutputFilter("date", "/rss/channel/item/yweather:condition/@date", "Response");

// run the choreo
GetWeatherByAddressChoreo.run();

// when the choreo results are available, print them to the serial monitor
while(GetWeatherByAddressChoreo.available()) {

char c = GetWeatherByAddressChoreo.read();
Serial.print(c);
display.display();
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println(c);


}
GetWeatherByAddressChoreo.close();

}

Serial.println("Waiting...");
Serial.println("");
delay(30000); // wait 30 seconds between GetWeatherByAddress calls
}

nataku
 
Posts: 36
Joined: Sun Feb 17, 2013 12:09 am

Re: Writing simple text to OLED 128x64 via SPI using Trinket

by nataku on Mon Jun 09, 2014 11:12 pm

Sorry wrong compile warning.
Here is the correct one.

Sketch uses 24,152 bytes (84%) of program storage space. Maximum is 28,672 bytes.
Global variables use 2,210 bytes (86%) of dynamic memory, leaving 350 bytes for local variables. Maximum is 2,560 bytes.
Low memory available, stability problems may occur

nataku
 
Posts: 36
Joined: Sun Feb 17, 2013 12:09 am

Re: Writing simple text to OLED 128x64 via SPI using Trinket

by adafruit_support_bill on Tue Jun 10, 2014 6:02 am

It seems that it will be useful to provide a smaller version of the Adafruit_GFX and Adafruit_SSD1306.h that is smaller in size that simply write text so that these smaller display and smaller microcontroller platform will work together.

It is not a matter of library code size. The display buffer size is a function of the display resolution: 128 x 64 = 8192 pixels. With 8 bits per pixel that is 1024 bytes. You can't make it any smaller and still have control of the whole screen.

adafruit_support_bill
 
Posts: 66820
Joined: Sat Feb 07, 2009 10:11 am

Re: Writing simple text to OLED 128x64 via SPI using Trinket

by nataku on Wed Jun 11, 2014 8:37 am

Got it.
Can I manually change the .h to make the screen smaller?

nataku
 
Posts: 36
Joined: Sun Feb 17, 2013 12:09 am

Re: Writing simple text to OLED 128x64 via SPI using Trinket

by adafruit_support_bill on Wed Jun 11, 2014 9:24 am

Even the 128x32 option requires 512K of buffer. That takes up 100% of the available SRAM and leaves nothing for stack, variables or heap.

adafruit_support_bill
 
Posts: 66820
Joined: Sat Feb 07, 2009 10:11 am

Re: Writing simple text to OLED 128x64 via SPI using Trinket

by nataku on Thu Jun 12, 2014 8:03 am

Why doesn't it work in Yun when clone with the Temboo read weather from Yahoo example?
I thought the Yun has more memory than Trinket?

nataku
 
Posts: 36
Joined: Sun Feb 17, 2013 12:09 am

Re: Writing simple text to OLED 128x64 via SPI using Trinket

by adafruit_support_bill on Thu Jun 12, 2014 8:41 am

The Yun has 5x as much SRAM as the Trinket (2.5K). So the display library should work with it, as long as your other code does not use up too much SRAM.

I'm not sure how much SRAM is required by the Temboo example, but it does include a lot of libraries. To see if it is a SRAM problem, see this guide: https://learn.adafruit.com/memories-of- ... ree-memory

adafruit_support_bill
 
Posts: 66820
Joined: Sat Feb 07, 2009 10:11 am

Re: Writing simple text to OLED 128x64 via SPI using Trinket

by Whizzkiddwill on Mon Jan 05, 2015 4:37 pm

Could you add an FRam I2c board With 32k to use as screen buffer for the oled or would this still not work with the Trinket?

Whizzkiddwill
 
Posts: 1
Joined: Mon Jan 05, 2015 4:33 pm

Re: Writing simple text to OLED 128x64 via SPI using Trinket

by adafruit_support_bill on Mon Jan 05, 2015 6:01 pm

Not with a Trinket. There would be a conflict between the SPI pins and the i2c pins. You couldn't use both at once.
https://learn.adafruit.com/introducing-trinket/pinouts

adafruit_support_bill
 
Posts: 66820
Joined: Sat Feb 07, 2009 10:11 am

Re: Writing simple text to OLED 128x64 via SPI using Trinket

by jboyton on Mon Jan 05, 2015 9:33 pm

It's not really true that a 1K buffer is needed for a 128x64 display. For example, the u8glib library provides full graphic support with a smaller buffer. U8glib trades speed for free ram: the smaller the buffer, the slower the graphics.

If you only want text it's possible to write to this display without any buffer at all. There is a library called SSD1306ASCII that does this. I took that library and modified/improved it and have been using it for a few months. Last time I checked it uses 61 bytes of sram when configured for SPI.

I'm not sure if u8glib has support for the Trinket or what issues might arise from porting it to that platform. I have only used the text-only library on an Uno.

Both u8glib and the text-only libraries work with I2C as well as SPI and software SPI.

U8glib is published and supported. The text-only library I am using is unpublished but I will happily share the latest version. The original SSD1306ASCII is available on the internet for download.

jboyton
 
Posts: 111
Joined: Tue Sep 16, 2014 2:52 pm

Re: Writing simple text to OLED 128x64 via SPI using Trinket

by arya on Wed Jan 14, 2015 3:25 pm

I created a segmented renderer for the adafruit SSD1306 library that allows the user to trade speed for SRAM. I created a pull request if anyone is interested in providing feedback or helping make it better.

https://github.com/adafruit/Adafruit_SSD1306/pull/20

arya
 
Posts: 1
Joined: Thu Dec 04, 2014 3:59 pm

Re: Writing simple text to OLED 128x64 via SPI using Trinket

by chunshao911 on Fri Oct 23, 2015 3:36 pm

hello,

I got some problems with displaying the images from the ssd1306 library, using 128*64 spi example.

I am using the OLED 128*64 and run the SPI mode. When I run the example code, the bitmap of adafruitt, white dot, and drawline are working and displayed on the screen. but the rest of images are not displayed. I don't know why? can you help?

Also, I notice that only the drawline() function doesn't has a "void" inside of the (). the other drawing function have something like this "void testscrolltext(void) ". I am wondering if it is the (void) block the code to draw?

There is a line in the Arduino "Low memory available, stability problems may occur." Is this related to the problem?

However, I tried to remove all the void inside of (), and the code still only showing the adafruit bitmap, white dot and lines.


Thanks!

chunshao911
 
Posts: 9
Joined: Wed Jul 01, 2015 12:41 pm

Re: Writing simple text to OLED 128x64 via SPI using Trinket

by adafruit_support_bill on Fri Oct 23, 2015 3:56 pm

What processor are you using?

adafruit_support_bill
 
Posts: 66820
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.