344374d41985e8a96e2cc4035223ff7034365330
Board-dat/DAS/DAS1043-dat/DAS1043-DAT.md
| ... | ... | @@ -1,6 +1,10 @@ |
| 1 | 1 | |
| 2 | 2 | # DAS1043 DAT |
| 3 | 3 | |
| 4 | +- [[L298-dat]] - [[buzzer-dat]] |
|
| 5 | + |
|
| 6 | +- [[MPU6050-dat]] |
|
| 7 | + |
|
| 4 | 8 | - legacy wiki page L298N - https://w.electrodragon.com/w/Category:L298#Download |
| 5 | 9 | |
| 6 | 10 |
Chip-dat/InvenSense-dat/MPU6050-DAT/MPU6050-DAT.md
| ... | ... | @@ -5,6 +5,21 @@ |
| 5 | 5 | |
| 6 | 6 | - [[sensor-motion-dat]] |
| 7 | 7 | |
| 8 | +https://invensense.tdk.com/products/motion-tracking/6-axis/mpu-6050/ |
|
| 9 | + |
|
| 10 | + |
|
| 11 | +- Accelerometer (AX/AY/AZ) — converted to g by: accel_g = raw / 16384.0 |
|
| 12 | +- Gyroscope (GX/GY/GZ) — converted to °/s by: gyro_dps = raw / 131.0 |
|
| 13 | +- Temperature — converted to °C by: T = (raw / 340.0) + 36.53 |
|
| 14 | + |
|
| 15 | + |
|
| 16 | +## boards |
|
| 17 | + |
|
| 18 | +- [[MPU6050-dat]] |
|
| 19 | + |
|
| 20 | + |
|
| 21 | + |
|
| 22 | + |
|
| 8 | 23 | ## SCH |
| 9 | 24 | |
| 10 | 25 |  |
| ... | ... | @@ -12,6 +27,11 @@ |
| 12 | 27 |  |
| 13 | 28 | |
| 14 | 29 | |
| 30 | + |
|
| 31 | +## code |
|
| 32 | + |
|
| 33 | +- [[MPU6050-code-1.ino]] |
|
| 34 | + |
|
| 15 | 35 | ## ref |
| 16 | 36 | |
| 17 | 37 | - [[sensor-motion-dat]] - [[invensense-dat]] |
| ... | ... | \ No newline at end of file |
code-dat/cod-BSP-dat/DAS1043-code/DAS1043-code-1.ino
| ... | ... | @@ -0,0 +1,83 @@ |
| 1 | + |
|
| 2 | +#include <Wire.h> |
|
| 3 | + |
|
| 4 | +#define EN_A 9 |
|
| 5 | +#define EN_B 11 |
|
| 6 | + |
|
| 7 | +#define DIR_A1 7 |
|
| 8 | +#define DIR_A2 8 |
|
| 9 | +#define DIR_B1 10 |
|
| 10 | +#define DIR_B2 12 |
|
| 11 | + |
|
| 12 | +#define buzzer 6 |
|
| 13 | +#define address 104 |
|
| 14 | + |
|
| 15 | +void setup() |
|
| 16 | +{ |
|
| 17 | + |
|
| 18 | + |
|
| 19 | + Wire.begin(); |
|
| 20 | + Serial.begin(115200); |
|
| 21 | + |
|
| 22 | + pinMode(EN_A, OUTPUT); |
|
| 23 | + pinMode(EN_B, OUTPUT); |
|
| 24 | + pinMode(DIR_A1, OUTPUT); |
|
| 25 | + pinMode(DIR_A2, OUTPUT); |
|
| 26 | + pinMode(DIR_B1, OUTPUT); |
|
| 27 | + pinMode(DIR_B2, OUTPUT); |
|
| 28 | + pinMode(buzzer, OUTPUT); |
|
| 29 | + |
|
| 30 | + digitalWrite (EN_A, HIGH); |
|
| 31 | + digitalWrite (EN_B, HIGH); |
|
| 32 | + |
|
| 33 | +} |
|
| 34 | + |
|
| 35 | + |
|
| 36 | +void I2C_check() { |
|
| 37 | + // int address = 104; |
|
| 38 | + |
|
| 39 | + Wire.beginTransmission(address); |
|
| 40 | + byte error = Wire.endTransmission(); |
|
| 41 | + // Serial.print (error); |
|
| 42 | + |
|
| 43 | + if (error == 0) |
|
| 44 | + { |
|
| 45 | + Serial.print("找到地址 I2C device found at address 0x"); |
|
| 46 | + if (address < 16) |
|
| 47 | + Serial.print("0"); |
|
| 48 | + Serial.print(address, HEX); |
|
| 49 | + Serial.println(" !"); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | +} |
|
| 53 | + |
|
| 54 | +void loop() |
|
| 55 | +{ |
|
| 56 | + |
|
| 57 | + I2C_check(); |
|
| 58 | + |
|
| 59 | + Serial.println("反转电机方向 flipping motor direction "); |
|
| 60 | + Serial.println(" "); |
|
| 61 | + |
|
| 62 | + digitalWrite (DIR_A1, HIGH); |
|
| 63 | + digitalWrite (DIR_A2, LOW); |
|
| 64 | + digitalWrite (DIR_B1, HIGH); |
|
| 65 | + digitalWrite (DIR_B2, LOW); |
|
| 66 | + |
|
| 67 | + digitalWrite (buzzer, LOW); |
|
| 68 | + |
|
| 69 | + delay(5000); |
|
| 70 | + |
|
| 71 | + I2C_check(); |
|
| 72 | + |
|
| 73 | + digitalWrite (DIR_A1, LOW); |
|
| 74 | + digitalWrite (DIR_A2, HIGH); |
|
| 75 | + digitalWrite (DIR_B1, LOW); |
|
| 76 | + digitalWrite (DIR_B2, HIGH); |
|
| 77 | + |
|
| 78 | + digitalWrite (buzzer, HIGH); |
|
| 79 | + |
|
| 80 | + delay(5000); |
|
| 81 | + |
|
| 82 | + |
|
| 83 | +} |
code-dat/code-sensor/MPU6050-code-1/MPU6050-code-1.ino
| ... | ... | @@ -0,0 +1,94 @@ |
| 1 | +// MPU6050-code-1.ino |
|
| 2 | + |
|
| 3 | +#include <Wire.h> |
|
| 4 | + |
|
| 5 | +const uint8_t MPU_ADDR = 0x68; // I2C address for MPU6050 |
|
| 6 | + |
|
| 7 | +// MPU6050 registers |
|
| 8 | +const uint8_t PWR_MGMT_1 = 0x6B; |
|
| 9 | +const uint8_t ACCEL_XOUT_H = 0x3B; |
|
| 10 | +const uint8_t TEMP_OUT_H = 0x41; |
|
| 11 | +const uint8_t GYRO_XOUT_H = 0x43; |
|
| 12 | + |
|
| 13 | +// Sensitivity scale factors (default ranges): |
|
| 14 | +// Accelerometer: ±2g -> 16384 LSB/g |
|
| 15 | +// Gyroscope: ±250 deg/s -> 131 LSB/(deg/s) |
|
| 16 | +const float ACCEL_SCALE = 16384.0; |
|
| 17 | +const float GYRO_SCALE = 131.0; |
|
| 18 | + |
|
| 19 | +void setup() { |
|
| 20 | + Serial.begin(115200); |
|
| 21 | + while (!Serial) { /* wait for Serial on some boards */ } |
|
| 22 | + |
|
| 23 | + Wire.begin(); |
|
| 24 | + |
|
| 25 | + // Wake up MPU6050 (clear sleep bit) |
|
| 26 | + Wire.beginTransmission(MPU_ADDR); |
|
| 27 | + Wire.write(PWR_MGMT_1); |
|
| 28 | + Wire.write(0x00); // set to zero (wakes up the sensor) |
|
| 29 | + Wire.endTransmission(); |
|
| 30 | + |
|
| 31 | + delay(100); |
|
| 32 | + Serial.println("MPU6050 initialized (0x68)"); |
|
| 33 | +} |
|
| 34 | + |
|
| 35 | +// Read 'count' bytes starting at register 'reg' into dest |
|
| 36 | +void readRegisters(uint8_t reg, uint8_t count, uint8_t* dest) { |
|
| 37 | + Wire.beginTransmission(MPU_ADDR); |
|
| 38 | + Wire.write(reg); |
|
| 39 | + Wire.endTransmission(false); // restart for read |
|
| 40 | + |
|
| 41 | + Wire.requestFrom((int)MPU_ADDR, (int)count); |
|
| 42 | + for (uint8_t i = 0; i < count && Wire.available(); i++) { |
|
| 43 | + dest[i] = Wire.read(); |
|
| 44 | + } |
|
| 45 | +} |
|
| 46 | + |
|
| 47 | +// Read a signed 16-bit value from two consecutive registers (big-endian) |
|
| 48 | +int16_t readInt16(uint8_t reg) { |
|
| 49 | + uint8_t buf[2]; |
|
| 50 | + readRegisters(reg, 2, buf); |
|
| 51 | + return (int16_t)((buf[0] << 8) | buf[1]); |
|
| 52 | +} |
|
| 53 | + |
|
| 54 | +void loop() { |
|
| 55 | + int16_t ax_raw = readInt16(ACCEL_XOUT_H); |
|
| 56 | + int16_t ay_raw = readInt16(ACCEL_XOUT_H + 2); |
|
| 57 | + int16_t az_raw = readInt16(ACCEL_XOUT_H + 4); |
|
| 58 | + |
|
| 59 | + int16_t temp_raw = readInt16(TEMP_OUT_H); |
|
| 60 | + |
|
| 61 | + int16_t gx_raw = readInt16(GYRO_XOUT_H); |
|
| 62 | + int16_t gy_raw = readInt16(GYRO_XOUT_H + 2); |
|
| 63 | + int16_t gz_raw = readInt16(GYRO_XOUT_H + 4); |
|
| 64 | + |
|
| 65 | + float ax = ax_raw / ACCEL_SCALE; // in g |
|
| 66 | + float ay = ay_raw / ACCEL_SCALE; |
|
| 67 | + float az = az_raw / ACCEL_SCALE; |
|
| 68 | + |
|
| 69 | + float temperature = (temp_raw / 340.0) + 36.53; // degrees C |
|
| 70 | + |
|
| 71 | + float gx = gx_raw / GYRO_SCALE; // deg/s |
|
| 72 | + float gy = gy_raw / GYRO_SCALE; |
|
| 73 | + float gz = gz_raw / GYRO_SCALE; |
|
| 74 | + |
|
| 75 | + // Simple tilt (degrees) |
|
| 76 | + float roll = atan2(ay, az) * 57.295779513; // rad->deg |
|
| 77 | + float pitch = atan2(-ax, sqrt(ay * ay + az * az)) * 57.295779513; |
|
| 78 | + |
|
| 79 | + Serial.print("AX:"); Serial.print(ax, 3); Serial.print(" g "); |
|
| 80 | + Serial.print("AY:"); Serial.print(ay, 3); Serial.print(" g "); |
|
| 81 | + Serial.print("AZ:"); Serial.print(az, 3); Serial.print(" g "); |
|
| 82 | + |
|
| 83 | + Serial.print("GX:"); Serial.print(gx, 2); Serial.print(" dps "); |
|
| 84 | + Serial.print("GY:"); Serial.print(gy, 2); Serial.print(" dps "); |
|
| 85 | + Serial.print("GZ:"); Serial.print(gz, 2); Serial.print(" dps "); |
|
| 86 | + |
|
| 87 | + Serial.print("T:"); Serial.print(temperature, 2); Serial.print(" C "); |
|
| 88 | + |
|
| 89 | + Serial.print("Roll:"); Serial.print(roll, 2); Serial.print(" deg "); |
|
| 90 | + Serial.print("Pitch:"); Serial.print(pitch, 2); Serial.println(" deg"); |
|
| 91 | + |
|
| 92 | + delay(200); |
|
| 93 | +} |
|
| 94 | + |