Hello everyone,
i'm having a problem with SerialTransfer library. i want to send a data from my NodeMcu to an arduino nano so i look for a library that can help me with that, and i found this SerialTransfer library.
I've tried to look for the answer in the topic with the serialTransfer, and tried it but in my case it still happens.
i tried the example code that comes with the library and modified the example code for Node MCU and my Nano.
I'm commenting the array cause when i try to send array, i get ERROR: CRC_ERROR in teh receiver side.
This is the code:
NodeMCU code (transmitter)
#include "SerialTransfer.h"
#include <SoftwareSerial.h>
#include <ESP8266WiFi.h>
//setting software serial
SoftwareSerial serialEsp(4,5);// 4-> D2 (RX) 5-> D1 (TX)
SerialTransfer myTransfer;
struct STRUCT {
char z;
float y;
} testStruct;
//char arr[] = "hello";
void setup()
{
Serial.begin(115200);
serialEsp.begin(115200);
myTransfer.begin(serialEsp);
testStruct.z = '$';
testStruct.y = 4.50;
}
void loop()
{
// use this variable to keep track of how many
// bytes we're stuffing in the transmit buffer
uint16_t sendSize = 0;
///////////////////////////////////////// Stuff buffer with struct
sendSize = myTransfer.txObj(testStruct, sendSize);
///////////////////////////////////////// Stuff buffer with array
//sendSize = myTransfer.txObj(arr, sendSize);
///////////////////////////////////////// Send buffer
myTransfer.sendData(sendSize);
delay(2000);
}
And The code for my Nano (receiver) is:
#include "SerialTransfer.h"
#include <SoftwareSerial.h>
//setting software serial
SoftwareSerial serialNano(2,3);//RX = 2 TX = 3
SerialTransfer myTransfer;
struct STRUCT {
char z;
float y;
} testStruct;
//char arr[6];
void setup()
{
Serial.begin(115200);
serialNano.begin(115200);
myTransfer.begin(serialNano);
}
void loop()
{
if(myTransfer.available())
{
// use this variable to keep track of how many
// bytes we've processed from the receive buffer
uint16_t recSize = 0;
recSize = myTransfer.rxObj(testStruct, recSize);
Serial.print(testStruct.z);
Serial.print(testStruct.y);
Serial.print(" | ");
//recSize = myTransfer.rxObj(arr, recSize);
//Serial.println(arr);
}
}
wen i run those code on my system i only get
$0.00 | $0.00 | $0.00 |
It also happen when i tried to change the y with int. i get $0 on the receiver side.
i dont know where did i do wrong....
Thanks in advance
im sorry
i don't see this line of code in the uart_rx_data.ino in the example file.
i just add the softwareserial pin an commenting the array. not deleting any other line.
Hello @gfvalvo, sorry for the delay...just took a day off from work yesterday.
the code is same with the example just add the SoftwareSerial pin.
here is the code on NodeMcu as transmitter:
#include <ESP8266WiFi.h>
#include "SerialTransfer.h"
#include <SoftwareSerial.h>
SerialTransfer myTransfer;
//setting software serial
SoftwareSerial serialEsp(4,5);// 4-> D2 (RX) 5-> D1 (TX)
struct __attribute__((packed)) STRUCT {
char z;
float y;
} testStruct;
char arr[] = "hello";
void setup()
{
Serial.begin(115200);
serialEsp.begin(115200);
myTransfer.begin(serialEsp);
testStruct.z = '$';
testStruct.y = 4.5;
}
void loop()
{
// use this variable to keep track of how many
// bytes we're stuffing in the transmit buffer
uint16_t sendSize = 0;
///////////////////////////////////////// Stuff buffer with struct
sendSize = myTransfer.txObj(testStruct, sendSize);
///////////////////////////////////////// Stuff buffer with array
sendSize = myTransfer.txObj(arr, sendSize);
///////////////////////////////////////// Send buffer
myTransfer.sendData(sendSize);
delay(2000);
}
And here is the code for Nano as the receiver:
#include "SerialTransfer.h"
#include <SoftwareSerial.h>
SerialTransfer myTransfer;
//setting software serial
SoftwareSerial serialNano(2,3);//RX = 2 TX = 3
struct __attribute__((packed)) STRUCT {
char z;
float y;
} testStruct;
char arr[6];
void setup()
{
Serial.begin(115200);
serialNano.begin(115200);
myTransfer.begin(serialNano);
}
void loop()
{
if(myTransfer.available())
{
// use this variable to keep track of how many
// bytes we've processed from the receive buffer
uint16_t recSize = 0;
recSize = myTransfer.rxObj(testStruct, recSize);
Serial.print(testStruct.z);
Serial.print(testStruct.y);
Serial.print(" | ");
recSize = myTransfer.rxObj(arr, recSize);
Serial.println(arr);
}
}
After i download those code to my board i'm only getting ERROR: CRC_ERROR on the receiver side.