Reset pin pullup

Hy, I'm dealing with with a project that works good on bench, but when I put it in car it starts to freeze or do things it is not supposed to.
I suspect that reset pin is picking up interference.

What is the lowest value resistor I can use to pullup reset pin?

I was also thinking of connecting pin directly to 5v.
I know that I cannot use reset button then, but can I use software reset -watchdog?

Thank you

Why?

1 Like

Its acting like its resseting sometimes. Just want to rule out that before messing with the code.

Mistake. There is a lot more hardware to look at first. Please post a complete schematic and images of your project.

The cause that you assumed, is exceedingly rare.

1 Like

As others have said, that's probably not the problem. However, to answer the question you ask it doesn't really matter how low you go within reason. I mean 0 Ohms would be a problem, 10 Ohms would be extreme but not a problem. I suggest that what you really need if noise on the reset pin is the problem is a capacitor between the pin and 0V, maybe 1μF, although the exact value does not matter.

A car is electrical a very hostile environment. Unless you take precautions with power supply conditioning any pin can pick up interference that will have the effect of resetting your Arduino, it is not just the reset pin that is being triggered.

By the way in the small print of the data sheet at the end it says that the processor is not suited for use in, amongst other things, automotive applications. It can void your insurance if you make modifications to a car that are not specifically approved.

I suspect your whole circuit is picking up interference (as per reply #6). Especially if the problem only occurs when the car is running (easy to test this). If so, then wrapping as many turns as you can of 12V power and GND through a ferrite core might be a solution.
image

We don't know your circuit and the current loading it has. Note that with the car running, there could be 13-15V at Vin, which would limit the current available from your circuit's on-board regulator. Might need to power it using 5V and an external 12V to 5V adapter.

Without a schematic, we can only guess.

It does not reset, I confirmed that, problem is somewhere else.

Let me present my project.

I`m making "usb / bluetooth addon" to BMW e39 bussiness radio.
Arduino does the following:

1.) IBUS message read via MCP2025 transciever (software serial modified for last parity) to record multifunction steering wheel buttons

2.) Writes to dot pixel display (original display of radio) via i2c

3.) Receives / writes messages from / to 8bit i2c expander (to capture button presses on radio frontplate)

4.) Controls 2 ADG411 ICs (via digital pins -logic 0 or 1), one IC switches connection to frontplate of the radio (display and buttons) between radios MCU and arduino. If mode is FM radio it connects MCU to frontplate, if USB or bluetooth mode it connects radios frontplate to arduino

5.) Monitors state of voltage on the tape deck motor transistor (if voltage is 5v -HIGH, that means mode selected on radio is TAPE and arduino disconnects radio MCU and connects itself (i2c) to the frontplate.... if voltage is 0v -LOW that means that FM radio is selected and arduino disconnects itself from i2c and connects radios MCU)

6.) Arduino controls mp3 / bluetooth (DFrobot BT401) module via hardware serial port (Play / Pause, next song, last song, USB / Bluetooth, ... and receives information -filename of playing song, songs number, number of total songs on usb, ...)

I had build this project from ground up with help of some forum members helping me with individual parts of code.
I am working on this project for about 3 months now and was troubleshooting bit by bit before adding new stuff.

Right now I have radio on the table running for about 2 hours and it is working as it should.

I took power from radios PCB where amplifier IC gets it. That means it is somehow filtered, I can see coil on ferrite toroid and a large capacitor (about 2200uf I would say), unfurtunately I cannot see anything else because radio is made in the way that I would need to desolder 2 amplifier ICs and one smaller IC in order to remove the cooler and gain access to the power circuit.

I should mention that no noise / buzz / hum / any other unwanted noise is comming from the speakers.

Here is the code, dont mind struggling with it. I know it is long and without studing it only I can understand the whole thing:

#include <Wire.h>
#include <DFRobot_BT401.h>
#include <SoftwareSerial.h>

SoftwareSerial ibusPort(2, 3); // RX, TX
//SoftwareSerial debugSerial(8, 9); //RX, TX
char acc = 2;
char lastAcc = 3;
unsigned long accCounter = 1001;
unsigned long val = 1000;
char accCounterTrigger = 0;
char rort = 2; //Radio = 0, Tape = 1
char lastRort = 3;
char rortCounter = 0;
char rortCounterTrigger = 0;
char rortStep = 50;
char mode = 0;
char queryMode = 1;
char queryDirSIZE = 1;
char INTERRUPT = 1;
char buttonPressed = 0;
char btnrd;
char PP = 0;
char FRD = 0;
char RWD = 0;
int FRDcounter = 0;
char FRDcounterTrigger = 0;
int RWDcounter = 0;
char RWDcounterTrigger = 0;
char FRDactivated = 0;
char RWDactivated = 0;
char ibus1 = 0;
char ibus2 = 0;
char ibus3 = 0;
char ibusA = 0;
char ibusB = 0;
char ibusC = 0;
char ibusUpCounter = 0;
char ibusDownCounter = 0;
char ibusUpCounterTrigger = 0;
char ibusDownCounterTrigger = 0;
char ibusCommandCaptured = 0;

char antilag = 0;
int displayRefresh = 0;


char queryFileName = 0;

String nowPlaying;
String songNUMBER;
String lastsongNUMBER;
String dirSIZE;
String lastdirSIZE;
String newdirSIZE;
String newsongNUMBER;


int period = 1000;
int period_display = 700;
int period_ibus = 20;
int period_btn = 700;
unsigned long time_now_ibus = 0;
unsigned long time_now = 0;
unsigned long time_now_display = 0;
unsigned long time_now_btn = 0;
char acolumn = 0;
char bcolumn = 1;
char ccolumn = 2;
char dcolumn = 3;
char ecolumn = 4;
char fcolumn = 5;
char gcolumn = 6;
char hcolumn = 7;
char icolumn = 8;




String inputText;
char inputText_len;
String smallDisplay;
char smallDisplay_len;


constexpr size_t numColumns = 5;



void getColumns(char c, uint8_t columns[numColumns]);

const uint8_t upperCase[][numColumns] PROGMEM = {
  {0X7E, 0X11, 0X11, 0X11, 0X7E}, // Column codes for 'A'
  {0X7F, 0X49, 0X49, 0X49, 0X36}, // Column codes for 'B'
  {0X3E, 0X41, 0X41, 0X41, 0X22}, // Column codes for 'C'
  {0X7F, 0X41, 0X41, 0X22, 0X1C}, // Column codes for 'D'
  {0X7F, 0X49, 0X49, 0X49, 0X41}, // Column codes for 'E'
  {0X7F, 0X09, 0X09, 0X09, 0X01}, // Column codes for 'F'
  {0X3E, 0X41, 0X49, 0X49, 0X7A}, // Column codes for 'G'
  {0X7F, 0X08, 0X08, 0X08, 0X7F}, // Column codes for 'H'
  {0X00, 0X41, 0X7F, 0X41, 0X00}, // Column codes for 'I'
  {0X20, 0X40, 0X41, 0X3F, 0X01}, // Column codes for 'J'
  {0X7F, 0X08, 0X14, 0X22, 0X41}, // Column codes for 'K'
  {0X7F, 0X40, 0X40, 0X40, 0X40}, // Column codes for 'L'
  {0X7F, 0X02, 0X0C, 0X02, 0X7F}, // Column codes for 'M'
  {0X7F, 0X04, 0X08, 0X10, 0X7F}, // Column codes for 'N'
  {0X3E, 0X41, 0X41, 0X41, 0X3E}, // Column codes for 'O'
  {0X7F, 0X09, 0X09, 0X09, 0X06}, // Column codes for 'P'
  {0X3E, 0X41, 0X41, 0X61, 0X3E}, // Column codes for 'Q'
  {0X7F, 0X09, 0X19, 0X29, 0X46}, // Column codes for 'R'
  {0X46, 0X49, 0X49, 0X49, 0X31}, // Column codes for 'S'
  {0X01, 0X01, 0X7F, 0X01, 0X01}, // Column codes for 'T'
  {0X3F, 0X40, 0X40, 0X40, 0X3F}, // Column codes for 'U'
  {0X07, 0X18, 0X60, 0X18, 0X07}, // Column codes for 'V'
  {0X3F, 0X40, 0X38, 0X40, 0X3F}, // Column codes for 'W'
  {0X63, 0X14, 0X08, 0X14, 0X63}, // Column codes for 'X'
  {0X07, 0X08, 0X70, 0X08, 0X07}, // Column codes for 'Y'
  {0X61, 0X51, 0X49, 0X45, 0X43} // Column codes for 'Z'
};

const uint8_t lowerCase[][numColumns] PROGMEM = {
  {0X20, 0X54, 0X54, 0X54, 0X78}, // Column codes for 'a'
  {0X7F, 0X48, 0X48, 0X48, 0X30}, // Column codes for 'b'
  {0X38, 0X44, 0X44, 0X44, 0X44}, // Column codes for 'c'
  {0X30, 0X48, 0X48, 0X48, 0X7F}, // Column codes for 'd'
  {0X38, 0X54, 0X54, 0X54, 0X58}, // Column codes for 'e'
  {0X00, 0X08, 0X7E, 0X09, 0X02}, // Column codes for 'f'
  {0X48, 0X54, 0X54, 0X54, 0X3C}, // Column codes for 'g'
  {0X7F, 0X08, 0X08, 0X08, 0X70}, // Column codes for 'h'
  {0X00, 0X00, 0X7A, 0X00, 0X00}, // Column codes for 'i'
  {0X20, 0X40, 0X40, 0X39, 0X00}, // Column codes for 'j'
  {0X00, 0X7F, 0X10, 0X28, 0X44}, // Column codes for 'k'
  {0X00, 0X41, 0X7F, 0X40, 0X00}, // Column codes for 'l'
  {0X7C, 0X04, 0X18, 0X04, 0X7C}, // Column codes for 'm'
  {0X7C, 0X08, 0X04, 0X04, 0X78}, // Column codes for 'n'
  {0X30, 0X48, 0X48, 0X30, 0X00}, // Column codes for 'o'
  {0X7C, 0X14, 0X14, 0X14, 0X08}, // Column codes for 'p'
  {0X7F, 0X04, 0X04, 0X04, 0X03}, // Column codes for 'q'
  {0X7C, 0X08, 0X04, 0X04, 0X08}, // Column codes for 'r'
  {0X48, 0X54, 0X54, 0X54, 0X24}, // Column codes for 's'
  {0X04, 0X04, 0X3F, 0X44, 0X24}, // Column codes for 't'
  {0X3C, 0X40, 0X40, 0X40, 0X3C}, // Column codes for 'u'
  {0X1C, 0X20, 0X40, 0X20, 0X1C}, // Column codes for 'v'
  {0X3C, 0X40, 0X30, 0X40, 0X3C}, // Column codes for 'w'
  {0X44, 0X28, 0X10, 0X28, 0X44}, // Column codes for 'x'
  {0X04, 0X48, 0X30, 0X18, 0X04}, // Column codes for 'y'
  {0X44, 0X64, 0X54, 0X4C, 0X44} // Column codes for 'z'
};

const uint8_t numerals[][numColumns] PROGMEM = {
  {0X3E, 0X45, 0X49, 0X51, 0X3E}, // Column codes for '0'
  {0X00, 0X42, 0X7F, 0X40, 0X00}, // Column codes for '1'
  {0X42, 0X61, 0X51, 0X49, 0X46}, // Column codes for '2'
  {0X22, 0X41, 0X49, 0X49, 0X36}, // Column codes for '3'
  {0X18, 0X14, 0X12, 0X7F, 0X10}, // Column codes for '4'
  {0X27, 0X45, 0X45, 0X45, 0X39}, // Column codes for '5'
  {0X3E, 0X49, 0X49, 0X49, 0X30}, // Column codes for '6'
  {0X01, 0X71, 0X09, 0X05, 0X03}, // Column codes for '7'
  {0X36, 0X49, 0X49, 0X49, 0X36}, // Column codes for '8'
  {0X06, 0X49, 0X49, 0X49, 0X3E} // Column codes for '9'
};

const uint8_t symbolsa[][numColumns] PROGMEM = {
  {0X00, 0X00, 0X5F, 0X00, 0X00}, // Column codes for '!'
  {0X00, 0X03, 0X00, 0X03, 0X00}, // Column codes for '"'
  {0X14, 0X7F, 0X14, 0X7F, 0X14}, // Column codes for '#'
  {0X24, 0X2A, 0X7F, 0X2A, 0X12}, // Column codes for '$'
  {0X23, 0X13, 0X08, 0X64, 0X62}, // Column codes for '%'
  {0X36, 0X49, 0X55, 0X22, 0X50}, // Column codes for '&'
  {0X04, 0X02, 0X02, 0X01, 0X00}, // Column codes for '''
  {0X00, 0X1C, 0X22, 0X41, 0X00}, // Column codes for '('
  {0X00, 0X41, 0X22, 0X1C, 0X00}, // Column codes for ')'
  {0X14, 0X08, 0X3E, 0X08, 0X14}, // Column codes for '*'
  {0X08, 0X08, 0X3E, 0X08, 0X08}, // Column codes for '+'
  {0X00, 0X00, 0X50, 0X30, 0X00}, // Column codes for ','
  {0X08, 0X08, 0X08, 0X08, 0X08}, // Column codes for '-'
  {0X00, 0X60, 0X60, 0X00, 0X00}, // Column codes for '.'
  {0X20, 0X10, 0X08, 0X04, 0X02} // Column codes for '/'
};

const uint8_t symbolsb[][numColumns] PROGMEM = {
  {0X00, 0X7F, 0X41, 0X41, 0X00}, // Column codes for '['
  {0X02, 0X04, 0X08, 0X10, 0X20}, // Column codes for '\'
  {0X00, 0X41, 0X41, 0X7F, 0X00}, // Column codes for ']'
  {0X04, 0X02, 0X01, 0X02, 0X04}, // Column codes for '^'
  {0X00, 0X00, 0X00, 0X00, 0X00}, // Column codes for '_'
  {0X00, 0X01, 0X02, 0X04, 0X00} // Column codes for '`'

};

const uint8_t symbolsc[][numColumns] PROGMEM = {
  {0X08, 0X36, 0X41, 0X41, 0X00}, // Column codes for '{'
  {0X00, 0X00, 0X7F, 0X00, 0X00}, // Column codes for '|'
  {0X00, 0X41, 0X41, 0X36, 0X08}, // Column codes for '}'
  {0X01, 0X02, 0X01, 0X20, 0X00}, // Column codes for '~'
};

const uint8_t equalSymbol [numColumns] PROGMEM = {0x14, 0x14, 0x14, 0x14, 0x14};

const uint8_t afnaSymbol [numColumns] PROGMEM = {0x32, 0x49, 0x71, 0x41, 0x3E};

const uint8_t space[numColumns] PROGMEM = {0x00, 0x00, 0x00, 0x00, 0x00};

const uint8_t unknown[numColumns] PROGMEM = {0x00, 0x00, 0x00, 0x00, 0x00};



DFRobot_BT401 bt;

void setup() {
  pinMode(12, INPUT); //acc
  pinMode(11, INPUT); // Radio or Tape - 0 = Radio, 1 = Tape
  pinMode(10, INPUT_PULLUP); //INTERRUPT
  pinMode(4, OUTPUT); //ADG411 pin for ibus -LOGIC 1 = ibus OFF, LOGIC 0 = on...
  pinMode(6, OUTPUT); //ADG411 pin for ARDUINO -LOGIC 1 = Arduino OFF, LOGIC 0 = on...
  pinMode(5, OUTPUT); // ADG411 pin for MCU -LOGIC 1 = mcu OFF, LOGIC 0 = on...

  digitalWrite(5, LOW);
  digitalWrite(6, HIGH);
  digitalWrite(12, LOW);
  digitalWrite(4, HIGH);


  Wire.begin();
  Wire.setWireTimeout(5000);
  Serial.begin(256000); // BT401 baudrate
  ibusPort.begin(9600);
  //debugSerial.begin(9600);
  /////////////////////////////////////////////////////////

  /*Delay for the BT401 to start*/
  while (!bt.begin(Serial)) {
    delay(1000);
  }
  bt.setVOl(30);
  delay(100);

}

void loop() {
  if (antilag <= 4) {
    antilag ++;
  }

  if (antilag == 5) {

    if (millis() >= time_now_ibus + period_ibus) {
      time_now_ibus += period_ibus;
      if (ibusCommandCaptured == 1) {
        //     debugSerial.println("IBUS COMMAND CAPTURED:");
        //     debugSerial.println(ibus1);
        //     debugSerial.println(ibus2);
        //     debugSerial.println(ibus3);
        //     debugSerial.println(ibusA);
        //     debugSerial.println(ibusB);
        //     debugSerial.println(ibusC);
        //     debugSerial.println("////////////////////////////////////////////////////////");
        ibus1 = 0;
        ibus2 = 0;
        ibus3 = 0;
        ibusA = 0;
        ibusB = 0;
        ibusC = 0;
        ibusCommandCaptured = 0;

      }

      if (ibusPort.available() > 0 && ibus1 == 0) {
        ibus1 = ibusPort.read();
        //     debugSerial.println("IBUS 1: ");
        //     debugSerial.println(ibus1);
        if (ibus1 != 0x50) {
          ibus1 = 0;
        }
      }

      if (ibusPort.available() > 0 && ibus1 == 0x50 && ibus2 == 0) {
        ibus2 = ibusPort.read();
        //     debugSerial.println("IBUS 2: ");
        //     debugSerial.println(ibus2);
        if (ibus2 != 0x04) {
          ibus1 = 0;
          ibus2 = 0;
        }
      }

      if (ibusPort.available() > 0 && ibus2 == 0x04 && ibus3 == 0) {
        ibus3 = ibusPort.read();
        //     debugSerial.println("IBUS 3: ");
        //     debugSerial.println(ibus3);
        if (ibus3 != 0x68) {
          ibus1 = 0;
          ibus2 = 0;
          ibus3 = 0;
        }
      }

      if (ibusPort.available() > 0 && ibus3 == 0x68 && ibusA == 0) {
        ibusA = ibusPort.read();
        //     debugSerial.println("IBUS A: ");
        //     debugSerial.println(ibusA);
      }

      if (ibusPort.available() > 0 && ibusA != 0 && ibusB == 0) {
        ibusB = ibusPort.read();
        //     debugSerial.println("IBUS B: ");
        //     debugSerial.println(ibusB);
      }

      if (ibusPort.available() > 0 && ibusB != 0 && ibusC == 0) {
        ibusC = ibusPort.read();
        //     debugSerial.println("IBUS C: ");
        //     debugSerial.println(ibusC);
      }

      if (ibusC != 0)
      {
        ibusCommandCaptured = 1;
      }



      //NEXT PRESSED
      if (ibusA == 0x3B && ibusB == 0X01 && ibusC == 0X06) {
        bt.next();
        ibusCommandCaptured = 1;
      }
      //PREV PRESSED
      if (ibusA == 0x3B && ibusB == 0x08 && ibusC == 0x0F) {
        bt.last();
        ibusCommandCaptured = 1;
      }
      //VOL UP PRESSED
      if (ibusA == 0x32 && ibusB == 0x11 && ibusC == 0x1F) {
        digitalWrite(4, LOW);
        //debugSerial.println("iBus ADG state: LOW");
        ibusUpCounterTrigger = 1;
        ibusCommandCaptured = 1;

      }
      //VOL DOWN PRESSED
      if (ibusA == 0x32 && ibusB == 0x10 && ibusC == 0x1E) {
        digitalWrite(4, LOW);
        //debugSerial.println("iBus ADG state: LOW");
        ibusDownCounterTrigger = 1;
        ibusCommandCaptured = 1;
      }


      //NEXT RELEASED
      if (ibusA == 0x3B && ibusB == 0X21 && ibusC == 0X26) {
        ibusCommandCaptured = 1;
      }
      //PREV RELEASED
      if (ibusA == 0x3B && ibusB == 0x28 && ibusC == 0x2F) {
        ibusCommandCaptured = 1;
      }
      //VOL UP RELEASED
      if (ibusA == 0x32 && ibusB == 0x31 && ibusC == 0x3F) {
        //DOESNT OCCUR
      }
      //VOL DOWN RELEASED
      if (ibusA == 0x32 && ibusB == 0x30 && ibusC == 0x3E) {
        //DOESNT OCCUR
      }



      if (ibusUpCounterTrigger == 1) {
        ibusUpCounter = ibusUpCounter + 1;


        if (ibusUpCounter <= 10 && ibusC == 0x1F) {
          ibusUpCounter = 0;
        }
        if (ibusUpCounter == 11 && ibusC != 0x1F) {
          digitalWrite(4, HIGH);
          //debugSerial.println("iBus ADG state: HIGH");
          ibusUpCounterTrigger = 0;
          ibusUpCounter = 0;
        }

      }



      /////////////////////////////////////////////////


      if (ibusDownCounterTrigger == 1) {
        ibusDownCounter = ibusDownCounter + 1;


        if (ibusDownCounter <= 10 && ibusC == 0x1E) {
          ibusDownCounter = 0;
        }
        if (ibusDownCounter == 11 && ibusC != 0x1E) {
          digitalWrite(4, HIGH);
          //debugSerial.println("iBus ADG state: HIGH");
          ibusDownCounterTrigger = 0;
          ibusDownCounter = 0;
        }

      }
    }
    ////////////////////////////////////////////////////////////
    if (mode != 0) {


      INTERRUPT = digitalRead(10);
      if (INTERRUPT == 0 && millis() >= time_now_btn + period_btn) {
        // debugSerial.println("interrupt = 0");
        time_now_btn += period_btn;
        Wire.requestFrom(0x20, 1);

        while (Wire.available()) {
          char btnrd = Wire.read();
          buttonPressed = btnrd;

          if (btnrd == 28) {

            Wire.beginTransmission(0x20);
            Wire.write(0x1D);
            Wire.endTransmission();
            Wire.requestFrom(0x20, 1);
            char btnrd = Wire.read();
            buttonPressed = btnrd;
          }

          if (btnrd == -116) {

            Wire.beginTransmission(0x20);
            Wire.write(0x03);
            Wire.endTransmission();
            Wire.requestFrom(0x20, 1);
            char btnrd = Wire.read();
            buttonPressed = btnrd;
          }

          Wire.beginTransmission(0x20);
          Wire.write(0x9c);
          Wire.endTransmission();
          //debugSerial.println(btnrd, HEX);
        }
        if (FRDcounterTrigger == 1)
        {
          FRDcounterTrigger = 0;
          buttonPressed = 0;
          if (FRDcounter <= 7009)
          {
            FRDcounter = -1;
            buttonPressed = 0;
          }
        }
        if (RWDcounterTrigger == 1)
        {
          RWDcounterTrigger = 0;
          buttonPressed = 0;
          if (RWDcounter <= 7009)
          {
            RWDcounter = -1;
            buttonPressed = 0;
          }
        }
        if (FRDactivated == 1)
        {
          FRDactivated = 0;
        }
        if (RWDactivated == 1)
        {
          RWDactivated = 0;
        }
        INTERRUPT = 1;
      }
    } //end of if mode != 0

    if (FRDcounter == 7012)
    {
      FRDcounter = 0;
      buttonPressed = 0;
    }
    if (RWDcounter == 7012)
    {
      RWDcounter = 0;
      buttonPressed = 0;
    }


    if (buttonPressed == 3 && mode == 0) //radio
    {
      mode = 1;
      queryMode = 1;
      buttonPressed = 0;
      delay(250);

    }

    if (buttonPressed == 3 && mode == 1) //USB
    {
      mode = 2;
      queryMode = 1;
      buttonPressed = 0;
      delay(250);
    }

    if (buttonPressed == 3 && mode == 2) //BLUETOOTH
    {
      buttonPressed = 0;
      queryMode = 1;
      mode = 0;
      digitalWrite(6, LOW);
      Wire.begin(0x20);
      Wire.write(3);
    }




    if (buttonPressed == 28 && mode != 0) //PLAY / PAUSE
    {
      //Serial.println("PLAY / PAUSE pressed");
      bt.playPause();

      buttonPressed = 0;
    }

    if (buttonPressed == 1 && mode != 0) //FRD
    {
      FRDcounterTrigger = 1;
    }

    if (FRDcounterTrigger == 1 && FRDcounter <= 7010)
    {
      FRDcounter = FRDcounter + 1;

    }

    if (FRDcounter == -1)
    {
      bt.next();
      FRDcounter = 0;
      FRDcounterTrigger = 0;


    }

    if (FRDcounter == 7010)
    {
      FRDactivated = 1;
      FRDcounterTrigger = 0;
      FRDcounter = 7012;
    }
    if (FRDactivated == 1)
    {
      bt.FRD();
    }

    if (buttonPressed == 2 && mode != 0) //RWD
    {
      RWDcounterTrigger = 1;
    }

    if (RWDcounterTrigger == 1 && RWDcounter <= 7010)
    {
      RWDcounter = RWDcounter + 1;

    }

    if (RWDcounter == -1)
    {
      bt.last();
      RWDcounter = 0;
      RWDcounterTrigger = 0;


    }

    if (RWDcounter == 7010)
    {
      RWDactivated = 1;
      RWDcounterTrigger = 0;
      RWDcounter = 7012;
    }
    if (RWDactivated == 1)
    {
      bt.RWD();
    }

  } // end of antilag


  acc = digitalRead(12);

  if (accCounter <= val)
  {
    accCounter = accCounter + 1;
  }




  if (acc == HIGH && acc != lastAcc && accCounter == val + 1) {
    if (mode == 0) {
      mode = 1;
      queryMode = 1;
    }
    bt.pause();
    lastAcc = HIGH;
    accCounter = 1;
    val = 150000;
  }

  if (acc == LOW && acc != lastAcc && accCounter == val + 1) {


    bt.play();
    lastAcc = LOW;
    accCounter = 1;
    val = 150000;
  }




  if (mode == 0 && queryMode == 1) //RADIO
  {
    inputText = "Radio";
    digitalWrite(6, HIGH);
    digitalWrite(5, LOW);
    digitalWrite(4, LOW);
    //debugSerial.println("iBus ADG state: LOW");
    queryMode = 0;
  }

  if (mode == 1 && queryMode == 1) //USB
  {
    digitalWrite(5, HIGH);
    digitalWrite(6, LOW);
    digitalWrite(4, HIGH);
    bt.usbMode();
    //debugSerial.println("iBus ADG state: HIGH");
    delay(500);
    Wire.beginTransmission(0x20);
    Wire.write(0x9c);
    Wire.endTransmission();
    lastsongNUMBER = "0";
    queryFileName = 1;
    queryDirSIZE = 1;
    queryMode = 0;
  }

  if (mode == 2 && queryMode == 1) //BLUETOOTH
  {
    digitalWrite(6, LOW);
    digitalWrite(5, HIGH);
    digitalWrite(4, HIGH);
    bt.bluetoothMode();
    //debugSerial.println("iBus ADG state: HIGH");
    inputText = "Bluetooth";
    smallDisplay = "--:--";
    queryMode = 0;
    acolumn = 0;
    bcolumn = 1;
    ccolumn = 2;
    dcolumn = 3;
    ecolumn = 4;
    fcolumn = 5;
    gcolumn = 6;
    hcolumn = 7;
    icolumn = 8;
  }
  inputText_len = inputText.length() + 1;

  if (mode == 1 && queryDirSIZE == 1) {
    do {
      dirSIZE = (bt.dirSIZE());
      if (lastdirSIZE != dirSIZE) {
        lastdirSIZE = dirSIZE;
        newdirSIZE = dirSIZE;
      }
    } while (! newdirSIZE.startsWith("M2"));
    newdirSIZE.replace("M2+00000", "");
    newdirSIZE.replace("0A", "1.0");
    newdirSIZE.replace("0B", "1.1");
    newdirSIZE.replace("0C", "1.2");
    newdirSIZE.replace("0D", "1.3");
    newdirSIZE.replace("0E", "1.4");
    newdirSIZE.replace("0F", "1.5");
    newdirSIZE.replace("10", "1.6");
    newdirSIZE.replace("11", "1.7");
    newdirSIZE.replace("12", "1.8");
    newdirSIZE.replace("13", "1.9");
    newdirSIZE.replace("14", "2.0");
    newdirSIZE.replace("15", "2.1");
    newdirSIZE.replace("16", "2.2");
    newdirSIZE.replace("17", "2.3");
    newdirSIZE.replace("18", "2.4");
    newdirSIZE.replace("19", "2.5");
    newdirSIZE.replace("1A", "2.6");
    newdirSIZE.replace("1B", "2.7");
    newdirSIZE.replace("1C", "2.8");
    newdirSIZE.replace("1D", "2.9");
    newdirSIZE.replace("1E", "3.0");

    newdirSIZE.replace(".", "");
    if (newdirSIZE != "000") {
      queryDirSIZE = 0;
    }
    //debugSerial.println(dirSIZE);
  }


  if (mode == 1 && millis() >= time_now + period) {
    time_now += period;
    songNUMBER = (bt.songNUM());
    if (lastsongNUMBER != songNUMBER) {

      do {
        songNUMBER = (bt.songNUM());
        lastsongNUMBER = songNUMBER;
        newsongNUMBER = songNUMBER;
      } while (! newsongNUMBER.startsWith("MO"));
      //debugSerial.println(newsongNUMBER);
      newsongNUMBER.replace("MO+000000", "");
      newsongNUMBER.replace("0A", "1.0");
      newsongNUMBER.replace("0B", "1.1");
      newsongNUMBER.replace("0C", "1.2");
      newsongNUMBER.replace("0D", "1.3");
      newsongNUMBER.replace("0E", "1.4");
      newsongNUMBER.replace("0F", "1.5");
      newsongNUMBER.replace("10", "1.6");
      newsongNUMBER.replace("11", "1.7");
      newsongNUMBER.replace("12", "1.8");
      newsongNUMBER.replace("13", "1.9");
      newsongNUMBER.replace("14", "2.0");
      newsongNUMBER.replace("15", "2.1");
      newsongNUMBER.replace("16", "2.2");
      newsongNUMBER.replace("17", "2.3");
      newsongNUMBER.replace("18", "2.4");
      newsongNUMBER.replace("19", "2.5");
      newsongNUMBER.replace("1A", "2.6");
      newsongNUMBER.replace("1B", "2.7");
      newsongNUMBER.replace("1C", "2.8");
      newsongNUMBER.replace("1D", "2.9");
      newsongNUMBER.replace("1E", "3.0");

      newsongNUMBER.replace(".", "");

      queryFileName = 1;
      smallDisplay = newsongNUMBER + newdirSIZE;
      //      debugSerial.println(smallDisplay);
      smallDisplay_len = smallDisplay.length() + 1;
    }
  }




  ///////////////////////////////////////////////////////////////

  if (queryFileName == 1)
  {
    do {
      nowPlaying = (bt.getFilename());

      inputText = nowPlaying;
      inputText.replace(".mp3", "  ");
      inputText_len = inputText.length() + 1;
    } while (! inputText.startsWith("MF+"));
    inputText.replace("MF+", "");
    acolumn = -1;
    bcolumn = 0;
    ccolumn = 1;
    dcolumn = 2;
    ecolumn = 3;
    fcolumn = 4;
    gcolumn = 5;
    hcolumn = 6;
    icolumn = 7;

    queryFileName = 0;
  }


  ///////////////////////////////////////////////////////////////////////////////////////////////////////

  if (millis() >= time_now_display + period_display) {
    time_now_display += period_display;
    char inputText_array[inputText_len];
    inputText.toCharArray(inputText_array, inputText_len);


    uint8_t ahr[numColumns];
    getColumns(inputText[acolumn], ahr);


    uint8_t bhr[numColumns];
    getColumns(inputText[bcolumn], bhr);


    uint8_t chr[numColumns];
    getColumns(inputText[ccolumn], chr);


    uint8_t dhr[numColumns];
    getColumns(inputText[dcolumn], dhr);

    uint8_t ehr[numColumns];
    getColumns(inputText[ecolumn], ehr);


    uint8_t fhr[numColumns];
    getColumns(inputText[fcolumn], fhr);


    uint8_t ghr[numColumns];
    getColumns(inputText[gcolumn], ghr);


    uint8_t hhr[numColumns];
    getColumns(inputText[hcolumn], hhr);


    uint8_t ihr[numColumns];
    getColumns(inputText[icolumn], ihr);


    char smallDisplay_array[smallDisplay_len];
    smallDisplay.toCharArray(smallDisplay_array, smallDisplay_len);

    uint8_t smla[numColumns];
    getColumns(smallDisplay[0], smla);
    uint8_t smlb[numColumns];
    getColumns(smallDisplay[1], smlb);
    uint8_t smlc[numColumns];
    getColumns(smallDisplay[2], smlc);
    uint8_t smld[numColumns];
    getColumns(smallDisplay[3], smld);
    uint8_t smle[numColumns];
    getColumns(smallDisplay[4], smle);


    if (inputText_len > 10 && icolumn < inputText_len) {

      acolumn = (acolumn + 1);
      bcolumn = (bcolumn + 1);
      ccolumn = (ccolumn + 1);
      dcolumn = (dcolumn + 1);
      ecolumn = (ecolumn + 1);
      fcolumn = (fcolumn + 1);
      gcolumn = (gcolumn + 1);
      hcolumn = (hcolumn + 1);
      icolumn = (icolumn + 1);

    } else {
      acolumn = 0;
      bcolumn = 1;
      ccolumn = 2;
      dcolumn = 3;
      ecolumn = 4;
      fcolumn = 5;
      gcolumn = 6;
      hcolumn = 7;
      icolumn = 8;
    }
    if (mode != 0) {

      //COMMANDS TO SET UP THE DISPLAY
      Wire.begin();
      Wire.beginTransmission(0x3C);
      Wire.write(0x55);             // set_mode  -normal video, mixed mode, MUX 1:8
      Wire.endTransmission();

      Wire.beginTransmission(0x3C);
      Wire.write(0x3e); // RAM access
      Wire.endTransmission();

      Wire.beginTransmission(0x3C);
      Wire.write(0x7c); //set start bank 0
      Wire.endTransmission();

      Wire.beginTransmission(0x3C);
      Wire.write(0x62); //device select
      Wire.endTransmission();


      //WRITING TO DISPLAY STARTS HERE

      Wire.beginTransmission(0x3C);
      Wire.write(0x0F); //load x address

      Wire.write(bhr[3]);             // DATA column 10
      Wire.write(bhr[2]);             // DATA column 9
      Wire.write(bhr[1]);             // DATA column 8
      Wire.write(bhr[0]);             // DATA column 7
      Wire.write(0x00);               // DATA column 6
      Wire.write(ahr[4]);             // DATA column 5
      Wire.write(ahr[3]);             // DATA column 4
      Wire.write(ahr[2]);             // DATA column 3
      Wire.write(ahr[1]);             // DATA column 2
      Wire.write(ahr[0]);             // DATA column 1

      Wire.endTransmission();     // stop transmitting


      Wire.beginTransmission(0x3C);
      Wire.write(0x05); //load x address

      Wire.write(dhr[1]);             // DATA column 20
      Wire.write(dhr[0]);             // DATA column 19
      Wire.write(0x00);               // DATA column 18
      Wire.write(chr[4]);             // DATA column 17
      Wire.write(chr[3]);             // DATA column 16
      Wire.write(chr[2]);             // DATA column 15
      Wire.write(chr[1]);             // DATA column 14
      Wire.write(chr[0]);             // DATA column 13
      Wire.write(0x00);               // DATA column 12
      Wire.write(bhr[4]);             // DATA column 11

      Wire.endTransmission();


      Wire.beginTransmission(0x3C);
      Wire.write(0x00); //load x address

      Wire.write(0x00);               // DATA MISSING COLUMN -BLANK
      Wire.write(0x00);               // DATA column 24
      Wire.write(dhr[4]);             // DATA column 23
      Wire.write(dhr[3]);             // DATA column 22
      Wire.write(dhr[2]);             // DATA column 21

      Wire.endTransmission();


      Wire.beginTransmission(0x3C);
      Wire.write(0x61); //device select
      Wire.endTransmission();


      Wire.beginTransmission(0x3C);
      Wire.write(0x1f); //load x address

      Wire.write(fhr[3]);             // DATA column 34
      Wire.write(fhr[2]);             // DATA column 33
      Wire.write(fhr[1]);             // DATA column 32
      Wire.write(fhr[0]);             // DATA column 31
      Wire.write(0x00);               // DATA column 30
      Wire.write(ehr[4]);             // DATA column 39
      Wire.write(ehr[3]);             // DATA column 28
      Wire.write(ehr[2]);             // DATA column 27
      Wire.write(ehr[1]);             // DATA column 26
      Wire.write(ehr[0]);             // DATA column 25

      Wire.endTransmission();


      Wire.beginTransmission(0x3C);
      Wire.write(0x61); //device select
      Wire.endTransmission();


      Wire.beginTransmission(0x3C);
      Wire.write(0x14); //load x address

      Wire.write(hhr[2]);             // DATA column 45
      Wire.write(hhr[1]);             // DATA column 44
      Wire.write(hhr[0]);             // DATA column 43
      Wire.write(0x00);               // DATA column 42
      Wire.write(ghr[4]);             // DATA column 41
      Wire.write(ghr[3]);             // DATA column 40
      Wire.write(ghr[2]);             // DATA column 39
      Wire.write(ghr[1]);             // DATA column 38
      Wire.write(ghr[0]);             // DATA column 37
      Wire.write(0x00);               // DATA column 36
      Wire.write(fhr[4]);             // DATA column 35

      Wire.endTransmission();


      Wire.beginTransmission(0x3C);
      Wire.write(0x61); //device select
      Wire.endTransmission();



      Wire.beginTransmission(0x3C);
      Wire.write(0x0A); //load x address

      Wire.write(0x00);             // DATA column 55
      Wire.write(0x00);             // DATA column 54
      Wire.write(ihr[4]);             // DATA column 53
      Wire.write(ihr[3]);             // DATA column 52
      Wire.write(ihr[2]);             // DATA column 51
      Wire.write(ihr[1]);             // DATA column 50
      Wire.write(ihr[0]);             // DATA column 49
      Wire.write(0x00);             // DATA column 48
      Wire.write(hhr[4]);             // DATA column 47
      Wire.write(hhr[3]);             // DATA column 46

      Wire.endTransmission();



      //SMALL DISPLAY

      //FOURTH
      Wire.beginTransmission(0x3C);
      Wire.write(0x60); //device select
      Wire.endTransmission();
      Wire.beginTransmission(0x3C);
      Wire.write(0x0A); //load x address

      Wire.write(0x00);
      Wire.write(smle[4]);             // DATA column 5
      Wire.write(smle[3]);             // DATA column 4
      Wire.write(smle[2]);             // DATA column 3
      Wire.write(smle[1]);             // DATA column 2
      Wire.write(smle[0]);             // DATA column 1


      Wire.endTransmission();

      //THIRD
      Wire.beginTransmission(0x3C);
      Wire.write(0x60); //device select
      Wire.endTransmission();
      Wire.beginTransmission(0x3C);
      Wire.write(0x10); //load x address


      Wire.write(smld[4]);             // DATA column 5
      Wire.write(smld[3]);             // DATA column 4
      Wire.write(smld[2]);             // DATA column 3
      Wire.write(smld[1]);             // DATA column 2
      Wire.write(smld[0]);             // DATA column 1


      Wire.endTransmission();


      //STRIPE OR SEMICOLUMN COLUMN
      Wire.beginTransmission(0x3C);
      Wire.write(0x60); //device select
      Wire.endTransmission();
      Wire.beginTransmission(0x3C);
      Wire.write(0x15); //load x address

      Wire.write(0x7F);             // 0x22 is semicolumn, 0x7F is stripe

      Wire.endTransmission();

      //SECOND
      Wire.beginTransmission(0x3C);
      Wire.write(0x60); //device select
      Wire.endTransmission();
      Wire.beginTransmission(0x3C);
      Wire.write(0x16); //load x address


      Wire.write(smlb[4]);             // DATA column 5
      Wire.write(smlb[3]);             // DATA column 4
      Wire.write(smlb[2]);             // DATA column 3
      Wire.write(smlb[1]);             // DATA column 2
      Wire.write(smlb[0]);             // DATA column 1


      Wire.endTransmission();

      //FIRST
      Wire.beginTransmission(0x3C);
      Wire.write(0x60); //device select
      Wire.endTransmission();
      Wire.beginTransmission(0x3C);
      Wire.write(0x1c); //load x address


      Wire.write(smla[4]);             // DATA column 5
      Wire.write(smla[3]);             // DATA column 4
      Wire.write(smla[2]);             // DATA column 3
      Wire.write(smla[1]);             // DATA column 2
      Wire.write(smla[0]);             // DATA column 1


      Wire.endTransmission();

    } //if mode != 0
  }

}

void getColumns(char c, uint8_t columns[numColumns]) {
  switch (c) {

    case 'A'...'Z':
      memcpy_P(&columns[0], &upperCase[c - 'A'][0], numColumns);
      break;

    case 'a'...'z':
      memcpy_P(&columns[0], &lowerCase[c - 'a'][0], numColumns);
      break;

    case '0'...'9':
      memcpy_P(&columns[0], &numerals[c - '0'][0], numColumns);
      break;

    case ' ':
      memcpy_P(&columns[0], &space[0], numColumns);
      break;

    case '!'...'/':
      memcpy_P(&columns[0], &symbolsa[c - '!'][0], numColumns);
      break;

    case '['...'`':
      memcpy_P(&columns[0], &symbolsb[c - '['][0], numColumns);
      break;

    case '{'...'~':
      memcpy_P(&columns[0], &symbolsc[c - '{'][0], numColumns);
      break;


    case '=':
      memcpy_P(&columns[0], &equalSymbol[0], numColumns);
      break;

    case '@':
      memcpy_P(&columns[0], &afnaSymbol[0], numColumns);
      break;



    default:
      memcpy_P(&columns[0], &unknown[0], numColumns);
      break;
  }

}

The schematic, basicly plan for protoboard -I will make two sided PCB and get read of connectors once I confirm that everything is 100% working:

I would like to add that I had checked the board multiple times, I have been soldering for a decade now to I can confidently say that there are no defects on the board itself. I can shake the whole thing on bench and problem doesnt occur.

Under the board I have metal sheet that is grounded.

I added two "jumpers" on rx and tx between arduino and BT401, I had removed them now and soldered pins together, because I had found that if I remove a jumper thing freezes the same.

Basicly text stops scrooling on the screen, music continues to play, but buttons are not responsive.

I have 1000uF capacitor between 12v and gnd before the LM7805 regulator and 220uF between the output (5v) and gnd, arduino does stay on when cranking the engine, so I think voltage drops are not a problem.

The only thing that I dont have on bench is IBUS, I will try without it, maybee that is making arduino to freeze.

Nice project!

Your diagram is better than nothing but there are details I cannot make out, these need to be clarified please. A proper schematic would be 1000 times better. Some of my comments below will reflect that I cannot read your diagram properly.

Are you powering the Arduino from 12V? First thing is to use a buck converter to reduce the 12V to 5V and power the Arduino at 5V to its 5V pin. The buck converter will add another layer to the noise protection.

The wiring you have is perfect for picking up electrical noise, lots of loops. Loops make wonderful aerials for picking up noise of all kinds. The general rules are to keep power and signal wires separate and keep the net current flow in a group of wires at zero. This means being aware of how the current flows between one device and another and making sure the wire(s) that caries the current to a device is paired with the wire(s) that carries it back. Think of a mains lead to any electrical appliance, the wires are bound together. This is not just convenient, it is good electrical practice. You need to do the same for parts of the circuit.

Ensure the case is connected to 0V.

What is the device with the aerial at the bottom left of the circuit board? Radio waves do not penetrate metal boxes, so it needs to be outside the main enclosure. Inside it can't work properly but adds to the interference inside the box.

Hy, thank you for reply.
Yes I messed up a bit with the board, will solve everything when I will be making next one, Im thinking of double sided pcb. Im using LM7805 do drop down to 5v. I had been using buck converters before in audio projects and..... I dont want to hear that telephone-modem-like noise every again :sweat_smile:

Case is at 0v, that device is mp3 / bluetooth module

OK, and point taken about noise from buck converters. In that case concentrate on the loops of wire for now. This requires some thought and planning.

That device is mp3 / bluetooth module

OK, well, it's radio, should be outside the screening to work properly.

Will do something with wires

Yes, but most likely I will discard the bluetooth function because it pick up noises that those chinesse bluetooth modules tend to.

What decoupling capacitors are there near the 7805?

I only have 1000uF at input and 220uf at output

When using SMPS always use a ferrite bead on the output:

image

image

Rather good. You could add something like 100 nF ceramic caps on both input and output. They stop spikes, high frequency noise. I often added a small and fast 1 uF to the output.
A single board computer ran for 10 years, laying in the front window, without any hickups. An LM7805 was powering the board and LED display. Okey, car model 1985 and not digital stuff....

Thats good to know, coming from diy audio world I always liked linear regulators more, only problem I see is them turning car battery into heat when parked.

Will add the caps, you think film ones would do the job? for some reason the only store near me only holds film type ones...

I had tryed, few of different types, but unfurtunately it didnt help much... that project is still waiting for me to add linear after smps...

I am 100% certain that film capacitors will not work for decoupling noise. They do not have the high frequency response needed to do any good. You need ceramic type capacitors.