|
板子是arduino UNO ,传感器用的是麦克风(串口通信))+MPU 6050 加速度计(IIC通信),分别连arduino,分别读取这俩传感器的数据都是没有问题的,但是两个同时连接到arduino上的时候,串口数据读不出来,求教这是怎么回事
连线方式为:
加速度计 VCC-VCC GND-GND scl-scl SDA-SDA int-2
麦克风 VCC-VCC GND-GND AUD-A0
代码如下
const int analogInPin0 = A0; // 定义声音传感器模拟值输入引脚为模拟0
int sensorValue0 = 0; // 定义声音传感器模拟值变量
#include "Wire.h"
#include "I2Cdev.h"
#include "MPU6050.h"
// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69
MPU6050 accelgyro;
int16_t ax, ay, az;
int16_t gx, gy, gz;
#define LED_PIN 13
//bool blinkState = false;
void setup() {
Wire.begin();
Serial.begin(38400);
Serial.println("Initializing I2C devices...");
accelgyro.initialize();
Serial.println("Testing device connections...");
Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
pinMode(LED_PIN, OUTPUT);
}
void loop() {
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
Serial.print("a/g:\t");
Serial.print(ax); Serial.print("\t");
Serial.print(ay); Serial.print("\t");
Serial.print(az); Serial.print("\t");
Serial.print(gx); Serial.print("\t");
Serial.print(gy); Serial.print("\t");
Serial.println(gz);
delay(50);
// blink LED to indicate activity
// blinkState = !blinkState;
// digitalWrite(LED_PIN, blinkState);
sensorValue0 = analogRead(analogInPin0); //读取模拟引脚声音传感器反馈的模拟值
Serial.print("\t");
Serial.print(sensorValue0); //串口打印声音传感器返回模拟值
Serial.print("\n");
delay(100);
}
求大佬指点
|
|