我刚买了一个 Arduino Uno,我目前正在尝试制作一个闪烁的 LED。我想知道我怎么能做到这一点,我查看了 Arduino Playground 并找到了一个程序来获取输入。我需要输出到 Arduino。我不可能使用除 Java 之外的任何东西,因为我已经有另一个需要 Arduino 的程序。请留下任何想法。
			
			14481 次
		
1 回答
            0        
        
		
编辑: 听起来你想在 java 中执行此操作。
OutputStream 带有 3 种不同的写入方法,可将数据从计算机发送到 Arduino。在上面的示例中,您可以使用
output.write(String)来发送数据,如output.write("Hello Arduino!").
如果您尝试使用 Java 写入 Arduino,那么这就是您的答案。
http://arduino.cc/playground/Interfacing/Java
编辑:如果你想使用 Java 以外的东西,你去:
问你应接受。您可以使用任何具有串行支持的编程语言来执行此操作。
每种语言肯定还有其他方法,但这里有一些我在 5 分钟内在 Google 机器上找到的
- Perl -设备::串行端口
- Python - pySerial通过Android Playground
- C++ - LibSerial(在下面使用)
注意:注意串行问题上令人讨厌的自动重置。有关详细信息,请参阅我之前的答案。
这是我的 C++ 代码(它很丑,但它有效)
#include <SerialStream.h>
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
class SerialComm {
    LibSerial::SerialStream myss;
public:
    SerialComm(int argc, char** argv) {
        myss = new LibSerial::SerialStream("/dev/ttyS0", ios_base::out);
        myss.SetBaudRate(LibSerial::SerialStreamBuf::BAUD_57600);
        myss.SetCharSize(LibSerial::SerialStreamBuf::CHAR_SIZE_8);
        myss.SetFlowControl(LibSerial::SerialStreamBuf::FLOW_CONTROL_NONE);
        myss.SetParity(LibSerial::SerialStreamBuf::PARITY_NONE);
        myss.SetNumOfStopBits(1);
        const int Dsize = 2;
        char buffer[1];
        buffer[0] = 125; //0b00000001;
        buffer[1] = '\0';
        bitset(buffer[0]);
        //myss << buffer;
        myss.write(buffer,1);
        //myss.Close();
    }
}
于 2012-07-05T15:26:05.563   回答