Hi,
I’m trying to extract data that I send to a bluetooth module (DSDtech HM-19) but the problem is that if I send a number, the one received by the arduino isn’t the same. If I send 1, the arduino receives 49 or if I send 22 the arduino receives 5050. It appears to be ASCII code but I can’t find a way to convert it if it is more than a simple number ( - ‘0’). Is there a function or something to do this ?
Use Serial.write(f)
Welcome to the forum
Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'
Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination
You could convert each character as it is read instead of trying to convert a multi digit number all at once
Or you could put each character in an array of chards as it is read, add a '\0' to the end to turn it into a C style string then use atio() to convert it to an integer
Or you could use Serial.parseInt() to do teh job for you
Using char instead of int didn’t change anything but here is the complete project, I just want to send a frequence to my arduino so that it plays it.
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(2,3);
char c = '0';
int f;
void setup() {
pinMode(12, OUTPUT);
Serial.begin(9600);
BTSerial.begin(9600);
}
void loop() {
if (BTSerial.available()) {
c = BTSerial.read();
f = c-'0';
}
if (c == 0) {
noTone(12);
Serial.print(c);
BTSerial.print("OFF");
}
else {
tone(12,f);
Serial.print(c);
BTSerial.print("ON");
}
}
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.