Raspberry Pi Robot – Assembly Part 2
This was the hardest part. If you wire the wrong things together you can brick your Pi. I took some time to decide on which pins to use, and after assembly and testing everything worked. I'll explain which pins I picked, but note that this information will not work with other hardware configurations.[
I originally had a Model B Pi, but due to needing the second hardware PWM (which is hidden on the B), switched to the B+. The B+ is largely the same, save for the 40 pin expansion headers instead of 26. On one of these pins, #35, the second PWM channel is connected. I got a complete kit for $60 or so, that came with a case, wireless USB, power supply, USB cable, heat sinks, etc.
There's a slight problem though. I have a parallel cable for a Model B, which is 26 pins. It didn't fit on the 40 pin B+ so I had to gently modify the 26 pin parallel cable with a grinder:
Technically I've probably comprimised the integrity of the plug's locking mechanism but if it doesn't work there are other options. You could use jumper wires, as you only really need 15 or so of them. The lonely blue jumper wire there is the sole reason I got the B+.
Anyway, now that the Pi is sorted, the real assembly comes in wiring up the prototype board.
That there is the version I have working as of this posting date. I moved the motor B's PWM input from pin 17 to a separate header, as I will get to next.
So here's the goal. We have a motor controller board that controls two motors, and two encoders. We need to connect up everything from the Pi to these two. That involves power:
- 12v for the motors
- 5v for the controller
- 3.3v for the encoders
The rest of the pins go to digital inputs on either the Pi or the controller. Now, I tried to be clever and hooked it up in a way I thought was logical, but besides the PWM connections, you can swap most everything else around.
|Physical Pin||BCM Pin||Purpose||Wire|
|3||2||ENC1||A Encoder White|
|5||3||ENC2||B Encoder White|
GPIO 2 (SDA) = Encoder 1 (to encoder's white wire)
GPIO 3 (SCL) = Encoder 2 (to encoder's white wire)
GPIO 4 = STBY (Yellow wire)
GPIO 18 (PWM) = PWMA (blue wire)
GPIO 19 (PWM) = PWMB (blue wire) (New connection, modification not pictured!)
GPIO 21/27 = BIN1
GPIO 22 = BIN2
GPIO 23 = AIN1
GPIO 24 = AIN2
A few notes:
- The encoders need a pullup to work. GPIO 2 and GPIO 3 have a 1.3kOhm pull up to 3.3v enabled by default. We just need to connect the red power wire for the encoders up to 3.3v as well. If you use another pin, you'll need to enable the pull-up in software.
- GPIO 18 and GPIO 35 (B+ only) have hardware PWM capabilities as an “alt function”, specifically “ALT_FUNC_5” for each of them.
Here's the bototm of the board. You can see the routing of the 5v and GND lines clearly.
The following is a photo of the voltage regulator that I have a 12v battery pack attached to. And here is the VM (motor voltage) wire hooked up straight to the batter source (so, +12v). This is a soldered jumper wire, so do not, under any circumstance, connect this to your Pi or motor controller except for the VM pin. It will destroy anything else.
And in Part 3, I will go over the finished construction.