Hi there,
I have a kinda strange problem with communication between 2 arduinos using wifi modules. My goal is sending data to RC car and then send some data back (voltage of battery and RPM of the engine). For that, I need to convert all data to the string, send it and decode at the opposite side. I've already successfully established bi-directional communication but only with sending and receiving just one value (without strings) or only with string at one side (one arduino makes string and sends it, second successfully receives and rotates servos). I can send "non-stringed" value back and receive it as well. But if I try to send and receive string on both sides, it stops working. I discovered, that "Joystick" program can run until I start "Servo". Immediately after it receives 1st message, it stops at radio.write(&stringy[1], sizeof(stringy[1]));. (This function isn't processed.) Arduino is absolutely lagged and only helps to disconnect it from a power supply.
Servo program runs without any issues, I think.
Memset have evidently no effect.
However, I don't need to send strings if there are any other solutions, but I don't know any.
// Joystick code
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define online 3
#define offline 9
RF24 radio(7, 8); // CNS, CE
const byte addresses[][6] = {"00001", "00002"};
boolean overeni = 0;
char stringy[][20] = {"odeslatJoystick", "prijatoJoystick"};
int potValue;
int potValue2;
int angleValue;
int angleValue2;
void setup() {
Serial.begin(9600);
pinMode(A2, INPUT);
pinMode(A0, INPUT);
pinMode(3, OUTPUT);
pinMode(9, OUTPUT);
radio.begin();
radio.openWritingPipe(addresses[1]); // 00001
radio.openReadingPipe(1, addresses[0]); // 00002
radio.setPALevel(RF24_PA_MIN);
}
void loop() {
Serial.println("Zacatek loopu");
// VYSILANI
delay(5);
radio.stopListening();
Serial.println("Vysilani zahajeno");
potValue = analogRead(A0);
angleValue = map(potValue, 0, 1023, 0, 180);
potValue2 = analogRead(A2);
angleValue2 = map(potValue2, 0, 1023, 0, 180);
Serial.println("Hodnoty precteny a namapovany");
sprintf(stringy[1], "%d,%d", angleValue, angleValue2);
Serial.println("String vytvoren");
radio.write(&stringy[1], sizeof(stringy[1]));
Serial.println("Data odeslana");
memset( stringy[1], 0, sizeof( stringy[1]));
// PRIJIMANI
delay(5);
radio.startListening();
if (!radio.available());
Serial.println("If prijimani");
radio.read(&stringy[0], sizeof(stringy[0]));
sscanf(stringy[0], "%d", &overeni);
Serial.println("Prijato");
Serial.println(overeni);
if (overeni == 1) {
digitalWrite(online, HIGH);
digitalWrite(offline, LOW);
}
else {
digitalWrite(online, LOW);
digitalWrite(offline, HIGH);
}
memset( stringy[0], 0, sizeof( stringy[0]));
}
// Servo code
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
RF24 radio(7, 8); // CNS, CE
const byte addresses[][6] = {"00001", "00002"};
boolean overeni = 0;
int angleV = 90;
int angleV2 = 90;
char stringy[][20] = {"odeslatServo", "prijatoServo"};
Servo myServo;
Servo myServo2;
void setup() {
Serial.begin(9600);
pinMode(5, OUTPUT);
pinMode(3, OUTPUT);
myServo.attach(5);
myServo2.attach(3);
radio.begin();
radio.openWritingPipe(addresses[0]); // 00002
radio.openReadingPipe(1, addresses[1]); // 00001
radio.setPALevel(RF24_PA_MIN);
}
void loop() {
Serial.println("Zacatek loopu");
// PRIJIMANI
delay(5);
radio.startListening();
if ( radio.available()) {
Serial.println("If proslo");
while (radio.available()) {
Serial.println("While proslo");
// Inty
radio.read(&stringy[0], sizeof(stringy[0]));
sscanf(stringy[0], "%d,%d", &angleV, &angleV2);
Serial.println("Prijmuto");
Serial.println(angleV);
Serial.println(angleV2);
myServo.write(angleV);
myServo2.write(angleV2);
}
}
memset( stringy[0], 0, sizeof( stringy[0]));
// VYSILANI
delay(5);
radio.stopListening();
sprintf(stringy[1], "%d", overeni);
Serial.println("String vytvoren");
radio.write(&stringy[1], sizeof(stringy[1]));
Serial.println("Overeni odeslano");
memset( stringy[1], 0, sizeof( stringy[1]));
}