Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using WiringPi in Qt and Raspberry Pi problem

Using WiringPi in Qt and Raspberry Pi problem

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 736 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • MucipM Offline
    MucipM Offline
    Mucip
    wrote on last edited by
    #1

    Hi,
    I want to use WiringPi library. I want to port below C program to Qt but an error appeared in

    MPU6050_Init();		                 /* Initializes MPU6050 */
    	
    

    line. Complete code is:

    /*
    	MPU6050 Interfacing with Raspberry Pi
    	http://www.electronicwings.com
    */
    
    #include <wiringPiI2C.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <wiringPi.h>
    
    #define Device_Address 0x68	/*Device Address/Identifier for MPU6050*/
    
    #define PWR_MGMT_1   0x6B
    #define SMPLRT_DIV   0x19
    #define CONFIG       0x1A
    #define GYRO_CONFIG  0x1B
    #define INT_ENABLE   0x38
    #define ACCEL_XOUT_H 0x3B
    #define ACCEL_YOUT_H 0x3D
    #define ACCEL_ZOUT_H 0x3F
    #define GYRO_XOUT_H  0x43
    #define GYRO_YOUT_H  0x45
    #define GYRO_ZOUT_H  0x47
    
    int fd;
    
    void MPU6050_Init(){
    	
    	wiringPiI2CWriteReg8 (fd, SMPLRT_DIV, 0x07);	/* Write to sample rate register */
    	wiringPiI2CWriteReg8 (fd, PWR_MGMT_1, 0x01);	/* Write to power management register */
    	wiringPiI2CWriteReg8 (fd, CONFIG, 0);		/* Write to Configuration register */
    	wiringPiI2CWriteReg8 (fd, GYRO_CONFIG, 24);	/* Write to Gyro Configuration register */
    	wiringPiI2CWriteReg8 (fd, INT_ENABLE, 0x01);	/*Write to interrupt enable register */
    
    	} 
    short read_raw_data(int addr){
    	short high_byte,low_byte,value;
    	high_byte = wiringPiI2CReadReg8(fd, addr);
    	low_byte = wiringPiI2CReadReg8(fd, addr+1);
    	value = (high_byte << 8) | low_byte;
    	return value;
    }
    
    void ms_delay(int val){
    	int i,j;
    	for(i=0;i<=val;i++)
    		for(j=0;j<1200;j++);
    }
    
    int main(){
    	
    	float Acc_x,Acc_y,Acc_z;
    	float Gyro_x,Gyro_y,Gyro_z;
    	float Ax=0, Ay=0, Az=0;
    	float Gx=0, Gy=0, Gz=0;
    	fd = wiringPiI2CSetup(Device_Address);   /*Initializes I2C with device Address*/
    	MPU6050_Init();		                 /* Initializes MPU6050 */
    	
    	while(1)
    	{
    		/*Read raw value of Accelerometer and gyroscope from MPU6050*/
    		Acc_x = read_raw_data(ACCEL_XOUT_H);
    		Acc_y = read_raw_data(ACCEL_YOUT_H);
    		Acc_z = read_raw_data(ACCEL_ZOUT_H);
    		
    		Gyro_x = read_raw_data(GYRO_XOUT_H);
    		Gyro_y = read_raw_data(GYRO_YOUT_H);
    		Gyro_z = read_raw_data(GYRO_ZOUT_H);
    		
    		/* Divide raw value by sensitivity scale factor */
    		Ax = Acc_x/16384.0;
    		Ay = Acc_y/16384.0;
    		Az = Acc_z/16384.0;
    		
    		Gx = Gyro_x/131;
    		Gy = Gyro_y/131;
    		Gz = Gyro_z/131;
    		
    		printf("\n Gx=%.3f °/s\tGy=%.3f °/s\tGz=%.3f °/s\tAx=%.3f g\tAy=%.3f g\tAz=%.3f g\n",Gx,Gy,Gz,Ax,Ay,Az);
    		delay(500);
    		
    	}
    	return 0;
    }
    

    Regards,
    Mucip:)

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      What error ?

      1 Reply Last reply
      1
      • MucipM Offline
        MucipM Offline
        Mucip
        wrote on last edited by
        #3

        Hi,
        Please forgive me. I solved it. Thanks...

        Regards,
        Mucip:)

        aha_1980A 1 Reply Last reply
        0
        • MucipM Mucip

          Hi,
          Please forgive me. I solved it. Thanks...

          Regards,
          Mucip:)

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Mucip Then don't forget to mark this topic as SOLVED too.

          Even better would be to tell us what went wrong and how you fixed it. We are curios :)

          Qt has to stay free or it will die.

          MucipM 1 Reply Last reply
          2
          • aha_1980A aha_1980

            @Mucip Then don't forget to mark this topic as SOLVED too.

            Even better would be to tell us what went wrong and how you fixed it. We are curios :)

            MucipM Offline
            MucipM Offline
            Mucip
            wrote on last edited by
            #5

            Dear @aha_1980 ,
            It's pitty for me infact. I forgot the create fınction when I copy it from C to Qt.

            Sorry... :)

            void MPU6050_Init(){
            	
            	wiringPiI2CWriteReg8 (fd, SMPLRT_DIV, 0x07);	/* Write to sample rate register */
            	wiringPiI2CWriteReg8 (fd, PWR_MGMT_1, 0x01);	/* Write to power management register */
            	wiringPiI2CWriteReg8 (fd, CONFIG, 0);		/* Write to Configuration register */
            	wiringPiI2CWriteReg8 (fd, GYRO_CONFIG, 24);	/* Write to Gyro Configuration register */
            	wiringPiI2CWriteReg8 (fd, INT_ENABLE, 0x01);	/*Write to interrupt enable register */
            
            	} 
            

            Regards,
            Mucip:)

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved