Notifications
Clear all

[Solved] 433 mhz receiver get confuse after receiving some data...

5 Posts
2 Users
0 Likes
774 Views
(@sly442)
Member
Joined: 4 years ago
Posts: 5
Topic starter  

Hi All,

I'm doing the remote control project with 2 Arduino's uno and the H bridge motor control. As seen in the articles "Using Inexpensive 433MHz Transmit and Receive Modules with Arduino" and "Wireless Joystick for Arduino Robot Car with nRF24L01+"

So I mixed 2 sketchs to be able to have it work with the RadioHead library and ASK. 

After several hours research and tries I do received the value of axes Y and X as long as I don't touch the joystick, When I move it it freezes.

 

My goal was to send an array without using string to send it but I tought sending an array value that could contain the x and y value at the same time like " joyVal[2] = {joypoVert, joyposHorz} " but I wasn't able to have it work. So I went back to the String construction of the axes.

  

[code] 

// Transmiter (Joystick)

...

void loop()
{

// Read the Joystick X and Y positions
joyposVert = analogRead(joyVert);
joyposHorz = analogRead(joyHorz);

str_joyposVert = String(joyposVert);
str_joyposHorz = String(joyposHorz);

str_out = str_joyposVert +","+ str_joyposHorz; // max size of the array = 9 cararcters

// Unit Test

Serial.print("joyposVert = ");
Serial.println(joyposVert);
Serial.print("joyposHorz = ");
Serial.println(joyposHorz);

static char *msg = str_out.c_str();

rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
delay(50); // Wait a bit before next transmission

----------------

 

// receiver

... 

void loop

{
uint8_t buf[9]; // string of xxxx,xxxx (9)
uint8_t buflen = sizeof(buf);
if (rf_driver.recv(buf, &buflen))
str_out = ((char *)buf);

{
for (int i = 0; i < str_out.length(); i++){
if (str_out.substring(i, i+1) == ","){
str_joyposVert = str_out.substring(0, i);
str_joyposHorz = str_out.substring(i+1);
}
}

joyposVert = str_joyposVert.toInt();
joyposHorz = str_joyposHorz.toInt();

// Unit Test reading values

Serial.print("joyposVert = ");
Serial.println(joyposVert);
Serial.print("joyposHorz = ");
Serial.println(joyposHorz);

[/code]

 

The receiver Serial monitor show this:

00:09:38.157 -> Driver available
00:09:38.194 -> joyposVert = 502
00:09:38.194 -> joyposHorz = 508
00:09:38.229 -> joyposVert = 502
00:09:38.229 -> joyposHorz = 508
00:09:38.267 -> joyposVert = 502
00:09:38.267 -> joyposHorz = 508
00:09:38.301 -> joyposVert = 502
00:09:38.335 -> joyposHorz =

 

 

So if someone could help me understand the way to do this I would very appreciate.

 

Thank you.


   
Quote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
 

@sly442

Them [code] and [/code] doesn't work here.

https://forum.dronebotworkshop.com/question-suggestion/sticky-post-for-editing/#post-4939

 


   
ReplyQuote
(@sly442)
Member
Joined: 4 years ago
Posts: 5
Topic starter  

   
ReplyQuote
(@sly442)
Member
Joined: 4 years ago
Posts: 5
Topic starter  

   
ReplyQuote
(@sly442)
Member
Joined: 4 years ago
Posts: 5
Topic starter  

The problem I ran into seem's to be an memory overflow.

 

How can I solve this?

 

From the point where the data I am receiving is an array of 3 numbers ex: (255, 0, 0) should I use de realloc function and free it after?


   
ReplyQuote