Skip to content

Commit 60cc551

Browse files
committed
Add test code for UnoR4
1 parent 2eee810 commit 60cc551

File tree

4 files changed

+73
-4
lines changed

4 files changed

+73
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
UART & serial_stream = Serial1;
10+
11+
const long SERIAL_BAUD_RATE = 115200;
12+
const int DELAY = 3000;
13+
14+
// Instantiate TMC2209
15+
TMC2209 stepper_driver;
16+
17+
18+
void setup()
19+
{
20+
Serial.begin(SERIAL_BAUD_RATE);
21+
22+
stepper_driver.setup(serial_stream);
23+
}
24+
25+
void loop()
26+
{
27+
if (stepper_driver.isSetupAndCommunicating())
28+
{
29+
Serial.println("Stepper driver is setup and communicating!");
30+
Serial.println("Try turning driver power off to see what happens.");
31+
}
32+
else if (stepper_driver.isCommunicatingButNotSetup())
33+
{
34+
Serial.println("Stepper driver is communicating but not setup!");
35+
Serial.println("Running setup again...");
36+
stepper_driver.setup(serial_stream);
37+
}
38+
else
39+
{
40+
Serial.println("Stepper driver is not communicating!");
41+
Serial.println("Try turning driver power on to see what happens.");
42+
}
43+
Serial.println();
44+
delay(DELAY);
45+
}

platformio.ini

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
[platformio]
2-
src_dir = examples/UnidirectionalCommunication/MoveAtVelocity
3-
#src_dir = examples/UnidirectionalCommunication/SoftwareSerial
4-
#src_dir = examples/BidirectionalCommunication/TestRP2040
5-
#src_dir = examples/UnidirectionalCommunication/TestRP2040
2+
;src_dir = examples/UnidirectionalCommunication/MoveAtVelocity
3+
;src_dir = examples/UnidirectionalCommunication/SoftwareSerial
4+
;src_dir = examples/BidirectionalCommunication/TestRP2040
5+
;src_dir = examples/UnidirectionalCommunication/TestRP2040
6+
;src_dir = examples/BidirectionalCommunication/TestUnoR4
67

78
lib_dir = src
89
default_envs = teensy40
@@ -51,6 +52,14 @@ lib_deps =
5152
SoftwareSerial
5253
${env.lib_deps}
5354

55+
[env:uno_r4_minima]
56+
platform = renesas-ra
57+
framework = arduino
58+
board = uno_r4_minima
59+
lib_deps =
60+
SoftwareSerial
61+
${env.lib_deps}
62+
5463
[env:pico]
5564
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
5665
board = rpipico

src/TMC2209.h

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ class TMC2209
5151
SerialAddress serial_address,
5252
int16_t alternate_rx_pin,
5353
int16_t alternate_tx_pin);
54+
#elif defined(ARDUINO_UNOR4_MINIMA)
55+
void setup(UART & serial,
56+
long serial_baud_rate,
57+
SerialAddress serial_address);
5458
#endif
5559

5660
#if SOFTWARE_SERIAL_INCLUDED

src/TMC2209/TMC2209.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ void TMC2209::setup(SerialUART & serial,
7373

7474
initialize(serial_baud_rate, serial_address);
7575
}
76+
#elif defined(ARDUINO_UNOR4_MINIMA)
77+
void TMC2209::setup(UART & serial,
78+
long serial_baud_rate,
79+
SerialAddress serial_address)
80+
{
81+
hardware_serial_ptr_ = &serial;
82+
hardware_serial_ptr_->end();
83+
hardware_serial_ptr_->begin(serial_baud_rate);
84+
85+
initialize(serial_baud_rate, serial_address);
86+
}
7687
#endif
7788

7889
#if SOFTWARE_SERIAL_INCLUDED

0 commit comments

Comments
 (0)