Float calculation from sensor event data?

Hi,

I am interfacing some sensors on Arduino uno. I encountered a problem with a LPS25 pressure sensor.
When i use the test code below, I can see the temperature and pressure reading in the serial monitor but when I include the two floating variable (Operator and result), the code don’t want to compile and return the following error:

" no match for ‘operator*’ (operand types are ‘sensors_event_t’ and ‘float’) "

How to use those data ? What is going on? I am new to this.

thank you

// Basic demo for pressure readings from Adafruit LPS2X
#include <Wire.h>
#include <Adafruit_LPS2X.h>
#include <Adafruit_Sensor.h>

// For SPI mode, we need a CS pin
#define LPS_CS 8
// For software-SPI mode we need SCK/MOSI/MISO pins
#define LPS_SCK 12
#define LPS_MISO 11
#define LPS_MOSI 9

Adafruit_LPS2X lps;

float Operator;     // The variable I put to try some math transformation 
float result;       // The variable I put to try some math transformation 

void setup(void) {
  Serial.begin(57600);
  while (!Serial) delay(10);     
  Operator = 17.52;              // Random value for testing
  Serial.println("Adafruit LPS2X test!");

  // Try to initialize!
  //if (!lps.begin_I2C()) {
  //if (!lps.begin_SPI(LPS_CS)) {
  if (!lps.begin_SPI(LPS_CS, LPS_SCK, LPS_MISO, LPS_MOSI)) {
    Serial.println("Failed to find LPS2X chip");
    while (1) { delay(10); }
  }
  Serial.println("LPS2X Found!");

  lps.setDataRate(LPS2X_RATE_1_HZ);
}

void loop() {
  sensors_event_t temp;
  sensors_event_t pressure;
  lps.getEvent(&pressure, &temp);
  result = temp * Operator / pressure;    // This is the line that return the error message
  Serial.print(temp);
  Serial.print(" ");
  Serial.print(pressure);
  Serial.print(" ");
  Serial.println(result);
  delay(1000);
}

sensors_event_t is a struct not a float type. You need to reference the field in the struct that you want.

Try this:

void loop() {
  sensors_event_t tempEvent;
  sensors_event_t pressureEvent;
  lps.getEvent(&pressureEvent, &tempEvent);
  result = tempEvent.temperature * Operator / pressureEvent.pressure;    // This is the line that return the error message
  Serial.print(tempEvent.temperature);
  Serial.print(" ");
  Serial.print(pressureEvent.pressure);
  Serial.print(" ");
  Serial.println(result);
  delay(1000);
}

This work but I don't understand why!

I guess I will have to read about Stuct.

and what is this : tempEvent.temperature

what is the " . " for?

thank you Todd

cdb101:
and what is this : tempEvent.temperature

what is the " . " for?

I guess I will have to read about Stuct.

You answered your own question.

cdb101:
This work but I don't understand why!

I guess I will have to read about Stuct.

and what is this : tempEvent.temperature

what is the " . " for?

thank you Todd

You need to study up on structs and also look at the documentation for Adafruit_Sensor.h. It will tell you what all of the members of the structures are.