arduino 运行linux,从Windows或Linux编译的Arduino草图执行效果不同

如果从Windows XP Home sp3或基本操作系统Luna(Ubuntu Linux发行版)编译并上传到Arduino,草图的表现会有所不同。从Windows或Linux编译的Arduino草图执行效果不同

本草图在其他事物之间从串行连接(蓝牙)读取一个字节并将其写回串行监视器。

这就是我从WinXP编译草图所得到的结果:我每次都从BTB连接字符串从“1”发送到“7”。这些字符串的ASCII码在字节中减少了48个字符串。结果是正确的,也正确调用指针数组中的函数。

9f8fc6658ea622c862cf47c008565005.png

这是我从Linux获得的。我从“1”到“7”每个字符串发送了4次,以查看结果与我需要得到的内容无关,并且与相同的输入数据不一致:例如,当我发送字符串“2”时,我得到104 106 106 104 .....并且相同的字节106被写入来自BT的不同字符串。 此外,函数不会被调用,所以它不是一个Serial.print问题。

887aff9a5c97b97548a38063772fe9d1.png

我敢肯定,这是一个编译问题,因为一旦草图中的Arduino上传它以同样的方式(正确与否)执行,如果我在WinXP或Linux使用的串行监控。

这里的草图

#include "Arduino.h"

#include

#include

#define nrOfCommands 10

typedef void (* CmdFuncPtr)(); // this is a typedef to command functions

//the following declares an arry of 10 function pointers of type DigitFuncPtr

CmdFuncPtr setOfCmds[nrOfCommands] = {

noOp,

leftWindowDown,

leftWindowUp,

bootOpen,

cabinLightOn,

cabinLightOff,

lockOn,

lockOff,

canStart,

canStop

};

#define cmdLeftWindowDown 1

#define cmdLeftWindowUp 2

#define cmdBootOpen 3

#define cmdCabinLightOn 4

#define cmdCabinLightOff 5

#define cmdLockOn 6

#define cmdLockOff 7

#define cmdCanStart 8

#define cmdCanStop 9

#define buttonPin 4 // the number of the pushbutton pin

#define bluetoothTx 2

#define bluetoothRx 3

int buttonState = 0; // variable for reading the pushbutton status

int androidSwitch=0;

byte incomingByte; // incoming data

byte msg[12];

byte msgLen=0;

byte msgIdMsb=0;

byte msgIdLsb=0;

//const byte cmdLeftWindowDown;

SoftwareSerial bluetooth(bluetoothTx,bluetoothRx);

void setup()

{

//Setup usb serial connection to computer

Serial.begin(115200);

//Setup Bluetooth serial connection to android

bluetooth.begin(115200);

//bluetooth.print("$$$");

randomSeed(analogRead(10));

delay(100);

//bluetooth.println("U,9600,E");

//bluetooth.begin(9600);

//time=0;

}

void loop() {

msgIdLsb=random(1,255);

msgIdMsb=random(0,5);

msg[0]=msgIdMsb;

msg[1]=msgIdLsb;

msgLen=random(9);

msg[2]=msgLen;

for (int x=3;x

msg[x]=random(255);

}

for (int x=3+msgLen;x<11;x++) {

msg[x]=0;

}

msg[11]='\n';

// read the state of the pushbutton value:

buttonState = digitalRead(buttonPin);

if ((buttonState == HIGH)||(androidSwitch==HIGH)) {

for (int x=0;x<12;x++) {

Serial<

bluetooth.write(uint8_t(msg[x]));

}

Serial<

}

//Read from bluetooth and write to usb serial

if(bluetooth.available())

{

incomingByte = bluetooth.read()-48;

Serial<

if (incomingByte

setOfCmds[incomingByte]();

}

delay(10);

}

void noOp(void)

{

Serial<

};

void leftWindowDown(void)

{

Serial<

};

void leftWindowUp(void)

{

Serial<

};

void bootOpen(void)

{

Serial<

};

void cabinLightOn(void)

{

Serial<

};

void cabinLightOff(void)

{

Serial<

};

void lockOn(void)

{

Serial<

};

void lockOff(void)

{

Serial<

};

void canStart(void)

{

androidSwitch=HIGH;

};

void canStop(void)

{

androidSwitch=LOW;

};

任何帮助将是非常有益的。 在此先感谢。

2014-01-06

martin.p

+0

验证您在两种情况下都使用相同的BT发射器。 “Serial << incomingByte << endl;”的输出可能是表现完全一样,但有所不同。这听起来像发射机的UTF问题。 –

+0

您是否试过将“Serial << incomingByte << endl;”与“Serial.println(incomingByte);” –

+0

我强烈建议去除输入。[建议debound库](https://github.com/thomasfredericks/Bounce-Arduino-Wiring) –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值