Hello Everybody,
I'm using a RN-42 module in order to send two data sensors (pressure (analog data) and mass flow (i2c data)) from arduino uno to my PC, visualizing them on serial monitor.
I use also a slide switch in order to keep the bluetooth and the sensor off and on as I want.
The problem comes when I switch on the circuit, because in order to visualize the data from bluetooth COM port I have to visualize them first from serial Arduino COM port.
After have opened the serial monitor of arduino COM, I can visualize the data also from the serial monitor of bluetooth COM.
Everytime i switch off and on the circuit, I have to do this.
Which could be the problem?
It could be a code problem or a bluetooth one?
I post the code below, hoping to be more clear:
#include <Wire.h>
#define address 0x40
#define offset 32768
#define scale_factor 120 // from sensor datasheet
unsigned int d;
byte a,b,c;
int a1,b1,c1;
float flow;
void setup() {
Wire.begin();
Serial.begin(9600);
Wire.beginTransmission(address);
Wire.write(16);
Wire.write(0);
Wire.endTransmission();
}
void loop() {
Wire.requestFrom(address,3); // to read flow sensor byte
a=Wire.read();
b=Wire.read();
c=Wire.read();
a1=int(a);
b1=int(b);
d=(a1*256)+b1;
Serial.print("\t");
flow=((d-offset)/float(scale_factor));
Serial.print(flow);
Serial.print("\t");
int sensorValue=analogRead(A0);
float pressure=(sensorValue*0.3965)-40.3512-160; //from pressure sensor datasheet
Serial.print("|");
Serial.print("\t");
Serial.println(pressure);
delay(30);
}