SerialTransfer icon indicating copy to clipboard operation
SerialTransfer copied to clipboard

Does this work with esp32?

Open camo200sx opened this issue 3 years ago • 5 comments
trafficstars

I get an error when using the tx/rx datum examples of

ERROR: STALE PACKET

regards

camo200sx avatar Feb 27 '22 18:02 camo200sx

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

felipe-mello avatar Feb 27 '22 18:02 felipe-mello

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.

felipe-mello avatar Feb 27 '22 18:02 felipe-mello

It does work with the ESP32, try using struct __attribute__((packed)) when creating structs to transfer

PowerBroker2 avatar Feb 28 '22 00:02 PowerBroker2

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);
  }
}

camo200sx avatar Feb 28 '22 04:02 camo200sx