Uncategorized
pi-top forum

Making a Rpi Pico Based Smart Vehicle

ProjectsJun 301 / 19Jun 301d ago

tlfong0113 Jun 30

I am going start a project on a Pico based smart vehicle. The project will be in many parts. The first part is summarized below.

Pico Smart Vehicle, Part 1 – Controlling a DC motor.

Introduction

This project is on how to use the Rpi Pico with a DC motor controller, such as L298N, to drive a toy DC motor with a speed encoder, such as the N20.

This first part of the project is focused on Pico, Motor Controller, and DC motor.

Rpi4B or Pi-Top 4 would be used as the master controller to communicate with this motor controller, and also controllers of other actuators and senors.

Update 2021jun30hkt2044

When I said above that I would use Rpi4B or Pi-Top 4 as the master controller, I had little confidence I was saying something sensible, because I never saw a Pi-Top 4 before. So I watched a recent video ([Ref 4])((https://www.youtube.com/watch?v=wFWbuj9JdiQ 2)) to make sure I know what is going on recently.

I was glad to see the video title “Rpi 4 on the Go” and that I can use Rpi OS instead of Pi-Top OS. The touch screen and BlueTooth keyboard also look impressive.

However, I am a very slow guy, so I will be going very slowly, with this Part 1 of controlling a DC motor. :slight_smile:

One other thing is that I am not too sure that I am doing the right thing in this forum. I used to write sort of blogs in rpi.org forum, and also short answers in StackOverflow and Stack Exchange Q&A sites such as for Rpi… So this kind of project discussion topic looks very new to me. I guess I need to search to find out how should I start a project discussion topic.

So I searched and found this post about projects category (Ref 5). I am glad to know that this is a new thing, so I arrived in good time.


References

  1. Compatible motors/cabling – @Ltrain, 2021may25 1
  2. N20 Gear Motor (50:1 Ratio, 460 rpm, with Encoder) – Servo City 2
  3. How to Use Your Raspberry Pi Pico With DC Motors (Using DRV8833, L298 or L9110S) – By Les Pounder, Tom’s Hardware 2021jan30 4
  4. Raspberry Pi 4 On The Go! Pi-Top 4 FHD Touch Display & Bluetooth Keyboard Review – 2021jan25, 74,468 views 2
  5. About the Projects category post – pi-topTEAM, 2021mar19
  6. Dr. William Rankin Lecture (On Design etc) 1:18 hrs – Arkansas State 1.2K subscribers, 579 views, 2014sep05

2 Replies2Reply

  • createdJun 30
  • last reply1d
  • 18replies
  • 692views
  • 1user
  • 3likes
  • 10links
  • 19

tlfong0110 Jul 1

Pico Smart Vehicle, Part 1 – Controlling a DC motor.

(1) How do I describe my project?

Just now I browsed the projects category here and found not too many examples for me to learn how to properly present my project work in progress.

I jumped to the quick conclusion that there are no strict and fast rules on how to describe your work in progress projects. For one project I saw a brief introduction post, followed by short replies of comments and discussions. For another project I saw the project proposer posts some videos in his Instagram.

My feeling is that the general rule is to post short messages on my work in progress, so other interested readers might comment and make suggestions, so I can modify my project specification and requirements for along the way.

For my previous Micky Mouse toy Rpi projects, I used to post messages in forums, such as in rpi.org, and my favourite section is “Automation, sensing and robotics”.

An example post is this DC Motor Post 1

The rpi.org forum accepts imgur.com images, but does not entertain videos. So I usually upload YouTube videos about my work in progress. such as this:

tlfong01’s Step Motor Test Youtube Video 2021may1501 1step_motor_test_2021jul01011024×288 125 KB


(2) Now I am reading the following tutorial to learn how to use Pico to control a DC motor. tlfong01:

How to Use Your Raspberry Pi Pico With DC Motors (Using DRV8833, L298 or L9110S) – By Les Pounder, Tom’s Hardware 2021jan30

How to Use Your Raspberry Pi Pico With DC Motors (Using DRV8833, L298 or L9110S) – By Les Pounder, Tom’s Hardware 2021jan30 4

I usually summarize what I have learned by a sequence of pictures which also are useful for refreshing memory later, or for newbie readers to get a rough picture of what I am doing.

And I usually modify slightly or sometimes heavily the tutorial’s hardware setup and software configurations etc. By not just blindly following everything in the tutorial but trying new things make me learn things deeper and remember ideas harder.


pico_motor_2021jul07011024×314 75.3 KB


pico_motor_2021jul07021134×361 82 KB


I also study the tutorial’s software code twice, the first time separate code segments and explanations, and the second time, the complete code. I make sure I understand every statement of the complete code, before I modify it for my version of project. Now the complete code listing below.

import utime
from machine import Pin

motor1a = Pin(14, Pin.OUT)
motor1b = Pin(15, Pin.OUT)

def forward():
   motor1a.high()
   motor1b.low()

def backward():
   motor1a.low()
   motor1b.high()

def stop():
   motor1a.low()
   motor1b.low()

def test():
   forward()
   utime.sleep(2)
   backward()
   utime.sleep(2)
   stop()

for i in range(5):
	test()


(3) Now I following the above Tom’s Harware tutorial to use the Pico and a DC motor driver to move a motor.


pico_setup_2021jul01011024×778 171 KB


(3.1) I am using the Chinese Windows 10 Thonny python IDE. This way everything is simple: (a) No external power supply is needed for now. Of course an external power supply for the motor is required later.

(3.2) I am using a simple “toggle the system LED” program to make sure the Pico hardware is setup more or less OK. The test program listing and a run program sample output is shown below.

# Program Name
#   toggle_pico_system_led_v03.py - tlfong01 2021jul01hkt1531
# Configuration
#   Thonny 3.3.3, Windows 10 (64-bit), Python 3.7.9 (32-bit), Tk 8.6.9, USB COM Port #3
# Intepreter
#   Micropython (Rapsberry Pi Pico)
# Program Function
#   Toggle Pico system LED at GPIO pin 15
# User Guide
#   Run code to toggle LED from On to Off or Off to On

from machine import Pin

systemLed = Pin(25, Pin.OUT)
systemLed.toggle()

# END

# Sample Output - tlfong01 2021jul01hkt1537
# MicroPython v1.14 on 2021-02-02; Raspberry Pi Pico with RP2040

# Type "help()" for more information.
# >>> %Run -c $EDITOR_CONTENT
# >>> 


(4) Now I using a modified version of Tom’s Hardware tutorial demo program to move a DC motor. To make things as simple, as cheap, and as newbie safe/proof as possible, for this prototyping stage, I am not using the very popular L298N motor driver, but MX1509, which is more efficient. And for the motor, not that expensive N20 gear motor with encoder, but the cheapest TT130 yellow toy motor.

The basic test of driving only one motor is OK. The program listing is shown below. More documentation will come later.


# Program Name
#   move_dc_motor_v01.py - tlfong01 2021jul01hkt1629
# Configuration
#   Thonny 3.3.3, Windows 10 (64-bit), Python 3.7.9 (32-bit), Tk 8.6.9, USB COM Port #3
# Intepreter
#   Micropython (Rapsberry Pi Pico)
# DC Motor
#   TT130 DC3~6V DC Gear Motor - AliEXpress US$1
#   https://www.aliexpress.com/item/32855311589.html
# DC Motor Driver
#   MX1508 2~10V, 1.5A, Dual H-Bridge DC Motor Driver - AliExpress US$1
#   https://www.aliexpress.com/item/32688083107.html

# Program Function
#   Move DC motor forward, backward, and stop
# User Guide
#   Run code to move motor

import utime
from machine import Pin

motor1a = Pin(10, Pin.OUT)
motor1b = Pin(11, Pin.OUT)

def moveMotorForward():
    motor1a.high()
    motor1b.low()

def moveMotorBackward():
    motor1a.low()
    motor1b.high()

def stopMotor():
    motor1a.low()
    motor1b.low()

def test():
    print('  Begin move motor test()')
    moveMotorForward()
    utime.sleep(1)
    moveMotorBackward()
    utime.sleep(1)
    stopMotor()
    print('  End   test()')

for i in range(2):
    print('Test ', i)
    test()

# *** End of program ***

# *** Sample Output - tlfong01  2021jul01hkt1707
'''
>>> %Run -c $EDITOR_CONTENT
Test  0
  Begin move motor test()
  End   test()
Test  1
  Begin move motor test()
  End   test()
>>> 
'''



mx1508_dc_motor_driver_rr1024×650 205 KB

Pico, MX1508 motor driver, TT130 motor test video


References

(1) MX1508 2~10V, 1.5A, Dual H-Bridge DC Motor Driver – AliExpress US$1

/ to continue, …2 RepliesReply1 MONTH LATER16 DAYS LATERShareBookmarkFlagReplyWatchingYou will receive notifications because you created this topic.

Suggested Topics

TopicRepliesViewsActivity
Turn Pi-Top 4 into a Portable Learning Management System (LMS)Projects1135May 29
MagicMirror – A Raspberry Pi Smart DisplayProjectsproject-software1488d
Pi Pico Controlled Model RailroadProjects18429d
Pi-top[4] IOT DeviceProjects2147May 21
[WIP] Raspberry Pi IOT ServerProjects5146Jun 12

Want to read more? Browse other topics in Projects or view latest topics.


Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.