ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
grove_tb6612fng.h
Go to the documentation of this file.
1#pragma once
2
5#include "esphome/core/hal.h"
6// #include "esphome/core/helpers.h"
7
8/*
9 Grove_Motor_Driver_TB6612FNG.h
10 A library for the Grove - Motor Driver(TB6612FNG)
11 Copyright (c) 2018 seeed technology co., ltd.
12 Website : www.seeed.cc
13 Author : Jerry Yip
14 Create Time: 2018-06
15 Version : 0.1
16 Change Log :
17 The MIT License (MIT)
18 Permission is hereby granted, free of charge, to any person obtaining a copy
19 of this software and associated documentation files (the "Software"), to deal
20 in the Software without restriction, including without limitation the rights
21 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
22 copies of the Software, and to permit persons to whom the Software is
23 furnished to do so, subject to the following conditions:
24 The above copyright notice and this permission notice shall be included in
25 all copies or substantial portions of the Software.
26 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32 THE SOFTWARE.
33*/
34
36
41
48
50 public:
51 void setup() override;
52 void dump_config() override;
53
54 /*************************************************************
55 Description
56 Enter standby mode. Normally you don't need to call this, except that
57 you have called notStandby() before.
58 Parameter
59 Null.
60 Return
61 True/False.
62 *************************************************************/
63 bool standby();
64
65 /*************************************************************
66 Description
67 Exit standby mode. Motor driver does't do any action at this mode.
68 Parameter
69 Null.
70 Return
71 True/False.
72 *************************************************************/
73 bool not_standby();
74
75 /*************************************************************
76 Description
77 Set an new I2C address.
78 Parameter
79 addr: 0x01~0x7f
80 Return
81 Null.
82 *************************************************************/
83 void set_i2c_addr(uint8_t addr);
84
85 /***********************************change_address
86 Drive a motor.
87 Parameter
88 chl: MOTOR_CHA or MOTOR_CHB
89 speed: -255~255, if speed > 0, motor moves clockwise.
90 Note that there is always a starting speed(a starting voltage) for motor.
91 If the input voltage is 5V, the starting speed should larger than 100 or
92 smaller than -100.
93 Return
94 Null.
95 *************************************************************/
96 void dc_motor_run(uint8_t channel, int16_t speed);
97
98 /*************************************************************
99 Description
100 Brake, stop the motor immediately
101 Parameter
102 chl: MOTOR_CHA or MOTOR_CHB
103 Return
104 Null.
105 *************************************************************/
106 void dc_motor_brake(uint8_t channel);
107
108 /*************************************************************
109 Description
110 Stop the motor slowly.
111 Parameter
112 chl: MOTOR_CHA or MOTOR_CHB
113 Return
114 Null.
115 *************************************************************/
116 void dc_motor_stop(uint8_t channel);
117
118 /*************************************************************
119 Description
120 Drive a stepper.
121 Parameter
122 mode: 4 driver mode: FULL_STEP,WAVE_DRIVE, HALF_STEP, MICRO_STEPPING,
123 for more information: https://en.wikipedia.org/wiki/Stepper_motor#/media/File:Drive.png
124 steps: The number of steps to run, range from -32768 to 32767.
125 When steps = 0, the stepper stops.
126 When steps > 0, the stepper runs clockwise. When steps < 0, the stepper runs anticlockwise.
127 rpm: Revolutions per minute, the speed of a stepper, range from 1 to 300.
128 Note that high rpm will lead to step lose, so rpm should not be larger than 150.
129 Return
130 Null.
131 *************************************************************/
132 void stepper_run(StepperModeTypeT mode, int16_t steps, uint16_t rpm);
133
134 /*************************************************************
135 Description
136 Stop a stepper.
137 Parameter
138 Null.
139 Return
140 Null.
141 *************************************************************/
142 void stepper_stop();
143
144 // keeps moving(direction same as the last move, default to clockwise)
145 /*************************************************************
146 Description
147 Keep a stepper running.
148 Parameter
149 mode: 4 driver mode: FULL_STEP,WAVE_DRIVE, HALF_STEP, MICRO_STEPPING,
150 for more information: https://en.wikipedia.org/wiki/Stepper_motor#/media/File:Drive.png
151 rpm: Revolutions per minute, the speed of a stepper, range from 1 to 300.
152 Note that high rpm will lead to step lose, so rpm should not be larger than 150.
153 is_cw: Set the running direction, true for clockwise and false for anti-clockwise.
154 Return
155 Null.
156 *************************************************************/
157 void stepper_keep_run(StepperModeTypeT mode, uint16_t rpm, bool is_cw);
158
159 private:
160 uint8_t buffer_[16];
161};
162
163} // namespace esphome::grove_tb6612fng
BedjetMode mode
BedJet operating mode.
void stepper_keep_run(StepperModeTypeT mode, uint16_t rpm, bool is_cw)
void dc_motor_run(uint8_t channel, int16_t speed)
void stepper_run(StepperModeTypeT mode, int16_t steps, uint16_t rpm)
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:144
int speed
Definition fan.h:3