1

I've been struggeling with this assignment for school for a couple of days. I have finally figured out where the problem lies. I have an oled screen that is supposed to print out the temperature of a DHT11, at the same time a RF sender should transmit the temperature to another microcontroller. The first microcontroller should also be able to recieve messages via RF and display them on the screen.

I've been having trouble with the oled screen. When i include my RF communication .head file, the oled wont work!!! I Cant understand why and it's really bugging me, I'm thinking it might be a memory problem, but the arduino IDE tells me it is only using 61% of the storage space. I'm using a arduino nano but i also have an Uno and a Mega laying around. Do you think i should try the Uno or is there a problem in the code somehow? Thank you so much!

main.ino:

#include "display.h";
//#include "DHT.h";
#include "Radiocom.h";


//long temperature;  
String message = "abc123";


void setup() 
{            
  Serial.begin(115200);
  //initDHT();
  initDisplay();
  //initRF();
} 


void loop()  
{
  //temperature = readTemp();
  //delay(1000);
  //printTemp(temperature);
  printMessage(message);
  //sendMsg();
  //RFlisten();
  delay(1000);
}

radiocom.h:

#include <RH_ASK.h>
//for feather huzzah ESP:
//RH_ASK rf_driver(2000,13, 12, 14);
RH_ASK rf_driver;

void initRF(){
  rf_driver.init();
  Serial.println("Radio transmitter initiated..");
}

void sendMsg(){
  const char *msg = "testing testing, one two";
  rf_driver.send((uint8_t *)msg, 24);
  rf_driver.waitPacketSent();
  delay(1000);

}

void RFlisten(){
  uint8_t buf[24];
  uint8_t buflen = sizeof(buf);
  if(rf_driver.recv(buf, &buflen)){
    Serial.print("Message received: ");
    Serial.println((char*)buf);

  }

}

display.h:

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>  // Include core graphics library for the display
#include <Adafruit_SSD1306.h>  // Include Adafruit_SSD1306 library to drive the display


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

// Define SPI pins:

#define OLED_MOSI   9
#define OLED_CLK   6
#define OLED_DC    7
#define OLED_CS    8
#define OLED_RESET 13

// Create display
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT,
  OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);


void initDisplay(){

  delay(100); 

  display.begin(SSD1306_SWITCHCAPVCC);

  display.clearDisplay();  // Clear the buffer

  display.setTextColor(WHITE);  // Set color of the text

  display.setRotation(0);  // Set orientation. Goes from 0, 1, 2 or 3

  display.setTextWrap(false);  // By default, long lines of text are set to automatically “wrap” back to the leftmost column.
                               // To override this behavior (so text will run off the right side of the display - useful for
                               // scrolling marquee effects), use setTextWrap(false). The normal wrapping behavior is restored
                               // with setTextWrap(true).

  display.dim(0);  //Set brightness (0 is maximun and 1 is a little dim)

  Serial.println("Display initiated..");

}


void printMessage(String message){
  display.setTextSize(0);  // Set text size. We are using a custom font so you should always use the text size of 0
  display.setTextColor(WHITE);
  display.setCursor(0,50);
  display.clearDisplay();
  display.print(message);
  display.display();
  Serial.println("printing message on display");
  delay(1000);

}
void printTemp(long temp){

  display.setTextSize(0);  // Set text size. We are using a custom font so you should always use the text size of 0

  display.clearDisplay();  // Clear the display so we can refresh
  // Print text:
  display.setCursor(25, 15);  // (x,y)
  display.println("temp:");  // Text or value to print
  // Draw rectangle:
  display.drawRect(79, 0, 35, 27, WHITE);  // Draw rectangle (x,y,width,height,color)
                                           // It draws from the location to down-right

  // Print variable with left alignment:
  display.setCursor(83, 20);  // (x,y)
  display.println(temp);  // Text or value to print

  display.display();  // Print everything we set previously
  Serial.println("Printing temp..");

}
  • I thought I rad somewhere that SPI on the nano uses 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK) - though, if that were a hard and fast rule, I guess your code wouldn't work with the OLED either way .. edit: oh, I see, you're using using software (bitbang) SPI – Jaromanda X Jan 14 '19 at 9:47
  • 1
    It could be memory, yes. What many people don't realise is that using the SSD1306 display normally eats up a quarter of their RAM with a dynamic allocation of a display buffer. This does not show in the "used memory" in the IDE. – Majenko Jan 14 '19 at 11:01
  • Make sure that when talking to your display it's chip select is asserted and your RF radio's chip select is de-asserted . Reverse this when talking to the radio. One of the drivers is likely leaving one of the chip selects in the wrong state. – Jeff Wahaus Jan 15 '19 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.