Git Product home page Git Product logo

crservof's Introduction

CRServoF - The CSRF serial protocol to PWM servo converter

I wanted to create a small project to mess around with PWM servo output for ExpressLRS, and thought this might be of use for other people.

YouTube Demo

What it does

If you have a receiver that outputs CRSF serial protocol (ExpressLRS, Crossfire, Tracer) but want to directly drive servos without a flight controller, I guess you're in the right place. That's exactly what this does. Hook up a CRSF RX to UART2 and your servos to various pins of an STM32F103C8 "blue pill" board and away you go. Not much to it other than that.

Wiring and Flashing

See the wiki Flashing and Wiring

Channel Mapping

To change the channel mapping, use the OUTPUT_MAP[] array at the top. These are 1-based channels from the CRSF output, so 1 is usually Roll, 2 is Pitch and so on. 5 is AUX1 up to 12 is AUX8 for ExpressLRS, or up to 16 AUX12 for Crossfire models. The default map is [ Roll, Pitch, Throttle, Yaw, AUX2, AUX3, AUX4, AUX12 ] for my radio setup. To invert the channel output, +100% becomes -100%, just use a negative number for the channel (e.g. -12 for AUX8 inverted).

Failsafe

The code has failsafe detection which happens if no channel packets are received for a short time (300ms currently). The default failsafe setting is to set CH1-4 to 1500, 1500, 988, 1500, CH4-7 to hold their last position, and CH8 to stop putting out pulses. To change the failsafe behavior, modify the OUTPUT_FAILSAFE[] array with either the microseconds position to set on failsafe or fsaNoPulses (stop outputting PWM) or fsaHold (hold last received value).

Arming / Disarming

CRServoF includes an optional feature to require an arming signal for other channels to be processed. To use this feature, include the buildflag USE_ARMSWITCH. CRServoF expects a "high" value (>1500us) on CH5 to arm. If disarmed, the failsafe values mentioned above will be sent, make sure that you use the correct values applicable to your use case.

VBAT

The code sends a BATTERY telemetry item back to the CRSF RX, using A0 as the input value. You can not plug VBAT directly in. The maximum input voltage is 3.3V so the voltage needs to be scaled down. The code expects a resistor divider VBAT -- 8.2kohm -A0- 1.2kohm -- GND with VBAT on one end, GND on the other, and A0 connected in the middle. That should be good up to 6S voltage if I did my math right. The voltage can be calibrated using the VBAT_SCALE define in the top of main.cpp, and different resistors can be used by changing the VBAT_R1 and VBAT_R2 defines.

ExpressLRS_via_BetaflightPassthrough

The serial UART will attempt to emulate a Betaflight CLI so ExpressLRS can flash the connected RX with yet another RC version. This works, I dunno, like 80% of the time? It is hard to get all the timing just right, but if it fails, you will likely need to repower the whole device because the RX is in the bootloader and probably at the wrong autobaud.

crservof's People

Contributors

capnbry avatar forceu avatar pitts-mo avatar sfjuocekr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

crservof's Issues

Porting serial passthrough to CRSFJoystick - Stuck on timeout

I figured since CRSFJoystick uses the crsfSerial library this should be possble. Here's my attempt at getting this to work on an rp2040 based CRSFJoystick:

https://gist.github.com/countofkrakow/1e26d9006461901a3011a02b911ca8a3

I try flashing an rx with the ELRS configurator and it seems to handle the handshake for going into bootloader mode but then I get a timeout after that. I looked into how serialpasssthrough is done by betaflight and copied the logic into a function and tried that but the configurator just hangs indefinitely that way. This can be found commented out in the gist above in checkSerialInPassthrough.

337919232_1176749242839025_3400717363831921380_n

Here is output from the configurator with my adapted arduino code.

`Building in release mode
PLATFORM : 'espressif8266'
BUILD ENV: 'HAPPYMODEL_EP_2400_RX_VIA_BETAFLIGHTPASSTHROUGH'
Retrieving maximum program size .pio\build\HappyModel_EP_2400_RX_via_BetaflightPassthrough\firmware.elf
Checking size .pio\build\HappyModel_EP_2400_RX_via_BetaflightPassthrough\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [==== ] 43.2% (used 35388 bytes from 81920 bytes)
Flash: [==== ] 37.1% (used 379552 bytes from 1023984 bytes)
Configuring upload protocol...
AVAILABLE: custom, espota, esptool
CURRENT: upload_protocol = custom
Uploading .pio\build\HappyModel_EP_2400_RX_via_BetaflightPassthrough\firmware.bin
Uploading .pio\build\HappyModel_EP_2400_RX_via_BetaflightPassthrough\firmware.bin
======== PASSTHROUGH INIT ========
Trying to initialize COM6 @ 420000

Attempting to detect FC UART configuration...
** Serial RX config detected: 'serial 5 64 0 0 0 0'
Enabling serial passthrough...
CMD: 'serialpassthrough 5 420000'
======== PASSTHROUGH DONE ========
======== RESET TO BOOTLOADER ========

  • Using full duplex (CRSF)
    Cannot detect RX target, blindly flashing!
    Uploading .pio\build\HappyModel_EP_2400_RX_via_BetaflightPassthrough\firmware.bin
    esptool.py v3.0
    Serial port COM6
    Connecting......................................_____

A fatal error occurred: Failed to connect to ESP8266: Timed out waiting for packet header
*** [upload] Error 2
========================= [FAILED] Took 20.10 seconds =========================

Environment Status Duration


HappyModel_EP_2400_RX_via_BetaflightPassthrough FAILED 00:00:20.101
==================== 1 failed, 0 succeeded in 00:00:20.101 ====================`

I looked around on the CRSFJoystick page and mikeneiderhauser thinks it's an issue with dynamic baud rate.

Any ideas?

My proto not running

Hello, thanks for this wonderful share !
I use this library https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json on a BluePill board.
I compile the sources under the Arduino IDE.
May be the libraries are bad for your system ?
For my test, i use a TBS TX/RX system.
So, my wiring is like that:
TARGET_BLUEPILL pinout
#define APIN_VBAT A0
#define USART_INPUT USART2 // UART2 RX=PA3 TX=PA2
#define OUTPUT_PIN_MAP PA_15, PB_3, PB_10, PB_11, PA_6, PA_7, PB_0, PB_1 // TIM2 CH1-4, TIM3CH1-4

When i shutdown my transmitter, the green led is off and when my transmitter is on , the green led is on.
But, i have no PWM signal on the channel 1.
We try to add to our OpenAVRc transmitter the CRSF protocol and we are not certain of our code.
Thanks for your help,

Pierre

Does not work with SoftwareSerial on atmega328

Hi, i am trying to use this library on Arduino pro mini with EP2 ELRS receiver. The small form factor of EP2 would be very good for making a lightweight flightcontroller.
to make it work, I had to change the library to SoftwareSerial, and use baud rate of 152000. However only about 70% of the channel readings are correct, and also channels are read only every 10seconds.... attached a screenshot of debug messages I added.
Bildschirm­foto 2023-05-07 um 15 56 46

Is there a chance to make it work?

Servos not working

Bluepill STM32F103C8 is connected to a HM EP1 RX.
TX to RX and vice versa UART connection.
EP1 communicates by CRSF with the 2.4 TX as I get nice 1RRSi values on the TX.
By ST-Link V2 I uploaded the firmware.bin file created from the PIO F103_serial folder by Platformio.
For uploading I used the ST32CubeProgrammer.
Program says upload succeed.
Yet I get no servo movement.
During programming the yellow BOOT pins I did not change as it is not mentioned although many YT videos show this with UART connection. But with the ST-Link it seems not needed, but I could be totally wrong. I also tried it with BOOT1 in HIGH mode, but same thing.

What more can I do?

PPM output support

I'm looking for something that could convert CRSF to PPM. Is this doable with this project

Should we design a custom PCB for this?

The bluepill is rather large and certainly not tailored to this application.

Would you like to work on a custom PCB? I could sketch something in KiCad, maybe with a smaller MCU, and make it better and more compact. I already like the fact that there's an analog input for the battery voltage, and we could pave the way for current measurements, too.

Target for CJMCU1038 - Purple Pill

I have some of these Purple Pill boards lying around:
https://stm32-base.org/boards/STM32F103C8T6-Purple-Pill.html
My Idea was to use them for your project, as they are small and have a proto area which makes it easy to solder a 6x3 Pin Header for the Servos.

I tried to make a new Target for the board using the pins that are broken out on the board.

#elif defined(TARGET_CJMCU1038)
      #define DPIN_LED        PB_11
      #define LED_INVERTED    1
      #define APIN_VBAT       PB_0
      #define USART_INPUT     USART1  // UART1 RX=PA10 TX=PA9
      #define OUTPUT_PIN_MAP  PA_0, PA_1, PA_2, PA_3, PB_3, PB_2, PB_1, PA_4 
 #endif

I am able to compile and flash the code, it seems to connect to the receiver but i don't get the right servo outputs.
I enabled some printlines in your code and the serial console says:

ADC=0 0V
ADC=0 0V
6666
�␌␔␀␀␀␀␀␄␀␀␀␀��␌␔␀␀␀␀␀␄␀␀␀␀ADC=0 0V
ADC=0 0V
ADC=0 0V
ADC=0 0V
tentative conn
30dBm

And then it seems stuck.

On pins PA_0, PA_1, PA_2, PA_3 i can see a 50Hz servo signal with 1700ms. The other pins show nothing.
I guess its some problem due to the used timers for my pins that need to be changed. Maybe you can point me in the right direction.

Thanks a lot
Johannes

sbus/cppm

Would you be able to make one with an sbus or cppm output?

Adding Failsafe Adjustment

Hello Bryan,

Is there an easy way for the user to adjust failsafe settings?

For example, could the ELRS team "simply" add the failsafe WebUI configurator to select non-PWM receivers?

Or, if that is not so simple, then could a LUA script be used to adjust Failsafe settings over UART from the receiver to the BluePill or RP2040?

CRSF Feature Creep

Bryan,

Good job on the adapter. Nice clean code.

Betaflight/CrossBow seem to have feature creep with CRSF. Do you know whether CRSF_FRAMETYPE_RC_CHANNELS_PACKED and CRSF_FRAMETYPE_LINK_STATISTICS packet types will remain the baseline for ExpressLRS. Some of us write our own flight control code and tracking moving specs does not thrill me. Apologies for the cross post on ExpressLRS..

Thanks
Greg

Add telemetry support for sensors

Hello,
I really like this project and would like to know if it is possible to add telemetry support, in order to send either digital or analog signals back to the transmitter.
There could be a lot of use: voltage or current sensor, barometer, GPS...
Thanks for your support,

How to add support for flightMode?

Hello, I would like to add support for flight mode to the library, but I'm not quite sure how to do it. In the Arduino file, I added a function:

void sendFlightMode(uint8_t flightMode) { crsf.queuePacket(CRSF_SYNC_BYTE, CRSF_FRAMETYPE_FLIGHT_MODE, &flightMode, sizeof(flightMode)); }

I uncommented the line
// CRSF_FRAMETYPE_FLIGHT_MODE = 0x21, //no need to support?'

I don't know how to modify the other library files. Could someone help me?

PETER

add PPM output option

any interest in adding PPM output instead of PWM?
a lot of us still have old flight controllers like APM,mini APM,CC3D and alikes which can be use with PPM inputs only.
although these are old flight controllers but i believe they are all still well capable and stable, the only missing right now is the converter CRSF to PPM output.
Hopefully can bring back these old flight controllers in service with your CRSF to PPM output converter.

thanks.

Use CrsfSerial with Arduino RP2040 Connect

Hi,

I'm building a robot using an Arduino RP2040 Connect. I want to control the robot using ELRS. I found this project which uses an Pi Pico CRSFJoystick that uses your library so it seems like your library should work with the RP2040 chip. I've uploaded the basic_crsf example to the board, it compiles just fine but I'm not seeing a signal. I'm not sure whether I'm using the right RX and TX pins on the board.

I see in the code you can select Serial1 or Serial2 but I'm not sure what they refer to. The Arduino pinout only lists one RX and TX so I tried that first but I also see that on the Pi Pico pinout there are other pins for other serial ports so I tried connecting to the equivalents of those pins.

Is there something else that I'm missing?

Thanks

Suggestion: Armed state LED indicator

Hello!

I think there can be a good idea if you add the LED output in case the CH5 is at high state (~2000ms).
This could be useful to indicate visually that the device is at the armed state.

Thank you.

Adapting to Pro Micro without "#include <functional>"

I'm trying to adapt CRSFJoystick, and so also this library, to run on a SparkFun Pro Micro. The error I am running into is:

CrsfSerial/CrsfSerial.h:4:10: fatal error: functional: No such file or directory

This means that I can't use the std::function syntax to declare the event handlers.

My software experience is primarily Python so I am struggling with the deep magic here, would you be able to help me get this compiled for my platform please? I don't really know what I am doing but I think I have worked out that the SparkFun board for the Arduino IDE doesn't have a new enough C compiler. Do you think that using platformio might be able to make a difference?

Adding ESP32 S2 support target hw: lolin_S2_mini

@CapnBry
Thanks for that code.

I managed to get the CRSF link running on the wemos LolinS2_mini.
The only challenge was to feed the used serial port in numbers to CRSR.begin() function, as on the ESP32 S2 they are not fixed.
Seen a lot of beauty in the code ... CRSF serial telemetry, I learned a lot.
Now merging some ESP HW PWM code to it.

add USB HID Joystick Support

Is there interest in adding a feature similar to the HID Joystick Support found in betaflight 3.4+?

I am not expecting there will be enough desire to yield implementation.

Thank you for building this @CapnBry,
-p

CrsfSerialStream undefined

Hello Bryan,

I am attempting to compile the CRServoF project but I keep getting an error that states CrsfSerialStream is undefined. I have looked through the following files and have determined the error is accurate.

CrsfSerial.h, CrsfSerial.cpp, and Crsf-protocol.h

CrsfSerialStream Undefined

Can you tell me what is CrsfSerialStream and where is it intended to be defined?

Thank you,

Target for CJMCU1038 - Purple Pill

I have some of these Purple Pill boards lying around:
https://stm32-base.org/boards/STM32F103C8T6-Purple-Pill.html
My Idea was to use them for your project, as they are small and have a proto area which makes it easy to solder a 6x3 Pin Header for the Servos.

I tried to make a new Target for the board using the pins that are broken out on the board.

#elif defined(TARGET_CJMCU1038)
      #define DPIN_LED        PB_11
      #define LED_INVERTED    1
      #define APIN_VBAT       PB_0
      #define USART_INPUT     USART1  // UART1 RX=PA10 TX=PA9
      #define OUTPUT_PIN_MAP  PA_0, PA_1, PA_2, PA_3, PB_3, PB_2, PB_1, PA_4 
 #endif

I am able to compile and flash the code, it seems to connect to the receiver but i don't get the right servo outputs.
I enabled some printlines in your code and the serial console says:

ADC=0 0V
ADC=0 0V
6666
�␌␔␀␀␀␀␀␄␀␀␀␀��␌␔␀␀␀␀␀␄␀␀␀␀ADC=0 0V
ADC=0 0V
ADC=0 0V
ADC=0 0V
tentative conn
30dBm

And then it seems stuck.

On pins PA_0, PA_1, PA_2, PA_3 i can see a 50Hz servo signal with 1700ms. The other pins show nothing.
I guess its some problem due to the used timers for my pins that need to be changed. Maybe you can point me in the right direction.

Thanks a lot
Johannes

Failsafe

失控故障时,CH5和CH6没输出自定义PWM值,其它通道输出了自定的WPM值,是什么原因?

In case of out-of-control fault, CH5 and CH6 do not output customized PWM values, while other channels output customized WPM values. What is the reason?

Use STM32 as a receiver.

Hello! I have a reverse question. I have a flight controller and I need to transmit control signals to it from STM32 via UART. I realized that CRSF is good for this task. Please tell me, is it possible to emulate a receiver (for example, ExpressLRS) on STM32? Thank you!

Servo.h and Servo.cpp

Hello Bryan,

I notice the code for a Pico will not compile. There are errors for undefined variables, some of which require Servo.h and Servo.cpp files, but these files are not included in the library.

Are the Servo.h and Servo.cpp files standard files that can be pulled from another source? Do you know where you were planning to get the Servo.h and Servo.cpp files?

SBUS output

Many fixed wing flight controllers require SBUS as an input. Can you add a change to output SBUS?

Thank you for your work on an ELRS converter.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.