Moving from a USB cable to bluetooth

I'm new to the forum and a Arduino novice.

I am trying to measure 3 temperatures on a UNO prototype board. I have created the code from a number of sources including a running average. The code works when UNO is connected to a PC through a USB cable but it doesn't with bluetooth. I can talk to the bluetooth device, a Sparkfun BlueSMiRF, by calling up the CMD function etc but isn't transferring data.

The code is

const int sensorPin0 = A0;
const int sensorPin1 = A1;
const int sensorPin3 = A2;
const float baselineTemp = 25.0;
#include "RunningAverage.h"

RunningAverage RAT0(10);
RunningAverage RAT1(10);
RunningAverage RAT3(10);

int samples = 0;

#include <SoftwareSerial.h>

int bluetoothTx = 2; // TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 3; // RX-I pin of bluetooth mate, Arduino D3

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup(void){
Serial.begin(9600);
Serial.println(FILE);
Serial.print("Version: ");
Serial.println(RUNNINGAVERAGE_LIB_VERSION);

// explicitly start clean
RAT0.clear();
RAT1.clear();
RAT3.clear();

//bluetooth.println("c,90A4DE9DEB95");
delay(1000); // Short delay, wait for the Mate to send back CMD
//bluetooth.println("U,9600,N"); // Temporarily Change the baudrate to 9600, no parity
// 115200 can be too fast at times for NewSoftSerial to relay the data reliably
bluetooth.begin(9600); // Start bluetooth serial at 9600

bluetooth.print("$$$");
delay(2000);
bluetooth.println("c,90A4DE9DEB95");
delay(1000);
bluetooth.println("U,9600,N");
delay(2000);
bluetooth.println("---");
}

void loop(){
// RAT0.addValue(temperature0);
// RAT1.addValue(temperature1);
// RAT3.addValue(temperature3);

//if(bluetooth.available())

int sensorVal0 = analogRead(sensorPin0);
Serial.print(sensorVal0);
bluetooth.print(sensorVal0);
// convert the ADC reading to voltage
float voltage0 = (sensorVal0/1024.0) * 5;
float temperature0 = (voltage0 - .5) * 100;
Serial.print(", ");
bluetooth.print(", ");
Serial.print(temperature0);
bluetooth.print(temperature0);
RAT0.addValue(temperature0);
Serial.print(", ");
bluetooth.print(", ");
Serial.print(RAT0.getAverage());
bluetooth.print(RAT0.getAverage());

int sensorVal1 = analogRead(sensorPin1);
Serial.print(sensorVal1);
bluetooth.print(sensorVal1);
// convert the ADC reading to voltage
float voltage1 = (sensorVal1/1024.0) * 5;
float temperature1 = (voltage1 - .5) * 100;
Serial.print(", ");
bluetooth.print(", ");
Serial.print(temperature1);
bluetooth.print(temperature1);
RAT1.addValue(temperature1);
Serial.print(", ");
bluetooth.print(", ");
Serial.print(RAT1.getAverage());
bluetooth.print(RAT1.getAverage());

int sensorVal3 = analogRead(sensorPin3);
Serial.print(sensorVal3);
bluetooth.print(sensorVal3);
// convert the ADC reading to voltage
float voltage3 = (sensorVal3/1024.0) * 5;
float temperature3 = (voltage3 - .5) * 100;
Serial.print(", ");
bluetooth.print(", ");
Serial.print(temperature3);
bluetooth.print(temperature3);
RAT3.addValue(temperature3);
Serial.print(", ");
bluetooth.print(", ");
Serial.println(RAT3.getAverage());
bluetooth.print(RAT3.getAverage());
delay(2000);
}

Please follow the advice given in the link below when posting code , use code tags and post the code here to make it easier to read and copy for examination

Your post was MOVED to its current location as it is more suitable.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

As requested code as per 'Auto Format' and 'Copy for Forum'

Anything else I need to do?

[code]
const int sensorPin0 = A0;
const int sensorPin1 = A1;
const int sensorPin3 = A2;
const float baselineTemp = 25.0;
#include "RunningAverage.h"

RunningAverage RAT0(10);
RunningAverage RAT1(10);
RunningAverage RAT3(10);

int samples = 0;

#include <SoftwareSerial.h>

int bluetoothTx = 2;  // TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 3;  // RX-I pin of bluetooth mate, Arduino D3

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup(void) {
  Serial.begin(9600);
  Serial.println(__FILE__);
  Serial.print("Version: ");
  Serial.println(RUNNINGAVERAGE_LIB_VERSION);

  // explicitly start clean
  RAT0.clear();
  RAT1.clear();
  RAT3.clear();

  //bluetooth.println("c,90A4DE9DEB95");
  delay(1000);  // Short delay, wait for the Mate to send back CMD
  //bluetooth.println("U,9600,N");  // Temporarily Change the baudrate to 9600, no parity
  // 115200 can be too fast at times for NewSoftSerial to relay the data reliably
  bluetooth.begin(9600);  // Start bluetooth serial at 9600

  bluetooth.print("$$$");
  delay(2000);
  bluetooth.println("c,90A4DE9DEB95");
  delay(1000);
  bluetooth.println("U,9600,N");
  delay(2000);
  bluetooth.println("---");
}


void loop() {
  //  RAT0.addValue(temperature0);
  //  RAT1.addValue(temperature1);
  // RAT3.addValue(temperature3);

  //if(bluetooth.available())

  int sensorVal0 = analogRead(sensorPin0);
  Serial.print(sensorVal0);
  bluetooth.print(sensorVal0);
  // convert the ADC reading to voltage
  float voltage0 = (sensorVal0 / 1024.0) * 5;
  float temperature0 = (voltage0 - .5) * 100;
  Serial.print(", ");
  bluetooth.print(", ");
  Serial.print(temperature0);
  bluetooth.print(temperature0);
  RAT0.addValue(temperature0);
  Serial.print(", ");
  bluetooth.print(", ");
  Serial.print(RAT0.getAverage());
  bluetooth.print(RAT0.getAverage());

  int sensorVal1 = analogRead(sensorPin1);
  Serial.print(sensorVal1);
  bluetooth.print(sensorVal1);
  // convert the ADC reading to voltage
  float voltage1 = (sensorVal1 / 1024.0) * 5;
  float temperature1 = (voltage1 - .5) * 100;
  Serial.print(", ");
  bluetooth.print(", ");
  Serial.print(temperature1);
  bluetooth.print(temperature1);
  RAT1.addValue(temperature1);
  Serial.print(", ");
  bluetooth.print(", ");
  Serial.print(RAT1.getAverage());
  bluetooth.print(RAT1.getAverage());

  int sensorVal3 = analogRead(sensorPin3);
  Serial.print(sensorVal3);
  bluetooth.print(sensorVal3);
  // convert the ADC reading to voltage
  float voltage3 = (sensorVal3 / 1024.0) * 5;
  float temperature3 = (voltage3 - .5) * 100;
  Serial.print(", ");
  bluetooth.print(", ");
  Serial.print(temperature3);
  bluetooth.print(temperature3);
  RAT3.addValue(temperature3);
  Serial.print(", ");
  bluetooth.print(", ");
  Serial.println(RAT3.getAverage());
  bluetooth.print(RAT3.getAverage());
  delay(2000);
}
[/code]
bluetooth.println("c,90A4DE9DEB95");

What are you trying to connect with? What do the status lights tell you about connection? Are you in master mode?

Here's the reference material. Have you reviewed it?

https://learn.sparkfun.com/tutorials/using-the-bluesmirf/all

https://cdn.sparkfun.com/assets/1/e/e/5/d/5217b297757b7fd3748b4567.pdf

This is just plain-vanilla datalogging. I understand the Bluesmurf is a standard SPP device, and therefore you should be able to connect it to hardware serial and use the same code as you already do with the serial monitor.

Probably wrong. Arduino Tx connects to Bluetooth Rx - for rather obvious reasons.

Probably all rubbish but you are right in that any software serial is bad news at 115200. You may find that improper wiring is your only problem.

Thanks for the reply, it told me that it wasn't essentially a software issue and I eventually resolved it by uninstalling the PC's com drivers and then reconnecting.
I did tweek the code from

bluetooth.print("$$$");

to

bluetooth.print("$");
bluetooth.print("$");
bluetooth.print("$");

It now works, but I found that the bluetooth screwed up the signals from analogue sensors. Such is life.

That sounds unlikely unless it is caused by the high baud rate that you are trying to use

I did say I was a novice ( mechanical background), I read that long leads, about 800mm in this case, were susceptible to noise and this was the case with the USB connection hence the averaging. However with averaging the temperature was where I would have expected it, but using the Bluetooth alone the reading is some 10 - 15 degrees C above. I assumed that was the Bluetooth.

I have now switched to a digital sensor that gives the expected temperature in both USB and Bluetooth without the averaging.

Thanks for the help and move. I will not make that mistake again. At the time I wasn't sure it was the right place but the sub sections weren't oblivious to me. I had read the guidance you refer to and with hind sight I can see that it is mentioned in a image box but I glazed over this focusing on the text. Can I suggest you add that this sub forum is the normal starting point in the text.

... Or maybe they were. :grin:

The joys of a dyslexic with a spell checker

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.