Go Down

Topic: Arduino - Bluesmirf: Trouble reading Serial (Read 2296 times) previous topic - next topic

firmaj

Oct 01, 2015, 01:50 pm Last Edit: Oct 01, 2015, 02:10 pm by firmaj
Hi!

I have two arduinos (One Micro and one Uno), each with one Bluesmirf Silver(configured as Master and Slave).

Setting up the connection between the modules does work (the green connect light lits up on both). My problem appears when I send a "1" from one and want to read it from the other.  I get this in the seriell monitor:




Does somebody have any ideas? I just want to send from one and receive from the other, that's the problem for now.



My Codes:

MASTER
Code: [Select]


int ledPin = 12;

int val = 0;

void setup() {
  Serial.begin(115200);
  Serial.print("$$$");

  delay(100);
  Serial.println("SM,1");
  delay(100);

  Serial.println("C,000666643C3D");
  delay(100);
  Serial.println("---");

  pinMode(ledPin, OUTPUT);
}

void loop() {
  if (Serial.available() > 0) {
    val = Serial.read();
    delay(2000);

    if (val == 1) {
      digitalWrite(ledPin, HIGH);
      delay(2000);
      digitalWrite(ledPin, LOW);
    }
  }
}




SLAVE
Code: [Select]


void setup() {
 
  Serial.begin(115200);
  Serial.print("$$$");
 
  delay(100);
  Serial.println("SM,0"); 
  delay(100);
   
  Serial.println("---");
 

}

void loop() {

  delay(2000);
  Serial.println(1);
  delay(2000); 

}



PaulS

Quote
sketch_oct01a:33: error: missing terminating ' character
sketch_oct01a.ino: In function 'void loop()':
sketch_oct01a:34: error: void value not ignored as it ought to be
sketch_oct01a:34: error: expected `)' before ';' token
sketch_oct01a.ino: At global scope:
sketch_oct01a:41: error: expected declaration before '}' token
Your master code won't even compile.

You seem to be trying to talk to the PC and the other Arduino using the same serial port, and expecting that somehow each will know when you mean to talking to it. That's a no-go.
The art of getting good answers lies in asking good questions.

firmaj

#2
Oct 01, 2015, 02:06 pm Last Edit: Oct 01, 2015, 02:07 pm by firmaj
Sorry, changed the master to try something out..... changed it back now.

How do I specify that I want to talk to the other Arduino? I forgot to say that I'm connected to RX/TX (pin 0 & 1) on the boards, I thought they would replace the USB serial?

PaulS

Quote
I thought they would replace the USB serial?
But you didn't remove the USB cable, did you?

Quote
How do I specify that I want to talk to the other Arduino?
Use SoftwareSerial and two other pins.
The art of getting good answers lies in asking good questions.

firmaj

Tried it without the USB connected but going to change to the SoftwareSerial and see if that helps. I'll be back with news.

Thanks for now

Robin2

Post the latest version of your two programs.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

firmaj

#6
Oct 02, 2015, 11:20 am Last Edit: Oct 02, 2015, 11:46 am by firmaj
EDIT:
I tried to disconnect the bluesmirf module and the code stills makes the same printout. so my bluetooth.available() and read() doesn't seem to read the bluetooth?


These are my codes that are in use right now, sorry about that.

So I'm now using SoftwareSerial and the devices connect fine, but I'm still having trouble reading values. This is what's coming out from the serial monitor on the master:




CODE FOR MASTER
Code: [Select]
#include <SoftwareSerial.h>

int LED_RED = 6;
int LED_YELLOW = 7;

int buttonPin = 4;
int ledPin = 12;
int buttonState = 0;

int value_BT = 0;

int bluetoothTx = 9;  // TX-O pin of Bluesmirf silver, Arduino D9
int bluetoothRx = 10;  // RX-I pin of Bluesmirf silver, Arduino D10

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup() {
  pinMode(LED_YELLOW, OUTPUT);
  pinMode(LED_RED, OUTPUT);

///Indicating that this is the master
  led_indicate_master();

  bluetooth.begin(115200);
  bluetooth.print("$$$");
  delay(100);
  bluetooth.println("SM,1");
  delay(100);
  bluetooth.println("C,000666643C3D");
  delay(100);
  bluetooth.println("---");
 

// initialize LED pin and pusbutton
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT);

  Serial.begin(115200);
  Serial.println("Debugging works");
}

void loop() {

  if (bluetooth.available() > 0) {
    value_BT = bluetooth.read();
    delay(50);
    Serial.println(value_BT);
    delay(50);
  }

}


void led_indicate_master() {
  digitalWrite(LED_YELLOW, HIGH);
  digitalWrite(LED_RED, HIGH);
  delay(500);
  digitalWrite(LED_YELLOW, LOW);
  digitalWrite(LED_RED, LOW);
  delay(50);
  digitalWrite(LED_YELLOW, HIGH);
  digitalWrite(LED_RED, HIGH);
  delay(500);
  digitalWrite(LED_YELLOW, LOW);
  digitalWrite(LED_RED, LOW);
  delay(50);
  digitalWrite(LED_YELLOW, HIGH);
  digitalWrite(LED_RED, HIGH);
  delay(500);
  digitalWrite(LED_YELLOW, LOW);
  digitalWrite(LED_RED, LOW);
  delay(50);

 
}




CODE FOR SLAVE
Code: [Select]


#include <SoftwareSerial.h>

int LED_RED = 5;
int LED_GREEN = 6;

int value_BT = 0;

int ledPin = 11;

int bluetoothTx = 9;  // TX-O pin of bluetooth mate, Arduino D9
int bluetoothRx = 10;  // RX-I pin of bluetooth mate, Arduino D10

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup() {
  pinMode(LED_RED, OUTPUT);
  pinMode(LED_GREEN, OUTPUT);

///Indicating that this is the slave
 
  led_indicate_slave();
 
  bluetooth.begin(115200);
  bluetooth.print("$$$");
  delay(100);
  bluetooth.println("SM,0"); 
  delay(100);
  bluetooth.println("---");
 
  pinMode(ledPin, OUTPUT);

}

void loop() {
 
  delay(2000);
  bluetooth.println(1);
  delay(2000);
 
}

void led_indicate_slave() {
  digitalWrite(LED_GREEN,HIGH);
  digitalWrite(LED_RED,HIGH);
  delay(5000);
  digitalWrite(LED_GREEN,LOW);
  digitalWrite(LED_RED,LOW);
  delay(50);
}


Robin2

I don't think SoftwareSerial will work at 115200 baud. Try 9600 and if that works try 19200 and maybe 38400.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

PaulS

Quote
This is what's coming out from the serial monitor on the master:
That is TEXT. That is the LAST picture of text that you will post.
The art of getting good answers lies in asking good questions.

firmaj

#9
Oct 02, 2015, 04:42 pm Last Edit: Oct 02, 2015, 05:25 pm by firmaj
I don't think SoftwareSerial will work at 115200 baud. Try 9600 and if that works try 19200 and maybe 38400.

...R
My BT modules won't connect at 9600, 19200 or 38400. Only 115200:S

That is TEXT. That is the LAST picture of text that you will post.
Didn't get this at all, have I done something to upset you? (Is there a rule that images aren't allowed to be inserted? If so than I've totally missed that. But why the anger?)

firmaj

I tried to replace bluetooth.print to digitalWrite(bluetoothRx, HIGH) and on the other arduino digitalRead(bluetoothTx) but I only get 1 all the time from the read.

PaulS

Quote
Is there a rule that images aren't allowed to be inserted?
Images are fine. Pictures of text are not.

Quote
But why the anger?
Two reasons. You are wasting bandwidth. And, I can't read the text in the picture.
The art of getting good answers lies in asking good questions.

Robin2

#12
Oct 02, 2015, 08:34 pm Last Edit: Oct 02, 2015, 08:37 pm by Robin2
My BT modules won't connect at 9600, 19200 or 38400. Only 115200:S
Then you may have arrived at the end of the SoftwareSerial road.
The Micro uses the 32U4 MCU and has a spare HardwareSerial port on pins 0 and 1.

I tried to replace bluetooth.print to digitalWrite(bluetoothRx, HIGH) and on the other arduino digitalRead(bluetoothTx) but I only get 1 all the time from the read.
Why would you think that might do anything useful ?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

firmaj

Images are fine. Pictures of text are not.
Two reasons. You are wasting bandwidth. And, I can't read the text in the picture.
Got it, my apologies!


Then you may have arrived at the end of the SoftwareSerial road.
The Micro uses the 32U4 MCU and has a spare HardwareSerial port on pins 0 and 1.

Why would you think that might do anything useful ?

...R
My problem exists when using the hardware serial as well. I can't read what I send. I get the same number combination when printing what is read. So there's no difference , thats the weird part

Robin2

My problem exists when using the hardware serial as well.
Post the code that demonstrates that and we will see if we can get it working properly.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up