Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lesson11 (mpu6050) scripts: Eugene.Ovdiyuk #118

Open
wants to merge 3 commits into
base: Eugene.Ovdiyuk
Choose a base branch
from

Conversation

ovdiyuk
Copy link

@ovdiyuk ovdiyuk commented Jan 7, 2019

  1. Implemented get_temperature.sh shell script which prints value of temperature (TEMP_OUT_H, TEMP_OUT_L) once per second using i2cget in infinite loop. Value converted to F and C. Upload the script into to folder ‘mpu6050_scripts’.
  2. Added ins_mod.sh and rm_mod.sh for fast Module load
  3. Fixed errors in driver mpu6050.c from the repository.
  4. Makefile was modified to build module on OrangePI
  5. Implemented GUI script gui_mpu6050.sh to pull mpu6050 module data in the terminal

Updated Makefile to build on OrangePI
Updated C file: corrected errors
insmod and rmmod scripts are added
gui_mpu6050.sh script added for pulling information in console
implemented get_temperature.sh to get Temp via i2c-tool
LB=$(sudo i2cget -y 0 0x68 0x42)

#Upper Bit + Lower Bit
TEMP=$(( (UB<<8)+LB-65535 ))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it require to use -65535?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is the only way to XOR all 16 bits. I don't know why, but ^0xFFFF works incorrectly in the bash.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do You need XOR for all bits?

TEMP=$(( (UB<<8)+LB-65535 ))

# Calc C value
TEMP_C=$(bc << EOF
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use bash operators using (( )) instead of calling bc.

Copy link
Author

@ovdiyuk ovdiyuk Jan 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not possible, because bash cannot work with decimal variables. Of cause, we can use 10^3 multiplicator and convert variable on UI. But I choose this solution.


#Read data
UB=$(sudo i2cget -y 0 0x68 0x41)
LB=$(sudo i2cget -y 0 0x68 0x42)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to read high and low part of data in single command using i2cget option '-w' ?

Copy link
Author

@ovdiyuk ovdiyuk Jan 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, "sudo i2cget -y 0 0x68 0x41 w" works. I didn't know about this. Thanks a lot

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then I need to swap Lo and Hi bytes. Not sure in a method for bash.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this: UB=$(sudo i2cget -y 0 0x68 0x41) && LB=$(sudo i2cget -y 0 0x68 0x42) && UBLB=$(sudo i2cget -y 0 0x68 0x41 w) && echo $UB $LB $UBLB

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose command 'sudo i2cget -y 0 0x68 0x41 w' will give You UBLB as result. Is it correct?

@yekovalyov yekovalyov added changes requested The PR review revealed issues which should be fixed (set by reviewer). and removed ready labels Jan 14, 2019
@ovdiyuk ovdiyuk added ready and removed changes requested The PR review revealed issues which should be fixed (set by reviewer). labels Jan 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants