RGB LED撞坏了我的arduino板?(发现错误,只需解释)

RGB LED撞坏了我的arduino板?(发现错误,只需解释),arduino,Arduino,所以我注意到我的arduino板在串行通信的前60秒停止后崩溃了,所以我决定随机注释掉代码块,看看是否能识别罪犯。幸运的是,我做到了 这是我的硬件设置: Board: Arduino Mega Pin 16,17: EC sensor Pin 14,15: pH sensor Pin 2,3,4: RGB LED 我已经确定initRGB和displayGreen、displayBlue和displayRed正在破坏我的板。为什么? 代码: 如果你能提供示意图也会有帮助。事情是如何联系起来的

所以我注意到我的arduino板在串行通信的前60秒停止后崩溃了,所以我决定随机注释掉代码块,看看是否能识别罪犯。幸运的是,我做到了

这是我的硬件设置:

Board: Arduino Mega
Pin 16,17: EC sensor 
Pin 14,15: pH sensor
Pin 2,3,4: RGB LED
我已经确定initRGB和displayGreen、displayBlue和displayRed正在破坏我的板。为什么?

代码:


如果你能提供示意图也会有帮助。事情是如何联系起来的


当您在串行端口上写入halt时,您的意思是您最后看到的任何活动的标志是串行端口上的打印输出?你试过在回路中闪烁板载LED吗?

理论:你的LED电流过大?@Dithermaster这不是真的,因为如果我在代码的RGB块中注释代码,LED仍然亮着,电路板不会“崩溃”
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include "utility/debug.h"
#include <Base64.h>


int RGB_RED = 4;
int RGB_GREEN = 3;
int RGB_BLUE = 2;


String ecSensorString = "";
String phSensorString = "";

...

// Set this on if you want to supply an IP address directly
#define IP_NOT_DOMAIN   true
#define PORT            8080

// This corresponds to 192.168.1.117
#define IP_1 192
#define IP_2 168
#define IP_3 1
#define IP_4 117

#define WEBSITE      "blah.appspot.com"
#define WEBPAGE      "/api/points/new/"

// This is needed for http basic authorization
String serial="serial";
String token="token";

uint32_t ip;


void setup() {
  //initRGB();
  Serial.begin(9600);

  ecSensorString.reserve(30);
  phSensorString.reserve(30);

  initSensors();
  initWireless();

  Serial.println("Setup Complete");
}

void loop() {
  Serial.println("Loop begins");

  Serial.print("Free RAM: ");
  Serial.println(getFreeRam(), DEC);

  getEC();
  getPH();
  Serial.println("Sensors reading completed");

  createPoint(ecSensorString, phSensorString);
  Serial.println("createPoint completed");

  delay(10*1000);
  Serial.println("delay completed");
}

/*
void initRGB() {
  pinMode(RGB_RED, OUTPUT);
  pinMode(RGB_GREEN, OUTPUT);
  pinMode(RGB_BLUE, OUTPUT);
  //displayBlue();     
}


void displayBlue() {
  analogWrite(RGB_RED, 0);
  analogWrite(RGB_GREEN, 0);
  analogWrite(RGB_BLUE, 255);
}

void displayRed() {
  analogWrite(RGB_RED, 255);
  analogWrite(RGB_GREEN, 0);
  analogWrite(RGB_BLUE, 0);
}

void displayGreen() {
  analogWrite(RGB_RED, 0);
  analogWrite(RGB_GREEN, 255);
  analogWrite(RGB_BLUE, 0);
}
*/

void initWireless() {
  /* Initialise the module */
  if (!cc3000.begin()) {
    Serial.println(F("Couldn't begin()! Check your wiring?"));
    //displayRed();
    while(1);
  }
  Serial.println(F("Initialization Complete"));

  Serial.print(F("Attempting to connect to "));
  Serial.println(WLAN_SSID);
  if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
    Serial.println(F("Failed!"));
    //displayRed();
    while(1);
  }
  Serial.println(F("Wireless Connected!"));

  /* Wait for DHCP to complete */
  while (!cc3000.checkDHCP()) {
    delay(100); // ToDo: Insert a DHCP timeout!
  }
  Serial.println(F("DHCP Requested!"));

  if (IP_NOT_DOMAIN) {
    ip = cc3000.IP2U32(IP_1, IP_2, IP_3, IP_4);
  } else {
    ip = 0;
    // Try looking up the website's IP address
    while (ip == 0) {
      if (! cc3000.getHostByName(WEBSITE, &ip)) {
        Serial.println(F("Couldn't resolve!"));
      }
      delay(500);
    }
  }
}


void initSensors() {
  Serial2.begin(38400);
  Serial3.begin(38400);

  // Tell the EC sensors to stop continuous mode
  Serial2.print("c,0\r");
  // Tell the pH sensor to stop all readings
  Serial3.print("E\r");

  // TODO: EC sensor's first reading is always empty, possibly delay?
}


void createPoint(String ec, String ph) {
  if (ec && ph) {
    postPointToServer("ec=" + ec + "&ph=" + ph);
  } else if (ec) {
    postPointToServer("ec=" + ec);
  } else if (ph) {
    postPointToServer("ph=" + ph);
  } else {
    Serial.println("createPoint: null");
  }
}


void postPointToServer(String data) {
  Serial.print("postPointToServer:");
  Serial.println(data);

  // Http Basic Authorization
  String auth_raw = serial + ":" + token;
  char auth_input[200];
  char auth_output[200];
  auth_raw.toCharArray(auth_input, auth_raw.length() + 1);
  base64_encode(auth_output, auth_input, auth_raw.length());

  Adafruit_CC3000_Client www = cc3000.connectTCP(ip, PORT);

  if (www.connected()) {
    www.fastrprint(F("POST ")); www.fastrprint(WEBPAGE); www.fastrprint(F(" HTTP/1.1\r\n"));
    www.fastrprint(F("Host: ")); www.fastrprint(WEBSITE); www.fastrprint(F("\r\n"));
    www.fastrprint(F("Authorization: Basic ")); www.fastrprint(auth_output); www.fastrprint(F("\r\n"));
    www.fastrprint(F("Content-Type: application/x-www-form-urlencoded")); www.fastrprint(F("\r\n"));

    char len_c[7];
    itoa(data.length(), len_c, 10);
    www.fastrprint(F("Content-Length: ")); www.fastrprint(len_c); www.fastrprint(F("\r\n"));

    // Extra empty line for post arguments
    www.fastrprint(F("\r\n"));

    char data_c[200];
    data.toCharArray(data_c, data.length() + 1);
    www.fastrprint(data_c); www.fastrprint(F("\r\n"));

    www.fastrprint(F("\r\n"));
    www.println();

    //displayGreen();
  } else {
    Serial.println(F("Connection failed"));
    //displayRed();
  }

  www.close();
}


void getEC() {
  ecSensorString = "";
  Serial2.print("r\r");       // Read only 1

  char inchar;
  while (Serial2.available()) {
    inchar = (char)Serial2.read();
    if (inchar != '\r') {
      ecSensorString += inchar;
    }
  }

  Serial.print("getEC:");
  Serial.println(ecSensorString);
}


void getPH() {
  phSensorString = "";
  Serial3.print("R\r");       // Read only 1

  char inchar;
  while (Serial3.available()) {
    inchar = (char)Serial3.read();
    if (inchar != '\r') {
      phSensorString += inchar;
    }
  }

  Serial.print("getPH:");
  Serial.println(phSensorString);
}