Using the SensorTag¶
This material will contain instructions on how to use the different perpheral devices in the SensorTag device. This material is live and updated frequently with more content.
Please take a look at the code examples and datasheets in the Finnish page.
We encourage you to participate to the exercise sessions during the implementation of the course project!
Links to device manuals¶
Manufacturers tutorial pages of how to program the device: Simplelink Academy.
- TI-RTOS 2.20 User’s Guide
- SYS/BIOS (TI-RTOS Kernel) v6.46 User's Guide
- Simplelink Technical Reference Manual
RTOS libraries¶
- Drivers API Very useful, includes code examples!
- This is the link to use to find information about programming SensorTag components!
- RTOS API Low level libraries, for more or less advanced students
Example projects¶
- CCS and CCS Cloud Main window ->
Project
-menu ->Examples...
-> opens the tab TI Resource explorer. - Menu hierarchy is the following:Software -> TI-RTOS for CC2650 -> Development Tools -> CC2650 SensorTag
- Note! The examples are for newer RTOS version, but should work with our version. Anyway, you should only use them as a reference.
- Now you can import project to the local CCS
- We will provide you a project template to use in the course project.
Display¶
Fall 2022 Due to limited number of devices, the display functionality is not required for the laboratory exercise nor the course project.
You can print text, create pixel-based graphics and show images on the integrated display.
The following libraries are at your use: Display.h to initialize the display and put text into it and DisplayExt.h to create graphics.
The display resolution for text 16 x 16 characters. Here is how to print out text.
...
#include <ti/mw/display/Display.h>
...
// Task
Void displayTask(UArg arg0, UArg arg1) {
// Initialize display
Display_Params params;
Display_Params_init(¶ms);
params.lineClearMode = DISPLAY_CLEAR_BOTH;
Display_Handle hDisplayLcd = Display_open(Display_Type_LCD, ¶ms);
if (hDisplayLcd) {
// print out text to coordinates (5,3)
Display_print0(hDisplayLcd, 5, 3, "Hello LCD!");
Task_sleep(5 * 1000000/Clock_tickPeriod);
Display_clear(hDisplayLcd);
}
}
Instead of giving parameters directly for the
Display_print1-5
functions, it is better to first create the printed string with sprintf
. ...
sprintf(str,"%02d:%02d:%02d",aika->tm_hour+3, aika->tm_min, aika->tm_sec);
Display_print0(hDisplayLcd, 0, 0, str);
...
Pixel graphics¶
The following functions are available for pixel graphics in the grlib.h library. The screen resolution is 96 x 96 pixels.
...
#include <ti/mw/display/Display.h>
#include <ti/mw/display/DisplayExt.h>
...
// Task
Void displayFxn(UArg arg0, UArg arg1) {
Display_Params params;
Display_Params_init(¶ms);
params.lineClearMode = DISPLAY_CLEAR_BOTH;
Display_Handle hDisplayLcd = Display_open(Display_Type_LCD, ¶ms);
if (hDisplayLcd) {
tContext *pContext = DisplayExt_getGrlibContext(hDisplayLcd);
if (pContext) {
// Draw two lines to the screen buffer
GrLineDraw(pContext,0,0,96,96);
GrLineDraw(pContext,0,96,96,0);
// Write the buffer to the screen
GrFlush(pContext);
}
}
}
Images¶
First, create a bitmap for the image..
...
/* Kuva: 8x8 bitmap (bit 1 is a pixel, bit 0 background)
11111111
10000001
10000001
10000001
10000001
10000001
10000001
11111111
*/
// The bitmap as array
const uint8_t imgData[8] = {
0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF
};
// Two colours: black and white
uint32_t imgPalette[] = {0, 0xFFFFFF};
// Define the image parameters
const tImage image = {
.BPP = IMAGE_FMT_1BPP_UNCOMP,
.NumColors = 2,
.XSize = 1,
.YSize = 8,
.pPalette = imgPalette,
.pPixel = imgData
};
...
Void taskFxn(UArg arg0, UArg arg1) {
...
if (pContext) {
GrImageDraw(pContext, &image, 0, 0);
GrFlush(pContext);
}
}
...
Using the display¶
SensorTag does not support using UART and the Display at the same time due to shared I/O pins.
Therefore, to use the display, we need to define a constant
BOARD_DISPLAY_EXCLUDE_UART
, in our project's Board.h
file:...
#ifdef __cplusplus
extern "C" {
#endif
// Define the constant here
#define BOARD_DISPLAY_EXCLUDE_UART
#include <ti/drivers/Power.h>
...
This constant has already been defined in the course project template.
Sensors¶
Here we show generally how to use the main features of integrated sensors. The sensor data sheets describe their features and operations fully.
In the course, we will use our own libraries to access the sensors. These libraries have not been optimized in any way, but give you a basic access to the data generated by the sensor.
Each sensor has two common functions:
sensorX_setup
, configure and open the sensor in your codesensorX_get_data
, ask data from the sensor- The required i2c message structure is not given, but described below for each sensor
- The required bitwise operations for the register data are not given. Students need to figure these out by themselves
- Use the given i2c message buffers
txBuffer
andrxBuffer
Temperature¶
We are using the register 0x03.
The bits
T13-T0
describe the temperature value, which you need to multiply by 0.03125.Communication¶
This sensor has the i2c-address
Board_TMP007_ADDR
. The above register has a constant TMP007_REG_TEMP
.i2c-messaging:
- Send one byte that is the register address
- Receive two bytes
Ambient light¶
We are interested in the Result register.
The value is calculated followingly.
Communication¶
This sensor has the i2c-address
Board_OPT3001_ADDR
. The above register has a constant OPT3001_DATA_REG
.i2c-messaging:
- Send one byte that is the register address
- Receive two bytes
Air pressure¶
We are interested in six registers pres_msb, pres_lsb ja pres_xlsb sekä temp_msb, temp_lsb ja temp_xlsb.
- First create two 20-bit numbers from these register in the order of MSB,LSB,XLSB
- Call function
bmp280_convert_temp
with the 20-bit temperature value as a parameter - call function
bmp280_convert_pres
with the 20-bit pressure value as a parameter
Communication¶
This sensor has the i2c-address
Board_BMP280_ADDR
. The above register has a constant BMP280_REG_PRESS_MSB
.i2c-messaging:
- Send one byte that is the register address
- Receive six bytes: the first byte is the pres_msb register, next is pres_lsb, etc.
Humidity¶
------------------------
NOTE! SENSOR DRIVER HAS A BUG, DO NOT USE!
------------------------
NOTE! SENSOR DRIVER HAS A BUG, DO NOT USE!
------------------------
We are interested about the register Humidity.
Communication¶
This sensor has the i2c-address
Board_HDC1000_ADDR
. The above register has a constant HDC1000_REG_HUM
.i2c-messaging:
- Send one byte that is the register address
- Receive two bytes: MSB, LSB
Movement sensor¶
This MPU9250 sensor is a real monster with integrated gyroscope, accelerometer and magnetometer.
Because this sensor requires second i2c bus, we give a code example how to use it in here.
The header file
mpu9250.h
is in the sensors
directory. Note that in the image, the register byte order is top-down.
Communication¶
This sensor has the i2c-address
Board_MPU9250_ADDR
. The first register has a constant ACCEL_XOUT_H
.i2c-messaging:
- Send one byte that is the register address
- Receive 14 bytes
Power button¶
Here is a code example of how to use the power button. This code is given in the course project template.
#include <ti/drivers/Power.h>
#include <ti/drivers/power/PowerCC26XX.h>
...
static PIN_Handle hButtonShut;
static PIN_State bStateShut;
PIN_Config buttonShut[] = {
Board_BUTTON1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,
PIN_TERMINATE
};
PIN_Config buttonWake[] = {
Board_BUTTON1 | PIN_INPUT_EN | PIN_PULLUP | PINCC26XX_WAKEUP_NEGEDGE,
PIN_TERMINATE
};
Void buttonShutFxn(PIN_Handle handle, PIN_Id pinId) {
Display_clear(hDisplayLcd);
Display_close(hDisplayLcd);
Task_sleep(100000 / Clock_tickPeriod);
PIN_close(hButtonShut);
PINCC26XX_setWakeup(buttonWake);
Power_shutdown(NULL,0);
}
Int main() {
...
hButtonShut = PIN_open(&bStateShut, buttonShut);
if( !hButtonShut ) {
System_abort("Error initializing button shut pins\n");
}
if (PIN_registerIntCb(hButtonShut, &buttonShutFxn) != 0) {
System_abort("Error registering button callback function");
}
...
}
Battery voltage¶
With this example code, you can read the coin battery remaining voltage.
uint32_t battery = HWREG(AON_BATMON_BASE + AON_BATMON_O_BAT);
The register values are:
Give feedback on this content
Comments about this material