Software apps and online services
Hand tools and fabrication machines
After assembling the robot, you should be able to program it using the BluPants Studio. Watch the video and check out how learning to code can be fun and easy.
The video shows lesson 5 from BluPants coding class. Find more lessons here. Other than the basic drag and drop coding blocks shown, it also natively supports Python for more advanced students. For more information about BluPants visit www.blupants.com or watch our Intro to BluPants video.
In order to get a robot similar to the video, you will need to complete all the 4 tutorials in the BluPants robots series:
- Build a base/MVP robot (this tutorial)
- Add a claw/gripper to the base robot (find the claw tutorial here)
- Add a distance sensor (find the distance sensor tutorial here)
- Add a camera to the robot (find the camera tutorial here)
It is up to you how many extra gadgets you want to add to your bot. But regardless whether or not you add more things to it, keep in mind that the basic/MVP robot is already a very good start for learning how to code. Let's see how you can start creating your own Raspberry Pi robot and learn to code with BluPants.Flashing BluPants image
The robot we present here is analogous to the "robot buggy" from the official Raspberry Pi Project page. So, if you already have your robot bug working, all you need to to is to flash the BluPants image to an SD card, and insert it to your existing robot. If you haven't built the "robot buggy" yet, no problem, we will bring you a step by step tutorial on how to build one. But, before we jump into that, let's make sure we have a proper SD card working with the BluPants image.
Download the BluPants image file available on this link and flash it to a micro SD card (8G minimum). We suggest the official Raspberry Pi documentation for that, or use this video for instructions on how to flash an SD card using Balena Etcher. Regardless the documentation you use, just make sure you flash the correct BluPants image file to your SD card.
The basic robot is the minimum viable product (MVP) that can be used with BluPants. It will only navigate in all directions (forward, backwards, turn left and turn right). It is the bare bone you will use to build more sophisticated bots in the future.
It is recommended to assemble the MVP first, and add extra features later (distance sensor, gripper claw, camera, extra servos, etc) as you get more experienced.
For the basic MVP robot, we are going to need the parts bellow:
The first thing to do is to connect the wires to the motors, before soldering. Make sure you have a good physical connection between the wires and the motors.
You may want to use a voltmeter or connect an AA battery to end of the wires to test whether or not you have a good physical connection. After that, you may want to solder it.
Get the chassis, and put it on the top of the motors with the exact setup we currently have on our table:
Hold the motors to the chassis and flip it. Notice that the letter "L" and "R" will no longer be visible because the chassis is attached to the motor on the same surface we had written the letters.
After flipping the chassis, put the other two external fasteners close to the motors and use the bolts to fix them. The bolts should come from the outside to the inside. The nuts should be attached from the inside of the chassis.
Install the swivel wheel to the back of the chassis.
Bring the motor wires to the top of the chassis and connect the two motor wheels.
Fix the L298N motor driver controller to the top of the chassis. The pictures show the L298N board being fixed to the chassis front-left. Later on, I realized it would make more sense to put it on the front-right corner for my project (so I would have more room to add extra devices in the future, such as camera, distance sensor, etc). Feel free to place it anywhere it is more convenient for your project.
The connection of the black and red wires to the L298N controller will define whether the motors drives forward or backwards (polarity) when power is applied. If you have any of your wheels spinning to the wrong direction, swap the black and red wires position on the L298N controller and repeat all the steps described in this section.
Connect the left motor wires to the connectors on left side of the L298N controller and the right motor wires to the right side, just like show in the pictures. Left motor wires should be connected to MOTOR A (OUT1 and OUT2) and right motor wires should be connected to MOTOR B (OUT3 and OUT4)
In our case, we connected black wire from left motor to OUT 1 and red wire from left motor to OUT2. The red wire from right motor was connected to OUT3 and right motor black wire to OUT4.
Yours might be different. After you finish the whole assembling try coding your robot to move forward. Let's say you notice your left motor is running on the correct direction, but the right motor is driving backwards. In this example the robot would spin clockwise rather than moving forward. In this case, you should keep the OUT1 and OUT2 (left) as is, but swap OUT3 and OUT4 (right). Try changing the setup until you get your motors polarity right.Connecting the L298N motor driver controller to your Raspberry Pi
The L298N board used in this project needs to be wired to the Raspberry Pi. Other boards may connect differently, and some boards can simply be placed onto the Raspberry Pi GPIO pins as a HAT. Make sure you look at the documentation for your board to see whether this is the case.
On the board used here there are pins labeled In1, In2, In3, and In4. Which GPIO pins on your Pi that you use is up to you; in this project, GPIO 7, 8, 9, and 10 have been used. If you use different GPIO pins, you will also need to update your blupants.json file to reflect your choice and restart the blupants service. Check "Tuning" section for more details.
Use four female-to-female jumper leads to connect the Raspberry Pi GPIO pins to the pins on the motor controller board.
- GPIO pin7 connects to In1
- GPIO pin8 connects to In2
- GPIO pin9 connects to In3
- GPIO pin10 connects to In4
In the project we use a single affordable power bank to supply power for the Raspberry Pi and L298N boards and for the motors. You may want to explore other options such as the one showed on the "Make your own power bank" from the official Raspberry Pi projects page.
In this project we use 2 male-to-male red jumpers and 1 male-to-male black jumper. Connect then to +12V, GND and +5V ports on the L298N board as shown bellow.
Connect the red jumpers to the "+" power rail and the black jumper to the "-" power rail on the breadboard.
Now that the power supply wiring is completed, let's place our power bank (battery) on the top of the chassis, but underneath the Raspberry Pi and the breadboard.
In this project mending plates are being used to fix the power bank to the chassis. You may want to use different approaches (tape, bolts and nuts, cable ties, etc).
The Raspberry Pi is fixed to the chassis using a bolt and nut, and also some cable tie to attache it to the mending plate.
Cable ties were used to fix the breadboard to the chassis
In order to connect the power supply to the breadboard "+" and "-" rails, use jumper pins to connect the USB alligator clips to the rails.
One very important thing to remember is to use a common ground for all boards and devices. So, make sure you also connect the Raspberry Pi GND pint to the "-" power rail on the breadboard. You will need to use a male-to-female (black preferably) to do that.
Notice that the two negative (-) power rails are connected by the black jumper wire on the bottom of the breadboard.
Connect the USB red alligator clip to the "+" rail and the black alligator clip to the "-" rail on the breadboard.
*Note: I only had the USB to alligator clip available. A much better option would be using a USB debug cable, since they are safer and easier to connect to the bread board. You just need to connect a red and black male-to-male jumper to the TTL connector. Here are two affordable options for the USB debug cable:
Connect the USB end to the power bank and check whether the L298N board powers on. If it doesn't, check your wiring.
Power on the Raspberry Pi 4 board, by connecting the USB-C cable to the power bank. If you are using a Raspberry Pi 3 or Zero, use a Micro USB to USB-A and connect it to the power bank (the power bank suggested on this tutorial has 2 USB-A output ports and 1 USB-C input/output port).
After powering on the robot, there is one last step before we can finally start coding: connect the robot to the WiFi network.Connect Raspberry Pi to WiFi
Please refer to the official Raspberry Pi documentation on how to connect your robot to WiFi. You can find a very well detailed documentation here. All you need to do, is to make sure you connect both the robot (running BluPants SD card image) and your browser (desktop, tablet or phone) to the same WiFi network, so you can program your robot with BluPants Studio.Coding Time!
Once you have your Raspberry Pi on and connected to the WiFi, open a browser and visit http://blupants.org. Make sure the computer you are using to browse is also connected to the same WiFi network you connected your Raspberry Pi.
On the "Robot" drop-down menu (bottom right), select the WiFi IP address of your Raspberry Pi and click "Play":
In this example the Raspberry Pi WiFi address is "10.0.0.119". If you cannot see any IP address try reloading the page, or opening and closing the browser. If you still can't connect, please refer to "Troubleshooting BluPants connection" section.
Now that you are connected, drag and drop one or two "move forward" command blocks, and click "Play" to execute it.
If the motors do not run on the desired direction, invert the red and black wires connection to revert the polarity and run the test again. Refer to "Motor Polarity" section for more details.
If everything works good, congratulations! You have just finished assembling your raspberry MVP robot. You are ready to write some code with BluPants to program your robot!
As you noticed on the video, our MVP robot may require some tuning. Check out the next section for more details.Tuning BluPants robot
For a better performance and more accuracy, it is strongly recommended that you tune the BluPants robot for your environment. But, before doing that, make sure you have a proper weight distribution and have the parts on the top of the chassis well fixed to it.
At the end of the video we notice the robot oversteering when performing the turn to the right. To overcome it, tuning is required.
For tuning and customization, you need to edit the file "/root/blupants.json" on your Raspberry Pi. The blupants.json file will be reloaded every time you click the play button and execute your code.
In the example we saw on video, we need to decrease the value of "turn_right_period", so the robot turns a little less when making a right turn. We make want to change the default value from:
to something like:
Another thing you can do, is for instance, you may want the robot to move further when executing the "move_forward()" command. For that, all you need to do is to increase the default value of
You can also compensate physical issues such as one motor running faster than the other (which prevents the robot from moving straight).
Let's say you want you motor 2 (the motor on the right) to run 20% slower. In order to do that, you change the second value of the duty_ratio from 1.0 to 0.8.
"duty_ratio": [1.0, 1.0, 1.0, 1.0],
Setup with motor on the right running 20% slower:
"duty_ratio": [1.0, 0.8, 1.0, 1.0],
Feel free to edit the file and test your code until you get the accuracy you are looking for. If for some reason, you break the json file and the robot no longer works, just download the original copy from github.
You may need to restart the service after restoring a broken blupants.json file. For restarting the service, open a command prompt, then run:
sudo service blupants restart
Feel free to add any comments to this article if you need any further help.Troubleshooting BluPants connection
If you cannot connect your browser to your Raspberry Pi, make sure your BluPants service is running. Login to your Raspberry Pi (default credentials are user: pi, password: raspberry) and open a command prompt. Then run the command:
sudo service blupants status
The expected result should be something like this:
If you need to restart your service, you can try:
sudo service blupants restart
And check the status again. Once you confirm the service is running properly, visit http://blupants.org on your browser and try to connect to your Raspberry Pi robot again.
Alternatively, you can try to provide your Raspberry Pi WiFi IP address directly on the URL. In order to manually get your WiFi IP address, run the following command from your Raspberry Pi command shell:
You should get something similar to this:
The IP address is shown on the third line (inet) as "10.0.0.14". Your IP will very likely be different. Now that we know our IP address, we can use it directly on our browser URL like this:
Make sure you replace "10.0.0.14" by your own IP address and paste it to your browser address bar. Open the page and click the "Play" button to connect.
If you need any further help, please add any comments to this article, and we will provide you assistance.What's next?
Stay tuned for more tutorials, so you can expand your basic robot. We have a new tutorial which shows how to add a gripper claw to your Raspberry Pi (same way as shown on the intro video for this tutorial). Follow us on Twitter to stay tuned with all new releases. The claw tutorial is a good candidate for the first expansion to your basic MVP robot. You can also add a distance sensor to your bot following this tutorial and/or add a camera to it by following this tutorial.
In the future we will be covering topics such, machine learning, text to speech, computer vision with OpenCV 4, etc. All those things are already natively included in the BluPants image you just flashed to your micro SD card today.
You may want to explore it further and try new things yourself. If you feel it, try building more stuff yourself. BluPants is a platform designed to allow you to learn by doing. If you want to drop us a line, please feel free to add comments and/or reach out to us directly.
See you next time!