Christian Martinez
Published © CC BY-NC-SA

A simple barometer with BME280, DIY arduino and DWIN display

DWIN displays are powerful, low cost. This small project shows how we can send sensor information to DWIN display.

IntermediateFull instructions provided3 hours939
A simple barometer with BME280, DIY arduino and DWIN display

Things used in this project

Hardware components

DWIN touch display 480x270
×1
DIY arduino board
×1
bme280 sensor
×1

Story

Read more

Schematics

Documentation

Zip file with DWIN_SET folder : to be copied to SD card and uploaded to display

Code

DWIN_BME280.ino

Arduino
Simple program to interact with DWIN display
#include <Wire.h>
#include "Seeed_BME280.h"
 
#define SEALEVELPRESSURE_HPA (1013.25)
BME280 bme280;
 
//float a; 
/* Adresses of all sensors */
/*unsigned char Buffer[9];
#define temperature_add   0x11
#define humidity_add     0x12
#define pressure_add   0x63
#define dewpoint_add     0x64
 
unsigned char   Temperature[8] = {0x5a, 0xa5, 0x05, 0x82, temperature_add , 0x00, 0x00, 0x00};
unsigned char      Humidity[8] = {0x5a, 0xa5, 0x05, 0x82, humidity_add, 0x00, 0x00, 0x00};
unsigned char   Pressure[8] = {0x5a, 0xa5, 0x05, 0x82, pressure_add , 0x00, 0x00, 0x00};
unsigned char      DewPoint[8] = {0x5a, 0xa5, 0x05, 0x82, dewpoint_add, 0x00, 0x00, 0x00};
*/ 
 
void setup()
{
  Serial.begin(115200);
  if(!bme280.init()){
   Serial.println("Device error!");
  }
}
 
 
void loop()
{
  sensor_data();
  delay(1000);

}
 
 
void sensor_data()
{
  float t = bme280.getTemperature();
  int h = bme280.getHumidity();
  int p = bme280.getPressure() / 100.0F;

  /*------Print data to Serial Monitor------*/
/* Serial.print("Temperature = ");
  Serial.print(a);
  Serial.println(" C");
 
  Serial.print("Humidity = ");
  Serial.print(h);
  Serial.println(" %");
 
  Serial.print("Pressure = ");
  Serial.print(p);
  Serial.println(" hPa");
*/
 sendFloatNumber(t,0x11);
 sendIntNumber(h,0x12);
 sendIntNumber(p,0x13);
 /*
  Temperature[6] = highByte(t);
  Temperature[7] = lowByte(t);
  Serial.write(Temperature, 8);
/* 
  Humidity[6] = highByte(h);
  Humidity[7] = lowByte(h);
  Serial.write(Humidity, 8);
 
  Pressure[6] = highByte(p);
  Pressure[7] = lowByte(p);
  Serial.write(Pressure, 8);
*/
}

void sendFloatNumber(float floatvalue,byte address)
{
  Serial.write(0x5A);
  Serial.write(0xA5);
  Serial.write(0x07);
  Serial.write(0x82);
  Serial.write(address);
  Serial.write(0x00);

  byte hex[4]={0};

  FloatToHex(floatvalue,hex);

  Serial.write(hex[3]);
  Serial.write(hex[2]);
  Serial.write(hex[1]);
  Serial.write(hex[0]);
  
  }

void sendIntNumber(int intvalue, byte address)
{
  Serial.write(0x5A);
  Serial.write(0xA5);
  Serial.write(0x05);
  Serial.write(0x82);
  Serial.write(address);
  Serial.write(0x00);

  byte hex[2]={0};

  IntToHex(intvalue,hex);

  Serial.write(hex[1]);
  Serial.write(hex[0]);
  
  }
void FloatToHex(float f,byte* hex)
{
  byte* f_byte=reinterpret_cast<byte*>(&f);
  memcpy(hex,f_byte,4);
}

void IntToHex(int f,byte* hex)
{
  byte* f_byte=reinterpret_cast<byte*>(&f);
  memcpy(hex,f_byte,2);
}

Test1 dwin.zip

Arduino
Zip with ressources for DWIN display (DWIN_set folder)
No preview (download only).

Credits

Christian Martinez
2 projects • 0 followers

Comments