TX and RX pins problem

Please consider the following schematic (it's a bit messy, and it's no official, I made it for the issue only)
Schematic

As you can see bluethoot's TXD pin goes to RX1 (pin 19) and bluetooth's RXD goes to TX1 (pin 18).

My code compiles just fine with this configuration. But by leading TXD and RXD to RX0 and TX0 ( pins 0 and 1). I receive the following error message :

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_recv(): checksum error
avrdude: stk500v2_recv(): checksum error
avrdude: stk500v2_recv(): checksum error
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: verification error, first mismatch at byte 0x0c7b

  • 0x85 != 0x0a*
    avrdude: verification error; content mismatch

Hence the code does not compile. Any idea why this happens?

(deleted)

Where's the code?

Does it have any text strings with three consecutive exclamation points ("!!!") in it?

Many Arduino Mega clones are still sold with an old version of the bootloader with a bug that causes the bootloader to enter a non-functional debugging mode when it encounters a "!!!" in the datastream being sent to it.

spycatcher2k:
Your code does compile, it won’t upload. How are you resetting your mega at upload time?

Indeed. You are right. I forgot to mention an important detail. I need to upload the code with the bluetooth off, by doing this I can ensure that my serial is clear (GND pin is removed). Then when I put it back to turn it on so It can be paired to another device, these errors occurs.

I’m not resetting it. I’m just trying to upload it to the board. And I can’t understand why pins 0 and 1 are not allowing me to do it. Thanks for your interest and feel free to ask.

DrAzzy:
Where’s the code?

Does it have any text strings with three consecutive exclamation points ("!!!") in it?

Many Arduino Mega clones are still sold with an old version of the bootloader with a bug that causes the bootloader to enter a non-functional debugging mode when it encounters a “!!!” in the datastream being sent to it.

No it does not. Here’s the code :

/* Biblioteca padrão do Arduino */
#include <Arduino.h>

#include <string.h>
#include "DefinicoesGlobais.h"

/* Bibliotecas de leitura e escrita para módulo SD */
#include <SD.h>
#include <SPI.h>

/* Bibliotecas de data/hora para módulo DS1307 RTC */
#include <Wire.h>
#include <RTClib.h>
#include <Time.h>
#include <TimeLib.h>
#include <TimeAlarms.h>

/*Biblioteca de Lista Encadeada*/
#include <LinkedList.h>

/* Biblioteca de HashMap */
#include <HashMap.h>

#include "Util.h"
#include "PinChangeInterrupt.h"

/* Biblioteca de Threads */
#include "Thread.h"
#include "ThreadController.h"


#include <Registrador.h>
#include <Mensageiro.h>
#include <Start.h>
#include <Fertilizantes.h>
#include <Eventos.h>
#include <Agendamentos.h>

const byte HASH_SETOR_SIZE = 15;
HashType<int, int> hashRawArray[HASH_SETOR_SIZE];
HashMap<int, int> hashMap = HashMap<int, int>( hashRawArray , HASH_SETOR_SIZE );

//--------- Decladando HashMap de Silos
const byte HASH_SILO_SIZE = 2;
HashType<char*, int> hashSiloArray[HASH_SILO_SIZE];
HashMap<char*, int> hashMapSilo = HashMap<char*, int>( hashSiloArray , HASH_SILO_SIZE);


RTC_DS1307 rtc;

Mensageiro mensageiro;
File arquivo;
File startcfg;
int indiceAgendamento, indiceEvento, indiceFert;
char registrador_nivel;
LinkedList<Agendamentos*> agendamentos = LinkedList<Agendamentos*>();
Agendamentos *chamaFuncao = new Agendamentos();
Start *start = new Start();

int numeroEvento = 0;
int numeroFert = 0;

ThreadController cpu;
Thread thread_teste = Thread();
Thread programacao = Thread();
Thread thread_prepara_irriga = Thread();
Thread thread_prepara_ferti = Thread();
Thread verifica_nivel_tanque = Thread();
Thread recebeVolumeAgua = Thread();
Thread recebeVolumeSilo = Thread();
Thread recupera_silos = Thread();
Thread injecao = Thread();
Thread nivel_injec = Thread();
Thread thread_purga = Thread();
Thread nivel_purga = Thread();

void setup() {

  hashMap.debug();
  hashMapSilo.debug();

  if (!rtc.begin()) {
    Registrador::error("Nao foi possivel encontrar modulo RTC");
    while (1);
  }

  if (! rtc.isrunning()) {
    Registrador::info("Inicializando m�dulo RTC!");
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }

  char pontoParada;
  Serial.begin(9600);
  pinMode(PINO_SD_CS, OUTPUT);
  if (!SD.begin(PINO_SD_CS)) {
    Serial.println("O cartao falhou ao iniciar ou nao esta presente"); // Trocar "Serial.printl" por "Registrador:error" ap�s os testes.
    return;
  }
hashMapSilo[0]("Silo 1", 39);
  hashMapSilo[1]("Silo 2", 41);

  //---------- Declarando todos os pinos como saidas
  pinMode(SETOR_1, OUTPUT);
  pinMode(SETOR_2, OUTPUT);
  pinMode(SETOR_3, OUTPUT);
  pinMode(SETOR_4, OUTPUT);
  pinMode(SETOR_5, OUTPUT);
  pinMode(SETOR_6, OUTPUT);
  pinMode(SETOR_7, OUTPUT);
  pinMode(SETOR_8, OUTPUT);
  pinMode(SETOR_9, OUTPUT);
  pinMode(SETOR_10, OUTPUT);
  pinMode(SETOR_11, OUTPUT);
  pinMode(SETOR_12, OUTPUT);
  pinMode(SETOR_13, OUTPUT);
  pinMode(SETOR_14, OUTPUT);
  pinMode(SETOR_15, OUTPUT);
  pinMode(BOMBA_CAPTACAO_LIGA, OUTPUT);
  pinMode(BOMBA_CAPTACAO_DESLIGA, OUTPUT);
  pinMode(BOMBA_INJEC_LIGA, OUTPUT);
  pinMode(BOMBA_INJEC_DESLIGA, OUTPUT);
  pinMode(VALVULA_DESCARTE, OUTPUT);
  pinMode(PA_MISTURA_LIGA, OUTPUT);
  pinMode(PA_MISTURA_DESLIGA, OUTPUT);
  pinMode(SILO_1, OUTPUT);
  pinMode(SILO_2, OUTPUT);
  pinMode(VALVULA_L2, OUTPUT);
  pinMode(CONTRA_LAVAGEM, OUTPUT);
  pinMode(BOIA_INFERIOR, INPUT);
  pinMode(BOIA_SUPERIOR, INPUT);

  // ---------- Declarando o estado inicial de todos os pinos
  digitalWrite(SETOR_1, HIGH);
  digitalWrite(SETOR_2, HIGH);
  digitalWrite(SETOR_3, HIGH);
  digitalWrite(SETOR_4, HIGH);
  digitalWrite(SETOR_5, HIGH);
  digitalWrite(SETOR_6, HIGH);
  digitalWrite(SETOR_7, HIGH);
  digitalWrite(SETOR_8, HIGH);
  digitalWrite(SETOR_9, HIGH);
  digitalWrite(SETOR_10, HIGH);
  digitalWrite(SETOR_11, HIGH);
  digitalWrite(SETOR_12, HIGH);
  digitalWrite(SETOR_13, HIGH);
  digitalWrite(SETOR_14, HIGH);
  digitalWrite(SETOR_15, HIGH);
  digitalWrite(BOMBA_CAPTACAO_LIGA, HIGH);
  digitalWrite(BOMBA_CAPTACAO_DESLIGA, HIGH);
  digitalWrite(BOMBA_INJEC_LIGA, HIGH);
  digitalWrite(BOMBA_INJEC_DESLIGA, HIGH);
  digitalWrite(VALVULA_DESCARTE, HIGH);
  digitalWrite(PA_MISTURA_LIGA, HIGH);
  digitalWrite(PA_MISTURA_DESLIGA, HIGH);
  digitalWrite(SILO_1, HIGH);
  digitalWrite(SILO_2, HIGH);
  digitalWrite(VALVULA_L2, HIGH);
  digitalWrite(CONTRA_LAVAGEM, HIGH);
  digitalWrite(BOIA_INFERIOR, HIGH);
  digitalWrite(BOIA_SUPERIOR, HIGH);

  programacao.setInterval(1000);
  programacao.onRun(Util::verificaProgramacao);
  cpu.add(&programacao);

  thread_prepara_irriga.enabled = false;
  thread_prepara_irriga.setInterval(start->getAtraso());
  thread_prepara_irriga.onRun(Util::irriga);
  cpu.add(&thread_prepara_irriga);

  thread_prepara_ferti.enabled = false;
  thread_prepara_ferti.setInterval(300);
  thread_prepara_ferti.onRun(Util::fertirriga);
  cpu.add(&thread_prepara_ferti);


  verifica_nivel_tanque.enabled = false;
  verifica_nivel_tanque.setInterval(1000);
  verifica_nivel_tanque.onRun(Util::monitoraTanque);
  cpu.add(&verifica_nivel_tanque);

  recebeVolumeAgua.enabled = false;
  recebeVolumeAgua.setInterval(200);
  recebeVolumeAgua.onRun(Util::enxeTanque);
  cpu.add(&recebeVolumeAgua);

  recebeVolumeSilo.enabled = false;
  recebeVolumeSilo.setInterval(200);
  recebeVolumeSilo.onRun(Util::lancaFert);
  cpu.add(&recebeVolumeSilo);

  recupera_silos.enabled = false;
  recupera_silos.setInterval(2000);
  recupera_silos.onRun(Util::despejaFert);
  cpu.add(&recupera_silos);

  injecao.enabled = false;
  injecao.setInterval(start->getPressurizacao());
  injecao.onRun(Util::injeta);
  cpu.add(&injecao);

  nivel_injec.enabled = false;
  nivel_injec.setInterval(200);
  nivel_injec.onRun(Util::controlaInjec);
  cpu.add(&nivel_injec);

  thread_purga.enabled = false;
  thread_purga.setInterval(500);
  thread_purga.onRun(Util::realizaPurga);
  cpu.add(&thread_purga);

  nivel_purga.enabled = false;
  nivel_purga.setInterval(400);
  nivel_purga.onRun(Util::controlaPurga);
  cpu.add(&nivel_purga);

void loop() {
  
  if (Serial.available() > 0) {
    mensageiro.lerSerial();
  }
  cpu.run();
}
}