Ambient Light Sensor Sample
Introduction
This documents how to work with the ambient light sensor sample.
Prerequisites
- Git installed on your computer.
- A DevEdge IoT Dev Kit.
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.
Follow the instructions here to install Zephyr.
-
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
The rest of the instructions stay the same.
- Stop at the Build the Blinky Sample section.
Step B
Clone the T-Mobile Zephyr RTOS and SDK.
- Open Terminal.
-
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
-
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
-
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.
-
Set the build environment by entering the below code into Terminal.
cd ~/zephyrproject
source DevEdge-IoTDevKit-ZephyrSDK/set-zephyr-build-env
-
Connect to your IoT Developer Kit via serial app.
-
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.
-
Open your serial app. For demonstration purposes we will use Serial.
-
Select the serial port that is connected to your IoT Developer Kit then click Open.
-
Under Terminal > Settings > Line Settings > Baud Rate make sure the following values are set then click OK:
- Baud Rate / Speed - 9600
- Data Rate - 8
- Parity - None
- Stop Bits - 1
-
Flow Control - None
-
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.
-
-
In Terminal, build the "Hello World" sample.
west build --board tmo_dev_edge --pristine=always DevEdge-IoTDevKit-ZephyrSDK/samples/illuminance
-
Flash the "illuminance" sample onto the kit.
west flash
-
If the flash occurred successfully you should see the below screenshot in your serial app.
Step D
Test the illuminance sample.
Test 1
-
Press the user button.
-
The following appears in your serial app. Notice the different states. Some states allow you to use your keyboard. Others do not.
Test 2
-
Shine a flashlight onto the developer kit / ambient light sensor TSL2540.
-
The following appears in your serial app if the illuminance is 1000lx or more.
Test 3
-
Cover the IoT Dev Kit with your hand.
-
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.