Go Down

Topic: 2 sensors on a OLED i2C display (Read 173 times) previous topic - next topic

nanoR4K

so i´ve be trying to make an glove with a heart pulse and temperature sensors, and i managed to make this code that displays the BPM from the pulse sensor on the OLED display, but i don´t know how to add the other two values on the display (umidity and temperature):

Code: [Select]
#include "U8glib.h"
#include "dht.h"
#define USE_ARDUINO_INTERRUPTS true
#include <PulseSensorPlayground.h>
dht DHT;

#define DHT11_PIN 1
const int PulseWire = A0;
const int LED13 = 13;
const int Threshold = 550;

int bpm = 0;

PulseSensorPlayground pulseSensor;

U8GLIB_SSD1306_128X64 SSD1306_Display;

void DrawHeartBeat( int pulseBPM )
{
  char
  szBpm[10];

  SSD1306_Display.setFont ( u8g_font_courB12);
  SSD1306_Display.drawStr (3,30 , "BPM:");
  SSD1306_Display.drawStr (2,45 , "TEMP:");
  SSD1306_Display.drawStr (3,60 , "UMD:");
  SSD1306_Display.drawStr (26, 13 , " MG-MARK-2 ");
  SSD1306_Display.drawLine(1,15, 128,15);
  SSD1306_Display.drawFrame(0, 0, 128, 64);
  SSD1306_Display.drawFrame(2,2, 21, 12);
  sprintf( szBpm, "%d", pulseBPM );
  SSD1306_Display.drawStr( 40,30, szBpm );
  SSD1306_Display.drawBox( 4 ,4, 5, 8);
  SSD1306_Display.drawBox( 10,4, 5, 8);
  SSD1306_Display.drawBox( 16,4, 5, 8);
  SSD1306_Display.drawBox( 22,4, 2, 8);

}

void setup(void)
{
  SSD1306_Display.setFont(u8g_font_courB12);
  Serial.begin(9600);

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

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

}

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

  timeNow = millis();
  if ( (timeNow - timeUpdate) < 500 )
    return;
  timeUpdate = timeNow;

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

}

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

  timeNow = millis();

  if ( (timeNow - timeUpdate) < 250 )
    return;
  timeUpdate = timeNow;

  SSD1306_Display.firstPage();
  do
  {
    DrawHeartBeat( bpm );
    Serial.print("BPM: ");
    Serial.println( bpm );

  } while ( SSD1306_Display.nextPage() );

}

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

}


i need this project ready for the science fair next tuesday so if you guys can help me out i would be very grateful for real...

6v6gt

What part are you having difficulty with ? Reading the dht11 sensor to obtain values for temperature and humidity or displaying these values on the screen?
Try finding some sample code for this dht11 and simply print the values to the serial monitor.
Try also to display some dummy values of temperature and humidity to the screen in a way which is compatible with the existing use of the screen for the BPM value.

nanoR4K

i don´t know how to obtain and include the DHT22 values on the OLED

6v6gt

I'm assuming the code that you have attached works, so just to get you started I've added some dummy values for temperature and humidity. You may have to experiment with the alignment of the values on the display.

Change the function DrawHeartBeat() to this:

Code: [Select]

void DrawHeartBeat( int pulseBPM )
{
  char
  szBpm[10];

  SSD1306_Display.setFont ( u8g_font_courB12);
  SSD1306_Display.drawStr (3,30 , "BPM:");
  SSD1306_Display.drawStr (2,45 , "TEMP:");
  SSD1306_Display.drawStr (3,60 , "UMD:");
  SSD1306_Display.drawStr (26, 13 , " MG-MARK-2 ");
  SSD1306_Display.drawLine(1,15, 128,15);
  SSD1306_Display.drawFrame(0, 0, 128, 64);
  SSD1306_Display.drawFrame(2,2, 21, 12);
 
  sprintf( szBpm, "%d", pulseBPM );
  SSD1306_Display.drawStr( 40,30, szBpm );

  sprintf( szBpm, "%d", 21 );              //new. reuses szBpm buffer for TEMP hardcoded to 21
  SSD1306_Display.drawStr( 50,45, szBpm ); //new. optimise the horizontal and vertical displacement if required

  sprintf( szBpm, "%d", 100 );             //new. reuses szBpm buffer for UMD hardcoded to 100
  SSD1306_Display.drawStr( 40,60, szBpm ); //new. optimise the horizontal and vertical displacement if required


  SSD1306_Display.drawBox( 4 ,4, 5, 8);
  SSD1306_Display.drawBox( 10,4, 5, 8);
  SSD1306_Display.drawBox( 16,4, 5, 8);
  SSD1306_Display.drawBox( 22,4, 2, 8);

}


but really you should find a tutorial for using that sensor, test it separately, and then integrate it with your existing code.

nanoR4K


Go Up