help with OLED SH1106 SPi

how can i send the readings from my sensor (heartbeat sensor) to my SH1106 1.3 128x64 7 pin spi oled display ?

i don´t have a good knowledge on C so don´t expect to much from me :slight_smile:

please if you are going to write something on those lines of "you need do learn the basics" don´t even bother to answer this topic :wink:

#define USE_ARDUINO_INTERRUPTS true
#include <PulseSensorPlayground.h>

const int PulseWire = 0;
const int LED13 = 13;
int Threshold = 530;

PulseSensorPlayground pulseSensor;

void setup() {

Serial.begin(9600);

pulseSensor.analogInput(PulseWire);
pulseSensor.blinkOnPulse(LED13);
pulseSensor.setThreshold(Threshold);

if (pulseSensor.begin()) {
Serial.println(" pulseSensor activated ");
}
}

void loop() {

int myBPM = pulseSensor.getBeatsPerMinute(); BPM as an "int".

if (pulseSensor.sawStartOfBeat()) {
Serial.println(" Heartbeat detected ");
Serial.print("BPM: ");
Serial.println(myBPM);

delay(20);

}

Having some knowledge in C is more then some questioners have.
If You use code tags, the leftmost symbol looking like </>, and copy Your code into it it is much more easy to read Your code for people not having a large Pc monitor to look at.
What is Your issue, what is Your actual question? Nobody posts a tested and ready sketch. You do the coding out of help with obstacles appearing.

my question is how i can show the serial monitor info in a external display like the one i listed up there

This compiles for a Nano but I have no clue if it's even close to working.

Note that you need to install the U8glib (Tools >Manage Libraries and search for U8glib.)

Hope it helps.

#include <U8glib.h>
#define USE_ARDUINO_INTERRUPTS true    
#include <PulseSensorPlayground.h>        

const int PulseWire = A0;       
const int LED13 = 13;          
const int Threshold = 530;           

//update with whatever pins you're using
const int pinSCK = 4;
const int pinMOSI = 5;
const int pinCS = 6;
const int pinDC = 7;

int bpm = 0;

PulseSensorPlayground pulseSensor;

U8GLIB_SH1106_128X64 SH1106_Display( pinSCK, pinMOSI, pinCS, pinDC );    

void DrawHeartBeat( int pulseBPM ) 
{
    char
        szBpm[10];
        
    sprintf( szBpm, "%d", pulseBPM );
    SH1106_Display.drawStr( 0, 0, szBpm );
    
}//DrawHeartBeat


void setup(void) 
{  
    SH1106_Display.setFont(u8g_font_gdr25r);
    Serial.begin(9600);          

    pulseSensor.analogInput(PulseWire);   
    pulseSensor.blinkOnPulse(LED13);       
    pulseSensor.setThreshold(Threshold);
    //
    if (pulseSensor.begin())
        Serial.println(" pulseSensor activated ");  

}//setup

void loop(void) 
{
    UpdateBPM();
    UpdateDisplay();
    
}//loop

void UpdateBPM( void )
{
    static unsigned long
        timeUpdate = 0;
    unsigned long
        timeNow;

    timeNow = millis();
    //update heart rate and LED at 50mS intervals
    if( (timeNow - timeUpdate) < 50 )
        return;
    timeUpdate = timeNow;

    bpm = UpdateHeartRate();
    if( bpm >= Threshold )
        digitalWrite( LED13, HIGH );
    else
        digitalWrite( LED13, LOW );
    
}//UpdateLED

void UpdateDisplay( void )
{
    static unsigned long
        timeUpdate = 0;
    unsigned long
        timeNow;

    timeNow = millis();

    //update heart rate at 250mS intervals
    if( (timeNow - timeUpdate) < 250 )
        return;
    timeUpdate = timeNow;
    
    SH1106_Display.firstPage(); 
    do 
    {
        DrawHeartBeat( bpm );
        Serial.print("BPM: ");                        
        Serial.println( bpm ); 
        
    } while( SH1106_Display.nextPage() );
    
}//UpdateDisplay

int UpdateHeartRate( void )
{
    return( pulseSensor.getBeatsPerMinute() );    
    
}//UpdateHeartRate

First thanks for the help, the only problem i found is that the oled is showing this random dot

You might try changing the line:

SH1106_Display.drawStr( 0, 0, szBpm );

to

SH1106_Display.drawStr( 15, 30, szBpm );

and see if anything changes.

thank you it worked :slight_smile:

nanoR4K:
please if you are going to write something on those lines of "you need do learn the basics" don´t even bother to answer this topic

The fact is though, you do need to.

It's unusual to be spoon-fed working code in most fora, and if you don't learn, you'll just be back again and again asking for more code to do , and until even Blackfin who seems to be one of the few members churning out turnkey code at the drop of a hat, may get pi$$ed off.