Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Error unknown typ name 'DS18B20'
Forum Updated to NodeBB v4.3 + New Features

Error unknown typ name 'DS18B20'

Scheduled Pinned Locked Moved Solved Mobile and Embedded
93 Posts 4 Posters 32.6k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #3

    Hi and welcome to forums

    Did you add the also right click the top project name and select add exiting file and point to this .h file ?
    alt text

    1 Reply Last reply
    0
    • SGaistS SGaist

      Hi and welcome to devnet,

      Can you show your code ?

      Can you also show the version of the header you are using ?

      A Offline
      A Offline
      AlexKrammer
      wrote on last edited by SGaist
      #4

      @SGaist

      #ifndef MAINWINDOW_H
      #define MAINWINDOW_H
      
      #include <QMainWindow>
      #include "ds18b20.h"
      
      namespace Ui {
      class MainWindow;
      }
      
      class MainWindow : public QMainWindow
      {
          Q_OBJECT
      
      public:
          explicit MainWindow(QWidget *parent = nullptr);
          ~MainWindow();
      
      public slots:
          void LOOP();
      
      
      private slots:
          void on_Button1_clicked();
          void on_Button2_clicked();
          void on_Button3_clicked();
          void on_horizontalSlider_valueChanged(int position);
      
      private:
          Ui::MainWindow *ui;
      
          QTimer * m_timer;
      
          DS18B20 *tempReader_;
      };
      
      #endif // MAINWINDOW_H
      
      

      I took this file:
      https://www.arduinolibraries.info/libraries/ds18-b20

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #5

        As silly as it may sound, the file on github at least is all uppercase, is it also the case for yours ?
        If so, then I would start by updating the include. Depending on your machine and configuration, the file system might be sensible to that.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        A 1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #6

          Hi
          Also when you extracted it, did you put it directly in your project folder or
          is in a sub folder called src ?

          1 Reply Last reply
          0
          • SGaistS SGaist

            As silly as it may sound, the file on github at least is all uppercase, is it also the case for yours ?
            If so, then I would start by updating the include. Depending on your machine and configuration, the file system might be sensible to that.

            A Offline
            A Offline
            AlexKrammer
            wrote on last edited by
            #7

            @SGaist
            no it wasn't. But if i changed it, i got the error "file not found"
            only i write it like ds18b20 i dont get an error.
            what do you mean it depends on machine and configuration?

            @mrjj
            First i put it in the project folder with an folder called "Libraries" in it.
            now i put it directly und after that in a folder called src. Nothing changed.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #8

              Some file systems are case insensitive and others not.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              A 1 Reply Last reply
              0
              • SGaistS SGaist

                Some file systems are case insensitive and others not.

                A Offline
                A Offline
                AlexKrammer
                wrote on last edited by
                #9

                @SGaist
                Yes. I know what you mean. But i think the mistake is not to include the file. because there is no error message.

                mrjjM 1 Reply Last reply
                0
                • A AlexKrammer

                  @SGaist
                  Yes. I know what you mean. But i think the mistake is not to include the file. because there is no error message.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #10

                  @AlexKrammer
                  Hi
                  I just tried putting DS18B20.h and DS18B20.cpp directly in the project folder.
                  (where .pro file is )
                  and then add them to the project using the Right-click menu as shown and
                  it seems to like it just fine.

                  A 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @AlexKrammer
                    Hi
                    I just tried putting DS18B20.h and DS18B20.cpp directly in the project folder.
                    (where .pro file is )
                    and then add them to the project using the Right-click menu as shown and
                    it seems to like it just fine.

                    A Offline
                    A Offline
                    AlexKrammer
                    wrote on last edited by
                    #11

                    @mrjj
                    Oh yes. Now it works. But if i tried the Library in github it didnt work.
                    i created a new .h and .cpp file and copied the .h und .cpp file from the post 3 years ago into that. now the bugs are fixed. Thanks for that.
                    Now the next problem ^^.
                    i just added "tempReader_ = new DS18B20(address);" to my MainWindow::MainWindow.
                    Now, what's adress?
                    The second thing:
                    If i try to create a new class called check temperature and i try to create a new object with "DS18B20 sensor;" i receive the following error massage: "No matching constructor for initialization of'DS18B20'.

                    My background. Im trying to create an app with RaspberryPi in QT with using C++ und wiringpi.
                    In order to control the temperature of 5 sections of an area im going to use the sensor DS18B20.
                    At the first problem. is the adress the pin that i chose to use for the sensor. e.g. digitalRead(22); but this cant be i think.

                    thanks for help!

                    mrjjM 1 Reply Last reply
                    0
                    • A AlexKrammer

                      @mrjj
                      Oh yes. Now it works. But if i tried the Library in github it didnt work.
                      i created a new .h and .cpp file and copied the .h und .cpp file from the post 3 years ago into that. now the bugs are fixed. Thanks for that.
                      Now the next problem ^^.
                      i just added "tempReader_ = new DS18B20(address);" to my MainWindow::MainWindow.
                      Now, what's adress?
                      The second thing:
                      If i try to create a new class called check temperature and i try to create a new object with "DS18B20 sensor;" i receive the following error massage: "No matching constructor for initialization of'DS18B20'.

                      My background. Im trying to create an app with RaspberryPi in QT with using C++ und wiringpi.
                      In order to control the temperature of 5 sections of an area im going to use the sensor DS18B20.
                      At the first problem. is the adress the pin that i chose to use for the sensor. e.g. digitalRead(22); but this cant be i think.

                      thanks for help!

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      @AlexKrammer
                      well the constructor is
                      DS18B20::DS18B20(uint8_t pin)
                      so it does seem like the pin.

                      • DS18B20 sensor;" i receive the following error message: "No matching constructor for initialization of'DS18B20'.

                      if we have the same .h , the compiler is correct. There is no default constructor
                      and you must create it with and uint8_t as a parameter.

                      also looking at this
                      https://www.tweaking4all.com/hardware/arduino/arduino-ds18b20-temperature-sensor/

                      its seems correct :)

                      A 1 Reply Last reply
                      0
                      • mrjjM mrjj

                        @AlexKrammer
                        well the constructor is
                        DS18B20::DS18B20(uint8_t pin)
                        so it does seem like the pin.

                        • DS18B20 sensor;" i receive the following error message: "No matching constructor for initialization of'DS18B20'.

                        if we have the same .h , the compiler is correct. There is no default constructor
                        and you must create it with and uint8_t as a parameter.

                        also looking at this
                        https://www.tweaking4all.com/hardware/arduino/arduino-ds18b20-temperature-sensor/

                        its seems correct :)

                        A Offline
                        A Offline
                        AlexKrammer
                        wrote on last edited by AlexKrammer
                        #13

                        @mrjj
                        no mine is a other one.
                        when i use the arduino library i got this.
                        screenshot.png
                        there are a lot of errors. then i delete it and created a .h and .cpp file with that code.

                        ds18b20.h

                        #define DS18B20_H_
                        #include <inttypes.h>
                        #include <stdio.h>
                        #include <stdlib.h>
                        #include <string.h>
                        #include <errno.h>
                        
                        #define CELCIUS 0
                        #define FAHRENHEIT 1
                        #define BUS "/sys/bus/w1/devices/"
                        #define TEMPFILE "/w1_slave"
                        
                        class DS18B20 {
                        public:
                            DS18B20(const char* address);
                            virtual ~DS18B20();
                            uint8_t getUnits();
                            void setUnits(uint8_t);
                            float getTemp();
                            float CtoF(float);
                        private:
                            uint8_t unit_;
                            char* address_;
                            char path[47]; // path should be 46 chars
                        
                        };
                        
                        

                        ds18b20.cpp

                        #include "ds18b20.h"
                        
                        DS18B20::DS18B20(const char* address) {
                            address_ = strdup(address);
                            unit_ = CELCIUS;
                            snprintf(path, 46, "%s%s%s", BUS, address_, TEMPFILE);
                        }
                        
                        DS18B20::~DS18B20() {
                        }
                        
                        float DS18B20::getTemp() {
                            FILE *devFile = fopen(path, "r");
                            if (devFile == NULL) {
                                printf("Count not open %s\n", path);
                                perror("\n");
                            }
                            float temp = -1;
                            if (devFile != NULL) {
                                if (!ferror(devFile)) {
                                    unsigned int tempInt;
                                    char crcConf[5];
                                    fscanf(devFile, "%*x %*x %*x %*x %*x %*x %*x %*x %*x : crc=%*x %s", crcConf);
                                    if (strncmp(crcConf, "YES", 3) == 0) {
                                        fscanf(devFile, "%*x %*x %*x %*x %*x %*x %*x %*x %*x t=%5d", &tempInt);
                                        temp = (float) tempInt / 1000.0;
                                    }
                                }
                            }
                            fclose(devFile);
                        
                            if (unit_ == CELCIUS) {
                                return temp;
                            } else
                                return CtoF(temp);
                        }
                        
                        uint8_t DS18B20::getUnits() {
                            return unit_;
                        }
                        
                        void DS18B20::setUnits(uint8_t u) {
                            unit_ = u;
                        }
                        
                        float DS18B20::CtoF(float temp) {
                            return temp * 1.8 + 32;
                        }
                        
                        

                        now im on this problem:
                        screenshot.png

                        what kind of .h file do u use and where did u download that, that there are no errors.

                        1 Reply Last reply
                        0
                        • mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #14

                          Hi
                          I downloaded from your link
                          https://www.arduinolibraries.info/libraries/ds18-b20
                          But i don't have a board so don't know if it actually works.
                          It does complain about me not having
                          #include "Arduino.h"
                          #include <OneWire.h>

                          but that is expected. The actual .h and .cpp seems happy enough.

                          I goggled the use of
                          DS18B20::DS18B20(const char* address)
                          to see what they would put as adresss but could not find a single example of that.
                          But plenty of DS18B20 examples otherwise

                          A 1 Reply Last reply
                          0
                          • mrjjM mrjj

                            Hi
                            I downloaded from your link
                            https://www.arduinolibraries.info/libraries/ds18-b20
                            But i don't have a board so don't know if it actually works.
                            It does complain about me not having
                            #include "Arduino.h"
                            #include <OneWire.h>

                            but that is expected. The actual .h and .cpp seems happy enough.

                            I goggled the use of
                            DS18B20::DS18B20(const char* address)
                            to see what they would put as adresss but could not find a single example of that.
                            But plenty of DS18B20 examples otherwise

                            A Offline
                            A Offline
                            AlexKrammer
                            wrote on last edited by
                            #15

                            @mrjj
                            now i removed the .h and .cpp file

                            i just downloaded the libraries again and i got the same problem like in the first picture. why dont you have
                            #include "Arduino.h"
                            #include <OneWire.h>
                            and what did you do that you dont get the error unkown type name "uint8_t"
                            the error is still hundreds time here.

                            mrjjM 1 Reply Last reply
                            0
                            • A AlexKrammer

                              @mrjj
                              now i removed the .h and .cpp file

                              i just downloaded the libraries again and i got the same problem like in the first picture. why dont you have
                              #include "Arduino.h"
                              #include <OneWire.h>
                              and what did you do that you dont get the error unkown type name "uint8_t"
                              the error is still hundreds time here.

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #16

                              hi
                              I dont have a board so i dont have the Arduino software / libs installed so no #include "Arduino.h" etc.

                              the uint8_t comes from
                              #include <stdint.h>

                              A 1 Reply Last reply
                              0
                              • mrjjM mrjj

                                hi
                                I dont have a board so i dont have the Arduino software / libs installed so no #include "Arduino.h" etc.

                                the uint8_t comes from
                                #include <stdint.h>

                                A Offline
                                A Offline
                                AlexKrammer
                                wrote on last edited by
                                #17

                                @mrjj i dont use arduino too. Raspberry Pi is what i use.
                                The stdint.h is just a standart library or where can i get it?

                                If this change remove the error do u thing when i type in a raspberry pin into the constructor e.g. 22 it will work?

                                mrjjM 1 Reply Last reply
                                0
                                • A AlexKrammer

                                  @mrjj i dont use arduino too. Raspberry Pi is what i use.
                                  The stdint.h is just a standart library or where can i get it?

                                  If this change remove the error do u thing when i type in a raspberry pin into the constructor e.g. 22 it will work?

                                  mrjjM Offline
                                  mrjjM Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #18

                                  @AlexKrammer
                                  Oh
                                  I just assume since it had Arduino included and most google searches talked about Arduino :)

                                  Well i just added
                                  #include <stdint.h>
                                  and it knew it.
                                  So its included on newer compilers.

                                  • If this change remove the error do u thing when i type in a raspberry pin into the constructor e.g. 22 it will work?

                                    Yes if it has that chip then yes.
                                    https://www.circuitbasics.com/raspberry-pi-ds18b20-temperature-sensor-tutorial/

                                  A 1 Reply Last reply
                                  0
                                  • mrjjM mrjj

                                    @AlexKrammer
                                    Oh
                                    I just assume since it had Arduino included and most google searches talked about Arduino :)

                                    Well i just added
                                    #include <stdint.h>
                                    and it knew it.
                                    So its included on newer compilers.

                                    • If this change remove the error do u thing when i type in a raspberry pin into the constructor e.g. 22 it will work?

                                      Yes if it has that chip then yes.
                                      https://www.circuitbasics.com/raspberry-pi-ds18b20-temperature-sensor-tutorial/

                                    A Offline
                                    A Offline
                                    AlexKrammer
                                    wrote on last edited by
                                    #19

                                    @mrjj
                                    And if i create a new class called "CheckTemlerature" how could i use the DS18B20 sensor.
                                    The first thing to open the constructor with input the Raspberry Pin.
                                    Second step Funktion getTemp?
                                    Third step close with destructor?
                                    Thanks for halp

                                    mrjjM 1 Reply Last reply
                                    0
                                    • A AlexKrammer

                                      @mrjj
                                      And if i create a new class called "CheckTemlerature" how could i use the DS18B20 sensor.
                                      The first thing to open the constructor with input the Raspberry Pin.
                                      Second step Funktion getTemp?
                                      Third step close with destructor?
                                      Thanks for halp

                                      mrjjM Offline
                                      mrjjM Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #20

                                      @AlexKrammer
                                      Yes, it seems that way looking over the examples.

                                      are you using the
                                      DS18B20::DS18B20(const char* address) version or the other version using uint pin ?

                                      A 2 Replies Last reply
                                      0
                                      • mrjjM mrjj

                                        @AlexKrammer
                                        Yes, it seems that way looking over the examples.

                                        are you using the
                                        DS18B20::DS18B20(const char* address) version or the other version using uint pin ?

                                        A Offline
                                        A Offline
                                        AlexKrammer
                                        wrote on last edited by
                                        #21

                                        @mrjj
                                        I deleted the DS18B20::DS18B20(const char* address) version and try it with your idea. I hope it will work but ill see it tomorrow. Its enough for today.
                                        Thanks a lot.

                                        1 Reply Last reply
                                        1
                                        • mrjjM mrjj

                                          @AlexKrammer
                                          Yes, it seems that way looking over the examples.

                                          are you using the
                                          DS18B20::DS18B20(const char* address) version or the other version using uint pin ?

                                          A Offline
                                          A Offline
                                          AlexKrammer
                                          wrote on last edited by
                                          #22

                                          @mrjj
                                          Now i removed the
                                          #include "Arduino.h"
                                          #include <OneWire.h>

                                          and added #include <stdint.h>

                                          screenshot.png

                                          But now i receive the error massage with OneWire again.
                                          How did you solve that problem?

                                          The second fault is that the .cpp produced a lot of errors too.
                                          I think it depends on the OneWire file.

                                          screenshot.png
                                          How did you solve that problem?

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved