I am making a robotic hand with flex sensors and servo motors. I want to connect both of them with wireless communication therefore I am using node mcu , but the problem is there are 5 servo motors so it requires 5 values to be sent at a time. Is there any way so that I can send an array of values from one node mcu to another????
If there was only one value, how would you send it?
Simply using String data = "**"
and then using the data variable
First, sending numbers as a String is very inefficient. You will first need to convert the number to a String on one side, and then do the reverse conversion on the other. If the data is an integer, this is how it should be sent
And secondly, I asked how you will send, for example, your string
Yes I agree using string will be inefficient (though I gave it as an e
I made both client and server as 2 different node mcu
void setup() {
WiFi.softAPConfig(local_IP, gateway, subnet);
WiFi.softAP(ssid, password);
Serial.begin(115200);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
server.begin();
used this in setup and
WiFiClient client = server.available();
if (client) {
if (client.connected()) {
client.flush();
for (int i=0;i<5;i++){
client.println(msg[i]); // sends the answer to the clien
}
Serial.println("success");
}
client.stop(); // tarminates the connection with the client
}
delay(500);
this in void loop
Sorry but I don't see in the code what is msg[] and where are you receive msg in the other side
#include <ESP8266WiFi.h>
#include <SPI.h> //the communication interface with the modem
WiFiServer server(80);
char ssid[20] = "robotic_arm";
char password[20] = "kunal_manan";
IPAddress local_IP(192,168,1,100);
IPAddress gateway(192,168,1,2);
IPAddress subnet(255,255,255,255);
// int data[0];
int msg[5]; //Total number of data to be sent (data package)
// //define the flex sensor input pins
int flex_5 = D4;
int flex_4 = D3;
int flex_3 = D2;
int flex_2 = D1;
int flex_1 = D0;
// //define variables for flex sensor values
int flex_5_val;
int flex_4_val;
int flex_3_val;
int flex_2_val;
int flex_1_val;
void setup() {
WiFi.softAPConfig(local_IP, gateway, subnet);
WiFi.softAP(ssid, password);
Serial.begin(115200);
server.begin();
delay(10000);
Serial.println(WiFi.softAPIP());
// put your setup code here, to run once:
}
void loop() {
// check the network status connection once every 10 seconds:
delay(1000);
//Serial.println(WiFi.softAPgetStationNum());
flex_5_val = analogRead(flex_5);
flex_5_val = map(flex_5_val, 630, 730, 80, 20);
flex_4_val = analogRead(flex_4);
flex_4_val = map(flex_4_val, 520, 710, 70, 175);
flex_3_val = analogRead(flex_3);
flex_3_val = map(flex_3_val, 510, 680, 140, 10);
flex_2_val = analogRead(flex_2);
flex_2_val = map(flex_2_val, 580, 715, 90, 175);
flex_1_val = analogRead(flex_1);
flex_1_val = map(flex_1_val, 550, 700, 90, 175);
msg[0] = flex_5_val;
msg[1] = flex_4_val;
msg[2] = flex_3_val;
msg[3] = flex_2_val;
msg[4] = flex_1_val;
WiFiClient client = server.available();
if (client) {
if (client.connected()) {
client.flush();
for (int i=0;i<5;i++){
client.println(msg[i]);
} // sends the answer to the clien
Serial.println("success");
}
client.stop(); // tarminates the connection with the client
}
delay(500);
}
this is the complete code for transmitter
I was able to establish connection between the two. For the sake of correction while checking a single data we got the output as -1 -1 -1 -1...
So there is a problem in sending data.
#include <ESP8266WiFi.h>
#include <Servo.h> //the library which helps us to control the servo motor
#include <SPI.h> //the communication interface with the modem
//define the servo name
Servo myServo1;
Servo myServo2;
Servo myServo3;
Servo myServo4;
Servo myServo5;
int msg[5];
int abc;
char ssid[] = "robotic_arm"; // SSID of server
char pass[] = "kunal_manan"; // password of server
//IPAddress localIp(192, 168, 15, 26);
//IPAddress gw(192, 168, 1, 100);
//IPAddress sn(255, 255, 255, 0);
IPAddress server(192, 168, 1, 100);
WiFiClient client;
void setup() {
//define the servo input pins
// myServo1.attach(15); //D0
// myServo2.attach(16); //D1
// myServo3.attach(17); //D2
// myServo4.attach(18); //D3
// myServo5.attach(19); //D4
Serial.begin(115200);
while (!Serial) {
;
}
Serial.println();
delay(2000);
// WiFi.config(localIp, gw, sn);
WiFi.begin(ssid, pass);
Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println();
Serial.print("Connected, IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
// put your main code here, to run repeatedly:
//
client.connect(server, 80);
client.println("Hello server! Are you sleeping?\r"); // sends the message to the server
// if (client.available()) {
// for (int i = 0; i < 5; i++) {
// msg[i] = client.read();
// }
// }
//if(client.available()){
// msg[0]=client.read();
//}
//if(client.available()){
// msg[1]=client.read();
//}
//if(client.available()){
// msg[2]=client.read();
//}
//if(client.available()){
// msg[3]=client.read();
//}
//if(client.available()){
// msg[4]=client.read();
//}
if(client.available()){
abc=client.read();
}
client.flush();
Serial.println(abc);
// for (int i = 0; i < 5; i++) {
// Serial.println(msg[i]);
// }
// myServo1.write(msg[0]); //D0
// myServo2.write(msg[1]); //D1
// myServo3.write(msg[2]); //D2
// myServo4.write(msg[3]); //D3
// myServo5.write(msg[4]); //D4
delay(1000);
}
code for receiver
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.