[solved]Bluetooth module (SoftwareSerial) not working with mcp23S17

Hi, i’m working at a big project and this is why i won’t explain what it does

The thing is that i’m using the following librarys:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
#include <LCD.h>
#include <LcdBarGraphX.h>
#include <EEPROM.h>
#include <SPI.h>              // We use this library, so it must be called here.
#include <MCP23S17.h>         // Here is the new class to make using the MCP23S17 easy.
MCP mcp(0, 2);
[u]#include <SoftwareSerial.h>
SoftwareSerial BTSerial(8, A1); // RX | TX[/u]

and when i only write the last 2 lines which are for a bluetooth module (SoftwareSerial), the expander, which is communicating too with my arduino nano in the same time, doesn’t work as it supposed to do

What is the problem ?

prologikus:
What is the problem ?

Your refusal to explain.
And the absence of your complete program.

…R

Robin2: Your refusal to explain. And the absence of your complete program.

...R

There are 1200 lines of code whitch isn't optimized at all, cause i'm a beginner. http://pastebin.com/h3hC4Tpq

Thanks for your replay but if you don't know the answer from the first post i don't think you'll know it even with the full code

The exact problem is that after finishing the setup, in the loop it stucks himself because he think that all the buttons from the expander are pressed( this happends only when those 2 lines are used, if i don't use them i have no problem, related to the expander )

EDIT: it has something to do with this ? |500x253

prologikus:
it has something to do with this ?

I don’t think I could have been expected to guess that you were using more than one SoftwareSerial port from your Original Post. So you can perhaps understand why you should have posted all your program.

On the other hand you were correct to assume that I would have been too lazy to study 1200 lines of code. How come it got as big as 1200 lines before the problem emerged?

For most practical purposes you can only use one instance of SoftwareSerial. If you need multiple serial ports I suggest you use a Mega which has three spare HardwareSerial ports.

…R

Robin2:
I don’t think I could have been expected to guess that you were using more than one SoftwareSerial port from your Original Post. So you can perhaps understand why you should have posted all your program.

On the other hand you were correct to assume that I would have been too lazy to study 1200 lines of code. How come it got as big as 1200 lines before the problem emerged?

For most practical purposes you can only use one instance of SoftwareSerial. If you need multiple serial ports I suggest you use a Mega which has three spare HardwareSerial ports.

…R

No, i’m using Nano, and everything works great without using the bluetooth module, since i inported the code for it, it doesn’t want to work.
i don’t know what else can i tell you, because i already told you all i know.

Everything works fine …;
Inserting
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(8, A1); // RX | TX
AND
BTSerial.begin(38400);
in the setup

and the expander communication with the nano doesn’t work no more

so … i’m still thinking that my nano can’t communicate with both of those devices in the same time and i might need to use listen function (softwareserial) to listen each other but how i can do that because the expander is using a library (SPI) not softwareserial …

I don't know why I bother asking, it might be simpler to take a wild guess at what you have connected to pins 0 and 1.

Nick_Pyner: I don't know why I bother asking, it might be simpler to take a wild guess at what you have connected to pins 0 and 1.

There is nothing connected to pin 0 and pin 1, i used pin 8 as RX and pin A1 as TX

I can't say I'm surprised to hear that. Read replies #1 and #3 again, and then consider if it might be a good idea to re-think all this serial stuff, check on what pins 0 and 1 are for, and why you don't use them.

prologikus: i'm still thinking that my nano can't communicate with both of those devices in the same time

What do you mean by "both of those devices"?

For f**ks sake, this is just a stupid guessing game where you have all the info and yet you won't share it with the people you want help from.

Try SoftwareSerial at 9600 baud. If that works, try a higher baud rate - you may be lucky.

DO NOT expect two instances of SoftwareSerial to work.

...R

Nick_Pyner:
I can’t say I’m surprised to hear that. Read replies #1 and #3 again, and then consider if it might be a good idea to re-think all this serial stuff, check on what pins 0 and 1 are for, and why you don’t use them.

Robin2:
[…]this is just a stupid guessing game where you have all the info and yet you won’t share it with the people you want help from.
[…]

Using pin 0 and 1 will work as good as it work using others, softwareSerial let me use other pins for this job.

The Bluetooth works without the rest of my code and my code works without bluetooth(softwareSerial)

After 4 hours of reuploading different types of code I concluded that there is a bigger problem, a unknown one
I was trying to upload only specific parts of my code trying using the bluetooth too, and sometimes it works, sometime doesn’t finish setup(), sometimes the expander(SPI) doens’t work, and a simple lcd.clear() which has nothing to do with those can fix the problem as much as another simple line which has no connection with the expander or serial can bring those problems back ^

Here i’ll give you an example of a code that works and the same one with one little difference that doesn’t:
the code is simplified

void loop()
{

  //BEGIN HOMEPAGES !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

      if (active == 1) {
        if (menumode == 0) { //Homepage 0 -- temperature + lock/unlock
          lcd.setCursor(0, 1);
          if (mcp.digitalRead(carlockPin) == LOW) {
            lcd.print("<Incuie masina>  ");
            if (mcp.digitalRead(buttonPin) == LOW) {
              lcd.setCursor(0, 1);
              toggle_sound();
              lcd.print("Incuiata!!     ");
              lock_door();
            }
          }
          else {
            lcd.print("<Descuie masina> ");
            if (mcp.digitalRead(buttonPin) == LOW) {
              unlock_door();
              toggle_sound();
              lcd.setCursor(0, 1);
              lcd.print("Descuiata!!     ");
            }
          }

          lcd.setCursor(0, 0);
          if (blcon == 0) {
            lcd.print("BL");
            lcd.write(8);
          }
          else {
            lcd.print("BL");
            lcd.write(7);
          }
          lcd.print(" ");
          if (mcp.digitalRead(contactPin) == LOW) {
            lcd.print("CAR");
            lcd.write(7);
          }
          else {
            lcd.print("CAR");
            lcd.write(8);
          }
        } //end menumode 0 ( homepage 1 )



        //Homepage 1 -- LED color
        if (menumode == -1) {
          lcd.setCursor(0, 0);
          lcd.print("<Culoarea Banda>");
          lcd.setCursor(0, 1);
          lcd.print("R:");
          lcd.print(redVal);
          lcd.print(" G:");
          lcd.print(grnVal);
          lcd.print(" B:");
          lcd.print(bluVal);
          if (mcp.digitalRead(buttonPin) == LOW) {
            menumode = -11;
            click_sound(); // --- buzzer sound
           // delay(400);
          }
        }
        if (menumode == -11) {
          lcd.setCursor(0, 1);
          lcd.print("R:");
          lcd.print(redVal);
          lcd.print(" G:");
          lcd.print(grnVal);
          lcd.print(" B:");
          lcd.print(bluVal);
          // -----------------------------------------BEGIN COLOR MIXER
          //--------------------------------------------------------
          potVal = analogRead(potPin);   // read the potentiometer value at the input pin

          if (potVal < 341)  // Lowest third of the potentiometer's range (0-340)
          {
            potVal = (potVal * 3) / 4; // Normalize to 0-255

            redVal = 256 - potVal;  // Red from full to off
            grnVal = potVal;        // Green from off to full
            bluVal = 1;             // Blue off
          }
          else if (potVal < 682) // Middle third of potentiometer's range (341-681)
          {
            potVal = ( (potVal - 341) * 3) / 4; // Normalize to 0-255

            redVal = 1;            // Red off
            grnVal = 256 - potVal; // Green from full to off
            bluVal = potVal;       // Blue from off to full
          }
          else  // Upper third of potentiometer"s range (682-1023)
          {
            potVal = ( (potVal - 683) * 3) / 4; // Normalize to 0-255

            redVal = potVal;       // Red from off to full
            grnVal = 1;            // Green off
            bluVal = 256 - potVal; // Blue from full to off
          }
          analogWrite(ledRPin, (redVal - ((redVal * ledlight) / 100)));   // Write values to LED pins
          analogWrite(ledGPin, (grnVal - ((grnVal * ledlight) / 100)));
          analogWrite(ledBPin, (bluVal - ((bluVal * ledlight) / 100)));
          delay(5);
          //--------------------------------------------------------
          //------------------------------------------ END COLOR MIXER
          if (mcp.digitalRead(buttonPin) == LOW) {
            //   EEPROM.write(0, redVal); //write to memory
            //   EEPROM.write(1, grnVal);
            //   EEPROM.write(2, bluVal);
            idlecount = 0;
            menumode = 0;
          //  delay(300);
            click_sound(); // --- buzzer sound
          }
        } //end homepage 1

      
      } //end if (active = 1)



      //keep the page with the pot value
      if (menumode > -5) {
        if (menumode <= 0) {
          int pot = map(analogRead(potPin), 0, 1000, 0, -4);  // number of settings submenus // to EDIT ~!~~~~~~~~~~~~~
          menusel = pot; //read the selection from the pot
          if (menumode != menusel) { //only if is not already set
            click_sound();
            menumode = menusel;
            lcd.clear();
            active = 1;
            idlecount = 0;
          }
        }
      }

Using this code won’t work, it will stuck the expander(SPI)
but removing the function IF (you can see that has nothing to do with other)

if (active == 1) {

make the program fully functional

THEN !!, by adding

                 delay(500);

under the

             lock_door();

stuck the expander again
BUT, by stopping using the SoftwareSerial library ( bluetooth module) everything works !!!

prologikus: Using pin 0 and 1 will work as good as it work using others,

Incomprehensible

softwareSerial let me use other pins for this job.

really? You might consider reading reply#3 again, twice.

The Bluetooth works without the rest of my code and my code works without bluetooth(softwareSerial) ........................ BUT, by stopping using the SoftwareSerial library ( bluetooth module) everything works !!!

So, if you want bluetooth, how about putting it on hardware serial?

I give up.

...R

Nick_Pyner: Incomprehensible really? You might consider reading reply#3 again, twice. So, if you want bluetooth, how about putting it on hardware serial?

I really thanks you man, i didn't know serial(hardware) is not the same with Software serial I no longer use the library but only standard serial and i now can comunicate with bluetooth and my code still works like it's supposed to do.

Funfact: it took me 3 days to connect a bluetooth module to my arduino, imagine others :D :D ...

[case solved]