Skip to content
Snippets Groups Projects
Commit 1038787b authored by Adrián Torres's avatar Adrián Torres
Browse files

xiao_motor_dco

parent e63c5d23
No related branches found
No related tags found
No related merge requests found
Pipeline #387481 passed
File added
File added
//Fab Academy 2023 - Fab Lab León
//Motor
//Adrianino
//Fab-Xiao RP2040
const int switch1Pin = 1; // switch 1
const int motor1Pin = 26; // H-bridge pin 0 (in2)
const int motor2Pin = 27; // H-bridge pin 1 (in1)
void setup() {
// set the switch pins as input pins and activate their internal pull up resistors
// so they are not in a floating state because their default state is now HIGH
pinMode(switch1Pin, INPUT);
// set H-bridge pins as outputs:
pinMode(motor1Pin, OUTPUT);
pinMode(motor2Pin, OUTPUT);
}
void loop() {
// if switch1 is pressed, (=LOW because the unpressed 'pulled up' state is HIGH)
if (digitalRead(switch1Pin) == HIGH) {
analogWrite(motor1Pin, 255); // set pin 1 of the H-bridge to 50% using PWM
analogWrite(motor2Pin, 0); // set pin 2 of the H-bridge to low state
}
// if neither of the switches are pressed, the motor will stand still
else
{
digitalWrite(motor1Pin, 0); // set pin 1 of the H-bridge low
digitalWrite(motor2Pin, 255); // set pin 2 of the H-bridge low
}
}
......@@ -109,6 +109,7 @@
<ul class="actions">
<li><a href="#outputs" class="button primary">Outputs</a></li>
<li><a href="#servo" class="button">Servo motor</a></li>
<li><a href="#motor" class="button">DC motor</a></li>
<li><a href="#oled" class="button">OLED</a></li>
<li><a href="#rgb" class="button">RGB LED</a></li>
</ul>
......@@ -912,6 +913,64 @@ void loop() {
<p><video controls width="100%"; max-width="800"><source src="images/fabxiao/servo.mp4" type="video/mp4"></video></p>
<h2><a id="motor"></a>DC motor</h2>
<p>To control a DC motor we will use an H bridge, such as the <a href="https://www.digikey.es/en/products/detail/TB67H451FNG%2cEL/264-TB67H451FNGELCT-ND/11568783"><b>Toshiba TB67H451FNG.</b></a> With this driver we can control all types of motors through <b>PWM signals.</b> </p>
<li><b>Connection and schematic</b></li>
<p>In this case, being a component without a module, I create my own. I design and manufacture a small board where I solder the Toshiba TB67H451FNG driver, a 1uF capacitor, a 10uF capacitor and with the flat connectors where there is no room for mistakes when connecting it. It includes two traces to feed with the 5V and ground. I use two digital output of the XIAO RP2040 GPIO 26 (Arduino pin 26) and GPIO 27 (Arduino pin 27).</p>
<span class="image main"><img src="images/fabxiao/xiao_26.jpg" alt="" /></span>
<p>Here you can find the design in Eagle and the PNG's to create the board.</p>
<p><a href="assignments/fabxiao/dc_motor_toshiba.zip"><b>- Motor Schematic + Board</b></a>
<p><a href="assignments/fabxiao/dc_motor_toshiba_traces.zip"><b>- Motor traces and interior</b></a></p>
<p><img src="images/fabxiao/xiao_27.jpg" width="50%"; max-width="700" /></p>
<li><b>Programming</b></li>
<p>Here you will find the programming to use a servo motor. Here you can find the Arduino file to download.</p>
<p><a href="assignments/fabxiao/xiao_motor/xiao_motor.ino"><b>- Arduino Motor</b></a>
<pre><code>//Fab Academy 2023 - Fab Lab León
//Motor
//Adrianino
//Fab-Xiao RP2040
const int switch1Pin = 1; // switch 1
const int motor1Pin = 26; // H-bridge pin 0 (in2)
const int motor2Pin = 27; // H-bridge pin 1 (in1)
void setup() {
// set the switch pins as input pins and activate their internal pull up resistors
// so they are not in a floating state because their default state is now HIGH
pinMode(switch1Pin, INPUT);
// set H-bridge pins as outputs:
pinMode(motor1Pin, OUTPUT);
pinMode(motor2Pin, OUTPUT);
}
void loop() {
// if switch1 is pressed, (=LOW because the unpressed 'pulled up' state is HIGH)
if (digitalRead(switch1Pin) == HIGH) {
analogWrite(motor1Pin, 255); // set pin 1 of the H-bridge to 50% using PWM
analogWrite(motor2Pin, 0); // set pin 2 of the H-bridge to low state
}
// if neither of the switches are pressed, the motor will stand still
else
{
digitalWrite(motor1Pin, 0); // set pin 1 of the H-bridge low
digitalWrite(motor2Pin, 255); // set pin 2 of the H-bridge low
}
}</code></pre>
<p><video controls width="100%"; max-width="800"><source src="images/fabxiao/motor_xiao.mp4" type="video/mp4"></video></p>
<h2><a id="oled"></a>OLED</h2>
<p>For this example I am going to use an OLED with an I2C communication module. In my case, I bought it through Amazon from AZDelivery, here is the <a href="https://www.amazon.com/AZDelivery-Display-Arduino-Pixels-Module/dp/B07F5JKXD9/ref=sr_1_7?dchild=1&keywords=128+x+64+OLED&qid=1601808816&sr=8-7"><b>link.</b></a> This company has a multitude of very interesting tutorials, including that of the <a href="https://www.az-delivery.de/en/products/1-3-zoll-display-kostenfreies-e-book?_pos=3&_sid=180149b80&_ss=r"><b>OLED module with I2C.</b></a></p>
......
docs/images/fabxiao/xiao_26.jpg

506 KiB

docs/images/fabxiao/xiao_27.jpg

142 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment