Idea
Use Raspberry Pi to control this custom made car model.
Implementation
Bill of Materials
Hardware
- Raspberry Pi Zero W
- Raspberry Pi, 1 to 2 expansion
- Pi Juice Hat
- Adafruit Motor Bonnet for Raspberry Pi
- DFrobot RPi zero IO Expansion Hat
- DFrobot Ultrasonic Sensor, URM09 Analog
- DFronot i2c Digital Wattmeter
- Mini Breadboard
- 3mm LED for front light
- Micro LED 0603 for back light
- 1.5V AA Batteries
- I used EBL ones
- Lego Power Functions Servo Motor
- One for steering and one for Transmission
- Lego Power Functions L-Motor
- I used two
- Lego Power Functions Battery Box for AA
- Lego Power Function Extension Cable, 20"
- Dupont Connector Kit
- Crimping Tool for Dupont Connectors
- Ferrule Crimping Toolset
- Wire Stripping Tool
- Paper/Utility knife
- To cut and separate wires of Lego extension cable
Software
- Raspberry Pi OS Lite,
- with no GUI as it's not needed on Car
- Adafruit python library for Motor Bonnet
- Edit /usr/local/lib/python3.7/dist-packages/adafruit_motorkit.py or locate adafruit_motorkit.py based on installation
- Add default parameter, pca_frequence=1600 like this
- Dfrobot Wattmeter Code
- PiJuice Code
- My Test Code. FOR REFERENCE ONLY, DON'T JUST COPY PASTE and USE IT.
- Controller.py
- Main file to control the car, it uses curses lib.
- + is shift up, - is shift down
- w is steering straight, a is steering left, d is steering right
- s is to stop
- UP arrow increase Throttle/power to motor
- Down arrow decrease Throttle/power to motor
- q to quit
- car.py
- Module which implements Car's functionalities
Wiring
I use Lego Extension cables when connecting Lego motors and motor driver board. This way, Lego motors can be reuse in pure Lego based projects.
Cable for Lego Power Functions Battery
Lego cable has four wires. Wires on each side doesn't change polarity when battery box switch turns to either side. Right outer cable is +ve and left outer is -ve. Use this to attach to desired power source.
See this picture to get an idea
Caution: Use multi meter to confirm polarity
Cable for Lego Power Functions Motor
Middle two wires are used to power Lego PF motors.
I prefer to use light grey head side, (which doesn't fit the battery), for motor connection as it can be attached to Lego Buggy Motor. Picture for information
Cable for Lego Power Functions Servo
Lego PF servo uses all four wires. Side wires are to power and middle two wires are used to set duty cycle and direction. I use breadboard to share battery power with PF Servos.My Raspberry Pi Zero W with other boards stacking looks like this
- Raspberry Pi Zero W
- 1 to 2 GPIO Expansion Kit
- Motor Driver board to the side
- Pijuice on Top side of GPIO Expansion Kit
- IO Expansion kit
- Breadboard attached to the kit
I updated model and attached, camera, distance sensor, lights, though they are not operational yet. Model looks like this
Demo
Without Load
Or
Running on floor
Or
Note engine speed on shifting to 4th gear, it's slow. Reading motor battery was on 3V. Not sure if batteries were not able to handle such load or was there any other issue.
Next Step
- Hook up sensors, lights, Camera and Automated Action
- Use a Remote not laptop, which looks something like this
- Yep, it has Google Coral
Good Work !!
ReplyDeleteCan you please make more videos on youtube?
I'm a big fan of your work.