MS5540C Drucksensor

Heute ist Stammtischzeit:
Jeden Donnerstag 20:30 Uhr hier im Chat.
Wer Lust hat, kann sich gerne beteiligen. ;)
  • Ich würde gerne aber die Zeit läuft mir davon.
    Den der Tank den ich Überwachen möchte ist zur Zeit noch leer und der Regen ist schon im Anmarsch.

    In weiterer Folge möchte ich einen Webserver realisieren der den Wasserstand anzeigt.
    Der Webserver läuft ja schon und die Temperatur Anzeige ist auch schon in Aktion.
    Ich dachte es geht mit dem Sensor auch so einfach aber leider ist es nicht so da es keine pyton Programme gibt

  • Hallo Maxx,


    Mein Problem ist ich habe nur ein Arduino Skript.


    Installiere doch die Programmiersprache Processing - das ist quasi wie Arduino C++ auf dem Raspberry. Identische bis sehr ähnliche Befehle und ansonsten auch gut dokumentiert. Da brauchst Du kaum Einarbeitung, um den Code zum Laufen zu bekommen.

    Beste Grüße

    Andreas

    Ich bin wirklich nicht darauf aus, Microsoft zu zerstören. Das wird nur ein völlig unbeabsichtigter Nebeneffekt sein.
    Linus Torvalds - "Vater" von Linux

    Linux is like a wigwam, no windows, no gates, but with an apache inside dancing samba, very hungry eating a yacc, a gnu and a bison.

  • So Ardoino uno besorgt alles verlötet und sketch eingespielt.

    nun habe ich ein problem das die Temperatur zeigt -407 °C und der druck 8630 mbar an.

    eines weis ich sicher das es bei mir in der Wohnung keine -407°C hat.

    was läuft da falsch??

    bitte um hilfe

    lg
    Maxx

    /*-----( Import needed libraries )-----*/
    #include <Wire.h> // Comes with Arduino IDE
    // Get the LCD I2C Library here:
    // https://bitbucket.org/fmalpartida/ne…ystal/downloads
    // Move any other LCD libraries to another folder or delete them
    // See Library "Docs" folder for possible commands etc.
    #include <LiquidCrystal_I2C.h>

    /*-----( Declare Constants )-----*/
    /*-----( Declare objects )-----*/
    // set the LCD address to 0x27 for a 16 chars 2 line display
    // A FEW use address 0x3F
    // Set the pins on the I2C chip used for LCD connections:
    // addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
    LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address


    #include <SPI.h>
    int clock = 9;
    void resetsensor() //this function keeps the sketch a little shorter
    {
    SPI.setDataMode(SPI_MODE0);
    SPI.transfer(0x15);
    SPI.transfer(0x55);
    SPI.transfer(0x40);
    }
    void setup() {
    lcd.begin(20,4); //Im Setup wird der LCD gestartet (anders als beim einfachen LCD Modul ohne 16,2 in den Klammern denn das wurde vorher festgelegt
    Serial.begin(9600);
    SPI.begin(); //see SPI library details on arduino.cc for details
    SPI.setBitOrder(MSBFIRST);
    SPI.setClockDivider(SPI_CLOCK_DIV32); //divide 16 MHz to communicate on 500 kHz
    pinMode(clock, OUTPUT);
    delay(100);
    }
    void loop()
    {
    TCCR1B = (TCCR1B & 0xF8) | 1 ; //generates the MCKL signal
    analogWrite (clock, 128) ;
    resetsensor();//resets the sensor - caution: afterwards mode = SPI_MODE0!
    //Calibration word 1
    unsigned int word1 = 0;
    unsigned int word11 = 0;
    SPI.transfer(0x1D); //send first byte of command to get calibration word 1
    SPI.transfer(0x50); //send second byte of command to get calibration word 1
    SPI.setDataMode(SPI_MODE1); //change mode in order to listen
    word1 = SPI.transfer(0x00); //send dummy byte to read first byte of word
    word1 = word1 << 8; //shift returned byte
    word11 = SPI.transfer(0x00); //send dummy byte to read second byte of word
    word1 = word1 | word11; //combine first and second byte of word
    resetsensor();//resets the sensor
    //Calibration word 2; see comments on calibration word 1
    unsigned int word2 = 0;
    byte word22 = 0;
    SPI.transfer(0x1D);
    SPI.transfer(0x60);
    SPI.setDataMode(SPI_MODE1);
    word2 = SPI.transfer(0x00);
    word2 = word2 <<8;
    word22 = SPI.transfer(0x00);
    word2 = word2 | word22;
    resetsensor();//resets the sensor
    //Calibration word 3; see comments on calibration word 1
    unsigned int word3 = 0;
    byte word33 = 0;
    SPI.transfer(0x1D);
    SPI.transfer(0x90);
    SPI.setDataMode(SPI_MODE1);
    word3 = SPI.transfer(0x00);
    word3 = word3 <<8;
    word33 = SPI.transfer(0x00);
    word3 = word3 | word33;
    resetsensor();//resets the sensor
    //Calibration word 4; see comments on calibration word 1
    unsigned int word4 = 0;
    byte word44 = 0;
    SPI.transfer(0x1D);
    SPI.transfer(0xA0);
    SPI.setDataMode(SPI_MODE1);
    word4 = SPI.transfer(0x00);
    word4 = word4 <<8;
    word44 = SPI.transfer(0x00);
    word4 = word4 | word44;

    long c1 = word1 << 1;
    long c2 = ((word3 & 0x3F) >> 6) | ((word4 & 0x3F));
    long c3 = (word4 << 6) ;
    long c4 = (word3 << 6);
    long c5 = (word2 << 6) | ((word1 & 0x1) >> 10);
    long c6 = word2 & 0x3F;
    resetsensor();//resets the sensor
    //Temperature:
    unsigned int tempMSB = 0; //first byte of value
    unsigned int tempLSB = 0; //last byte of value
    unsigned int D2 = 0;
    SPI.transfer(0x0F); //send first byte of command to get temperature value
    SPI.transfer(0x20); //send second byte of command to get temperature value
    delay(35); //wait for conversion end
    SPI.setDataMode(SPI_MODE1); //change mode in order to listen
    tempMSB = SPI.transfer(0x00); //send dummy byte to read first byte of value
    tempMSB = tempMSB << 8; //shift first byte
    tempLSB = SPI.transfer(0x00); //send dummy byte to read second byte of value
    D2 = tempMSB | tempLSB; //combine first and second byte of value
    resetsensor();//resets the sensor
    //Pressure:
    unsigned int presMSB = 0; //first byte of value
    unsigned int presLSB =0; //last byte of value
    unsigned int D1 = 0;
    SPI.transfer(0x0F); //send first byte of command to get pressure value
    SPI.transfer(0x40); //send second byte of command to get pressure value
    delay(35); //wait for conversion end
    SPI.setDataMode(SPI_MODE1); //change mode in order to listen
    presMSB = SPI.transfer(0x00); //send dummy byte to read first byte of value
    presMSB = presMSB << 8; //shift first byte
    presLSB = SPI.transfer(0x00); //send dummy byte to read second byte of value
    D1 = presMSB | presLSB;

    const long UT1 = (c5 * 8) + 20224;
    const long dT =(D2 - UT1);
    const long TEMP = 200 + ((dT * (c6 + 50))/1024);
    const long OFF = (c2*4) + (((c4 - 512) * dT)/4096);
    const long SENS = c1 + ((c3 * dT)/1024) + 24576;

    long PCOMP = ((((SENS * (D1 - 7168))/16384)- OFF)/32)+250;
    float TEMPREAL = TEMP/10;
    Serial.print("pressure = ");
    Serial.print(PCOMP);
    Serial.println(" mbar");
    const long dT2 = dT - ((dT >> 7 * dT >> 7) >> 3);
    const float TEMPCOMP = (200 + (dT2*(c6+100) >>11))/10;
    Serial.print("temperature = ");
    Serial.print(TEMPCOMP);
    Serial.println(" °C");
    Serial.println("************************************");
    lcd.setCursor(0,0);
    lcd.print("Druck");
    lcd.setCursor(0,1); // lcd.setCursor um Zeichen und Zeile anzugeben
    lcd.print(PCOMP); // lcd.print um etwas auf dem Display anzeigen zu lassen.
    lcd.print(" mbar");
    lcd.setCursor(0,2);
    lcd.print("Temp");
    lcd.setCursor(0,3 ); // lcd.setCursor um Zeichen und Zeile anzugeben
    lcd.print(TEMPCOMP); // lcd.print um etwas auf dem Display anzeigen zu lassen.
    lcd.print(" C");

    delay(1000);
    }

Jetzt mitmachen!

Du hast noch kein Benutzerkonto auf unserer Seite? Registriere dich kostenlos und nimm an unserer Community teil!