اطلاعیه

Collapse
No announcement yet.

کمک در راه اندازی GY-271

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    کمک در راه اندازی GY-271

    سلام
    من ماژول GY-271را تهیه کردم می خواستم بدونم برای دریافت محور xها با ید چه عددی وارد i2c_write(); شود اگر میشه یک مثالی هم بگذارید

    tnx

    #2
    پاسخ : کمک در راه اندازی GY-271

    توی این لینک یک کد هست البته لینک فیلتره

    https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=we b&cd=1&cad=rja&ved=0CCMQFjAA&url=h ttp%3A%2F%2Fdavidegironi.blogspot.com%2F2013%2F01% 2Favr-atmega-hmc5883l-magnetometer-lib-01.html&ei=ztgIU9WjHYvP4QTywYDABQ&usg=AFQj CNEiPOU5PO037qxp4yl8N0jYTxbCMg

    دیدگاه


      #3
      پاسخ : کمک در راه اندازی GY-271

      من کدی را نوشتم اما اشتباه نشون می ده
      ایا من اشتباه کردم :sad: :sad: :sad:

      کد:
       i2c_start();
          delay_ms(10);
          i2c_write(0x3C);  //write to HMC 
          delay_ms(10);
          i2c_write(0x02);  //mode register
          delay_ms(10);
          i2c_write(0x00);  //continuous measurement mode
          delay_ms(10);
          i2c_stop();
       //===================================================================================   
          //must read all six registers plus one to move the pointer back to 0x03
          i2c_start();
          delay_ms(10);
          i2c_write(0x3D);     //read from HMC
          delay_ms(10);
          xh = i2c_read(1);  //x high byte
          delay_ms(10);
       xl = i2c_read(1); //x low byte
          delay_ms(10);
          xo = xl|(xh << 8); 
          //lcd_gotoxy(0,0);
          //itoa(xo,bb);
          //lcd_puts(bb); 
          //delay_ms(500); 
           if(xo>0 && xo<45){
                 lcd_putsf("N");
          
          } 
           if(xo>45&&xo<80){
                 lcd_putsf("NE");
          
          }
           if(xo>90&&xo<120){
                 lcd_putsf("E");
          
          }  
           if(xo>120&&xo<189){
                 lcd_putsf("SE");
          
          } 
           if(xo>179&&xo<189){
                 lcd_putsf("S");
          
          }
           if(xo>190&&xo<265){
                 lcd_putsf("SW");
          
          } 
           if(xo>257&&xo<289){
                 lcd_putsf("W");
          
          } 
           if(xo>290&&xo<349){
                 lcd_putsf("NW");
          
          }
       //==================================================================================
        delay_ms(10);
          i2c_write(0x3D);     //read from HMC
          delay_ms(10);
          yh = i2c_read(1);  //x high byte
          delay_ms(10);
       yl = i2c_read(1); //x low byte
          delay_ms(10);
          yo = yl|(xh << 8);
         // lcd_gotoxy(0,4);
         //itoa(yo,cc);
         // lcd_puts(cc);
         // delay_ms(500);
          i2c_write(0x3D);     //must reach 0x09 to go back to 0x03
          //delay_ms(10);
          
          
          
          
          i2c_stop();
      
         angle= atan2((double)yo,(double)xo) * (180 / 3.14159265) + 180; // angle in degrees
          angle*=10; 
      //itoa(angle,aa);; 
      //lcd_gotoxy(1,0);
      //lcd_puts(aa);
          delay_ms(1000);
          lcd_clear();

      دیدگاه

      لطفا صبر کنید...
      X