- SF800 Solar Speicher Tutorial         
Ergebnis 1 bis 10 von 20

Thema: Wasserwaage

Baum-Darstellung

Vorheriger Beitrag Vorheriger Beitrag   Nächster Beitrag Nächster Beitrag
  1. #12
    Erfahrener Benutzer Robotik Einstein Avatar von i_make_it
    Registriert seit
    29.07.2008
    Ort
    Raum DA
    Alter
    57
    Beiträge
    2.814
    Ich habe das mal schnell mit einem ADXL345 mit +-2g (10 Bit Auflösung) implementiert.
    Beim ADXL345 ist die Auflösung nicht besser.
    2g - 10Bit
    4g - 11Bit
    8g - 12Bit
    16g - 13Bit

    Mit einer Kreditkarte (0,75mm) unter dem Breadboard (85mm) ist die Änderung grade mal 2-3 mal so Groß wie das Sensorrauschen.
    Die "----------------" Linien sind nachträglich eingefügt.
    Erster Abschnitt, eine Seite 0,75mm erhöht
    Zweiter Abschnitt, Beim Rausziehen der Karte
    Dritter Abschnitt, Breadboard liegt eben auf dem Tisch
    (Ob der Tisch im Wasser steht habe ich nicht geprüft)
    Code:
    h = 0.75mm
    Hypotenuse = ca. 85mm
    
    6,3,251
    5,3,253
    7,3,253
    6,3,252
    6,2,252
    7,3,254
    6,3,252
    6,4,252
    6,3,252
    7,3,253
    6,3,253
    6,4,252
    6,4,252
    5,4,253
    6,5,252
    7,4,253
    7,4,253
    7,4,254
    7,4,252
    8,3,254
    6,4,252
    6,4,252
    6,3,252
    5,5,252
    6,3,252
    7,4,253
    7,3,252
    7,3,253
    6,5,252
    ------------------
    6,1,254
    10,6,252
    3,7,250
    5,16,243
    8,-4,259
    4,7,251
    13,-3,258
    -27,-27,214
    3,11,252
    4,16,252
    5,8,252
    4,2,254
    5,8,254
    5,1,251
    5,55,252
    6,5,255
    2,1,251
    1,-1,254
    3,3,252
    -------------------
    4,4,252
    5,2,252
    4,4,252
    4,3,252
    3,4,252
    4,4,253
    4,3,253
    4,3,253
    3,4,253
    3,4,253
    3,3,251
    4,4,253
    5,3,253
    4,4,252
    4,4,253
    3,4,253
    4,3,252
    5,4,252
    3,5,253
    4,4,252
    3,4,254
    3,4,253
    3,3,253
    4,3,253
    2,4,252
    4,3,252
    Damit wäre eine maximale Auflösung von 3-4mm auf 1 Meter möglich (nahe der Waagerechten).
    Klicke auf die Grafik für eine größere Ansicht

Name:	ADXL345_h0.75-85.jpg
Hits:	10
Größe:	8,9 KB
ID:	32179
    Und Noch mal der Serial Plott vom Arduino.

    Und zum Nachvollziehen:
    Code:
    //Zielplatform Arduino Nano v3
    //ADXL345 Modul mit I2C 5V
    //I2C SCL ist A5 bei Arduino Nano
    //I2C SDA itt A4 bei Arduino Nano
    // http://forum.arduino.cc/index.php?topic=100287.0
    
    #include <Wire.h>
    
    byte DEVICE_ADDRESS = 0x53; //This address is fixed for the board we use because pin 12 is fixed to GND
    
    byte POWER_CTRL = 0x2D;    //Power Control Register
    // byte BW_RATE = 0x30 // Data Rate Register
    byte DATA_FORMAT = 0x31;   //Data Format & Measurement Range Register
    
    
    byte DATAX0 = 0x32;        //X-Axis Data 0
    byte DATAX1 = 0x33;        //X-Axis Data 1
    byte DATAY0 = 0x34;        //Y-Axis Data 0
    byte DATAY1 = 0x35;        //Y-Axis Data 1
    byte DATAZ0 = 0x36;        //Z-Axis Data 0
    byte DATAZ1 = 0x37;        //Z-Axis Data 1
    
    byte values[10];
    int x,y,z;
    
    unsigned long prev1micros = 0; //Blink LED time
    int togglestate = LOW; //Blink LED State
    
    void setup() {
      
    pinMode(13, OUTPUT); //Blink LED für Funktionskontrolle
    
      Wire.begin();    //Initiate the Wire library and join the I2C bus as a master. This is called only once.
      Serial.begin(9600);
    //  writeRegister(DEVICE_ADDRESS, BW_RATE, 0x1100); //Put the ADXL345 Output Datarate to 400Hz
      writeRegister(DEVICE_ADDRESS, DATA_FORMAT, 0x00); //Put the ADXL345 into +/- 2G range by writing the value 0x00 to the register.
    //  writeRegister(DEVICE_ADDRESS, DATA_FORMAT, 0x01); //Put the ADXL345 into +/- 4G range by writing the value 0x01 to the register.
    //  writeRegister(DEVICE_ADDRESS, DATA_FORMAT, 0x10); //Put the ADXL345 into +/- 8G range by writing the value 0x10 to the register.
    //  writeRegister(DEVICE_ADDRESS, DATA_FORMAT, 0x11); //Put the ADXL345 into +/- 16G range by writing the value 0x11 to the register.
      writeRegister(DEVICE_ADDRESS, POWER_CTRL, 0x08); //Put the ADXL345 into Measurement Mode by writing the value 0x08 to the register.
    
    /*
      Serial.print("Text - ");  
      readRegister(0x53, 0x32, 4, values);
      Serial.println(values[0]);
      Serial.println(values[1]);
      Serial.println(values[2]);
      Serial.println(values[3]);
    */  
    }
    
    void loop() {
      readRegister(DEVICE_ADDRESS, DATAX0, 6, values);
    
      //The ADXL345 gives 10-bit acceleration values, but they are stored as bytes (8-bits). To get the full value, two bytes must be combined for each axis.
      //The X value is stored in values[0] and values[1].
      x = ((int)values[1]<<8)|(int)values[0];
      //The Y value is stored in values[2] and values[3].
      y = ((int)values[3]<<8)|(int)values[2];
      //The Z value is stored in values[4] and values[5].
      z = ((int)values[5]<<8)|(int)values[4];
    
      //Below is an optional section, it maps the raw output to a different range.
      //  x = map(x, -150, 150, 0, 255);
      //  y = map(y, -150, 150, 0, 255);
      //  z = map(z, -150, 150, 0, 255);
      //End of optional section.
    
    
      Serial.print(x, DEC);
      Serial.print(',');
      Serial.print(y, DEC);
      Serial.print(',');
      Serial.println(z, DEC);
    //  Serial.print(',');
    //  Serial.println(millis());
     
      //Blink LED für Funktionskkontrolle
      unsigned long cur1micros = millis();
      if (cur1micros - prev1micros >= 200) {
        prev1micros = cur1micros;
        if (togglestate == LOW){
          togglestate = HIGH;
        }else{ 
          togglestate = LOW;
        }
      }  
      digitalWrite(13, togglestate);
    
    }
    
    void writeRegister(byte device, byte registerAddress, byte value) {
      Wire.beginTransmission(device);    //Start transmission to device
      Wire.write(registerAddress);       //Specify the address of the register to be written to
      Wire.write(value);                 //Send the value to be writen to the register
      Wire.endTransmission();            //End transmission
    }
    
    void readRegister(byte device, byte registerAddress, int numBytes, byte *values) {
    
      byte address = 0x80|registerAddress;
      if (numBytes > 1) address = address|0x40;
    
      Wire.beginTransmission(device);
      Wire.write(address);
      Wire.endTransmission();
    
      Wire.beginTransmission(device);    
      Wire.requestFrom(device, numBytes);  //Request 6 bytes from device
    
      int i = 0;
      while (Wire.available()) {          //Device may send less than requested
        values[i] = Wire.read();          //Receive a byte from device and put it into the buffer
        i++;
      }
      Wire.endTransmission();
    }
    Geändert von i_make_it (05.11.2016 um 07:24 Uhr)

Ähnliche Themen

  1. Elektronische Wasserwaage (2D) oder "Libelle"
    Von zackareli im Forum Sensoren / Sensorik
    Antworten: 11
    Letzter Beitrag: 07.09.2005, 20:35

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •  

Labornetzteil AliExpress