Электронный уровень.

kayot
kayot аватар
Offline
Зарегистрирован: 11.04.2014

вот тоже ваял уровеь компас и тп

как jeka_tm  писал

вывод на жк от 6110

#include "Wire.h"
#include "I2Cdev.h"
#include "HMC5883L.h"
#include "MPU6050.h"
#include "BMP085.h"

#include <ColorLCDShield.h>

LCDShield lcd;


#define CLOCK_RADIUS 33  // radius of clock face
#define CLOCK_CENTER 96  // If you adjust the radius, you'll probably want to adjust this
#define S_LENGTH  30  // length of second hand

#define BACKGROUND  BLACK 
#define R_COLOR  RED  
#define B_COLOR  BLUE  
#define G_COLOR  GREEN   
#define Y_COLOR  YELLOW 
#define W_COLOR  WHITE

HMC5883L compass;
BMP085 barometer;

int temperature;
int pressure;
int heading;
int32_t lastMicros;
int analogPin = 1;     
int hum = 0;           
int sensorValue  = 5000;

int n;
int acc;
float altitude;
int dx, dy;
  

// class default I2C address is 0x68

MPU6050 accelgyro;
int16_t ax, ay, az;
int16_t gx, gy, gz;

#define OUTPUT_READABLE_ACCELGYRO

#define LED_PIN 13
bool blinkState = false;

void setup() {
    
    analogReference(DEFAULT);
    Wire.begin();
   
    compass = HMC5883L();

    compass.SetScale(1.3); // Set the scale of the compass.
    compass.SetMeasurementMode(Measurement_Continuous);
    accelgyro.initialize();
    barometer.initialize();
      
 
  
  lcd.init(PHILIPS);  // Initializes lcd, using an PHILIPSdriver
  lcd.contrast(63);  // -51's usually a good contrast value
  lcd.clear(BACKGROUND);  // clear the screen
   

  
lcd.setStr("MAG", 0,0,  W_COLOR, BACKGROUND);  
lcd.setStr("TMP", 15,0, W_COLOR, BACKGROUND);
lcd.setStr("PRE", 30,0, W_COLOR, BACKGROUND);
lcd.setStr("ALT", 45,0, W_COLOR, BACKGROUND);  
lcd.setStr("GIRO",60,0, W_COLOR,BACKGROUND);  
lcd.setStr("X", 75, 0,  W_COLOR, BACKGROUND);
lcd.setStr("Y", 90, 0,  W_COLOR, BACKGROUND);
lcd.setStr("Z", 105,0,  W_COLOR, BACKGROUND);   
lcd.setStr("ACCEL", 0,70,  W_COLOR, BACKGROUND);  
lcd.setStr("X", 15, 70,  W_COLOR, BACKGROUND);    
lcd.setStr("Y", 30, 70,  W_COLOR, BACKGROUND);    
lcd.setStr("HUM", 45, 70,  W_COLOR, BACKGROUND);    
  

    
    pinMode(LED_PIN, OUTPUT);

}
void loop() {
  
  dislayAcc();
  
  drawClock();

  char intro[10];
  char temp[10];
  unsigned int kk;
  float pressure;  
  float temperature;
 

 
 // Retrived the scaled values from the compass 
  MagnetometerRaw scaled = compass.ReadRawAxis();
  

  // Calculate heading when the magnetometer is level, then correct for signs of axis.
 
  float heading = atan2(scaled.YAxis, scaled.XAxis);
  
  float declinationAngle = 0.0457;
  heading += declinationAngle;
  
  // Correct for when signs are reversed.
  if(heading < 0)
    heading += 2*PI;
    
  // Check for wrap due to addition of declination.
  if(heading > 2*PI)
    heading -= 2*PI;

  // Convert radians to degrees for readability.
  float headingDegrees = heading * 180/M_PI; 


// To calculate heading in degrees. 0 degree indicates North
   
   dtostrf(headingDegrees,3,0,intro);
   lcd.setStr(intro, 0,30, G_COLOR, BACKGROUND);
   displayangleDdraw(headingDegrees);


//датчик влажности 
 sensorValue = analogRead(analogPin);     // считываем значение
   
     hum=(sensorValue*0.12);   
     dtostrf(hum,3,0,temp);
     lcd.setStr(temp, 45,100, G_COLOR, BACKGROUND);
 
 
    
  
    // read raw accel/gyro measurements from device
    accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
   
    // these methods (and a few others) are also available
   // accelgyro.getAcceleration(&ax, &ay, &az);
    
    //accelgyro.getRotation(&gx, &gy, &gz);

    #ifdef OUTPUT_READABLE_ACCELGYRO
       
        dtostrf(ax/500,4,0,temp);
    lcd.setStr(temp, 75,10, G_COLOR, BACKGROUND);
        dtostrf(ay/500,4,0,temp);
    lcd.setStr(temp, 90,10, G_COLOR, BACKGROUND);
       dtostrf(az/500,4,0,temp);
    lcd.setStr(temp,105,10, G_COLOR, BACKGROUND);
        dtostrf(gx/500,4,0,temp);
    lcd.setStr(temp, 15,80, G_COLOR, BACKGROUND);
        dtostrf(gy/500,4,0,temp);
    lcd.setStr(temp, 30,80, G_COLOR, BACKGROUND);
    


    #endif

    // request temperature
    barometer.setControl(BMP085_MODE_TEMPERATURE);

    // wait appropriate time for conversion (4.5ms delay)
    lastMicros = micros();
    while (micros() - lastMicros < barometer.getMeasureDelayMicroseconds());
    //delay(10);
    // read calibrated temperature value in degrees Celsius
    temperature = barometer.getTemperatureC();
   
    dtostrf(temperature,4,1,temp);
    lcd.setStr(temp, 15,30, G_COLOR, BACKGROUND);
  

   
    // request pressure (3x oversampling mode, high detail, 23.5ms delay)
     barometer.setControl(BMP085_MODE_PRESSURE_3);
     while (micros() - lastMicros < barometer.getMeasureDelayMicroseconds());
     delay (50);
    // read calibrated pressure value in Pascals (Pa)
     pressure = barometer.getPressure();
    
     dtostrf(pressure/133.322,3,0,temp);
     lcd.setStr(temp, 30,30, G_COLOR, BACKGROUND);
  
    // calculate absolute altitude in meters based on known pressure
    // (may pass a second "sea level pressure" parameter here,
    // otherwise uses the standard value of 101325 Pa)
    altitude = barometer.getAltitude(pressure);
   
    dtostrf(-altitude/10,3,0,temp);
    lcd.setStr(temp, 45,30, G_COLOR, BACKGROUND);
   


    // blink LED to indicate activity
    blinkState = !blinkState;
    digitalWrite(LED_PIN, blinkState);

//delay(100);
}

  void drawClock()

  /* Draw the circle */
{ 
  lcd.setCircle(CLOCK_CENTER, 96, CLOCK_RADIUS, W_COLOR,3);
  lcd.setStr("N", CLOCK_CENTER - CLOCK_RADIUS, 100-9, Y_COLOR, BACKGROUND);
  lcd.setStr("E", CLOCK_CENTER - 9, 96 + CLOCK_RADIUS - 12, Y_COLOR, BACKGROUND);
  lcd.setStr("S", CLOCK_CENTER + CLOCK_RADIUS - 18, 95-4, Y_COLOR, BACKGROUND);
  lcd.setStr("W", CLOCK_CENTER - 9, 96 - CLOCK_RADIUS + 4, Y_COLOR, BACKGROUND);
}
void displayangleDdraw (int s)
{
 
  static int  sx, sy;
  static int  nx, ny;
  

  /* Delete old lines: */
  lcd.setLine(CLOCK_CENTER-1, 96-1,  CLOCK_CENTER-sx-1, 96-sy-1, BACKGROUND);
  lcd.setLine(CLOCK_CENTER,   96,    CLOCK_CENTER-sx,   96-sy, BACKGROUND);  // delete second hand
  lcd.setLine(CLOCK_CENTER+1, 96+1,  CLOCK_CENTER-sx+1, 96-sy+1, BACKGROUND);  // delete second hand
  /* Calculate and draw new lines: */
  s = map(s, 0, 360, 0, 360);  // map the 0-60, to "360 degrees"
  sx = S_LENGTH * cos(3.14 * ((double) s)/-180 );  // woo trig!
  sy = S_LENGTH * sin(3.14 * ((double) s)/-180);  // woo trig!
  lcd.setLine(CLOCK_CENTER-1 , 96-1, CLOCK_CENTER-sx-1, 96-sy-1, B_COLOR);
  lcd.setLine(CLOCK_CENTER ,   96,   CLOCK_CENTER-sx,   96-sy, B_COLOR);  // print second hand
  lcd.setLine(CLOCK_CENTER+1 , 96+1, CLOCK_CENTER-sx+1, 96-sy+1, B_COLOR);
  /* Delete old lines: */
  lcd.setLine(CLOCK_CENTER-1, 96-1,  CLOCK_CENTER+nx-1, 96+ny-1, BACKGROUND);  // delete second hand
  lcd.setLine(CLOCK_CENTER,   96,    CLOCK_CENTER+nx,   96+ny, BACKGROUND);
  lcd.setLine(CLOCK_CENTER+1, 96+1,  CLOCK_CENTER+nx+1, 96+ny+1, BACKGROUND);
  /* Calculate and draw new lines: */
  n = map(s, 0, 360, 0, 360);
  nx = S_LENGTH * cos(3.14 * ((double) n)/-180 );  // woo trig!
  ny = S_LENGTH * sin(3.14 * ((double) n)/-180);  // woo trig!
  lcd.setLine(CLOCK_CENTER-1 , 96-1, CLOCK_CENTER+nx-1,  96+ny-1, R_COLOR);  // print second hand=
  lcd.setLine(CLOCK_CENTER   , 96,   CLOCK_CENTER+nx,    96+ny, R_COLOR);
  lcd.setLine(CLOCK_CENTER+1 , 96+1, CLOCK_CENTER+nx+1,  96+ny+1, R_COLOR);
}
  void dislayAcc()
  {

  lcd.setCircle(CLOCK_CENTER, 96, 5, W_COLOR,1);
  lcd.setCircle(CLOCK_CENTER-dx, 96+dy, 3, BACKGROUND,FILL);
  dx=ax/500; dy=ay/500;
  lcd.setCircle(CLOCK_CENTER-dx, 96+dy, 3, W_COLOR,FILL); 
    
    
  }

 

jeka_tm
jeka_tm аватар
Offline
Зарегистрирован: 19.05.2013

а фото?

kayot
kayot аватар
Offline
Зарегистрирован: 11.04.2014

к сожалению разобрал

вот фото железок используемых

на экранчике  в левом нижнем углу рисовался круг со стрелкой компаса и типа шарик уровня   а на остаольной площади выводились значения датчиков в цифрах

Яковлевич
Offline
Зарегистрирован: 18.01.2019

          Требуется помощь...Необходима Ваша консультация по прибору. 

  Прошу ответить;  E-mail; A/Verbakh@yandex.ru