Replies: 2 comments 2 replies
-
You're very welcome. =^/.^= For ESP32 targets: Currently, there isn't a built-in way to assign custom pins as of yet. When I add it in, the documentation will reflect this. If you need more information, CRSF for Arduino is reasonably documented and comes with its own API Reference, plus a section on resource management. When you're using CRSF for Arduino in particular, it is strongly #include "CRSFforArduino.h"
/* Declare CRSF for Arduino as a null pointer. */
CRSFforArduino *crsf = nullptr;
void setup()
{
/* Allocate memory and a custom UART to CRSF for Arduino. */
crsf = new CRSFforArduino(&Serial1);
/* Allocate and initialise the hardware required by CRSF for Arduino. */
if (crsf->begin() == true)
{
/* Hardware allocated successfully.
The rest of CRSF for Arduino's functionality should be initialised here.
Anything else that depends on CRSF for Arduino `MUST` be initialised here, as well.
EG Servos, motor controllers etc.
From Woodchuck's example, CRSF for Arduino may try to internally initialise Serial1
with its default settings. So, it `SHOULD` be overridden here. */
// 1. Clean out both Tx and Rx buffers.
Serial1.flush();
while(Serial1.available())
{
Serial1.read();
}
// 2. De-allocate the previous lot of configurations, and wait a little.
Serial1.end();
delay(100); // This delay `MAY NOT` be necessary.
// 3. Re-initialise `Serial1` with the required configuration.
Serial1.begin(420000, SERIAL_8N1, D8, D7);
// 4. Lastly, ensure there's no "garbage" in the UART's Rx buffer.
while(Serial1.available())
{
Serial1.read();
}
}
else
{
/* Hardware allocation failed.
Anything that succeeded during the call to 'begin()' MUST be
freed to avoid hardware and memory leaks. */
crsf->end();
delete crsf;
crsf = nullptr;
/* You may choose to stop here, although it is `RECOMMENDED` that you avoid this practice,
because you could be starving other tasks and/or parts of your firmware that `MAY` run, but
aren't dependent on CRSF for Arduino.
If you do this, either do a 20 ms delay _or_ ensure 'yield()' is called, especially if you're using
an ESP32 target. */
// while (1)
// {
// delay(20);
// }
}
}
void loop()
{
/* CRSF for Arduino's API `MUST NOT` be accessed unless an instance of itself has been created. */
if (crsf != nullptr)
{
/* Run CRSF for Arduino's main function. */
crsf->update();
/* Anything else that depends on CRSF for Arduino's functionality, you `SHOULD NOT` run that outside the
context of this statement block. */
}
} |
Beta Was this translation helpful? Give feedback.
-
We've updated to use the 1.0.2 release and its support for assigning pins in the constructor. It works great!! |
Beta Was this translation helpful? Give feedback.
-
Thank you sooo much for this library. My son has built a little mouse-sized treadmobile from scratch, and this has allowed us to control it via a Matek ELRS receiver and an Arduino Nano esp32. Our biggest obstacle to getting this working was getting the serial ports configured. This is partly due to my unfamiliarity with the Arduino API, and may not apply to other devices the same way, but it might be helpful to expand the documentation to show how to explicitly configure Serial for Serial Monitor output, and Serial1 (or Serial2) with pins of your choosing -- 8 and 7 in our case:
Beta Was this translation helpful? Give feedback.
All reactions