Exercise: 3pi in Serial Slave mode
Objective
When developing more complex application that require additional I/O, more computation capabilities, or communication protocols not supported by the 3pi (e.g. SPI, I2C), it is helpful to use the 3pi as a Serial Slave of another microcontroller. According to the documentation: "This slave program receives serial data on port PD0 (RX) of the 3pi and transmits responses (when necessary) on port PD1 (TX), using a 115.2 kbaud, TTL-level serial protocol. "
In this exercise, we will create a robot that will move away if you touch it.
Steps and observations
- Load the Serial Slave program onto your 3Pi Robot
- Devise a way to mount a traditional Arduino (an "Uno") onto the 3Pi robot; consider building a parallel plate that mounts on top of the 3pi robot, held up with long machine screws and plastic spacers.
- Connect the I2C gyro/accelerometer from your course kit to the Uno; create a sketch and reads the accellerometer values from this sensor.
- Extend the program so that when the accellerometer readings from the sensor show movements above a certain threshold, the Uno sends serial commands to the 3Pi robot to make it move away. Refer to the table on this page from the Pololu site for references on the commands you can send to the 3Pi robot over serial, using the SoftwareSerial library (the built in SoftwareSerialExample sketch is a good reference as well). If you instead use the built in Serial library with the regular TX/RX pins, you may have issues uploading the sketch.
- Connect the TX pin of the 3pi to the RX pin you defined in the sketch. Connect the RX pin of the 3pi to the TX pin you defined in the
sketch. If you keep the defaults that are in the SoftwareSerialExample sketch, you would connect the TX pin of the 3pi to pin 10 of the Uno
and the RX pin of the 3pi to pin 11 of the Uno.
- Experiment with different choreographies of "moving away", for instance: a quick/jerky move, and then a 180-degree turn
Comments
This execise involves integrating a number of important lessons from the past exercises into a single applicaiton. These include serial communitation, I2C protocol f or sensing, and designing systems with variable time-based behavior.
In order to add additional components to the 3Pi, it's best to create a 2nd level on top of the robot. This can be achieved by laser cutting hardboard or plexi in the shape of the 3Pi's base, and mounting this second plate to the 3Pi using hardware. Please see the link below for a digital drawing of the right shape
Other Files
- Pololu 3pi Components and Pin Assignment Table
- Drawings of a 3Pi base plate: DXF, DWG, Illustrator (AI), Rhino (3dm), Soldworks (SLDPRT)