Hey guys, below is a piece of code that I have been changing to fit my needs on running multiple MLX90333 sensors. The code currently reads the alpha and beta angles of a magnetic field orientation and I would like it to read x-y-z positioning. There is direction in the spec sheet on how to read x-y-z but I am not sure how to translate it to my code.
Can anyone give me direction?
Here is my code:
#include <SPI.h>
#include <stdint.h>
//*******Arduino MICRO SPI pins********
#define SS1 2
byte dataBuffer[8];
void setup() {
pinMode(SS1, OUTPUT);
pinMode(SS, OUTPUT);
digitalWrite(SS1, HIGH);
digitalWrite(SS, HIGH);
Serial.begin(9600);
SPI.begin;
}
void loop() {
//Sensor 1
delay(20); //MLX90333 startup takes 16ms
SPI.beginTransaction(SPISettings(160000, MSBFIRST, SPI_MODE1)); //320000 is about max
delay(5);
int j;
for (j=0; j<10; j++){
digitalWrite(SS, LOW);
delay(20); //Short delay necessary here
int i;
for (i=0; i<8; i++){
dataBuffer[i] = SPI.transfer(255); // Must transfer 1's, 0's don't work
}
digitalWrite(SS, HIGH);
SPI.endTransaction();
Serial.print(dataBuffer[2],8); //Print 3rd byte, MSB for Alpha
Serial.print(", ");
Serial.print(dataBuffer[4],8); //Print 5th byte, MSB for Beta
Serial.print(", ");
}
//Sensor 2
delay(20); //MLX90333 startup takes 16ms
SPI.beginTransaction(SPISettings(160000, MSBFIRST, SPI_MODE1)); //320000 is about max
delay(5);
for (j=0; j<10; j++){
digitalWrite(SS1, LOW);
delay(20); //Short delay necessary here
int i;
for (i=0; i<8; i++){
dataBuffer[i] = SPI.transfer(255); // Must transfer 1's, 0's don't work
}
digitalWrite(SS1, HIGH);
delay(1000);
SPI.endTransaction();
Serial.print(dataBuffer[2],8); //Print 3rd byte, MSB for Alpha
Serial.print(", ");
Serial.print(dataBuffer[4],8); //Print 5th byte, MSB for Beta
Serial.print(", ");
}
}
Here is a link to the spec sheet. Special attention to page 20.
Thanks to anyone who can help me!