DShotRMT/examples/dshot300/dshot300.ino

65 lines
1.6 KiB
Arduino
Raw Normal View History

2023-04-13 20:10:51 +01:00
/*
* Title: dshot300.ino
* Author: derdoktor667
* Date: 2023-04-13
2023-04-15 23:50:32 +01:00
*
2023-04-13 20:10:51 +01:00
* Description: A simple example of using the DShotRMT library to
2023-04-15 23:50:32 +01:00
* generate a DShot300 signal for blheli_s escs.
2023-04-13 20:10:51 +01:00
*/
2021-06-30 02:06:02 +01:00
#include <Arduino.h>
2025-03-26 12:49:56 +00:00
#include <DShotRMT.h>
2021-06-30 02:06:02 +01:00
2023-04-13 20:10:51 +01:00
// USB serial port needed for this example
2023-04-15 07:12:37 +01:00
const auto USB_SERIAL_BAUD = 115200;
2023-04-13 20:10:51 +01:00
#define USB_Serial Serial
2021-06-30 02:06:02 +01:00
2023-04-13 20:10:51 +01:00
// Define the GPIO pin connected to the motor and the DShot protocol used
2025-06-10 20:40:45 +01:00
const auto MOTOR01_PIN = GPIO_NUM_17;
2023-04-15 07:12:37 +01:00
const auto DSHOT_MODE = DSHOT300;
2023-04-13 20:10:51 +01:00
// Define the failsafe and initial throttle values
2023-04-15 07:12:37 +01:00
const auto FAILSAFE_THROTTLE = 999;
const auto INITIAL_THROTTLE = 48;
2021-06-30 02:06:02 +01:00
2023-04-13 20:10:51 +01:00
// Initialize a DShotRMT object for the motor
DShotRMT motor01(MOTOR01_PIN, RMT_CHANNEL_0);
2021-06-30 02:06:02 +01:00
2022-11-25 15:08:58 +00:00
void setup()
{
2025-05-14 14:19:38 +01:00
USB_Serial.begin(USB_SERIAL_BAUD);
2025-05-14 14:19:38 +01:00
// Start generating DShot signal for the motor
motor01.begin(DSHOT_MODE);
2025-06-10 20:40:45 +01:00
Serial.println("DShotRMT Demo started.");
Serial.println("Enter a throttle value (02047):");
2021-06-30 02:06:02 +01:00
}
2022-11-25 15:08:58 +00:00
void loop()
{
2025-05-14 14:19:38 +01:00
// Read the throttle value from the USB serial input
int throttle_input = read_SerialThrottle();
2025-05-14 14:19:38 +01:00
// Send the throttle value to the motor
motor01.sendThrottleValue(throttle_input);
2021-06-30 02:06:02 +01:00
}
// ...just for this example
2023-04-13 20:10:51 +01:00
// Read the throttle value from the USB serial input
2025-05-14 14:19:38 +01:00
int read_SerialThrottle()
2022-11-25 15:08:58 +00:00
{
2025-06-10 20:40:45 +01:00
static int last_throttle = INITIAL_THROTTLE;
2025-05-14 14:19:38 +01:00
if (USB_Serial.available() > 0)
{
auto throttle_input = (USB_Serial.readStringUntil('\n')).toInt();
2025-06-10 20:40:45 +01:00
last_throttle = throttle_input;
Serial.print("Throttle set to: ");
Serial.println(last_throttle);
Serial.println(" ");
Serial.println("Enter a throttle value (02047):");
}
2025-06-10 20:40:45 +01:00
return last_throttle;
2021-06-30 02:06:02 +01:00
}