when i try to print 10 it gives two numbers one ascii value for 1 and one ascii value of 0 so its like two different numbers but one number how do i get them to be like 10 and not like
1
0
1
0
1
0
and also i am trying to get more than one value like one for one servo and the other is for the other servo and when i read the serial value it just gives a value you can only store in one variable how do i separate them for different servos.
Your code seems to be a state secret and your headline misleading. At a guess your problem has nothing to do with HC-05 per se, and quite a lot to do with everything else. You imply that you are getting the wrong result, but the fact that you are getting a result at all strongly suggests that there is nothing wrong with Bluetooth.
i am trying to send data with hc 05 for my aurdino mega and uno. i had a problem with it, it was giving me data but it was in ascii then i tried to use atoi, that didnt work so i just subtracted 48 from it so now the problem is that i can send multiple data with hc 05 and on the slaves side it becomes one piece of data so i am trying to figure out how to seperate them for different servos.
master code:
void setup() {
// put your setup code here, to run once:
Serial.begin(38400);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.write("10");
Serial.write("23");
}
Slaves code:
void setup() {
// put your setup code here, to run once:
Serial.begin(38400);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available()>0)
{
int x=Serial.read();
x=x-48
Serial.println(x)
}
}
when i run the code i get this in the serial moniter.
1
0
2
3
1
0
2
3
1
0
2
3
1
0
2
3
1
0
2
3
how do i store different values in different variables.
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.
Serial.write("10");
Serial.write("23");
Try Serial.print instead and first send it to a terminal on a phone. I assume you have properly configured HC-05 to run at 38400?
The results are still the same. i Am trying to get 10 potentiometers to control 10 Servos through hc-05.
The serial input basics tutorial may help.
i looked at the serial inputs but it seems like i can only receive integer from the hc 05.
Default Bd setting of HC-05 is 9600.
You are operating it at 38400 Bd for which you have configured it, hopefully.
Your transmission codes are:
Serial.write("10"); //0x31 and 0x30 are being transmitted
Serila.write("23"); //0x32 and 0x33 are being transmitted
Your reception codes cold be like these:
myData[0] = Serial.read();
myData[1] = Serial.read();
myData[2] = '\0';
int x = atoi(myData);
Serial.print(x, DEC) ; //shows: 10
//-------------------------------------
omg thank you soo much it worked so i modified it to send 10 values and receive ten values the code is
master:
void setup()
{
Serial.begin(38400);
}
void loop(){
Serial.print("111");
Serial.print("222");
Serial.print("333");
Serial.print("444");
Serial.print("555");
Serial.print("666");
Serial.print("777");
Serial.print("888");
Serial.print("999");
Serial.print("000");
}
slave:
void setup()
{
Serial.begin(38400);
}
void loop()
{
if(Serial.available() >= 0){
char number1[4] = { Serial.read(), Serial.read() , Serial.read() , '\0'};
char number2[4] = { Serial.read(), Serial.read() , Serial.read() , '\0' };
char number3[4] = { Serial.read(), Serial.read() , Serial.read() , '\0' };
char number4[4] = { Serial.read(), Serial.read() , Serial.read() , '\0' };
char number5[4] = { Serial.read(), Serial.read() , Serial.read() , '\0' };
char number6[4] = { Serial.read(), Serial.read() , Serial.read() , '\0' };
char number7[4] = { Serial.read(), Serial.read() , Serial.read() , '\0' };
char number8[4] = { Serial.read(), Serial.read() , Serial.read() , '\0' };
char number9[4] = { Serial.read(), Serial.read() , Serial.read() , '\0' };
char number10[4] = { Serial.read(), Serial.read() , Serial.read() , '\0' };
Serial.print("number1: ");
Serial.println(number1);
Serial.print("number2: ");
Serial.println(number2);
Serial.print("number3: ");
Serial.println(number3);
Serial.print("number4: ");
Serial.println(number4);
Serial.print("number5: ");
Serial.println(number5);
Serial.print("number6: ");
Serial.println(number6);
Serial.print("number7: ");
Serial.println(number7);
Serial.print("number8: ");
Serial.println(number8);
Serial.print("number9: ");
Serial.println(number9);
Serial.print("number10: ");
Serial.println(number10);
}
}
idk why but the values of each number keep changing like number one would be 111 then it would be different number i want number one to stay 111. and i did configure the hc 05 baudrate to be 38400.
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.
Note that what you are doing here is really just a "hello world", which is fine as proof of concept. If you get serious with this in matters of real data, things may get a bit more involved, and you should keep reply #6 close to hand.
i set my hc 05 as slave and master with the baud rate of 38400
master code:
void setup()
{
Serial.begin(38400);
}
void loop(){
Serial.print("111");
Serial.print("222");
Serial.print("333");
Serial.print("444");
Serial.print("555");
Serial.print("666");
Serial.print("777");
Serial.print("888");
Serial.print("999");
Serial.print("000");
}
slave code:
void setup()
{
Serial.begin(38400);
}
void loop()
{
if(Serial.available() >= 0){
char number1[4] = { Serial.read(), Serial.read() , Serial.read() , '\0'};
char number2[4] = { Serial.read(), Serial.read() , Serial.read() , '\0' };
char number3[4] = { Serial.read(), Serial.read() , Serial.read() , '\0' };
char number4[4] = { Serial.read(), Serial.read() , Serial.read() , '\0' };
char number5[4] = { Serial.read(), Serial.read() , Serial.read() , '\0' };
char number6[4] = { Serial.read(), Serial.read() , Serial.read() , '\0' };
char number7[4] = { Serial.read(), Serial.read() , Serial.read() , '\0' };
char number8[4] = { Serial.read(), Serial.read() , Serial.read() , '\0' };
char number9[4] = { Serial.read(), Serial.read() , Serial.read() , '\0' };
char number10[4] = { Serial.read(), Serial.read() , Serial.read() , '\0' };
Serial.print("number1: ");
Serial.println(number1);
Serial.print("number2: ");
Serial.println(number2);
Serial.print("number3: ");
Serial.println(number3);
Serial.print("number4: ");
Serial.println(number4);
Serial.print("number5: ");
Serial.println(number5);
Serial.print("number6: ");
Serial.println(number6);
Serial.print("number7: ");
Serial.println(number7);
Serial.print("number8: ");
Serial.println(number8);
Serial.print("number9: ");
Serial.println(number9);
Serial.print("number10: ");
Serial.println(number10);
}
}
the problem is that when it prints it to the serial moniter the values of each number keep changing for example the first time number one would be 111 then it would be a different number and then a different number. how do i get number one to stay 111 and not change same for all the other numbers.
i already looked at the serial inputs it just made me more confused.
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.
what do you mean?
This looks familiar. Why a new thread?
In reply #6 of your other thread I linked the serial input basics tutorial. Read that. Play with the code.
I thought you said that you had this working? If that is not the case, the chances are pretty good that it has something to do with data buffering. I am only saying that because your transmission is a huge torrent of data that is never ending, and I can only guess at the result, having never experienced it.
I submit you should not bother trying to fix this problem. It is just a silly exercise that has no real purpose, but I believe that you have proven that there is nothing wrong with Bluetooth, or your use of it. In short, the headline of your topic is wrong. Your problem is entirely to do with the absence of a sensible objective. If you embarked on a proper real-life project, you will probably be quite OK. Indeed, the fact the you have successfully reconfigured Bluetooth to run at 38400, and auto-connected, strongly suggests that you already know what you need to know about HC-05
my data is 30 bytes i think i should be able to send 32 bytes. how do i fix it? i really need my data to be precise for my robot. this is not an exercise i need it for my project i need 10 potentiometer to control 10 different servos over Bluetooth, the only problem i was having was with transferring data and receiving it with hc 05. is there any way to fix this problem.
daudhtm:
my data is 30 bytes i think
I think you think wrong. It is a never-ending stream at lightning speed, with not the slightest trace of any control, timing, markers, or logic. In short, the code is junk, hence my previous comment. I don't know anything about robots, but I can't imagine any robot making use of code remotely like this. You can't be the first person on this forum to ever want to send data to a robot, and I suggest you look in the robot section for some sensible inspiration, rather than flog this dead horse. You might even find that my previous comment about using serial print, while appropriate at the time, was not actually appropriate for your real purpose.
I repeat, this is not an HC-05 problem. I seem to recall mentioning that a few days ago. You also seem to be disinterested in checking out serial input basics. You might find some stuff therein about buffers and markers.
@daudhtm, do not cross-post. Threads merged.
I am really sorry for the inconvenience, I am a beginner forgive me for all the trouble. I have a question about hc-05 I see many youtube videos where for the slave people just write something like serial.write("10")for slave
and for the slave they do
if(Seiral.available()>=0);
{
int x=Serial.read();
}
and it works for them and they control servo with potentiometer like this why is it not working for me.
Second of all can someone please help me i looked at the serial inputs and used their code and i get the same result, and sometimes when i turn on the aurdino i receive reverse question marks and i reset it then it works .
daudhtm:
I see many youtube videos where for the slave people just write something
You say that, but I bet you didn't see code like you wrote in reply#9 on YouTube, and that is where your problem lies. All you need do is:
- stop insisting that you have an HC-05 problem,
- concede that checking the serial input link offered you on several occasions might be a pretty good idea, and
- check what all the other servo<>potentiometer guys are doing in the appropriate forum.
You might also note that it doesn't matter whether they are using Bluetooth or wires, the job is the same.