Display Output Content from Serial Monitor to OLED Display

Hello,

I have been researching and looking through forum posts, but have not been able to find a solution unless I have been searching for it the wrong way.

I am building a transmitter and receiver module, with two Arduino Uno's. They are already successfully communicating with one another and display the right code in their own serial monitors. Transmitter serial monitor will display "Signal Sent", Receiver serial monitor will display "Signal Received: Message", "Message", is what is being sent from transmitter to receiver. What I am trying to do now is incorporate an OLED display for each Arduino. I am using a 1.3" IIC (4 pins - VCC, GND, SCL, SDA).

Is it possible for the OLED to display the given messages instead of on the serial monitor? Basically want to use the OLED display as my "serial monitor" for each Arduino.

Thank you for your feedback!

NOTES
I have the OLED connected to the 3.3V power supply so that the transmitter and receiver have the 5V supply (this way worked best in my application, the transmitter and receiver stopped communicating otherwise). I tried implementing basic code to display my name, on the Transmitter it would work, but on the receiver, it would either mess up my Receiver serial monitor, or it would not display my name on the OLED display. Or it would display my name, but add extra unknown characters to the Receiver's serial monitor (i.e. "Signal Received: Message??!#").

Here is the transmitter code:

#include <Wire.h>     //Includes conncetion and interface with Arduino
#include <RH_ASK.h>   // Include the RH_ASK library
#include <SPI.h>      // Not actually used but needed to compile the RH_ASK library

//OLED portion
#include "U8glib.h"
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE);

RH_ASK radio(2000, 11, 12);

//OLED draw function
///*
void draw(void) {
  u8g.setFont(u8g_font_profont11);
  u8g.setPrintPos(0, 10);
  u8g.print("BEAST88");
}
//*/

void setup()
{
    Serial.begin(9600);   // Use this for debugging
 
    // Speed of 2000 bits per second
    
    if (!radio.init())
    {
         Serial.println("Radio module failed to initialize");
    }
}
 
void loop()
{
    // Create our message
    const char *msg = "";
 
    // Send our message
    radio.send((uint8_t*)msg, strlen(msg));
 
    // Wait until the data has been sent
    radio.waitPacketSent();

    delay(1000);
 
    // Also inform the serial port that we are done
    Serial.println("Signal Sent");

   //OLED calling Draw function
   u8g.firstPage();
    do {
      draw();
    } while (u8g.nextPage() );

}

Here is the receiver code: (commented out sections are where I have tried to display on the OLED but it did not work properly)

#include <RH_ASK.h>
#include <SPI.h>

//OLED portion
#include "U8glib.h"
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE);

RH_ASK radio;

//OLED draw function
/*
void draw(void) {
  u8g.setFont(u8g_font_profont11);
  u8g.setPrintPos(0, 10);
  u8g.print("BEAST88");
}
//*/

void setup()
{
    Serial.begin(9600);
 
    // Speed of 2000 bits per second
    if (!radio.init())
    {
         Serial.println("Radio module failed to initialize");
    }
}
 
void loop()
{  
  // Create a 32 byte char buffer
  uint8_t receive_buffer[34];
  uint8_t buflen = sizeof(receive_buffer);
 
  // If data is available, print it
  if (radio.recv(receive_buffer, &buflen))
  {
    Serial.print("Signal Received: ");
    Serial.println((char*)receive_buffer);
  }
  
  /*
  u8g.firstPage();
  do {
    draw();
  } while (u8g.nextPage() );
  //*/
}

What you commented out looks plausible at a glance.

Have you verified operation and wiring for the OLED display using example code you didn’t write or ruin in any way?

Post the small program that proves you’ve hooked it up right, you know, kinda just just display BEAST, though Hello World! would be better.

Then we see why it doesn’t in your sketch. Work.

a7

Hello alto777,

The commented-out code works, but it would add a couple of characters to the serial monitor's output message. Also, the OLED is wired up correctly and works on both the transmitter and receiver!

I was just trying to see if I can display whatever is showing in the serial monitor to the OLED display, kind of like an external serial monitor.

Thank you for your reply!

The code you posted doesn’t seem to be trying to print anything but BEAST88.

Post the malfunctioning code in its entirety with nothing commented out, they code that is trying at all to mirror you Serial output and we can mebbe see why.

a7

I see what you're saying, but that is the problem that I am trying to understand....is it even possible to mirror the serial monitor onto a display, if so, is there a certain function that needs to be called? Or is the serial monitor its own separate thing, that can not be mirrored onto a display?

Just send the same stuff to the OLED using its functions that you send to Serial.print.

You could probably figure a modern clever way to accomplish the mirroring, which might look prettier.

Well obvsly you can’t and neither can I… but it seems like the kind of thing the C++ heavies would be all over, let’s see if they bite.

In the meantime, just send it both places.

This low rent method might be helped a bit if you used sprintf to form the string (null terminated character array) once, then Serial.print it and also put it on the OLED.

Imma let you google sprintf, string, character array and null terminated.

AND you could post the code that adds garbage on the OLED - that should be fixable.

a7

Thank you so much! I will go ahead and look into that. Thank you for your reply!