问题与Android的东西开发者预览版5(RPI3)UART头
我试图使用Android的东西开发者预览版5.下一个皮头进行交流沟通是按照官方Android我已经创建了首部通信类事情文档:问题与Android的东西开发者预览版5(RPI3)UART头
public class UartComm {
private static final String UART_DEVICE_NAME = "UART1";
private UartDevice mDevice;
private void configureUartFrame(UartDevice uart) throws IOException {
// Configure the UART port
uart.setBaudrate(115200);
}
public void onCreate() {
try {
PeripheralManagerService manager = new PeripheralManagerService();
List<String> deviceList = manager.getUartDeviceList();
if (deviceList.isEmpty()) {
Log.i(TAG, "No UART port available on this device.");
} else {
Log.i(TAG, "List of available devices: " + deviceList);
}
mDevice = manager.openUartDevice(UART_DEVICE_NAME);
configureUartFrame(mDevice);
mDevice.registerUartDeviceCallback(mUartCallback);
} catch (Exception e) {
Log.w(TAG, "Unable to access UART device", e);
}
}
public void readUartBuffer(UartDevice uart) throws IOException {
// Maximum amount of data to read at one time
final int maxCount = 40;
byte[] buffer = new byte[maxCount];
uart.read(buffer, maxCount);
String data = new String(buffer, "UTF-8");
Log.d(TAG, data);
}
private UartDeviceCallback mUartCallback = new UartDeviceCallback() {
@Override
public boolean onUartDeviceDataAvailable(UartDevice uart) {
// Read available data from the UART device
try {
readUartBuffer(uart);
} catch (IOException e) {
Log.w(TAG, "Unable to access UART device", e);
}
// Continue listening for more interrupts
return true;
}
@Override
public void onUartDeviceError(UartDevice uart, int error) {
Log.w(TAG, uart + ": Error event " + error);
}
};
}
在我的MainActivity我做UartComm device = new UartComm()
创建UartComm的实例,并在继续调用device.onCreate()
我还修改了/boot/cmdline.txt
和删除控制台= serial0,115200与控制台取代了它= tty0,我有阿尔斯o尝试在不添加console = tty0的情况下删除控制台行。在/boot/config.txt
我也删除enable_uart=1
和core-freq=400
也加入dtoverlay=pi3-miniuart-bt
我也试图通过做dtoverlay=pi3-disable-bt
无济于事完全移除蓝牙支持。
我已经测试了报头的工作原理以及在Rapsbian,其中I交换的/ dev/ttyAMA0和/ dev/ttyS0来正确配置且工作正常。我能够在Raspbian上运行screen
命令,默认波特率为115200,并能够获得所需的信息。
我想在做事情的Android开发者预览版5的相同,并且具有在迷你UART ttyS0形式蓝牙跑了ttyAMA0头运行。我期望的结果是通过UART0访问头文件。
具有相同的功能一个旧的USB串口设备的工作原理,但我宁愿UART设备在物理上Pi的顶部,所以这不是一个选项。
可能是错的,但不应该:
private static final String UART_DEVICE_NAME = "UART1";
是UART0即
private static final String UART_DEVICE_NAME = "UART0";
我在这里做一个UART例如https://github.com/blundell/androidthings-uart/blob/master/app/src/main/java/com/blundell/tut/MainActivity.java(明显不同的硬件),但它连接到覆盆子pi引脚以如下方式相同:
感谢您将变量更改为UART0后的回复我收到此错误: 无法访问UART设备 com.google.android.things.pio.PioException:android.os.ServiceSpecificException:BCM14未能应用所需的引脚多路复用器:无效的参数(代码22) –
另外我看到你使用的是UART0,你是否有任何修改/boot/config.txt或/boot/cmdline.txt以使其工作? –
是的,我按照官方文档中的解释对它进行了编辑。但是现在如果你使用新的AndroidThings'0.5.0',你不必使用Pin Multiplexing:https://developer.android.com/things/hardware/raspberrypi-mode-matrix.html – Blundell
您想标记一种语言吗?这可能会吸引正确的答案。 – Yunnosch
刚刚标记了Java –