Virtual Machine has been updated. Please, be sure to use latest version.
Session 2¶
Step 1: Booting the virtual machine or setting up environment¶
For this lab work you You can use your own computer or use any of the University workstations. We strongly recommend using the university workstations. In any case at this stage only one member of the team need to do the setup.
If you want to use your computer¶
In this case you have also two options:
- Option 1 Install Virtual Box and Virtual Box Extension Pack . The extension Pack can be installed using the following instructions. After that follow the same instructions as for the users utilizing university workstations (see below)
- Option 2 Set up CCSStudio IDE:
This is the longer path. You will need to follow instructions in Lovelace for setting up CCS Studio IDE (that actually you should have already followed at home)
If you are using the university workstation¶
- Download the virtual image (.ova file). Can be found in Lovelace section Virtual Machine and history
- In Virtual Box select
File -> Import appliance
and select the previous .ova file. In the next screen select the folder where you want to deploy the image,and press import. - After a while you can see an image like this one. Select the corresponding virtual image and press start at the top right.
This will start your virtual image, and get you ready for the next step.
Course SensorTag Project¶
Setup¶
Next, we will import the course project template into the development environment. Download the .zip file containing an empty project and import the empty project into your workspace ( see session 1 instructions).
Finally, we will add some new files and libraries. You can download the files from this Github project. Download and extract the zip file to your computer. Then, import the following files into your project:
- project_main.c
- sensors directory (all files must be in the sensor folder. You can drag and drop the folders into the project).
Note! The file
project_main.c
will be our main file, so remove all other files containing a main
function from the build.Task 1 - Buttons and LEDs¶
Let's start with the basics and see how we can enable buttons and LEDs on our device using the lecture materials. The materials can be found in chapter 15. "Input / Output".
In this task, we will use one of the buttons on the SensorTag to turn the red LED on/off. You need to:
- Introduce global RTOS variables for the button and LED pins.
- Define the correct configurations for the pins.
- Create an interrupt handler for the button.
- Integrate the pins into the program in the
main
function.
Note! Keep in mind that the SensorTag has more LEDs than we can use in the program. For the course, we are only interested in the two programmable LEDs visible at the bottom of the device (in the gap of the red rubber cover): the red and green LEDs. Additionally, there are two debugger LEDs between the display and debugger that we cannot use programmatically.
Task 2 - Reading Sensor Data¶
In this task, we will enable the I2C bus in the program and read measurement values from the light sensor OPT3001. For testing purposes, we will print the measured sensor values to the console window in the development environment through the debugger. The materials can be found in chapters 17. "Serial Communication", 20. "SensorTag Peripherals", and 8. "C Language Input and Output".
In this task:
- Add the I2C bus to the program in the
main
function. - Implement the following in the
sensorTask
: - Initialize and open the I2C connection.
- Initialize the sensor with the
opt3001_setup
function (the header fileopt3001.h
is in thesensors
directory). - Continuously read data from the sensor using the
opt3001_get_data
function in an infinite loop. - In the
opt3001.c
file in thesensors
library, implement the following in theopt3001_get_data
function: - Define the I2C message structure for communicating with the OPT3001 sensor. The necessary details can be found in the lecture chapter 20. "SensorTag Peripherals".
- Define the correct buffer sizes for the message structures
txBuffer
andrxBuffer
. (Commented out in the task code). - Set the sensor's I2C address in the
.slaveAddress
member of the message structure. - Set the correct register address in the transmission buffer
txBuffer
. - Implement the bit operations to extract the 16-bit register value from the bytes received in the I2C message
rxBuffer
. (See bit operations in lecture chapter 5 and sensor usage chapter 20). - Calculate the measurement value in lux from the 16-bit register value (perhaps using your own exercise solution?).
- The function returns the measurement value in lux.
- Print the measurement value in lux to the console window through the debugger.
Task 3 - State Machine¶
In this task, you will implement the state machine shown in the diagram. That is, whenever a new measurement value is obtained from the sensor in the
sensorTask
, the program's state changes to DATA_READY
, and the value is passed to the uartTask
via a global variable. In both tasks, print the measurement value to the console window through the debugger. The necessary states, the global state variable, and the variable for passing the measurement value are provided in the code.You might want to reduce the
uartTask
's sleep period to something smaller, like 100ms. Why?Task 4 - UART Communication¶
The idea of this task is to send the string printed in the console window by
uartTask
over a serial (UART) connection to the development environment. The materials can be found in the chapter 17. "Serial Communication".The task requires connecting the serial port to the development environment. Instructions can be found at this link: Session 1 UART part. The SensorTag's serial port can be recognized by the name 'XDS110 Class Application/User UART', if you need to search for the port using the operating system's tools.
- On Windows, it's
COMn
- On Ubuntu, it's
/dev/tty/ACM0
- On other Linux systems, it might be...
/dev/ttySn
In this task:
- Add UART functionality to the program in the
main
function. - Initialize the UART connection in the
uartTask
with parameters 9600, 8n1. - Use the
UART_write
function to send the string from Task 3 over the serial connection to the development environment.
Note! As you will notice, with a UART serial connection, just using \n (newline, or line feed) for a line break is not enough. You also need to include a carriage return, so add the sequence \n\r at the end of the line. Well, these are some of the historical quirks of serial communication protocols that we have to live with.
Task 5 - Using UART with an External Terminal¶
Sometimes it is useful to connect an external serial terminal to interact with the device. In fact, your final project UARTGateway will use this connection. In this task, we will check how we can use an external terminal (in this case,
screen
) to see the data the SensorTag writes via UART. You can find information about screen in this tutorial.In this task:
- Disconnect the terminal from CCS Studio.
- Debug your project.
- Before resuming the main program, open a Linux terminal and type
screen /dev/ttyACM0
. - You should see your UART output there.
- To exit, press
Ctrl-A
, thenk
.
Conclusion¶
That's it. Now we've managed to blink an LED, read sensor data, and communicate with the outside world using the SensorTag!