Laboratory 1: Digital Input/Output (GPIO)

Laboratory Description

In this lab, simple digital inputs are used to program the TI-RSLK to drive in a desired pattern composed of independent segments:

  1. drive and turn left 90°

  2. drive and turn left 45°

  3. drive forward

  4. drive and turn right 45°

  5. drive and turn right 90°

  6. stop for 1 second.

The bumper buttons on the car will be used to input each sequential step while a breadboard wired slide switch will cause the inputted pattern to execute and/or stop. A breadboard wired pushbutton is used to delete the last step inputted. A BiColor LED will provide indication of if the pattern is running (GREEN), the pattern is complete (RED) or the program is waiting for user input (OFF).

Laboratory Goals

This laboratory is designed to further a student’s understanding of:

  • The Code Composer Studio (CCS) Integrated Development Environment

  • Programming the MSP432P401R microcontroller,

  • The implementation and use of inputs and outputs,

  • The development of modular C programs towards producing a function system, and

  • The working of the TI Robotics System Learning Kit (TI-RSLK).

Preparation

Students should complete Activities 1-5 prior to starting this laboratory. A good understanding of the tasks in Activity 5 will be very helpful for this laboratory.

Hardware and Tools

  • TI-RSLK Robotic Car

  • Breadboard

  • Components (provided):

    • 1x Pushbutton

    • 1x Slideswitch

    • 1x BiColor LED (BiLED)

    • Various Resistors ( 1x 510Ω, 2x 1kΩ)

  • Wire (available in classroom)

Project Template

Part A: (Class 1) Build and Test I/O

The first day of this lab consists of building the hardware required, producing the GPIO initialization code, and implementing tests to verify the correct operation of all inputs and outputs. The circuitry needed is shown in the Figure Lab 1 Schematic. Note that this schematic provides both the circuitry included on the RSLK and that which needs to be built. The circuitry that needs to be built should be done on an external breadboard, not the one mounted on the RSLK, to allow for other teams to use the same car.

Warning

There are no 5V connections within Lab 1 Schematic, only 3.3V! This is because the microcontroller pins are only 3.3V tolerant and will likely fail if 5V is applied to them. Ensure that you never use 5V when connecting to this microcontroller!

../_images/lab1_schematics.svg

Lab 1 Circuit Schematic

Both the left and right drive motors on the RSLK are controlled by two output lines: On/Off and Direction. The On/Off line will turn the motor on (High) or off (Low) whereas the Direction pin indicates if the wheel should rotate forward (Low) or reverse (High).

With the circuitry built, the GPIO pins must be initialized. You must use the template project lab1_template.zip. This template project has a purpose-built library (Lab1Lib Driver Library) for interacting with the motors. Within this project, initialize the pins as specified in the schematic within GPIOInit() using the DriverLib functions only; do not use registers. We will not be using registers to interface with the MSP432 for the rest of the course.

Important

You must use the DriverLib function

void GPIO_setAsInputPinWithPullUpResistor( uint8_t port,uint8_t pins);

to initialize the bumper buttons. This is needed as the corresponding resistor, R_PU, as shown on the schematic is part of the microcontroller and not an actual component. Therefore, R_PU must be enabled through the microcontroller to create the needed pullup resistor.

Finally, finish the code provided within function TestIO() to test the inputs and outputs. The input values should be printed each time a keyboard key is pressed. Further, if the keyboard key pressed is contained within the list below, the specified operation should be completed to test the output. An example on how to complete this is given in the template code.

Key

Function

a

LEDFL On

z

LEDFL Off

s

LEDFR On

x

LEDFR off

q

BiLED1 Red

w

BiLED1 Off

e

BiLED1 Green

Warning

Do not forget to turn the car on to test! The motors will not work without the car being turned on; however, all other components work regardless.

To turn on/off the car: Push the very small button marked “Power” on the back corner of the car. A blue LED will light near the car to indicate it is on, assuming there are charged batteries in the car.

Please remember to turn off the car when you are done with it!

Ask a staff member to check off Part A when complete; then continue with Part B.

Part B: (Class 2) Pattern Input and Running

With the inputs and outputs built, configured, and tested, the pattern control routine may be added to the project. As provided in the description above, each of the bumper buttons are used to input a specific action into the pattern. They should be configured such that:

  • BMP0 adds the “turn right 90°” segment

  • BMP1 adds the “turn right 45°” segment

  • BMP2 adds the “drive forward” segment

  • BMP3 adds the “stop for 1s” segment

  • BMP4 adds the “turn left 45°” segment

  • BMP5 adds the “turn left 90°” segment

Each time a bumper button is pressed, LEDFR and LEDFL should switch off or on, with one always being on; this used to indicate a success input of a segment. If the breadboard pushbutton is pressed, the last segment input should be deleted from the program. Finally, if the breadboard slide switch is toggled from off to on, the program should trigger the pattern to be run and the BiLED lit to GREEN. Once the pattern completes, the BiLED should be lit RED until the slide switch is toggled back off. While the BiLED is lit either color, the inputs are ignored.

The simple functional description above can be translated into a flow diagram: Lab 1 Flowchart. Blocks with * indicate functionality provided by functions within the Lab1Lib Driver Library..

../_images/lab1_flow.svg

Lab 1 Flowchart. Blocks with * indicate functionality provided by functions within the Lab1Lib Driver Library.

Warning

The bumper buttons are prone to bouncing. You will need to debounce your button press/release and slide swith on/off detection to avoid registering multiple button presses for a single physical press.

Implement the control scheme above within the function ControlSystem(). The flow chart must be explicitly followed; that is, do not make assumptions about system behavior that are not described by the diagram. You will need to comment out the function call to TestIO() and uncomment the call to ControlSystem() within the main() function’s while(1) loop. As ControlSystem() is called within a while(1), there is no need to have an additional while(1) loop within this function, though other while() or for() loops are required.

Ask a staff member to check off Part B when complete and submit the final code to Gradescope. The code must successfully implement the logic as described above and not be prone to button bouncing. For demonstrational purposes, a simplistic obstacle course may be set up in the classroom for the cars to traverse.


Lab1Lib Driver Library Functions

The following are functions that are provided by the Lab1Lib Driver Library and are provided within src/Lab1lib.lib. The documentation provided here is also available in inc/lab1lib.h

init_Sequence

void init_Sequence(void)

This function initializes the Lab1Lib Driver.

record_Segment

int8_t record_Segment(int8_t mv)

This function adds a segment to the programmed sequence. The input, int8_t mv, represents the segment to add:

mv value

Corresponding Segment

-2

Drive and Turn 90° Left

-1

Drive and Turn 45° Left

0

Drive Straight

1

Drive and Turn 45° Right

2

Drive and Turn 90° Right

127

Stop for 1s

This function will output:

  • 0 if segment was added to the sequence

  • 1 if the segment has reached the maximum length (50), segment was not added

  • -1 if the value of mv is not in the table above

pop_Segment

uint8_t pop_Segment(void)

This function removes the most recently added segment. Outputs 0 if a segment was erased or 1 is there is no segments to erase (sequence is empty).

clear_Sequence

void clear_Sequence(void)

Erase the currently programmed sequence.

run_Sequence

uint8_t run_Sequence(void)

Runs the programmed sequence. Returns 0 if started properly, 1 if the sequence is empty, or 2 if the GPIO pins for the motor are not set up properly. In the case of a return of 2, the program will also print a message indicating the issue.

status_Segment

int8_t status_Segment(void)

Returns the currently running segment in the sequence (see table for record_Segment) or 100 if the sequence is not running (either hasn’t run or is complete).

status_Sequence

uint8_t status_Sequence(void)

Returns the step that a running sequence is on (1,2,3, etc.) or 100 if the sequence is not running (either hasn’t run or is complete)

get_SequenceLength

uint8_t get_SequenceLength(void)

Returns the total number of segments currently programmed into the sequence. The maximum length of a sequence is 50.