Új hozzászólás Aktív témák

  • Imy

    veterán

    Arduinoval szeretnék megoldani egy ellenállás mérést, ami hőt mér, és egy KY-040-el egy hőmérséklet beállítást. Ha ezt a kódot [link] futtatom a doksi végén, akkor hiba nélkül megy az encoder poziciójának számolása. Ha ez után beteszem a hőmérséklet mérést, akkor már nem mey, össze-vissza számol:
    #include <Adafruit_MAX31865.h>
    // Use software SPI: CS, DI, DO, CLK
    Adafruit_MAX31865 thermo = Adafruit_MAX31865(10, 11, 12, 13);
    // use hardware SPI, just pass in the CS pin
    //Adafruit_MAX31865 thermo = Adafruit_MAX31865(10);
    // The value of the Rref resistor. Use 430.0 for PT100 and 4300.0 for PT1000
    #define RREF      430.0
    // The 'nominal' 0-degrees-C resistance of the sensor
    // 100.0 for PT100, 1000.0 for PT1000
    #define RNOMINAL  100.0
    //Resistance meter
    float Ra = 0.00385;
    float R0 = 20.9;
    float Rt;
    float T;
    //HW-040 encoder
    int pinA = 3; // Connected to CLK on KY-040
    int pinB = 4; // Connected to DT on KY-040
    int encoderPosCount = 0;
    int pinALast;
    int aVal;
    boolean bCW;
    void setup() {
      Serial.begin(115200);
      Serial.println("Adafruit MAX31865 PT100 Sensor Test!");
      thermo.begin(MAX31865_2WIRE);  // set to 2WIRE or 4WIRE as necessary
      pinMode (pinA, INPUT);
      pinMode (pinB, INPUT);
      pinALast = digitalRead(pinA);
    }
    void loop() {
      /////////////ENCODER//////////////////////////////////////////////////////////////////////////////
      aVal = digitalRead(pinA);
      if (aVal != pinALast) { // Means the knob is rotating
        // if the knob is rotating, we need to determine direction
        // We do that by reading pin B.
        if (digitalRead(pinB) != aVal) { // Means pin A Changed first - We're Rotating Clockwise
          encoderPosCount ++;
          bCW = true;
        } else {// Otherwise B changed first and we're moving CCW
          bCW = false;
          encoderPosCount--;
        }
        Serial.print ("Rotated: ");
        if (bCW) {
          Serial.println ("clockwise");
        } else {
          Serial.println("counterclockwise");
        }
      }
      pinALast = aVal;
      Serial.print("Encoder Position: ");
      Serial.println(encoderPosCount);
      ///////////MAX31865////////////////////////////////////////////////////////////////////////////
      uint16_t rtd = thermo.readRTD();
      //Serial.print("RTD value: "); Serial.println(rtd);
      float ratio = rtd;
      ratio /= 32768;
      Rt = RREF * ratio;
      T = ((Rt - R0) / (R0 * Ra));
      //Serial.print("Ratio = "); Serial.println(ratio,8);
      Serial.print("Resistance = "); Serial.print(RREF * ratio, 2); Serial.println(" ohm");
      //Serial.print("Temperature = "); Serial.println(thermo.temperature(RNOMINAL, RREF));
      Serial.print("PakaTemp = "); Serial.print(T, 2); Serial.println(" C");
      // Check and print any faults
      uint8_t fault = thermo.readFault();
      if (fault) {
        Serial.print("Fault 0x"); Serial.println(fault, HEX);
        if (fault & MAX31865_FAULT_HIGHTHRESH) {
          Serial.println("RTD High Threshold");
        }
        if (fault & MAX31865_FAULT_LOWTHRESH) {
          Serial.println("RTD Low Threshold");
        }
        if (fault & MAX31865_FAULT_REFINLOW) {
          Serial.println("REFIN- > 0.85 x Bias");
        }
        if (fault & MAX31865_FAULT_REFINHIGH) {
          Serial.println("REFIN- < 0.85 x Bias - FORCE- open");
        }
        if (fault & MAX31865_FAULT_RTDINLOW) {
          Serial.println("RTDIN- < 0.85 x Bias - FORCE- open");
        }
        if (fault & MAX31865_FAULT_OVUV) {
          Serial.println("Under/Over voltage");
        }
        thermo.clearFault();
      }
      Serial.println();
      //delay(1000);
    }

Új hozzászólás Aktív témák

Hirdetés