PA Designer Learn 2: LED and Loudness Sensor

This is the second challenge within the Robotics with GoPiGo and Python Curriculum.

Your task is to program your robot to alert a person with a hearing impairment to visiting house guests.

Learn how to use the Loudness Sensor alongside Jupyter Notebooks.

8. Test: Loudness Sensor

Now we’re ready to code up the sensor reading loop. We no longer need the code that we wrote to test the LED so

      1. let’s clear this code from the Main Code cell.
      2. Now type the following code into it

# perform all variable declaration and initialization 
init()
 
# repeat the following instructions for 10 seconds
while elapsed_time() < 10:
    print (f“Loudness = {loudness.read()}”)
    time.sleep(0.02)

Click on Run Selected Cell.

If everything is in order, you should see a stream of loudness readings displayed below the code cell (your numbers will be different):

Loudness = 171
Loudness = 126
Loudness = 314

If you don’t get any readings, run through the troubleshooting steps, noting that we are using port “AD2” for the loudness sensor, and try again.

      1. Have you plugged the Loudness Sensor board into the Analog Digital 2 port?
      2. Does your code initialize the Loudness Sensor using port “AD2”?
      3. Are both ends of the connector cable fully inserted?