LEARN.PARALLAX.COM
Published on LEARN.PARALLAX.COM (https://learn.parallax.com)
Home > Hacker Port Expansion

Hacker Port Expansion

The Scribbler 3 Hacker Port offers unlimited potential for expanding your robot with additional sensors and devices like the PING))) Ultrasonic Distance Sensor, Parallax Standard Servo, and more.

The tutorials in this section will teach you how to use the exposed Hacker Port to connect and integrate peripheral sensors into your BlocklyProp programs.

You will need a window or tab open to the BlocklyProp website to follow along with these tutorials.

Before you begin, you should have already completed:

  • Getting Started with BlocklyProp for the S3
  • Lights and Sounds
  • Simple Motion with Motors Blocks
  • Navigating With Sensors

If you are ready to proceed, click the following links to get started!

What's A Hacker Port?

One of the standard warnings on many electronic gadgets is that opening the case voids the manufacturer’s warranty. This has discouraged many users from hacking, or making creative modifications to a device. But, it has served as a dare to others to boldly void the warranty and hack away!

Luckily, hacking the S3 is not discouraged but is instead encouraged. To support and encourage hacking, the S3 includes an exposed and labeled Hacker Port. HACK away! As Parallax President Ken Gracey says, “If you can’t hack it, you don’t own it!”

First let’s find the Hacker Port and then look at the pins made available for us to use. Then, let’s try connecting two different circuits to the Hacker Port: an LED, and then a rear bumper.

Parts Required

  • (1) Yellow LED (#350-00007)
  • (1) 3-wire female-female extension cable, 8-inch (#800-00080)
  • (1) 220 ohm resistor (red-red-brown) (#150-02210)
  • (1) 10 k-ohm resistor (brown-black-orange) (#150-01030)
  • Jumper wires (#800-00016)

Other household items needed are listed with each circuit below.


Did You Know?

The term hacker first appeared in the 1960s. It was used to describe a programmer or someone who hacked or modified computer code (oftentimes to cause harm to the computer or its users). Today the term is used more broadly, including to describe someone who has an advanced understanding of computers, networking, programming, or hardware, but who hacks as a hobby or as a way to improve code, or hardware. A hacker culture has developed among a larger commjunity, called Makers, who create, modify or re-purpose all sorts of things. In our case – robots!


What Exactly Is a Hacker Port?

Roboticists love to hack. We encourage this practice, so we made sure that the S3 Hacker Port is fully exposed and situated right on the top of the robot. Take a look at your S3, or at the labeled diagram of the top part of the shell that is included in your Startup Guide. The Hacker Port is on the left hand side next to the front of the left drive wheel. Inside the port you will see three columns and eight rows of pins. These pins are your direct connection to the powerful inner working of the S3 robot. What is so great about these pins being exposed? You don’t have to open the robot’s case to access them. Adding a peripheral sensor can be as easy as simply plugging in a cable.

Each of these pins has a purpose. To understand the purpose of each pin, engineers create what is called a Pinout diagram. Your Hacker Port label shows pin numbering, supply voltage, and ground connection.

The pinout diagrams for Propeller microcontrollers are very detailed. If you’re curious, do an online search for “Parallax Propeller pinout.” You will notice that the Propeller microcontroller has a lot more pins than what is available on our Hacker Port. Many of these, however, are reserved for monitoring and controlling the many built-in sensors and other features of your S3 robot.

Let’s look at this pinout diagram of the S3’s Hacker Port, taken from the S3 User Guide included with your Scribbler. 

Let’s try doing something useful with a few of the pins in the Hacker Port.

Connect an LED

A diode is an electrical part that only lets electricity flow through it in one direction.  A light-emitting diode (LED) emits light when current passes through it. In order for an LED to light up, it must be connected in the correct way. If you plug an LED in backward it will not emit light.

An LED has two terminals: the anode and the cathode. The anode lead, the wide part of the triangle in the schematic symbol, is labeled with the plus-sign (+).  The cathode lead, labeled with a minus-sign (-), is the verticle line across the point of the triangle in the schematic symbol.

You can tell the anode and cathode apart by the shape of the LED’s plastic case.  Look closely – it’s mostly round, but there is a small flat area near the cathode lead. Also note that the LED’s leads are different lengths. Usually, the shorter lead is connected to the cathode. 

Always check the LED’s plastic case.  Sometimes the leads have been clipped to the same length, or a manufacturer does not follow this convention.

One of the simplest things you can attach to the Hacker Port is an LED.  To build an LED circuit for your Scribbler Robot, you will need the items below:

  • 3-pin cable
  • 220 ohm resistor (red-red-brown)
  • Yellow LED
  • tape, such as masking tape or electrical tape

Before connecting anything to your Scribbler robot’s Hacker Port, make sure your Scribbler is turned off and unplugged from its programming cable!

  • Connect the long leg of the LED to one of the legs of the resistor.  You can make this connection by simply twisting the legs together until they make a good electrical connection. Then, cover this connection with a small amount of tape.

  • Insert the unconnected leg of the resistor into the white wire’s connection on one end of the 3-pin cable, and insert the short leg of the LED into the black wire’s connection of the 3-pin cable.
  • Find the P5 row of the Hacker Port and plug in the 3-pin cable – make sure the black wire is connected to the Ground pin and the white wire is connected to the P5 (signal) pin.

  • Build the following program using blocks from the HACKER PORT > PINS categories and load it onto your Scribbler Robot:

Your LED should now be blinking!

How it works

When P5 is turned high by the make pin block, that means it begins sending a positive voltage out of that pin. That positive voltage pushes an electrical current through the resistor and then the LED.  Since the LED is connected to Ground, the circuit is completed and the LED glows.  When the make pin block sets P5 low, both ends of the circuit are at zero volts, which means there is no voltage to push an electrical current through the LED, which makes it stop glowing.

Build a Rear Bumper

The Scribbler Robot has an infrared obstacle detector in the front, but it has no way to know if it backs into an obstacle.  Using a few simple materials, you can add a rear obstacle detector (bumper) to your Scribbler!

You will need:

  • (1) 3-pin cable
  • 1 large paperclip
  • 1 piece of aluminum, tin, or copper foil (approximately 1/2 inch wide by 6 inches long)
  • 2 jumper wires
  • 1 10 kohm or larger resistor (brown-black-orange)
  • masking or duct tape

 

Make sure your Scribbler robot is turned off before connecting anything to the Hacker Port.

  • Bend the large paperclip into the shape shown:

  • Tightly twist the exposed end of one jumper wire onto the paperclip.  It may help to strip some of the insulation off of the jumper wire to expose more of the bare wire before wrapping it around the paperclip.
  • Tape the foil across the back of the Scribbler robot.
  • Poke one end of the other jumper wire through the foil at one end, and tape the connection between the foil and wire down.
  • Cover the end of the foil with tape so that the paperclip you are about to tape down on top of it does not make electrical contact with it.

  • Tape the paperclip down as shown:

  • Insert one leg of the resistor into the white wire’s pin, and the other leg into the red wire’s pin on the 3-pin cable.
  • Insert one jumper wire into the white wire’s pin (with the resistor), and the other jumper wire into the black wire’s pin on the 3-pin cable.

  • Find the P4 row of the Hacker Port, and plug in the 3-pin cable. Make sure the black wire is connected to the ground pin and the white wire is connected to the P4 (signal) pin.
  • Build the program shown using the HACKER PORT > PINS > check pin block, and load it to your Scribbler:

  • Observe the terminal output.  Press the paperclip so that it makes contact with the foil.  If your connections are working properly, the number displayed should change:

How it works

The check pin block sets P4 to an input.  This means that it senses when voltage is (or is not) applied to it. The resistor “pulls” the signal pin (white wire) up to a positive voltage so that when the bumper is not pressed, the value of the check pin block will be 1.  When the paperclip touches the foil, the signal wire becomes connected directly to ground (0 volts).  This means that when the bumper is pressed, the value of the check pin block will be 0.  

Try This 

  • Build the program shown below, and load it to your Scribbler robot:

Your Scribbler will drive backward until it bumps into something.  Then it will drive forward for 2 seconds before driving backwards again.

Your Turn

  • Try using the obstacle sensors in addition to the rear bumper to make your Scribbler robot roam around a room completely on its own.

Special thanks to Parallax friend Whit Stodghill for his assistance in writing, editing, and testing material for these S3 tutorials.

Controlling a Standard Servo

Let’s start putting the S3’s Hacker Port to use by connecting and controlling a Parallax Standard Servo. This tutorial will first demonstrate how to make a Standard Servo hold three different positions, and then how to approximate smooth, continuous motion with small, evenly-timed changes in position. With the S3’s Hacker Port, the physical connection is extremely easy and with BlocklyProp, coding is greatly simplified.

You will need the following accessory parts:

  • (1) Parallax Standard Servo (#900-00005)
  • (1) 3” Jumper Wire (#800-00016) or long twist-tie

A hobby servo is a small device that controls the position of flaps, rudders, and steering in many radio-controlled toy planes, boats, and cars. The Parallax Standard Servo is a hobby servo that can also be useful in many robotics and animatronics projects.  Since it can both move to and hold a position, it is ideal for tasks like rotating a distance sensor or controlling the fingers in a robotic hand.
For more information on Standard Servos and how they work, see: Propeller C Simple Devices – Standard Servo.

 

Servo Angle Marker

It helps to create some sort of angle marker on the turning part of the servo, the horn, to more easily indicate which position it is in. A jumper wire or twist-tie works well for this.

  • Find the middle of the servo’s range by gently twisting the horn right and left to find the mechanical stops, then positioning it in the middle of its range.
  • Twist the wire through the top two holes at the center of its range to mark the “middle” position. When finished, it will most likely look something like the figure below.

A Parallax Standard Servo is rated for a 4 to 6 V (volt) supply. The S3 User Guide notes that the S3 provides regulated 5V power, Ground (G) and access to I/O Pins 0 – 5 from the Hacker Port. Connections to 3.3 V power and Analog Pins 0 and 1 are also available from the Hacker Port.

All the info you need to properly connect the servo to your S3 is in the image below. Remember that it is printed right on the surface of your S3 directly adjacent to the Hacker Port. As you can see, there are 8 rows of pins arranged in 3 columns.

 

Connect the Servo to the S3

Make sure the power is off on your S3 and it is unplugged from your programming/charging cable. Connect the Standard Servo’s black/red/white cable connector to the pin row marked P0. Orient the connector so that the black wire is connected to the Ground column, the red wire is connected to the middle (5V), and the white signal connector is on the pin column – all along the row marked P0. Be careful not to accidently connect it to one of the rows labeled A0 or A1.

 

Holding Three Positions

Now, you can write the BlocklyProp Standard Servo test program to hold the three positions shown above. The code should move the servo to the three positions (0°, 90°, and 180° ) with three seconds to move between and hold each position. This code will also change the indicator LEDs based on the servo position. While the program is running, the servo will resist any attempt to move it out of position. When the program finishes, the servo will stop resisting.

  • Point your browser to BlocklyProp, login, and begin a new project for the S3.
  • Name your program Standard Servo Test.

In the ACTIONS > MOTORS category, you will find the rotate servo block and disable servo block. Other blocks will not be discussed, as they were used in previous tutorials.

  • Snap the following program together with the settings shown.
  • Save, compile, load to EEPROM, and run the program. Verify that the servo holds the 0° position, then the 90° position, and finally the 180° position each for about 3 seconds.

With BlocklyProp, the code explains itself:

  • The drop-down menu in the rotate servo block allows you to set the pin (the image is set to 0, the default, because that is the row the servo is connected to).
  • The number block allows input of an angle value in degrees. Click in the window to change this setting (0 to 180 when using a Standard Servo.
  • The wait block allows you to set your wait time value to 3000 ms (3 seconds) between each move as intended. Finally, the disable servo block is added and set for the same pin # (P0). Note the indicator LED feedback at each position.

As the image above shows, the rotate servo block allows you to set two parameters: the pin the servo is connected to and the servo angle in degrees. For example, to make the servo connected to P0 turn to 90-degrees, the block is set to P0 and 90. Keep in mind that the rotate servo block does not wait for the servo to get into position – it is necessary to include a wait block for the servo to reach the desired position before setting a new angle. Finally, the disable servo block makes sure that pulses to the servo are ended.

Note: Standard Servos have a 180-degree range, plus or minus small differences between individual units. Be careful not to enter a servo angle greater than 180 degrees or you could damage the motor.

 

Your Turn

  • Try modifying the program to make the servo hold a 45° angle and a 135° angle. Again, use LED feedback. Disable the servo. Verify it works as you would expect.
  • Use a loop (x times) block to program the servo to move from 0° to 180° back and forth continuously with an appropriate delay between the moves – ten times – with LED feedback. Disable the servo at the end.

Special thanks to Parallax friend Whit Stodghill for his assistance in writing, editing, and testing material for these S3 tutorials.

Standard Servo Pen Lifter

Suppose you want to use your S3 to scribble the word “Robot”. If you wanted each letter to be separate, you would need to remove the pen tip from the drawing surface between each letter. In handwriting or drawing terms, this is called a pen lift. (Here is a video of a Parallax S2 doing just that.)

 

 

Hardware Hack Instructions

In a previous tutorial, you learned how to control a Standard Servo by connecting it to your S3’s Hacker Port. In the pen lift hack, you can use a servo to lift the pen between letters or for other special purposes when we are scribbling. Follow this tutorial to learn how.

The video below shows the mechanical assembly of the pen lift device.

Photos, instructions, and the pdf print-out you will need are listed below. It is a simple and creative way to add a pen lifter to your S3 using a Standard Servo and some simple tools.

Parts List

  • S3 Robot
  • Parallax Standard Servo (#900-00005)
  • 1/2″ by 1 1/2” piece of double-sided foam tape or similarly sized Command® Strips
  • 3/4” wide clear tape (clear, double sided tape will not be strong enough)
  • Pen that fits in the S3 – Sharpie® or whiteboard marker
  • Scissors
  • Phillips-head screwdriver
  • Diagonal cutters or tin snips (or hand saw and clamps)
  • Safety glasses (always a good idea, but use every time when cutting things!)
  • Cable tie or twist tie
  • S3 Pen Lifter Paper Template

 

Preparing the Pen and Attachment Loop

  • Print out the Pen Lifter Template document, from the parts list.
  • Use scissors or a paper cutter to cut out one of the templates.

  • Fold lengthwise, along line “a”.

  • Using a piece of tape the length of the paper strip, tape over/around the long seam, so that it can not be unfolded. 

  • Fold widthwise, along line “b”.

  • Align the bottom of the paper template (indicated by the word “cap”) with the cap of your pen, making sure that the side labeled “this side against the pen” is exactly that.
  • Place a piece of tape over the “c” tape area to secure it to the pen.

  • Tape “d” to the pen in the same way, making sure the template lays flat against the pen. The two ends of the template will NOT be matched up.

  • Carefully push a pencil or similar instrument through the loop of paper just enough to open it up.

 

Modify the Servo Horn

  • Use your hand to gently rotate the servo horn as far counterclockwise as you can. Be careful not to force it.
  • Use a phillips-head screwdriver to remove the servo horn.
  • Use diagonal cutters, tin snips, or a hand saw to cut off three of the points. Be sure to wear safety glasses and, if using a hand saw, hold servo horn with clamp – not your hands!

 
Test and Configure the Servo

  • Make sure the power is off on your S3. Connect the 3-wire cable to the pin row marked P5. Orient the connector so that the black wire is connected to the Ground column, the red wire is connected to the middle or 5V pin, and the white signal connector wire is on the pin column.
  • Open BlocklyProp, login, make a new program called Pen Down Test, and construct the code below.  Hint: You will need to use a set variable block and a get variable block to complete this code, renaming as below.

  • Save it, compile, and load to EEPROM. This sets the servo to the center position and sets the center LED to green.
  • Place the modified servo horn back over the servo output shaft in the orientation shown below, push down onto the output shaft, and replace the screw to secure.

  • Now rerun the code by pressing the blue reset button. Find the exact angle setting so that the horn is centered as shown above. Insert that new angle as the pen_down variable value. Power down your S3 when done.

 

Putting it All Together

  • Cut a ½” by 1 ½” strip of double-sided foam tape.
  • Adhere the tape to your S3 on the surface adjacent to the pinout silkscreen, about 3/4” back from the face that has S3 written on it.

  • Place the servo over the tape in the position shown and press/hold in place for 30 seconds to ensure a good, strong bond.

  • Plug the servo into P5 of the Hacker Port, if not already connected, and use the cable tie to contain the extra cable.

  • Place your S3 over a safe writing surface (remember Sharpie ink is permanent).
  • Remove the cap from the pen and place ink down in the pen holder. Twist the paper loop over and onto the servo horn as shown in the next set of photos.

  • Congratulations, you’ve completed the Pen Hack! Now, let’s write one more piece of BlocklyProp code to test and set the pen’s “up” position.

 

Try This

  • Open BlocklyProp, login, and open your Pen Down Test. Save a copy as Pen Down and Up Test. Then modify the code as shown below.

This code depicts the following: First, you add a pen_up set variable block. Your values may vary – see note below. Next, you loop the body of the code 5 times. A green LED indicates that the pen is down, where it stays for 500 ms. The red LED shows that the pen is up, again for 500 ms.  As before, the servo is attached to P5. Finally, you disable the servo when finished.
Note: pen_down and pen_up values will vary based on your servo position, paper loop size and position, but the 20 degrees between values should be close to correct. Play with it to find out what works best for you.

  • Save it, compile, and load to EEPROM. Make sure that the pen is in contact with the surface at pen down and raised above the surface at pen up. Adjust the variables for these settings in your code, if necessary, save it and test it again.
  • Modify the program. Name it “Pen Down and Up Drive Test”- adding a speed variable block and drive speed block.

  • Now add the stop driving block at the end. This code makes the S3 move forward as the pen moves from down to up – making a dotted line.

  • Save, compile, load to EEPROM, and run the program. Adjust the settings so that your pen lifter works optimally. Change the drive speed variable and wait time to change the dotted line pattern.

 

Your Turn

  • Modify the Pen Down and Up Drive Test – adding a variable for the wait block setting. That makes the previous “Try This” a snap!
  • Modify some of the BlocklyProp programs you created in the Draw Simple Shapes or Turning Shapes into Art – adding pen lifts to make the shapes with dotted lines.
  • Check out this BlocklyProp program (created by Parallax-friend Whit Stodghill) and see if you can figure out what it does.
  • Save a copy of it as S3 Scribble, compile, and load to EEPROM. (Note: Use the best variable settings for your personal S3 robot that you discovered earlier.) 
  • Place your pen in the pen holder attach the paper loop to the servo horn. To run the program, press the reset button once.

Did your S3 do what you expected? If not, check out the Youtube Video of this program in action here.

Special thanks to Parallax friend Whit Stodghill for his assistance in writing, editing, and testing material for these S3 tutorials.

Sense Distance with a PING)))

The PING))) Ultrasonic Distance Sensor

The PING))) measures the round-trip echo time of ultrasonic sound to determine how far away an object is, and can measure distances anywhere from 3 centimeters to 3 meters.  In addition to being a great distance sensor for robots, the PING))) is also useful for things such as detecting when a person passes through a doorway, approaches art exhibits, and walks near holiday props.

Want to go a bit more in depth? Check out this article about the speed of sound vs. air temperature, and learn how the temperature of your environment can impact distance measurements from your PING))) sensor.

Connection and Parts

The PING))) sensor only needs three connections to do its job: I/O pin, power, and ground. The connections are easily accessible at the Hacker Port, making for a simple hacking project with the S3. BlocklyProp makes programming the PING))) simple and fun.

To complete this tutorial, you will need these parts:

  • (1) – PING))) Ultrasonic Distance Sensor (#28015)
  • (1) – 3-Pin Signal-Power-Ground Cable Extension (8″) (#800-00080)
  • S3 robot with programming cable.
  • A means of mounting the PING))) sensor (ideas are listed below)

 

BlocklyProp Test Code

Let’s have some fun in BlocklyProp and test some code. This particular code will display the distance in centimeters to an object placed in front of the sensor, providing Terminal and LED feedback. 

  • Point your browser to BlocklyProp, login, and begin a new project for the S3. Name your program PING))) Test.
  • In the HACKER PORT > SENSORS category, find the Ping))) distance block. With this you can set the unit of measure and the Pin connection. Now, snap together the following program with the settings shown in the image below. (Hint: you will also need the wait block, loop forever block, and the ACTIONS > COMMUNICATE category blocks shown.)

  • Find a simple way to mount the PING))) to your S3. The example shown below uses a clothespin wrapped in black tape. Sharpie® pens with the cap on can also work well as a base, since they fit nicely into the pen port. Some sort of tape will likely be needed.
  • Orient and seat the connector cable on the PING))) pins so that the black wire is connected to the Ground (GND) column, the red wire is connected to the middle or 5V pin, and the white signal connector is on the SIG column.
  • Connect the other end of the cable to the Hacker Port pins at P5, making sure to verify that the wires are connected properly. The black cable wire should be connected to GND.

  • Save, compile, load to EEPROM, and run the program.
  • Place an object in front of the PING))) sensor and verify that the measurements change appropriately as you move the object closer and farther away.

 

How it Works

After the PING))) sensor receives a low-high-low start pulse from the S3’s Propeller Chip, it makes a brief ultrasonic chirping sound. Humans cannot hear this ultrasonic cound, but it is loud enough that its own ultrasonic transducer can detect when the echo comes back.

As soon as the PING))) sensor makes its chirp, it sets its output pin high.  When the echo comes back, it sets the pin low.  The Propeller measures how long the PING))) sensor holds this pin high. This number is the round trip time it takes for the sound to return.

The BlocklyProp Ping))) distance block contains functions that send the start pulse and measure the echo time pulse.  It also utilizes functions that use the speed of sound in air to convert the echo time to a specified distance as set in the block.

 

 

Your Turn

  • Modify your program to connect on a different row of Pins (0-4) of the Hacker Port. Do not use pins A0 or A1.
  • Modify your program to measure and display the distance in another unit of measurement on the terminal.
  • Create the following new program. Try to predict what it is going to do once you run it.

  • Save, compile, load to EEPROM, and run the program.
  • Place your hand in front of the PING))) sensor about 2 feet away and watch how the program controls the S3. Can you see how the behavior is controlled by the code shown? Did it do what you thought it would? Why or why not?

Special thanks to Parallax friend Whit Stodghill for his assistance in writing, editing, and testing material for these S3 tutorials.

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2024


Source URL:https://learn.parallax.com/courses/hacker-port-expansion/
Links