Skip to content

Commit 295ee33

Browse files
committed
Added an ESP-IDF sample project.
1 parent 2959b1e commit 295ee33

File tree

7 files changed

+165
-0
lines changed

7 files changed

+165
-0
lines changed

examples/ESPIDFExample/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/build
2+
/.vscode
3+
/managed_components
4+
/sdkconfig
5+
/dependencies.lock

examples/ESPIDFExample/CMakeLists.txt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# For more information about build system see
2+
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
3+
# The following five lines of boilerplate have to be in your project's
4+
# CMakeLists in this exact order for cmake to work correctly
5+
6+
cmake_minimum_required(VERSION 3.16)
7+
8+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
9+
10+
project(idf_project_example)

examples/ESPIDFExample/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
This folder contains a bare bones functional ESP-IDF project.
2+
3+
You can create one using the **ESP-IDF: New Project** command in
4+
Visual Studio code, or use this one as a basis. If you do use this one
5+
as a basis for your own project, review the `.gitignore` file as it
6+
excludes files you would not want to exclude in a normal project.
7+
Normally only the `managed_components` and `build` folders would be
8+
excluded from version control.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FILE(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.c ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
2+
3+
idf_component_register(
4+
SRCS ${SOURCES}
5+
INCLUDE_DIRS "."
6+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
dependencies:
2+
TMC2209:
3+
path: ../../..
4+
# Alternatively you can point this directly at the GitHub repository:
5+
# git: https://github.com/janelia-arduino/TMC2209.git

examples/ESPIDFExample/main/main.cpp

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#include <TMC2209.h>
2+
3+
// This example will not work on Arduino boards without HardwareSerial ports,
4+
// such as the Uno, Nano, and Mini.
5+
//
6+
// See this reference for more details:
7+
// https://www.arduino.cc/reference/en/language/functions/communication/serial/
8+
9+
HardwareSerial & serial_stream = Serial1;
10+
11+
const long SERIAL_BAUD_RATE = 115200;
12+
const int DELAY = 2000;
13+
14+
// Instantiate TMC2209
15+
TMC2209 stepper_driver;
16+
17+
extern "C" void app_main()
18+
{
19+
Serial.begin(SERIAL_BAUD_RATE);
20+
21+
stepper_driver.setup(serial_stream);
22+
23+
Serial.println("*************************");
24+
Serial.println("getSettings()");
25+
TMC2209::Settings settings = stepper_driver.getSettings();
26+
Serial.print("settings.is_communicating = ");
27+
Serial.println(settings.is_communicating);
28+
Serial.print("settings.is_setup = ");
29+
Serial.println(settings.is_setup);
30+
Serial.print("settings.software_enabled = ");
31+
Serial.println(settings.software_enabled);
32+
Serial.print("settings.microsteps_per_step = ");
33+
Serial.println(settings.microsteps_per_step);
34+
Serial.print("settings.inverse_motor_direction_enabled = ");
35+
Serial.println(settings.inverse_motor_direction_enabled);
36+
Serial.print("settings.stealth_chop_enabled = ");
37+
Serial.println(settings.stealth_chop_enabled);
38+
Serial.print("settings.standstill_mode = ");
39+
switch (settings.standstill_mode)
40+
{
41+
case TMC2209::NORMAL:
42+
Serial.println("normal");
43+
break;
44+
case TMC2209::FREEWHEELING:
45+
Serial.println("freewheeling");
46+
break;
47+
case TMC2209::STRONG_BRAKING:
48+
Serial.println("strong_braking");
49+
break;
50+
case TMC2209::BRAKING:
51+
Serial.println("braking");
52+
break;
53+
}
54+
Serial.print("settings.irun_percent = ");
55+
Serial.println(settings.irun_percent);
56+
Serial.print("settings.irun_register_value = ");
57+
Serial.println(settings.irun_register_value);
58+
Serial.print("settings.ihold_percent = ");
59+
Serial.println(settings.ihold_percent);
60+
Serial.print("settings.ihold_register_value = ");
61+
Serial.println(settings.ihold_register_value);
62+
Serial.print("settings.iholddelay_percent = ");
63+
Serial.println(settings.iholddelay_percent);
64+
Serial.print("settings.iholddelay_register_value = ");
65+
Serial.println(settings.iholddelay_register_value);
66+
Serial.print("settings.automatic_current_scaling_enabled = ");
67+
Serial.println(settings.automatic_current_scaling_enabled);
68+
Serial.print("settings.automatic_gradient_adaptation_enabled = ");
69+
Serial.println(settings.automatic_gradient_adaptation_enabled);
70+
Serial.print("settings.pwm_offset = ");
71+
Serial.println(settings.pwm_offset);
72+
Serial.print("settings.pwm_gradient = ");
73+
Serial.println(settings.pwm_gradient);
74+
Serial.print("settings.cool_step_enabled = ");
75+
Serial.println(settings.cool_step_enabled);
76+
Serial.print("settings.analog_current_scaling_enabled = ");
77+
Serial.println(settings.analog_current_scaling_enabled);
78+
Serial.print("settings.internal_sense_resistors_enabled = ");
79+
Serial.println(settings.internal_sense_resistors_enabled);
80+
Serial.println("*************************");
81+
Serial.println();
82+
83+
Serial.println("*************************");
84+
Serial.println("hardwareDisabled()");
85+
bool hardware_disabled = stepper_driver.hardwareDisabled();
86+
Serial.print("hardware_disabled = ");
87+
Serial.println(hardware_disabled);
88+
Serial.println("*************************");
89+
Serial.println();
90+
91+
Serial.println("*************************");
92+
Serial.println("getStatus()");
93+
TMC2209::Status status = stepper_driver.getStatus();
94+
Serial.print("status.over_temperature_warning = ");
95+
Serial.println(status.over_temperature_warning);
96+
Serial.print("status.over_temperature_shutdown = ");
97+
Serial.println(status.over_temperature_shutdown);
98+
Serial.print("status.short_to_ground_a = ");
99+
Serial.println(status.short_to_ground_a);
100+
Serial.print("status.short_to_ground_b = ");
101+
Serial.println(status.short_to_ground_b);
102+
Serial.print("status.low_side_short_a = ");
103+
Serial.println(status.low_side_short_a);
104+
Serial.print("status.low_side_short_b = ");
105+
Serial.println(status.low_side_short_b);
106+
Serial.print("status.open_load_a = ");
107+
Serial.println(status.open_load_a);
108+
Serial.print("status.open_load_b = ");
109+
Serial.println(status.open_load_b);
110+
Serial.print("status.over_temperature_120c = ");
111+
Serial.println(status.over_temperature_120c);
112+
Serial.print("status.over_temperature_143c = ");
113+
Serial.println(status.over_temperature_143c);
114+
Serial.print("status.over_temperature_150c = ");
115+
Serial.println(status.over_temperature_150c);
116+
Serial.print("status.over_temperature_157c = ");
117+
Serial.println(status.over_temperature_157c);
118+
Serial.print("status.current_scaling = ");
119+
Serial.println(status.current_scaling);
120+
Serial.print("status.stealth_chop_mode = ");
121+
Serial.println(status.stealth_chop_mode);
122+
Serial.print("status.standstill = ");
123+
Serial.println(status.standstill);
124+
Serial.println("*************************");
125+
Serial.println();
126+
127+
Serial.println();
128+
delay(DELAY);
129+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Required by the android-esp32 component.
2+
CONFIG_FREERTOS_HZ=1000

0 commit comments

Comments
 (0)