Water pressure struggling with sketch



  • Can some help with this sketch I can't seem to figure it out. I will be so happy when I get past this newbie stage.

    #include <SPI.h>
    #include <MySensor.h>  
    #define BARO_CHILD 0
    MySensor gw;
    MyMessage pressureMsg(BARO_CHILD, V_PRESSURE);
    
    int pSensor=A0; //assigning pressure sensor to pin A0
    int readValue; //declaring our readValue Variable
    float Voltage; // declare  voltage variable
    float PSI; // declare pressure variable
    
    void setup()
    {
      gw.begin();
    
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Water Pressure", "1.1");
    
      // Register sensors to gw (they will be created as child devices)
      gw.present(BARO_CHILD, S_BARO);
    
    
     pinMode(pSensor,INPUT); //declare psensor as a input
     Serial.begin(9600); //start serial port
    }
    
    void loop() {
      
      readValue = analogRead(pSensor); // read psensor and put value in read value
      Voltage = (5./1023.)*readValue; //calculating real  world voltage
      PSI = 17.78*Voltage -8; // Calculate pressure PSI
    
      {
        gw.send (PSI);
      }
    
    Serial.println(PSI); //print results to serial monitor
      delay(1000);   // delay one second
    
    }
    


  • What is your error message?
    In your loop, this looks wrong:

    Voltage = (5./1023.)readValue; 
    

    Are you sure you didn't miss an operator or something ?

    You are also missing a presentation of your node, and I don't see anything declaring the radio to be used.
    What are you trying to do?



  • he error that I get is
    Arduino: 1.6.7 (Windows 7), Board: "Arduino Nano, ATmega328"

    C:\Users\repair\Desktop\Ardunio Files\my_pressure_sketch_1\my_pressure_sketch_1.ino: In function 'void loop()':

    my_pressure_sketch_1:34: error: no matching function for call to 'MySensor::send(float&)'

     gw.send (PSI);
    
                 ^
    

    C:\Users\repair\Desktop\Ardunio Files\my_pressure_sketch_1\my_pressure_sketch_1.ino:34:17: note: candidate is:

    In file included from C:\Users\repair\Desktop\Ardunio Files\my_pressure_sketch_1\my_pressure_sketch_1.ino:2:0:

    C:\Program Files (x86)\Arduino\libraries\MySensors/MySensor.h:215:7: note: bool MySensor::send(MyMessage&, bool)

    bool send(MyMessage &msg, bool ack=false);

       ^
    

    C:\Program Files (x86)\Arduino\libraries\MySensors/MySensor.h:215:7: note: no known conversion for argument 1 from 'float' to 'MyMessage&'

    exit status 1
    no matching function for call to 'MySensor::send(float&)'

    This report would have more information with
    "Show verbose output during compilation"
    enabled in File > Preferences.
    @tripy


  • Mod

    Change

    gw.send(PSI);
    

    to

    gw.send(pressureMsg.set(PSI, 0));
    


  • I'm a bit blind here, but your issue seems to be that you are trying to send a raw float value, without encapsulating it inside a message.
    Looking at the example, in the 1.5 version it is:

    gw.send(pressureMsg.set(pressure, 0));
    

    Looking at the 1.5 API (http://www.mysensors.org/download/sensor_api_15#MyMessage), creating the message from a float should be

    MyMessage& set(float value, uint8_t decimals);
    

    So, you should not use

    gw.send (PSI);
    

    but

    //declare and init the message
    MyMessage msg(BARO_CHILD, V_PRESSURE);
    //set it's content
    msg.set(PSI,4); //float value with a 4 numbers after decimal precision
    //and send the message
    gw.send (msg);


  • @tripy Thanks ; Tripy your solution solve the problem and pointed me in new info . I am slowly learning the solutions are available here .



  • Glad I was able to help.


Log in to reply
 

Suggested Topics

  • 3
  • 2
  • 1
  • 8
  • 5

56
Online

11.4k
Users

11.1k
Topics

112.6k
Posts