Introduction: Open Source Turtle Robot (OSTR)
Robotics is the exciting intersection of a number of engineering fields including mechanical engineering, electrical engineering, and computer science. This project was designed as the basis for a two-day workshop for high school age students to introduce them to engineering principles and giving them a jumping off point for exploring their interests further. There is something for everyone here, even if it is just for the art it creates.
What is Turtle Robot? The concept can be traced back to William Walter’s robotics work in the 1940s which investigated complex behaviors in simple systems. Turtle robots are generally slow moving with tight turning radiuses and can trace a design that shows their behavior over time. They make excellent teaching aides in that their programmed output can be seen visually. A number of programming languages have “Turtle Graphics” built in. Turtle graphics can also be used to investigate advanced topics like L-systems or affine geometry
What is Open Source? If you can look past licences and lawyers, Open Source is a philosophy that ideas should be shared, and if you use an idea you attribute the originator, and if you improve on it, you should share your improvement. Every part of this project, from the circuit board to the 3D designs, are available for study, replicating, and improving. Not only that, but it was designed and programmed used Open Source programs like Arduino and KiCad. All you would have to do is use a computer running Linux (an Open Source operating system) and print the parts on a RepRap based 3D printer (an Open Source project), and you would have Open Source Turtles All the Way Down. This project is certified as Open Source Hardware by the OSHWA.
This project is just the latest iteration of my “Low-Cost, Arduino Compatible Robot”, which in turn is based on the work of others. The concept of two wheel drive with pen in the center is from the Mirobot. Improvements over the Arduino version include a printed circuit board for ease of construction and robustness, infrared sensors for obstacle detection, and a more compact and stiff chassis for more accurate movement and lower printing cost. Rewiring port assignments and firmware improvements help remove stuttering caused by Arduino’s digialWrite() inefficiencies.
In keeping with the engineering fields we are exploring, this project is broken into three distinct sections:
- Electrical (EE: PCB assembly and testing),
- Mechanical (ME: chassis assembly), and
- Software (SW: calibration and programming).
Disambiguation: I've published a couple of different drawing robots and it is getting confusing. Here is a breakdown.
- Ardunio based, no soldering version
- Compact Adafruit Tinket based no soldering version
- Large stepper, chalk drawing robot
- With Turtle Robot Board Kit:
Step 1: Parts
The current Bill of Materials with part numbers and URLs is located at: https://github.com/aspro648/OSTR/. A number of components like resistors and capacitors are generic, so substitutions are acceptable. In general, the cost is about $60-80.
A kit for this project is available on Tindie.com. Purchasing the kit will save you the time and expense of ordering from several different vendors and avoid the minimum PCB order premium. You will also be helping me develop and share other projects in my workshops!
In general, here is an outline:
- Turtle Robot Board Kit
- Adafruit ItsyBitsy Microconroller (M4 recommended)
- USB micro cable
- 2 Geared 5V 28byj Steppers
- 1 Micro servo
- 2 2 x AA Battery Holders
- 4 AA batteries
- 2 wheels
- M3 screws and nuts
- 5/8 steel bearing
- 2 Dash 223 O-rings
Step 2: Electrical Engineering Overview
Electrical Engineers deal with the application of electronics, electricity, and electromagnetism. The field is broad and has many sub-disciplines:
- Power: Generation, transmission, and distribution of electricity, which could include solar, wind, and hydroelectric applications.
- Control: Electrical control of dynamic systems such as aircraft, automotive, or industrial automation.
- Microelectronic: Dealing with the design and manufacture of the circuitry inside microchips used in computers and cell phones.
- Signal Processing: Dealing with the transmission and analysis of electrical signals such as in radar, communication, or audio.
- Instrumentation: Design and use of sensor systems to measure physical properties.
As part of an engineering team, Electrical Engineers need to work closely with Mechanical Engineers to ensure motors and sensors meet system requirements. They may also work with Firmware engineers to help troubleshoot and repair electronics as they are developed and tested with software.
As part of the Turtle Robot project, you could be expected to explain how the robot is powered, how it’s stepper and servo motors function and are controlled, and how the circuit was designed, manufactured, assembled, and tested. The electrical schematics and printed circuit board (PCB) layout files were created in the Open Source KiCad program and are located in the /design_files folder.
Step 3: Electrical Engineering (EE): TLDR;
A well designed circuit should be "build-able" by an experienced hobbiest based on the bill of materials and the PCB silkscreen. For those of you who like to charge ahead, this graphic should be enough to get you past any quirks in the design.
For the rest of us mere mortals, follow along and I'll discuss assembly in detail.
Step 4: EE: Resistance Is Essential.
I like starting with the resistor because:
- They are relatively heat resistant while you are getting into your soldering groove and the iron is coming up to temp,
- They have no polarity, so orientation is not critical, and
- They are the lowest component on the board so sit tight when soldering when the board is flipped on it's back.
Since these are our first components, we'll cover them a little more in depth starting out. There are three pairs of two different values:
- 10K ohm for sensors [brown - black - orange - gold]
- 330 ohm for LED current limiting [orange - orange -brown -gold]
Check out www.resistorguide.com/resistor-color-code/ if you want to
learn more about reading resistor color codes.
You can do one at a time, or all six at once.
- Bend the leads to the width of the pads and insert the resistor.
- Flip the board over and heat both the pad and lead for about two seconds.
- Introduce solder, and maintain heat until the solder melts and flows around the pad.
- Remove the solder, and then the heat, in that order.
- If your solder gets stuck, just re-heat the joint.
- Trim the leads with flush cuts.
Step 5: EE: Eyes!
The front end of the robot contains two sets of devices for detecting and indicating obstacles, one for the left side, and one for right. From the outer edge working inward, we have an:
- IR Detector (black),
- IR Emitter (clear), and
- LED (colored).
They each have polarity, so must be put in the correct orientation. I've tried to make it easy and have all devices with the same orientation. Long leg goes through the square pad. Bend the legs so the device points toward the edge of the board.
- Solder one lead of each component.
- Verify they are oriented and seated correctly.
- Trim the excess lead with flush-cut pliers.
Step 6: EE: Button and IC Socket
We have a single button to use for input.
- Match the holes with the leads and gently press them in.
- Solder them in place and clip the leads.
The IC Socket is a small bit of insurance against putting the chip in backwards. It also allows a chip to be replaced if needed (never had to on these boards yet).
- Solder one lead in each corner.
- Verify the component is seated flat.
- Solder the remaining leads.
Step 7: EE: Capacitors
There are three capacitors of various capacities to help smooth power transients that occur while the motor signals switch on and off. The two larger black capacitors (1 uF and 10 uF) are electrolytic and have polarity. Like the LEDs, the long leg is positive, and there is a white strip on the body indicating negative.
The smaller capacitor (0.1 uF) is ceramic and has no polarity.
Step 8: Power Switch
The power switch can installed in either direction.
- Insert the switch and solder a single lead.
- Verify the switch sits flush on the board and adjust if necessary.
- Solder the remaining leads and cut flush.
Step 9: EE: Headers & Terminals
The two stepper motors are connected using the white JST headers. They have two slot on one side that face outward. There is also a small locating pin that fits in a hole in the circuit board.
- Insert the header and verify it is seated correctly.
- Solder the pins in place.
Power from the two battery holders are connected via the two black terminal headers. The openings face outward as well.
- Solder one pin from each terminal.
- Flip the board and verify the terminal is flat and openings facing out.
- Solder the remaining pin.
The control from the board comes from a microcontroller inserted in to two rows of 14 pin headers.
- Solder one pin of the header (any location).
- Verify the header is seated flat and vertical and adjust if needed.
- Solder the remaining pins.
Step 10: Servo Header
The servo is connected via a 3-pin header. There is a pin for power (+), ground (-), and signal (s).
- Insert the header and solder a single pin.
- Flip the board and verify the header is flat and vertical.
- Solder the remaining pins.
Step 11: Speaker
We are going to use a small piezo speaker to generate tones.
- Fold the leads flat to the body so the speaker will be vertical when mounted (we ran out of board space!).
- Insert the speaker and solder a single lead.
- Flip the board and verify the arrangement is suitable.
- Solder the remaining lead and clip flush with board.
Step 12: EE: Darling Darlington
The single IC on the board is a Darlington array, which is used to control the power going to the motors. From the manufacture, IC pins are splayed slightly outward and need to be bent to 90 degrees to fit in the holes.
- Place the IC on a flat surface and bend each side inward gently.
- Match the divot on the end marking the side with pin one with the silk screen.
Step 13: EE: Brains
The Adafruit ItsyBitsy connects to the motor board via two 14-pin female headers.
- Cut the headers to length and insert them into the sockets with the short ends upward.
- Place the ItsyBitsy onto the pins.
- Ensure the the top (USB, microchip, and reset pin) are upward!
- USB connector toward the edge.
Step 14: Mechanical Engineering Overview
Mechanical Engineers use physics, math, and material science to help design, build, and maintain mechanical systems. Like Electrical Engineering, it is a broad field with many sub categories:
- Mechanics: Not the one who works on your car, but someone who studies forces and motion including static and dynamic forces as well as fluid dynamics.
- Mechatronics and Robotics: The combination of mechanics and electronics in systems as small as the drive ejection on the CD player and up to large industrial robots.
- Structural Analysis: Dealing with how material and parts handle force and stresses.
- Thermodynamics: Studying energy creation, flow, and transfer in systems such as engines, power plants, and ventilation.
As part of an engineering team, Mechanical engineers would be responsible for designing the chassis and drivetrain of the mechanical systems, working closely with the Electrical Engineers to understand the size and forces involved. They would use computer assisted drafting (CAD) to create drawing and oversee their manufacture and testing of parts by a machine shop or using 3D printing.
The Turtle Robot chassis was designed using CAD and 3D printed. The quick turnaround for 3D parts means an engineer can rapidly test and modify parts to meet the system requirements or explore new ideas.
Step 15: Mechanical Engineering (ME): Parts
Time to switch gears from Electrical Engineering to Mechanical Engineering.
The required hardware is on the bill of materials (BOM): https://github.com/aspro648/OSTR/blob/master/BOM.md.
A current copy of printable STLs are located on Thingaverse. You will need:
- 1 Chassis
- 2 Wheels
- 1 Caster
- 1 Pen Collar
- 1 Nameplate (optional).
Again, a kit for this project is available on Tindie.com if you don't have access to 3D printing.
Step 16: ME: Chassis Prep
A "chassis" is the fame of a motor vehicle or other wheeled conveyance, and in this case the robot's chassis forms the platform for the electronics, motors, and servos.
Time to get familiar with your hardware. We will be using three different types of Phillips screws you will have to be able to identify:
- Pan Head Screw (M3 x 6 mm) -> Stepper motors to Chassis
- Flat Head Screw (M3 x 6 mm) -> Battery Holders to Chassis
- Round Head Thread-Forming Screw (#2 x 1/4") -> PCB to Chassis
In order to attach parts, we are going to embed M3 nuts into the chassis.
- Use an M3 round-head screw and tighten it to pull the nut into the pocket so it is seated flush.
- Remove the screw.
Step 17: ME: Batteries
Integrating the electrical components like motors and batteries with the chassis will fall into the ME's domain.
- Attach the battery holders using two M3 flat-head screws and thread the wires through the openings under the motor mounts.
- Put on your "EE" hat and attach the positive and negative wires to the terminals marked "+" and "-", one set of batteries for each terminal.
- Attach the circuit board to the chassis using #2x1/4 thread-forming screws.
- If the screws wont start, remove the PCB and use the tip of the screw driver to open them up a bit.
Step 18: ME: Servo
The servo is used to raise and lower the pen for drawing.
- Place the arm on the hub and gently rotate the stepper counter-clockwise looking down on it until it reaches the stop.
- Remove the arm and position it facing left (this will be the down position).
- Insert the small thread-forming screw and tighten.
- Insert the servo in the mount with the hub end upward and attach using two larger thread-forming screws.
Step 19: ME: Stepper Motors
Before we mount the stepper motors, check the fit of the wheels on the shaft. These should slid on fairly tightly if your printer is calibrated correctly.
- If they are too tight, use a jewelers file to open up clearance. You can also heat the hub with a hair drier, but do so sparingly to avoid warping the rim.
- If they are too loose, you can use an M3 round-head screw to hold the wheel to the shaft (after the motor is mounted).
We are going to pass the wires of the stepper (and servo) under the body to help with wire management.
- Start with the left side and thread the wires for the stepper (and servo) through the opening with wires coming from the stepper following down the back side.
- Insert the motor into the mount and attach with two M3 round-head screws and nuts.
- Gently pull the wires through.
Step 20: ME: Caster
The caster allows the robot to pivot with low friction.
- Gently press the bearing into the holder.
- If it is too tight, use a hair dryer to soften the plastic.
- Attach the caster to the chassis using M3 round-head screws.
Step 21: ME: Wheels
- Slip the o-ring into the rim groove and stretch it to snap in place.
- Gently press the wheel on to the stepper shaft as far as it will go.
- If the wheel is too loose on the shaft, you can drill a hole and thread a M3 round-head screw in the hub.
Step 22: ME: Power
- Attach the stepper connectors to the terminal headers on the PCB.
- Fold and press the wires into the cavities between the headers and the steppers to keep them clear of the servo arm during operation.
- Insert the Adafruit Trinket Pro into the headers with the USB hub facing the edge and press into place.
- Ensure the power switch is set to off.
- Insert the batteries.
Step 23: Software Engineering Overview
A software engineer is a person who applies the principles of software engineering to the design, development, maintenance, testing, and evaluation of computer software.
Margaret Hamilton promoted the term "software engineering" during her work on the Apollo program. The term "engineering" was used to acknowledge that the work should be taken just as seriously as other contributions toward the advancement of technology. A software engineer is responsible for writing and maintaining software used to control electrical hardware devices such as cell phones or systems in automobiles.
Educational requirements vary, but include degrees in computer science, information systems, information technology, or software engineering. A software engineer would be expected to have familiarity with electronics and mechanical systems.
As part of a robotics engineering team, the software engineer would be responsible for writing the code that control the motors and servos and may create graphical user interfaces (GUIs) to control and test functions of the robot. They would work closely with the mechanical and electrical engineers to understand the specifications and control of the various components used.
Turtle robot has stepper motors, servo motors, sensors, and LEDs that all need to be programmed in order for it to function. The robot is programmed in Python, a popular and useful language that is known for it ease of learning and readability.
The ItsyBitsy board controlling the robot was designed and manufactured by Adafruit Industries in New York, a company founded by Limor Fried, also known as Lady Ada, a MIT graduate. Her company promotes Open Source DIY electronic projects. Visit http://Adafruit.com for inspiration on your next project. The ItsyBitsy can be removed from the robot and placed in a breadboard or other project and reprogrammed to do your bidding.
Step 24: Software (SW): Testing and Blinking
The current design uses the Adafruit ItsyBitsy microcontroller family, which come in a number of flavors. These are the ones that will work with the robot
The 32U4 is inexpensive, but it is a bit more difficult for beginners to use and limits you to using the Arduino IDE to program it. Follow the link above to learn how to set it up. Firmware is located on Github, but I have not done too much work on it other than to test basic functionality. Check the V1 firmware folder for C examples.
The M4 version is slightly more expensive, but is powerful enough to run Python which makes it the perfect platform for beginners.
If you bought a kit from Tindie, the ItsyBitsy will come with the correct version of CircuitPython and be preloaded with firmware and examples. You only need to install the Mu editor as outlined below:
- Follow the Adafruit instructions to install the Mu editor. It recognizes the ItsyBitsy automatically and gives us access to serial console and plotting.
- The firmware was written to work with Circuit Python 4.1. Depending on when are where you get your Itsy from, you may need to update it. Follow these instructions.
- Download and unzip the Turtle Firmware and copy it onto your ItsyBitsy.
If all has gone well, the RGB LED on the ItsyBitsy should turn magenta while the current Python script is running.
- If the board is plugged into the Robot Base, you should also hear some beeps.
- If the batteries are installed and the power switch is on, the robot should exercise the servo motor twice and then begin to draw squares.
If these do not happen, don't panic! Skip ahead to the trouble shooting section. If all else false, ask for help! I've done my best to ensure your success, but if you have trouble you can help me improve it by helping me figure out why.
Step 25: SW: Calibration
Because of variations in assembly and alignment, the robot must be calibrated so that it can move precise distances and angles. This is controlled by two parameters, the diameter of the wheel and the distance between the wheels. While we can measure these, they need to be tweaked a bit to get more precision.
The Python code to make the calibration squares is called "wheel_calibration.py" and is executed by the main "code.py" script. Calibration parameters, if they need adjusting, are located in "calibration.py"
Prepare the pen:
- Remove the cap and slide the pen collar from the tip side.
- Insert pen in holder with servo arm straight up.
- Ensure the pen is just barely above the paper in this position.
- If the pen binds in the shaft, us a file to remove any roughness.
Draw a square:
- Slide the power switch to "On".
- Wait several seconds for the bootloader to begin.
- After the robot completes it's first square, remove the pen and turn the robot off.
Adjust wheel_dia parameter first. Measure the length of side of the square. It should be 100 mm:
- If the measured distance is too long, increase wheel_dia.
- If the measured distance is too short, decrease wheel_dia.
After you have the distance calibration, adjust the wheel_base parameter which affects the angle of the turn. Place the robot on a fresh sheet of paper, turn it on and let it draw all four squares:
- If the robot is turning too sharply (box is rotating clockwise), decrease wheel_base value.
- If robot is not turning sharply enough (box is rotating counter-clockwise), increase wheel_base value.
- Because of rounding errors in the stepping code and slop in the gears of the inexpensive steppers, you will never get it perfect, so don't spend too much effort on it.
Step 26: SW: Servo Adjustment
The servo raises and lowers the pen. At the beginning of the wheel calibration script, it raises and lowers the servo twice. If it is not traveling between vertical and horizontal, we can adjust the parameters in calibration.py.
If it does not appear to be moving a full 90 degrees, you can try changing the min_pulse and max_pulse parameters.
If you are unable to achieve the positions you want, you may have to remove the servo, unscrew and remove the horn, and readjust it's position.
Step 27: SW: Vision Check
Now that you have a calibrated turtle, let's look at how it's eyes work. There are lots ways for robots to detect their environment:
- Bump sensors (limit switches).
- IR emitter/detector pair
- Laser range finding
- Beacon detection
We are using IR because it is easy and inexpensive. The downside is that detection distance is short (several inches), varies by surface reflectance, and is subject to interference from other IR sources like the sun.
- Modify "code.py" to run "turtle_eye_check.py" and save it.
- Click the [Serial] button on Mu. You should see a stream of numbers.
- What happens if you move your hand in front of the detector?
- Click on the [Plotter] button in Mu.
If you are not getting the desired response:
- Use a phone or camera to observe the IR emitters are working.
- Verify the emitter and detector alignment. If they angle toward each other, it will cause interference.
- Direct or indirect sunlight contains IR and can interfere with the signal.
Step 28: Trouble Shooting
This is a pretty complex project, and will likely give you fits at some point. I like to tell workshop participants that they need to have:
- Patience - Don't give up at your first failure.
- Persistence - You have to keep trying different things to solve problems.
- A Positive Attitude - You can do it!
If you are having trouble saving sketches to the ItsyBitsy:
- Unplug and reinsert the USB cable.
- When saving any sketch, the board should reset (you should here beeps).
- Ask for help in the comments or Adafruit forums.
No power when on-switch turned on:
- Ensure you have fresh batteries.
- Ensure batteries installed correctly.
- Double-check battery connections to terminal blocks.
- Disconnect servo & steppers.
- Use a volt meter to verify voltage at terminal blocks.
Wheels do not move or stop moving during run for calibration step:
- Ensure you have fresh batteries installed correctly.
- Check white stepper connectors inserted fully.
- Ensure battery wires are not binding the wheels.
- Ensure steppers rotate by hand.
Robot turns the wrong direction:
- You have the left and right steppers plugged in to the opposite headers.
Pen doesn't leave a trace:
- Ensure pen is free in barrel and will drop below the wheel.
- Use a file to remove roughness and open barrel diameter.
- Ensure pen holder is at the proper level hold the pen up.
- Ensure servo points straight up during penup() command. If not, adjust PENUP angle in firmware.
Pen Too Loose:
- Verify your 3D printing parameters.
- Add some tape to the pen to increase the barrel diameter.
If you are stuck, ask for help in the comments. I've done my best to make this a successful beginners project, but it is complex. Asking for help lets me know what needs improvement.
Step 29: Curriculum Ideas
For my workshops, we use the Hour of Code activity at GROK Learning: https://groklearning.com/hoc/activity/snowflake/. It provides a gentle introduction to Python, Turtle commands, and loops.
Once the participants finish, they can create their own custom snowflake in the browser. This can be directly placed in the "mySnowflake.py" template. The firmware also contains the final snowflake example from the tutorial in "turtle_snowflake_example1.py".
In addition, the following example scripts are available in the firmware folder:
- music_example.py: Generate 8-bit style music using a tone(duration, frequency) command.
- rtttl_example.py: Generates tunes based on the Nokia ring tone codes. Examples are include for Star Wars, MahnaMahna, and The Simpsons to name a few.
- obstacles.py: Uses the IR sensors to stop the robot when an obstacle is encountered. Encourage the student to complete the algorithm to have the turtle maneuver to avoid the obstacle.
The following examples can run on the robot, or in a Python interpreter on a computer. This allows the student to modify the scripts and test them virtually before unleashing them on the robot.
|turtle_snowflake_example1.py from the groklearning tutorial.|
|turtle_snowflake_example2.py from the Code with Anna and Elsa tutorial.|
|turtle_font_example.py: Uses a simple vector font to write messages out.|
|turtle_cursive_example.py: Uses a vector font from the 1960s called "Hershey font". It was originally designed to write text on CRT screens.|
|turtle_goto_example.py: Uses the goto(x, y) command to create simple line drawings. The example recreates the turtle icon used in the Python Turtle implementation. How is that for meta?|
- From the snowflake tutorial, create your own custom snowflake and put the code in my_snowflake.py template.
- In snowflake examples, use the function random.randint(low, high) to generate random number of arms, angles, and/or lengths.
- Modify turtle_font_example.py or turtle_cursive_example.py to write your name or a message. Could you use random.randint(low, high) to create random messages?
- In turtle_obstacles.py, the turtle only stops when sensing a wall. Write code to have turtle navigate away from obstacles it senses.
- Create a maze for the student to solve. (example)
- Try the different songs in rtttl_example.py to find your favorite.
- Open music_example.py to see how tones are played. Can you adapt your favorite tune in code?
- What does turtle_goto_example.py draw? Use the handout to create your own object.
- There is a isButtonPushed() function that returns True if pushed, False if not. What could you use that for? Hint: look in eye_check.py!
- Bonus level: Since turtle can see and emit IR, with a friend could you create a predator / prey pair, with one seeking IR, and the other fleeing IR?
Step 30: Workshop Notes
Join the Turtle Robots forum to share your robot and teaching ideas!
Resources are always limited when doing workshops, so I've been breaking students into three groups and rotating them through three areas, each with a knowledgeable volunteer.
- Electrical: Soldering the PCB.
- Soldering irons, one for every two students so they can work in pairs.
- Flush cuts
- Safety glasses
- hot glue
- Laptops/computers, at least one for every two students so they can work in pairs.
- Rulers for calibration
- Pre-built robots for testing code if they haven't assembled their robot yet.
Safety with the electrical portion is important and should be discussed before starting. Safety glasses should be worn. I have a squirt bottle of water at the table for cooling burns (and wetting sponges).
Here are a couple of the soldering videos I like to show:
Most examples run on a 8.5" x 11" sheet of paper. Lay down some butcher paper on the floor for larger drawings.
Step 31: Bonus Activity: 3D Name Plate
I like having the 3D printer at the workshops since it shows how the robot was made. I usually print out tree frogs to give the students. They usually end up riding the robots around.
If time allows, a simple 3D design exercise allows the student to learn more about 3D printing while creating a custom name plate for their robot. The flat, thin object prints quick, and swapping filament out creates a nice contrast.
Step 32: Turtles in the Wild
I love seeing these robots out in the wild, especially when they have been modified in ways I would have never have thought. Here are a couple of notable examples, with hopefully more to come:
|Instructable User Aaqup has taken the Turtle to the next level with his Otto Turtle Project! He was able to make it more compact by having the pen travel through the circuit board!|
|Russ Hughes does workshops and has created a custom circuit board, uses Tiny Basic, and has implemented the Hersey Vector Font.|
|Instructable user seancuttlefish added both sonar and line following|
|An in the "where there is a will, there is a way" category, Samarsis created a version with no 3D printing!|
If you make a Turtle bot inspired from my examples, use the "I Made It!" button below, upload a picture, and make my day!
Second Prize in the