Open camo200sx opened 2 years ago
Hello! I've just used this library to communicate between an ESP 32 and a Teensy 4.0 and I had no problems whatsoever.
One thing I noticed, though, is that if you send a lot of data in a small amount of time, some is lost. For my application, I only need about 10 transactions per second and It's been working fine.
Unfortunately, I am still a beginner with the library, so I don't know exactly what could be causing your error. If I must do an educated guess, I would say that there's a sync problem between your boards (must be that you're trying to send a lot of data at once, or the baud rates are not set correctly). Without the actual code, is kind of difficult to actually know what's going on.
Best
Quick update: I also got the STALE PACKET error here. Turns out it was just a bad connection. I moved the cables a little bit and everything started to work again... I guess checking your connections could also be a way to go.
It does work with the ESP32, try using struct __attribute__((packed))
when creating structs to transfer
Hmmm thanks for the help and suggestions.
So I have further tested it. I was trying to get it going using HC-12 modules as they talk in serial but got the stale packet. Also tried with the esp's connected direct, same deal. I then changed the baud rate and it appears it is working @ 4800. I was originally using 1200 as this allows the HC12 to work at the longest possible range (which I need). I'm yet to try the HC-12 at above 1200 yet but direct serial connection is good at 4800
This then leads me to the question. Can it be done at 1200?
I have tried using __attribute__((__packed__))
but no dice @ 1200. I'm quite the noob so unsure if using that correctly. Will post my code :)
SEND
#include <Arduino.h>
#include <Wire.h>
#include "SerialTransfer.h"
SerialTransfer myTransfer;
struct __attribute__((__packed__)) STRUCT
{
char z;
float y;
} testStruct;
void setup()
{
Serial.begin(4800);
Serial2.begin(4800);
myTransfer.begin(Serial2);
testStruct.z = '$';
testStruct.y = 4.5;
}
void loop()
{
myTransfer.sendDatum(testStruct);
delay(500);
}
RECEIVE
#include <Arduino.h>
#include <Wire.h>
#include "SerialTransfer.h"
SerialTransfer myTransfer;
struct __attribute__((__packed__)) STRUCT {
char z;
float y;
} testStruct;
void setup()
{
Serial.begin(4800);
Serial2.begin(4800);
myTransfer.begin(Serial2);
}
void loop()
{
if(myTransfer.available())
{
myTransfer.rxObj(testStruct);
Serial.print(testStruct.z);
Serial.println(testStruct.y);
}
}
I get an error when using the tx/rx datum examples of
ERROR: STALE PACKET
regards