Closed rei-vilo closed 7 years ago
I've managed to read data from the HDC1000, TMP007 and OPT3001 sensors.
Last one, the MPU9250, raises some issues.
MPU PWR
or DIO_12
. Calling Board_MPU_POWER
as defined in Energia.app/Contents/Resources/Java/hardware/emt/ti/runtime/wiring/cc26xx/variants/CC2650STK_BLE/Board.h results in an error.pinMode(Board_MPU_POWER, OUTPUT);
digitalWrite(Board_MPU_POWER, Board_MPU_POWER_ON);
DIO_09
and DIO_08
. Calling Wire1.begin()
after Wire.begin()
raises an error.TwoWire Wire1(1);
Wire1.begin();
To be more specific,
Either
Wire.begin()
or
TwoWire Wire1(1);
Wire1.begin();
works separately.
Wire.begin()
TwoWire Wire1(1);
Wire1.begin();
See #863.
The MPU9250 includes a DMP. The DMP is a processor that fusions the data from the accelerometer, gyroscope and magnetometer and calculates the Euler angles.
Such a library is available for Arduino at https://github.com/rpicopter/ArduinoMotionSensorExample
Hi rei-vilo,
I am also interested in programming the cc2650 sensor tag with Energia. Have there been any updates or example code uploaded recently? Could you direct me to some resources you have used that could get me started with BLE and reading data off the the sensor tag?
The libraries for BLE aren't available due to licence restrictions.
So are there currently no work arounds to read or respond to BLE events using the Energia platform? I was wondering if I could make simple modifications to current sensortag program operation without programming with CCS
Nope. BLE support is dead in the water, or dead on arrival should be the preferred phrase, due to TI's own legal issues. Embarrassing, really, but using CCS is the only way to do this (and you have to grok the BLE-Stack and TI-RTOS stuff at least on a superficial level, from what I gathered).
For the moment, no.
You can download the BLE stack from TI, then try and wrap it into a C++ interface for your project only.
Cool, thanks for the quick responses. Guess there is no way around learning RTOs and the BLE-Stack. Its been a pretty steep learning curve so far for me with just a background with Arduino programming. Aside from the software manual, RTOs tutorial videos and basic sensortag tutorial, do you have any suggested readings or sites you found helpful to help break down learning how to program the sensortag?
Thanks! Looks like some good starting points off your site.
Hi @rei-vilo I have started exploring the sensor tag and are trying to run this example to test the MPU's capabilities. https://github.com/energia/emt/blob/a350116673c64a5ba71a034b3baaa384b888776e/src/ti/runtime/wiring/cc26xx/tests/alan/mpu9250.cpp when I run the code it hangs at Wire1.endTransmission();
Do you have an example I could follow or a possible fix? my goal is to print the readings of the accelerometer over the serial. My code is with small modification is here:
/*
* ======== mpu9250.cpp ========
* This code initially came from http://www.lucidarme.me/?p=5057
*/
#include <Energia.h> // Energia Wiring API
#include <Wire.h>
#include <ti/sysbios/family/arm/m3/Hwi.h>
//#include "app.h"
#include "MPU6500.h"
#define MPU9250_ADDRESS 0x68
#define MAG_ADDRESS 0x0C
#define GYRO_FULL_SCALE_250_DPS 0x00
#define GYRO_FULL_SCALE_500_DPS 0x08
#define GYRO_FULL_SCALE_1000_DPS 0x10
#define GYRO_FULL_SCALE_2000_DPS 0x18
#define ACC_FULL_SCALE_2_G 0x00
#define ACC_FULL_SCALE_4_G 0x08
#define ACC_FULL_SCALE_8_G 0x10
#define ACC_FULL_SCALE_16_G 0x18
#define LED RED_LED
#define BUZZER 23
TwoWire Wire1(1);
/*
* ======== I2Cread ========
* This function read Nbytes bytes from I2C device at address Address.
* Put read bytes starting at register Register in the Data array.
*/
void I2Cread(uint8_t Address, uint8_t Register, uint8_t Nbytes, uint8_t* Data)
{
Wire1.begin();
// Set register address
Wire1.beginTransmission(Address);
Wire1.write(Register);
Serial.println("read data ok");
Wire.write(1);
Wire1.endTransmission();
Serial.println("read end ok");
//Wire1.end();
// Read Nbytes
Wire1.requestFrom(Address, Nbytes);
Serial.println("read request ok");
uint8_t index = 0;
while (Wire1.available()) {
Data[index++] = Wire1.read();
}
}
/*
* ======== I2CwriteByte ========
* Write a byte (Data) in device (Address) at register (Register)
*/
void I2CwriteByte(uint8_t Address, uint8_t Register, uint8_t Data)
{
//Wire1.begin();
// Set register address
Wire1.beginTransmission(Address);
Wire1.write(Register);
Wire1.write(Data);
Serial.println("write data ok");
Wire1.write(1);
Wire1.endTransmission();
//Wire1.end();
Serial.println("write end ok");
}
/*
* ======== blinkSetup ========
*/
void blinkSetup()
{
// Arduino initializations
Wire1.begin();
Serial.begin(9600);
pinMode(LED, OUTPUT);
Serial.println("blink setup ok");
for (int i = 0; i < 2; i++) {
digitalWrite(LED, 1);
delay(250);
digitalWrite(LED, 0);
delay(250);
}
// reset the device
I2CwriteByte(MPU9250_ADDRESS, MPU6500_RA_PWR_MGMT_1, 0x80);
Serial.println("i2c write 1 ok");
delay(100); // page 42 - delay 100ms
// ensure all axis of acc and gyro are enabled
I2CwriteByte(MPU9250_ADDRESS, MPU6500_RA_PWR_MGMT_2, 0x00);
Serial.println("i2c write 2 ok");
// reset gyro, accel, temp
I2CwriteByte(MPU9250_ADDRESS, MPU6500_RA_SIGNAL_PATH_RESET, 0x07);
Serial.println("i2c write 3 ok");
delay(100); // page 42 - delay 100ms
uint8_t id;
I2Cread(MPU9250_ADDRESS, MPU6500_RA_WHO_AM_I, 1, &id);
Serial.print("id should be 0x71: ");
Serial.println(id, HEX);
// Set DLPF_CFG to 1: 1kHz Gyro sampling, 184Hz bandwidth
I2CwriteByte(MPU9250_ADDRESS, MPU6500_RA_CONFIG, 0x01);
// Default: 1kHz Accel sampling, 480Hz cutoff
// enable temperature, gyro, and accelerometer output
I2CwriteByte(MPU9250_ADDRESS, MPU6500_RA_FIFO_EN,
MPU6500_FIFO_EN_ACC | MPU6500_FIFO_EN_TEMP | MPU6500_FIFO_EN_GYRO);
// Configure gyroscope range
I2CwriteByte(MPU9250_ADDRESS, 27, GYRO_FULL_SCALE_250_DPS);
// Configure accelerometers range
I2CwriteByte(MPU9250_ADDRESS, 28, ACC_FULL_SCALE_16_G);
// Set bypass mode for magnetometer (host can directly address it on I2C)
I2CwriteByte(MPU9250_ADDRESS, 0x37, 0x02);
// Put magnetometer (AK8963) into single measurement mode
I2CwriteByte(MAG_ADDRESS, 0x0B, 0x01); /* soft reset */
I2CwriteByte(MAG_ADDRESS, 0x0A, 0x01);
}
/*
* ======== blinkLoop ========
* Main loop, read and display data
*/
int16_t ax, ay, az;
int16_t gx, gy, gz;
int16_t mx, my, mz;
/*
* ======== blinkLoop ========
*/
void blinkLoop()
{
Serial.println("blinkLoop ok");
static uint32_t newTone, oldTone;
// ____________________________________
// ::: accelerometer and gyroscope :::
// Read accelerometer and gyroscope
uint8_t Buf[14];
I2Cread(MPU9250_ADDRESS, 0x3B, 14, Buf);
// Create 16 bits values from 8 bits data
// Accelerometer
ax = Buf[0] << 8 | Buf[1];
ay = Buf[2] << 8 | Buf[3];
az = Buf[4] << 8 | Buf[5];
// Gyroscope
gx = Buf[8] << 8 | Buf[9];
gy = Buf[10] << 8 | Buf[11];
gz = Buf[12] << 8 | Buf[13];
// Display values
#if 1
// Accelerometer
Serial.print("Axyz: ");
Serial.print(ax, DEC);
Serial.print("\t");
Serial.print(ay, DEC);
Serial.print("\t");
Serial.print(az, DEC);
Serial.print("\n");
// Gyroscope
Serial.print("Gxyz: ");
Serial.print(gx, DEC);
Serial.print("\t");
Serial.print(gy, DEC);
Serial.print("\t");
Serial.print(gz, DEC);
Serial.print("\n");
// _____________________
// ::: Magnetometer :::
// Read register Status 1 and wait for the DRDY: Data Ready
uint8_t ST1;
do {
I2Cread(MAG_ADDRESS, 0x02, 1, &ST1);
} while (!(ST1 & 0x01));
// Read magnetometer data
uint8_t Mag[6];
I2Cread(MAG_ADDRESS, 0x03, 6, Mag);
// Request next magnetometer single measurement
I2CwriteByte(MAG_ADDRESS, 0x0A, 0x01);
// Create 16 bits values from 8 bits data
// Magnetometer
mx = Mag[1] << 8 | Mag[0];
my = Mag[3] << 8 | Mag[2];
mz = Mag[5] << 8 | Mag[4];
// Magnetometer
Serial.print(mx, DEC);
Serial.print("\t");
Serial.print(my, DEC);
Serial.print("\t");
Serial.print(mz, DEC);
Serial.print("\t");
// End of line
Serial.println("");
#endif
newTone = ax/2 + 2000;
if (abs(newTone - oldTone) > 20) {
tone(BUZZER, newTone, 0);
oldTone = newTone;
}
delay(100); /* otherwise get data 100 times per sec */
}
Hi @rei-vilo thank you for answering.
Yes I am aware of the Wire and Wire1 conflict, i am only using Wire1 for now. I am not doing anything to power the MPU9250, is there a pin I should set high?
Hello, I am working on a Sensortag board. I am using Energia last version. it is no Radio support yet for the CC2650. Could you help me? How can I porting a Bluetooth open-source on the board?
For legal reason, the BLE stack isn't available for Energia.
However, you can register and download it from Bluetooth low energy software stack.
I have tried with TIVA and MPU9250. https://github.com/PAk-CatchFire/MPU9250-Tivaware
Energia 1.6.10E18 no longer supports the CC2650 SensorTag.
CC2650 has been removed from Energia due to the lack of BLE support that could not be enabled because of licensing issues with the BLE stack.
Among other