Bluetooth Arduino多SPI问题

Bluetooth Arduino多SPI问题,bluetooth,arduino,wifi,spi,Bluetooth,Arduino,Wifi,Spi,我实际上是在我的项目的最后一部分,它是采取控制一个锅使用数字锅。我有一个MCP4131数字罐,但我似乎无法让它工作。我想这是由于我连接的wifly屏蔽,因为它也使用SPI。我有一个arduino mega连接到WIFFLY屏蔽,我还有一个蓝牙模块连接到另一个arduino,还有一个TFT连接到另一个arduino。蓝牙模块和tft屏幕只向串行(2和3)发送数据,因此我知道这不是问题所在。我将在下面发布我的代码,如果有人能帮我解决这最后一点,我将非常感谢 #include <SPI.h&g

我实际上是在我的项目的最后一部分,它是采取控制一个锅使用数字锅。我有一个MCP4131数字罐,但我似乎无法让它工作。我想这是由于我连接的wifly屏蔽,因为它也使用SPI。我有一个arduino mega连接到WIFFLY屏蔽,我还有一个蓝牙模块连接到另一个arduino,还有一个TFT连接到另一个arduino。蓝牙模块和tft屏幕只向串行(2和3)发送数据,因此我知道这不是问题所在。我将在下面发布我的代码,如果有人能帮我解决这最后一点,我将非常感谢

 #include <SPI.h>
#include <WiFly.h>
#include <Wire.h>


WiFlyServer server(2000);

byte address = 0x11;

int CS= 10;


int led = 47;

String readString;
String readString2;
char c;
int i;
char d;


int photocellReading;



int number_4 = 255;
int number_5 = 111;
int number_6 = 93;
int number_7 = 75;
int number_8 = 56;
int number_9 = 38;
int number_10 = 18;
int number_11 = 0;

int pwmpin = 9; 


void setup() {
    WiFly.begin();
    Serial.begin(9600);
    Serial3.begin(9600);
    Serial2.begin(9600);
      server.begin();
      pinMode (CS, OUTPUT);
     SPI.begin();
       pinMode(led, OUTPUT);
        pinMode(pwmpin, OUTPUT);



}

void loop() {

//resetFunc();
WiFlyClient client = server.available();

if(Serial2.available()){ 
while(Serial2.available() > 0) {
    char d = Serial2.read();  //gets one byte from serial buffer
    readString2 += d; //makes the string readString
    delay(5);  //slow looping to allow buffer to fill with next character

}


if (readString2.length() >0){

   int commaIndex2 = readString2.indexOf(',');
   int secondCommaIndex2 = readString2.indexOf(',', commaIndex2+1);

String firstValue2 = readString2.substring(0, commaIndex2);
String secondValue2 = readString2.substring(commaIndex2+1, secondCommaIndex2);
String thirdValue2 = readString2.substring(secondCommaIndex2+1); // To the end of the string

int x2 = firstValue2.toInt();
int y2 = secondValue2.toInt();
int z2 = thirdValue2.toInt();
if(x2 == 200){
if(y2 == 4){
digitalWrite(led, LOW);

}
}
}
//empty for next input

}



if (client.connect()){


      while (client.available()) {

        c = client.read();
        readString += c; //makes the string readString
    delay(5);  //slow looping to allow buffer to fill with next character

      }

if (readString.length() >0){

   int commaIndex = readString.indexOf(',');
   int secondCommaIndex = readString.indexOf(',', commaIndex+1);

String firstValue = readString.substring(0, commaIndex);
String secondValue = readString.substring(commaIndex+1, secondCommaIndex);
String thirdValue = readString.substring(secondCommaIndex+1); // To the end of the string

int x = firstValue.toInt();
int y = secondValue.toInt();
int z = thirdValue.toInt();

Serial.println(x);

if(x == 4){

digitalWrite(led, HIGH);

digitalWrite(CS, LOW);
SPI.transfer(address);
SPI.transfer(number_4);
digitalWrite(CS, HIGH);


  }

}

}
if (!client.connected() || !server.available()){

  while(SpiSerial.available() > 0) {

#if ARDUINO >= 100
    Serial3.write(SpiSerial.read());
#else
    Serial3.print(SpiSerial.read(), BYTE);
#endif
delay(100);
  }

  if(Serial3.available()) { // Outgoing data
#if ARDUINO >= 100  
    SpiSerial.write(Serial3.read());
#else
    SpiSerial.print(Serial3.read(), BYTE);
#endif

  }

}



readString=""; //empty for next input
readString2=""; 


 }
#包括
#包括
#包括
WiFlyServer(2000);
字节地址=0x11;
int CS=10;
int-led=47;
字符串读取字符串;
字符串readString2;
字符c;
int i;
chard;
内部光电管读数;
整数4=255;
整数_5=111;
整数_6=93;
整数_7=75;
整数_8=56;
整数_9=38;
整数_10=18;
整数_11=0;
int-pwmpin=9;
无效设置(){
WiFly.begin();
Serial.begin(9600);
连载3.开始(9600);
序列2.开始(9600);
server.begin();
pinMode(CS,输出);
SPI.begin();
引脚模式(led,输出);
pinMode(pwmpin,输出);
}
void循环(){
//resetFunc();
WiFlyClient=server.available();
如果(Serial2.available()){
while(Serial2.available()>0){
char d=Serial2.read();//从串行缓冲区获取一个字节
readString2+=d;//使字符串为readString
延迟(5);//缓慢循环以允许缓冲区填充下一个字符
}
如果(readString2.length()>0){
int commaIndex2=readString2.indexOf(',');
int secondCommaIndex2=readString2.indexOf(',',commaIndex2+1);
String firstValue2=readString2.substring(0,commaIndex2);
字符串secondValue2=readString2.substring(commaIndex2+1,secondCommaIndex2);
String thirdValue2=readString2.substring(secondCommaIndex2+1);//到字符串末尾
int x2=firstValue2.toInt();
int y2=secondValue2.toInt();
int z2=第三个值2.toInt();
如果(x2==200){
如果(y2==4){
数字写入(led,低电平);
}
}
}
//下一次输入为空
}
if(client.connect()){
while(client.available()){
c=client.read();
readString+=c;//使字符串为readString
延迟(5);//缓慢循环以允许缓冲区填充下一个字符
}
if(readString.length()>0){
int commaIndex=readString.indexOf(',');
int secondCommaIndex=readString.indexOf(',',commaIndex+1);
String firstValue=readString.substring(0,commaIndex);
String secondValue=readString.substring(commaIndex+1,secondCommaIndex);
String thirdValue=readString.substring(secondCommaIndex+1);//到字符串末尾
int x=firstValue.toInt();
int y=secondValue.toInt();
intz=thirdValue.toInt();
序列号println(x);
如果(x==4){
数字写入(led,高电平);
数字写入(CS,低电平);
SPI.传输(地址);
SPI.传输(编号4);
数字写入(CS,高);
}
}
}
如果(!client.connected()| |!server.available()){
而(SpiSerial.available()>0){
#如果ARDUINO>=100
Serial3.write(SpiSerial.read());
#否则
Serial3.print(SpiSerial.read(),字节);
#恩迪夫
延迟(100);
}
if(Serial3.available()){//传出数据
#如果ARDUINO>=100
SpiSerial.write(Serial3.read());
#否则
SpiSerial.print(Serial3.read(),字节);
#恩迪夫
}
}
readString=“;//下一次输入为空
readString2=“”;
}
正如你所看到的,蓝牙和tft屏幕只是用来发送数据的,我唯一的问题就是这个。如前所述,如果有人能帮我弄到这本书,我将不胜感激