YostLabs 3 Space Sensor IMU over SPI to UNO

I am pairing an Arduino UNO with a Yost Labs 3-Space Sensor Nano, the user manual for said sensor can be found here.

This is my code, pretty straight forward (although this is my first time working with SPI). I am 100% sure the wiring is correct.

I believe that as per the user manual, this should successfully return 3 floats in 4 bytes each, corresponding to the filtered euler angles of pitch, yaw, and roll. However, all I am reading is bytes full of 0xFF which I believe corresponds to null / no command.

Are there any visible errors in my code?

 #include <SPI.h>

SPISettings settings(6000000, MSBFIRST, SPI_MODE0 ); //variable to hold SPI settings
//Set Slave Select, MOSI, MISO, CLK 
const int CSN = 10;
const int SO = 11;
const int SI = 12;
const int CLK = 13;

// Needed to convert the bytes from SPI to float
union u_types {
   byte b[4];
   float fval;
} data[3];  // Create 3 unions, one for each euler angle

void setup() {
 //Set Pin Modes
 pinMode(CSN, OUTPUT);
 pinMode(SI, OUTPUT);
 pinMode(SO, INPUT);
 pinMode(CLK, OUTPUT);
 //Set Slave Select High to Start i.e disable chip
 digitalWrite(CSN, HIGH);
 //Initialize SPI
 SPI.begin();
 //pour a bowl of serial
 Serial.begin(9600);
}

//function to transfer commands through SPI
byte transferByte(byte byteToWrite) {

 byte Result = 0x00;
 digitalWrite(CSN,LOW);
 delay(1);
 Result = SPI.transfer(byteToWrite);
 delay(1);
 digitalWrite(CSN,HIGH);
 return Result; 
}

//function to swap endian
void endianSwap(byte temp[4]) {
 byte myTemp = temp[0];
 temp[0] = temp[3];
 temp[3] = myTemp;
 myTemp = temp[1];
 temp[1] = temp[2];
 temp[2] = myTemp;
}

void loop() {
 SPI.beginTransaction(settings);

 // Clear the internal data buffer on the IMU
 byte result = transferByte(0x01);
     Serial.print("Cleared internal buffer. Result: "),Serial.println(result);

 // Send start of packet:
 result = transferByte(0xF6);
      Serial.print("Send start of packet. Result: "),Serial.println(result);
 
 // Send command (tared euler angles)
 result = transferByte(0x01);
      Serial.print("Send commmand 0x01. Result: "),Serial.println(result);
 
 // Get status of device:
 result = transferByte(0xFF);
      Serial.print("Status of device. Result: "),Serial.println(result);

 while (result != 0x01) {  // Repeat until device is Ready
   delay(1);
   result = transferByte(0xFF);
   Serial.print("Status of device. Result: "),Serial.println(result);
 }
 
 // Get the 12 bytes of return data from the device:
 for (int ii=0; ii<3; ii++) {
   for (int jj=0; jj<4; jj++) {
     data[ii].b[jj] =  transferByte(0xFF);
     delay(1);
   }
 }  

 SPI.endTransaction();

 for( int mm=0; mm<3; mm++) {
   endianSwap(data[mm].b);
 }
 
 
 Serial.print("fval 1:"), Serial.println(data[0].fval);
 Serial.print("fval 2:"), Serial.println(data[1].fval);
 Serial.print("fval 3:"), Serial.println(data[2].fval);

 delay(3000);
}

All 0XFFs from an SPI device can be a wiring error, can you show your schematic.

What logic voltage level conversion are you using ?

I have attached a graphic of my wiring.

No logic voltage level converter, do I need one? Arduino Uno SPI seems to operate at 5V versus the 3.3V MAX the sensor can take, I did not realize that,

What does the device datasheet say about the maximum voltage on an input pin ?

Sadly, the sensor may have been damaged or destroyed by applying 5V to the SPI pins. Even if it seems to work when properly interfaced, it probably can’t be trusted to continue functioning for long.

We’ve all made similar mistakes at one time or another, so chalk it up to a learning experience.

Untitled.png

Thanks @jremington. Can't believe i missed something that obvious. Will provide proper I/O voltage and try again.

@hat_tr1ck

Other post/duplicate DELETED Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you also take a few moments to Learn How To Use The Forum. It will help you get the best out of the forum in the future. Other general help and troubleshooting advice can be found here.

Thanks for the warning but I gotta say my post was different, I changed the wiring schematic and provided more info. Next time I will just edit, thank you.

jremington: Sadly, the sensor may have been damaged or destroyed by applying 5V to the SPI pins. Even if it seems to work when properly interfaced, it probably can't be trusted to continue functioning for long.

We've all made similar mistakes at one time or another, so chalk it up to a learning experience.

|500x141

So I've added a logic voltage converter as per my diagram here

I also changed the IMU (glad I ordered 2), to make sure it isn't damaged. The code is still not working, it outputs 11111111 repeatedly, which as per the manual would mean no command.

Please edit your post to include the image in line. Image posting guide.

Why do you think the SPI settings "MSBFIRST, SPI_MODE0" are correct? There are several other possibilities, and given that SPI is a poorly defined standard, why use it at all?

I suggest to use a MUCH simpler protocol, like the UART. Perfectly standard TTL level, 8N1, 115200 Baud.

jremington: Please edit your post to include the image in line. Image posting guide.

Why do you think the SPI settings "MSBFIRST, SPI_MODE0" are correct? There are several other possibilities, and given that SPI is a poorly defined standard, why use it at all?

I suggest to use a MUCH simpler protocol, like the UART. Perfectly standard TTL level, 8N1, 115200 Baud.

MSBFIRST and SPI_MODE0 are as per the datasheet. That's the one thing both of their datasheets agree on.