Ambient Light Sensor Sample

Introduction

This documents how to work with the ambient light sensor sample.

Prerequisites

Why would I want to implement the instructions in this document?

If you wish to use the IoT Developer Kit as a stand alone ambient light sensor, this sample will help you accomplish this.

Some Important Things to Note

  • This document assumes that you are already familiar with the DevEdge IoT Dev Kit.
  • This document was created on a Mac, so all the examples are based on the macOS.

Configuration

Step A

Install Zephyr.

  1. Follow the instructions here to install Zephyr.

  2. Under Get Zephyr and install Python dependencies > Step 4, replace

    west init ~/zephyrproject

    with

    west init -m https://github.com/tmobile/DevEdge-IoTDevKit-ZephyrRTOS.git ~/zephyrproject

  3. The rest of the instructions stay the same.

  4. Stop at the Build the Blinky Sample section.


Step B

Clone the T-Mobile Zephyr RTOS and SDK.

  1. Open Terminal.
  2. Enter the following to download the T-Mobile Zephyr SDK, aka tmo_shell:

    The release version will change over time.

    cd ~/zephyrproject
    git clone https://github.com/tmobile/DevEdge-IoTDevKit-ZephyrSDK.git
    cd DevEdge-IoTDevKit-ZephyrSDK
    git checkout tmz-sdk-1.19.1-qa
    
  3. Clone the T-Mobile Zephyr RTOS repository:

    The release version will change over time.

    cd ~/zephyrproject
    rm -rf zephyr
    git clone https://github.com/tmobile/DevEdge-IoTDevKit-ZephyrRTOS.git zephyr
    cd zephyr
    git checkout tmz-1.19.1-qa
    
  4. Refresh the Zephyr modules by running the following commands.

    Do this whenever cloning or pulling the Zephyr repo.

    cd ~/zephyrproject
    west update
    

Step C

Build your "illuminance" sample then flash the board.

  1. Set the build environment by entering the below code into Terminal.

    cd ~/zephyrproject
    source DevEdge-IoTDevKit-ZephyrSDK/set-zephyr-build-env
    
  2. Connect to your IoT Developer Kit via serial app.

    1. Connect your developer kit to your MacBook. Plug in your USB-C to USB-A cable into the board like in the screenshot below. Ensure that the USB-C end it plugged into the J-Link USB-C Debug port.

    2. Open your serial app. For demonstration purposes we will use Serial.

    3. Select the serial port that is connected to your IoT Developer Kit then click Open.

    4. Under Terminal > Settings > Line Settings > Baud Rate make sure the following values are set then click OK:

      1. Baud Rate / Speed - 9600
      2. Data Rate - 8
      3. Parity - None
      4. Stop Bits - 1
      5. Flow Control - None

    5. At the command line screen press Enter on your keyboard. The uart command prompt appears. To learn more about uart, please read the document Interacting with the Kit at CLI via tmo_shell.

  3. In Terminal, build the "Hello World" sample.

    west build --board tmo_dev_edge --pristine=always DevEdge-IoTDevKit-ZephyrSDK/samples/illuminance
  4. Flash the "illuminance" sample onto the kit.

    west flash
  5. If the flash occurred successfully you should see the below screenshot in your serial app.

    Hello World flash successful.

Step D

Test the illuminance sample.

Test 1

  1. Press the user button.

  2. The following appears in your serial app. Notice the different states. Some states allow you to use your keyboard. Others do not.


Test 2

  1. Shine a flashlight onto the developer kit / ambient light sensor TSL2540.

  2. The following appears in your serial app if the illuminance is 1000lx or more.


Test 3

  1. Cover the IoT Dev Kit with your hand.

  2. The following appears in your serial app if the illuminance is 10lx or less.

Troubleshooting

  • Problem 1 - After cloning the Zephyr repositories from https://github.com/tmobile I cannot build the sample. What could be wrong?
  • Solution 1 - Try doing a west update then try building the sample again.


FAQ

  • Question 1 - How do I get my kit back to the tmo_shell sample?
  • Answer 1 - Please follow the code below:

    cd ~/zephyrproject
    west build $HOME/zephyrproject/DevEdge-IoTDevKit-ZephyrSDK/samples/tmo_shell -p -b tmo_dev_edge
    west flash
    


  • Question 2 - Besides pressing the user button how else can the SUSPEND state be ended?
  • Answer 2 - Flashing a light on the kit's ambient light sensor can end the suspend state. So can covering up the sensor.