찾기
내용으로 건너뛰기
추적
문서의 이전 판을 선택했습니다!
저장하면 이 자료로 새 판을 만듭니다.
미디어 파일
{{tag> mpu6050 }} ====== MPU6050====== [[esp32]]에서 MPU6050을 [[i2c]]방식으로 읽어서, pitch, roll 값으로 보여주는 코드 {{:tech:mpu6050.webp|}} <file c MPU6050.ino> // // MPU6050을 읽어서, pitch, roll 값으로 보여주는 코드 // #include <Wire.h> #define MPU6050_ADDR 0x68 void setup() { Serial.begin(115200); Wire.begin(21, 22); // SDA=21, SCL=22 (ESP32 기본) // MPU6050 깨우기 (Sleep 해제) Wire.beginTransmission(MPU6050_ADDR); Wire.write(0x6B); // 전원 관리 레지스터 Wire.write(0); // 0 → sleep 해제 Wire.endTransmission(true); } void loop() { Wire.beginTransmission(MPU6050_ADDR); Wire.write(0x3B); // ACCEL_XOUT_H (데이터 시작 주소) Wire.endTransmission(false); Wire.requestFrom(MPU6050_ADDR, 14, true); // 가속도+온도+자이로 14바이트 int16_t ax = Wire.read() << 8 | Wire.read(); int16_t ay = Wire.read() << 8 | Wire.read(); int16_t az = Wire.read() << 8 | Wire.read(); int16_t temp = Wire.read() << 8 | Wire.read(); int16_t gx = Wire.read() << 8 | Wire.read(); int16_t gy = Wire.read() << 8 | Wire.read(); int16_t gz = Wire.read() << 8 | Wire.read(); float AccX = ax / 16384.0; float AccY = ay / 16384.0; float AccZ = az / 16384.0; float pitch = atan2(-AccX, sqrt(AccY * AccY + AccZ * AccZ)) * 180 / PI; float roll = atan2(AccY, AccZ) * 180 / PI; Serial.print("Pitch: "); Serial.print(pitch); Serial.print("°, Roll: "); Serial.println(roll); delay(100); } </file>
저장
미리 보기
취소
편집 요약
참고: 이 문서를 편집하면 내용은 다음 라이선스에 따라 배포하는 데 동의하는 것으로 간주합니다:
CC Attribution-Noncommercial-Share Alike 4.0 International
연결문서
Wheely bot (ESP32, Balancing)
문서 도구
문서 보기
이전 판
연결문서
맨 위로
다크 모드로 보기
☀️
Toggle Menu
기술
너두 고쳐두 됩니다.
사이트 도구
최근 바뀜
미디어 관리자
사이트맵
사용자 도구
등록
로긴
최근 수정된 문서
5138_4147
5128_4376
2816_5926
3570_5986
[가라앉은 고대 도시 (Sunken Ancient City)]
4089_3750
3807_3645
4890_4285
[제비갈매기 만 (Skimmer's Cove)]
5208_4206
개_찾기
6635_3444
6855_3996
6708_3530
6768_3787
7452_4919
4906_3918
6918_2078
7042_2360