mirror of
https://gitlab.dit.htwk-leipzig.de/phillip.kuehne/dezibot.git
synced 2025-05-19 19:11:48 +02:00
added general readRegister Method for IMU
This commit is contained in:
parent
21f8dc65f1
commit
c948b5515b
@ -7,15 +7,14 @@ void setup() {
|
|||||||
//dezibot.motionDetection.end();
|
//dezibot.motionDetection.end();
|
||||||
// put your setup code here, to run once:
|
// put your setup code here, to run once:
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// put your main code here, to run repeatedly:
|
// put your main code here, to run repeatedly:
|
||||||
|
|
||||||
//Serial.println(dezibot.motionDetection.getTemperature());
|
//Serial.println(dezibot.motionDetection.getTemperature());
|
||||||
//Serial.println(dezibot.motionDetection.getAcceleration().z);
|
Serial.println(dezibot.motionDetection.getAcceleration().z);
|
||||||
//Serial.println(dezibot.motionDetection.getRotation().x);
|
//Serial.println(dezibot.motionDetection.getRotation().x);
|
||||||
Serial.println(dezibot.motionDetection.getWhoAmI());
|
Serial.println(dezibot.motionDetection.getWhoAmI());
|
||||||
delay(5);
|
delay(5000);
|
||||||
}
|
}
|
||||||
|
@ -14,11 +14,10 @@ void MotionDetection::begin(void){
|
|||||||
|
|
||||||
digitalWrite(34,LOW);
|
digitalWrite(34,LOW);
|
||||||
// set Accel and Gyroscop to Low Noise
|
// set Accel and Gyroscop to Low Noise
|
||||||
//handler->transfer(0x1F);
|
handler->transfer(0x1F);
|
||||||
//handler->transfer(0x0F);
|
handler->transfer(0x0F);
|
||||||
//busy Wait for startup
|
//busy Wait for startup
|
||||||
//delayMicroseconds(200);
|
delayMicroseconds(200);
|
||||||
handler->transfer(cmdRead(WHO_AM_I));
|
|
||||||
|
|
||||||
digitalWrite(34,HIGH);
|
digitalWrite(34,HIGH);
|
||||||
//handler->endTransaction();*/
|
//handler->endTransaction();*/
|
||||||
@ -58,26 +57,19 @@ float MotionDetection::getTemperature(){
|
|||||||
handler->beginTransaction(SPISettings(frequency,SPI_MSBFIRST,SPI_MODE0));
|
handler->beginTransaction(SPISettings(frequency,SPI_MSBFIRST,SPI_MODE0));
|
||||||
digitalWrite(34,LOW);
|
digitalWrite(34,LOW);
|
||||||
handler -> write(cmdRead(REG_TEMP_HIGH,REG_TEMP_LOW));
|
handler -> write(cmdRead(REG_TEMP_HIGH,REG_TEMP_LOW));
|
||||||
uint16_t raw_temperatur = handler->transfer16(cmdRead(REG_TEMP_HIGH,REG_TEMP_LOW));
|
int16_t raw_temperatur = handler->transfer16(cmdRead(REG_TEMP_HIGH,REG_TEMP_LOW));
|
||||||
|
|
||||||
digitalWrite(34,HIGH);
|
digitalWrite(34,HIGH);
|
||||||
handler->endTransaction();
|
handler->endTransaction();
|
||||||
return raw_temperatur/128 +25;
|
return raw_temperatur/128 +25;
|
||||||
};
|
};
|
||||||
|
|
||||||
uint8_t MotionDetection::getWhoAmI(){
|
int8_t MotionDetection::getWhoAmI(){
|
||||||
handler->beginTransaction(SPISettings(frequency,SPI_MSBFIRST,SPI_MODE0));
|
return readRegister(WHO_AM_I);
|
||||||
digitalWrite(34,LOW);
|
|
||||||
uint8_t result;
|
|
||||||
//handler->transferBytes(cmd,result,1);
|
|
||||||
result = handler->transfer(cmdRead(WHO_AM_I));
|
|
||||||
result = handler->transfer(0x00);
|
|
||||||
digitalWrite(34,HIGH);
|
|
||||||
handler->endTransaction();
|
|
||||||
return result;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint16_t MotionDetection::cmdRead(uint8_t regHigh,uint8_t regLow){
|
uint16_t MotionDetection::cmdRead(uint8_t regHigh,uint8_t regLow){
|
||||||
return (CMD_READ | (regHigh & ADDR_MASK))<<8 & (CMD_READ | regLow & ADDR_MASK);
|
return (CMD_READ | (regHigh & ADDR_MASK))<<8 & (CMD_READ | regLow & ADDR_MASK);
|
||||||
};
|
};
|
||||||
@ -90,3 +82,18 @@ uint8_t MotionDetection::cmdRead(uint8_t reg){
|
|||||||
uint8_t MotionDetection::cmdWrite(uint8_t reg){
|
uint8_t MotionDetection::cmdWrite(uint8_t reg){
|
||||||
return (CMD_WRITE | (reg & ADDR_MASK));
|
return (CMD_WRITE | (reg & ADDR_MASK));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int8_t MotionDetection::readRegister(uint8_t reg){
|
||||||
|
handler->beginTransaction(SPISettings(frequency,SPI_MSBFIRST,SPI_MODE0));
|
||||||
|
digitalWrite(34,LOW);
|
||||||
|
uint8_t result;
|
||||||
|
result = handler->transfer(cmdRead(reg));
|
||||||
|
result = handler->transfer(0x00);
|
||||||
|
digitalWrite(34,HIGH);
|
||||||
|
handler->endTransaction();
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
int16_t MotionDetection::readDoubleRegister(uint8_t lowerReg){
|
||||||
|
return 0;
|
||||||
|
}
|
@ -54,6 +54,9 @@ protected:
|
|||||||
uint8_t cmdRead(uint8_t reg);
|
uint8_t cmdRead(uint8_t reg);
|
||||||
uint8_t cmdWrite(uint8_t reg);
|
uint8_t cmdWrite(uint8_t reg);
|
||||||
|
|
||||||
|
int8_t readRegister(uint8_t reg);
|
||||||
|
int16_t readDoubleRegister(uint8_t lowerReg);
|
||||||
|
|
||||||
SPIClass * handler = NULL;
|
SPIClass * handler = NULL;
|
||||||
|
|
||||||
|
|
||||||
@ -96,6 +99,12 @@ public:
|
|||||||
*/
|
*/
|
||||||
float getTemperature();
|
float getTemperature();
|
||||||
|
|
||||||
uint8_t getWhoAmI();
|
/**
|
||||||
|
* @brief Returns the value of reading the whoAmI register
|
||||||
|
* When IMU working correctly, value should be 0x67
|
||||||
|
*
|
||||||
|
* @return the value of the whoami register of the ICM-42670
|
||||||
|
*/
|
||||||
|
int8_t getWhoAmI();
|
||||||
};
|
};
|
||||||
#endif //MotionDetection
|
#endif //MotionDetection
|
Loading…
x
Reference in New Issue
Block a user