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.
Them [code] and [/code] doesn't work here.
https://forum.dronebotworkshop.com/question-suggestion/sticky-post-for-editing/#post-4939
Thank you @robotBuilder for the advice.
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.
So here's the 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); // Construction of String str_out = str_joyposVert +","+ str_joyposHorz; // max size of the array = 9 cararcters // 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() { delay(10); if (rf_driver.available()) Serial.println("Driver available"); { 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(); // Test reading value Serial.print("joyposVert = "); Serial.println(joyposVert); Serial.print("joyposHorz = "); Serial.println(joyposHorz); --------
The receiver Serial monitor show this and then Freeze when I move the joystick
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.
I kept searching and I found some answer to my problem after reading a post about pointers in C .(FreeCodeCamp 11 august 2020 by Srijan)
So now me sketch is able to read the data I sent with my Joystick but it still freezes after few seconds and I can't figure out a pattern.
The driver seems not available, I think so because i Add a serial print to see if it's available or not.
So my transmitter is sending Motorcontrol array [3]
And my receiver reconstruct the array and then the values are sent to the Ln298 H-Bridge motor.
This is my receiver code if anyone could help.
void loop() { delay(100); if (rf_driver.available()) Serial.println("Driver available"); else Serial.println("Driver Stoped"); { int buf[] = {0,0,0}; uint8_t buflen = sizeof(buf); if (rf_driver.recv((uint8_t*)buf, &buflen)){ for (int i = 0; i < 3; i++) { motorcontrol[0] = buf[0]; motorcontrol[1] = buf[1]; motorcontrol[2] = buf[2];
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?