PetitCaillou
Published

Study of Grounds for ST

An engineering school project.

IntermediateShowcase (no instructions)64
Study of Grounds for ST

Things used in this project

Hardware components

STM32 Nucleo L432KC
×1
DHT22 Temperature Sensor
DHT22 Temperature Sensor
×1
Adafruit Waterproof DS18B20 Digital temperature sensor
Adafruit Waterproof DS18B20 Digital temperature sensor
×1
DFRobot SEN0193
×1
Adafruit BMP183
×1
Seeed MPU9250
×1

Software apps and online services

Arm Mbed mbed
Sigfox
Sigfox
Ubidots
Ubidots
Node-RED on IBM Cloud
Node-RED on IBM Cloud

Story

Read more

Schematics

btnjqe_2jo7TsDys1.PNG

Btnjqe 2jo7tsdys1

Code

Programme main

C/C++
// PROGRAMME PRINCIPALE

#include "mbed.h"
#include "DHT.h"
#include "ssd1306.h"
#include "standard_font.h"
#include "bold_font.h"
#include "DS1820.h"
#include "BMP183.h"
//#include "MPU9250.h"

#define TIMERR 2
#define DEBUG 0
#define SLEEPTIME 3600

Serial sig(D1,D0);
Serial sig2(USBTX,USBRX);

DigitalOut ChipSelectBaro(A3);
//SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK)
SPI spi(D11, D12, D13);

AnalogIn moisture(A0);

DHT C1(A2,AM2302);

DigitalOut myled(LED1);

SSD1306 oled(D3 /* cs */, D6/* reset */, A5 /* dc */,
             A4 /* clock */, D2 /* data */);

DS1820 probe(A1);

int Dht22(void);
int Ds1820(void);
int Sen0193(void);
int Baro(BMP183 baro);
int InitBaro(BMP183 baro);

float temp,hum,tempS;
float pres,alt;
float humS;

int varReveil;
void callbackReveil (void){
    varReveil = 0;
}
Ticker flipper;


int main()
{
     int test =0;
     
   // BMP183 baro(SPI_MOSI, SPI_MISO, SPI_SCK, D2);
    BMP183 baro(D11, D12, D13, A3);
    oled.initialise();
    oled.clear();
    oled.set_contrast(255); // max contrast
 
    oled.set_font(bold_font, 8);
    oled.printf("Petit Callou\r\n Des Alpes\r\n");
 
    oled.set_font(standard_font, 6);
  //  oled.printf("\r\n Test program\n");
    //oled.printf("******************\r\n");
    wait(1); // wait 1 second for device stable status
 
    oled.update();

    test = InitBaro(baro);
    baro.getCalibrationData();

int i=0;
 while(1){
      
      Dht22();
      Ds1820();
      Sen0193(); 
      if(test == 1);
            Baro(baro);
      
      
        oled.printf("\r\n****Petit Caillou****\r\n");
        oled.printf("Temp Air: %2.2fC \r\nSol: %2.2fC\r\n",temp,tempS);
        oled.printf("Hum Air: %2.2f/100 \r\nSol: %2.2f/100\r\n",hum,humS/10);
        oled.printf("Pres %2.2fPa \r\nAlt: %2.2fm\r\n", pres, alt);
        oled.update();
      
      
      temp = temp*100;
      hum = hum *100;
      tempS = tempS*100;
      humS = humS/10;


      sig.printf("AT$SF=");
      sig.printf("%04x%04x%04x%04x%04x%04x",(int)temp,(int)hum,(int)tempS,(int)pres,(int)alt,(int)humS);
      sig.printf("\r\n");
      sig2.printf("AT$SF=");
      sig2.printf("%04x%04x%04x%04x%04x%04x",(int)temp,(int)hum,(int)tempS,(int)pres,(int)alt,(int)humS);
      sig2.printf("\r\n");
       if(DEBUG == 1)
     {
      oled.printf("Msg Envoye\n\r");
      }

     i++;
     
     varReveil = 1;
     flipper.attach(&callbackReveil, SLEEPTIME);
     while(varReveil==1){
        sleep(); 
        }
    flipper.detach();    
    // wait(6);
 }
    
}

int InitBaro(BMP183 baro){
    int status;
    int go = -1;
    status = baro.getID();
    
    if(status != 0x55) {
        go = -1;
        oled.printf("Communication to Baro failed...\n");
    } else {
        oled.printf("Baro OK!\n\r");
        go = 1;
    }
    return go;
}

int Baro(BMP183 baro){
    baro.read();
    
    pres = baro.Pressure;
    alt = baro.Altitude;
    if(DEBUG == 1)
    {
        oled.printf("\r\n*****BMP183****\r\n");
        oled.printf("Temp.: %f\r\n", baro.Temperature);
        oled.printf("Pres.: %f\r\n", pres);
        oled.printf("Alt.: %f\r\n", alt);
        oled.printf("***************\r\n");
        oled.update();
    }
    return 0;
}

int Ds1820(void){
    probe.convertTemperature(true, DS1820::all_devices);         //Start temperature conversion, wait until ready
    tempS = probe.temperature();
    if(DEBUG == 1)
    {
    oled.printf("\r\n*****Ds1820****\r\n");
    oled.printf("It is %3.1foC\r\n", tempS);
    oled.printf("***************\r\n");
    oled.update();
    }
   // wait(TIMERR);
    return 0;
}

int Dht22(void){
    
   // float temp,hum;
    C1.readData();
    hum = C1.ReadHumidity();
    temp = C1.ReadTemperature(CELCIUS);
     if(DEBUG == 1)
    {
    oled.printf("\r\n******DHT22******\r\n");
    oled.printf("temp =  %6.2f C\r\n", temp);
    oled.printf("hum =  %6.2f%\r\n", hum);
    oled.printf("*****************\r\n");
    oled.update();
    }
   // wait(TIMERR);
    return 0;
}


int Sen0193(void){
    
    float value = 0.0f,valuefin=0.0f;
    int valueint=0;
    value = moisture;
    valueint = moisture *100;
    valuefin = (78-valueint )* 100  / 40;
    humS=valuefin;
     if(DEBUG == 1)
    {
    oled.printf("\r\n*****SEN0193****\r\n");
    oled.printf("hum du sol : %2.2f // : %2.2f/100\n", value,valuefin);
    oled.printf("\r\n*****************\r\n");
    oled.update();
    }
   // wait(TIMERR);
    return 0;
}

Credits

PetitCaillou

PetitCaillou

1 project • 0 followers

Comments

Add projectSign up / Login