Adding and using the SerialTransfer.h library in my sketch i go to 99% memory for global variables leaving only 7 bytes free. Before adding that library 60% was occupied. Any suggestions ? Arduino Uno board...
Don't use that library for your project
Please show your code before and after adding the libary
the extra code that i use with that library is the folowing. I use it to send a struct to esp8266-01 board. i have spent countless hours trying without the library but it doesent work well... but with the library everything is perfect in the tests but consumes a lot or resources ! The code uses 43% of Dynamic memory for global variables
// send to esp8266
#include "SerialTransfer.h"
SerialTransfer myTransfer;
struct __attribute__((packed)) STRUCT {
float x=4.5;
float y=36.7;
uint8_t p=1;
uint8_t z=1;
float MOB_course=312.85;
uint32_t MOB_dist=7545;
uint8_t a=0x38;
// float MOB1_course=320.5;
// char MOB_cardinal[3]="NNW";
} txData;
// timing variables for sending frequently to 8266
unsigned long prevUpdateTime = 0;
unsigned long updateInterval = 500;
void setup() {
Serial.begin(115200);
myTransfer.begin(Serial);
}
void loop() {
// updates the data in txData for 8266
updateDataToSend();
// this function sends the data to 8266
transmitData();
}
//-------------- updateDataToSend() ----------------------------------
void updateDataToSend() {
if (millis() - prevUpdateTime >= updateInterval) {
prevUpdateTime = millis();
//test data
int V1 = random(1, 10);
txData.x=1.33*V1;
int V2 = random(1, 90);
txData.y = 1.33*V2;
txData.p=1;
txData.z=2;
txData.MOB_course=310.05;
txData.MOB_dist=1966;
}
}
//----------------- transmitData() -------------------------------
//sends data to 8266
void transmitData() {
myTransfer.sendDatum(txData);
}
Alternate library or method that you have ?
I don't even know what the library does (never heard of it before today), so I don't know if I have an alternative.
Maybe take a look at the source, and see what you can cherry-pick, and see what you really don't need.
Every instantiation of the lib's base class has two 250+ byte buffers, so it's not something you want to use on low memory devices like the Uno (unless your sketch is fairly simple). Not a problem on Teensy 3.X and 4.X devices, though (I highly recommend them)
Edit: The only real alternative to this lib would be EasyTransfer (sort of inspired SerialTransfer, but is much less flexible)
Is the library just transfer the defined structure from one mcu to another? Why you need a library for it?
Thanks for your reply !
I try EasyTransfer and it works on Arduino uno side (transmit) but it doesent seem to work (for me) on the receiver side esp8266-01...(after some attends). Thinking to return researching to the simple struct on both sides that does not work well (and make me searching for libraries or other ways to pass the data...) Maybe i will try sprintf() to combine the data and send them as sting
Thanks anyway !
For unknown reason for me with only the first 3 (x,y,p, variables) the struct work on both sides well. If adding more variables same type (float) and keeping identical structure on both sides data received is not ok...
What the arduino boards do you use in both sides?
The esp8266 expects 32 bit alignment on 4 byte data types. Your struct does not have that hence the
attribute((packed))
hack. Which means there is extra code generated on the esp8266 to handle that.
If you have control over the struct I would suggest reformatting to get the proper alignment, getting rid of the packed and try a simple data transfer. For example move p and z down to just before or after a.
I consider the packed attribute to be an abomination only to be used when you have no other choice.
Transferring an entire struct byte by byte is not exactly trivial. While a lib isn't 100% necessary, it is very nice to have and highly suggested. Plus, SerialTransfer.h has a number of other added features that would be difficult to implement in a custom sketch every time you want to use them.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.