ADIS16470 and ESP32?

Hello, I am trying to view data coming from an ADIS16470 IMU using an ESP32. The eventual intent is to use the WiFi capability of the ESP32 to transmit the IMU data wireless. However, I am very new to Arduino and the IDE, and the only known code I could find applicable to this sensor is below (found on this GitHub repo), originally intended for a Teensy 3.2. The only changes made were for the pins used for Chip Select, Data Ready, and Interrupt so that it is compatible with the ESP32 pins. When I run the code, it does not print anything to serial, and just hangs whenever restarted.

The code compiles and uploads without error. I have found that if I put my own Serial.print statement anytime after this line:


IMU.configSPI(); // Configure SPI communication


I get a backwards question mark instead of the statement I am printing. I am not experienced with this sensor, and fairly new to ESP32. Any help to get this running would be appreciated, especially if there are differences between the Teensy and the ESP that would affect this. Please let me know if any other information is needed.

Below is the code I am using, and I have also attached the wiring schematic I am using (right now, the 5V voltage regulator is not being used, the IMU is being powered through the plugged in ESP)

#include <ADIS16470.h>
#include <SPI.h>

// Uncomment to enable debug
//#define DEBUG

// Initialize Variables
// Temporary Data Array
uint16_t *burstData;

// Checksum variable
int16_t burstChecksum = 0;

// Accelerometer
float AXS, AYS, AZS = 0;

// Gyro
float GXS, GYS, GZS = 0;

// Control registers
int MSC = 0;
int FLTR = 0;
int DECR = 0;

// Temperature
float TEMPS = 0;

// Delay counter variable
int printCounter = 0;

// Call ADIS16470 Class
ADIS16470 IMU(5,22,21); // Chip Select, Data Ready, Reset Pin Assignments

void setup()
{
    Serial.begin(115200); // Initialize serial output via USB
    IMU.configSPI(); // Configure SPI communication
    delay(500); // Give the part time to start up
    IMU.regWrite(MSC_CTRL, 0xC1);  // Enable Data Ready, set polarity
    IMU.regWrite(FILT_CTRL, 0x04); // Set digital filter
    IMU.regWrite(DEC_RATE, 0x00), // Disable decimation
    
    // Read the control registers once to print to screen
    MSC = IMU.regRead(MSC_CTRL);
    FLTR = IMU.regRead(FILT_CTRL);
    DECR = IMU.regRead(DEC_RATE);

    attachInterrupt(22, grabData, RISING); // Attach interrupt to pin 2. Trigger on the rising edge
}

// Function used to read register values when an ISR is triggered using the IMU's DataReady output
void grabData()
{
    burstData = {};
    IMU.configSPI(); // Configure SPI before the read. Useful when talking to multiple SPI devices
    burstData = IMU.wordBurst(); // Read data and insert into array
}

// Function used to scale all acquired data (scaling functions are included in ADIS16470.cpp)
void scaleData()
{
    GXS = IMU.gyroScale(*(burstData + 1)); //Scale X Gyro
    GYS = IMU.gyroScale(*(burstData + 2)); //Scale Y Gyro
    GZS = IMU.gyroScale(*(burstData + 3)); //Scale Z Gyro
    AXS = IMU.accelScale(*(burstData + 4)); //Scale X Accel
    AYS = IMU.accelScale(*(burstData + 5)); //Scale Y Accel
    AZS = IMU.accelScale(*(burstData + 6)); //Scale Z Accel
    TEMPS = IMU.tempScale(*(burstData + 7)); //Scale Temp Sensor
}

// Main loop. Print data to the serial port. Sensor sampling is performed in the ISR
void loop()
{
    printCounter ++;
    if (printCounter >= 50000) // Delay for writing data to the serial port
    {
        detachInterrupt(22); //Detach interrupt to avoid overwriting data
        scaleData(); // Scale data acquired from the IMU
        burstChecksum = IMU.checksum(burstData); // Calculate checksum based on data array

        //Clear the serial terminal and reset cursor
        //Only works on supported serial terminal programs (Putty)
        Serial.print("\033[2J");
        Serial.print("\033[H");

        // Print header
        Serial.println(" ");
        Serial.println("ADIS16470 Teensy Burst Read Example Program");
        Serial.println("Juan Chong - November 2017");
        Serial.println(" ");

        // Print control registers to the serial port
        Serial.println("Control Registers");
        Serial.print("MSC_CTRL: ");
        Serial.println(MSC,HEX);
        Serial.print("FLTR_CTRL: ");
        Serial.println(FLTR,HEX);
        Serial.print("DEC_RATE: ");
        Serial.println(DECR,HEX);
        Serial.println(" ");
        Serial.println("Raw Output Registers");
        
        // Print scaled gyro data
        Serial.print("XGYRO: ");
        Serial.println(GXS);
        Serial.print("YGYRO: ");
        Serial.println(GYS);
        Serial.print("ZGYRO: ");
        Serial.println(GZS);
      
        // Print scaled accel data
        Serial.print("XACCL: ");
        Serial.println(AXS);
        Serial.print("YACCL: ");
        Serial.println(AYS);
        Serial.print("ZACCL: ");
        Serial.println(AZS);
        Serial.println(" ");

        Serial.println("Status Registers");

        // Print Status Registers
        Serial.print("DIAG_STAT: ");
        Serial.println((*(burstData + 0)));
        Serial.print("TIME_STMP: ");
        Serial.println((*(burstData + 8)));
        Serial.print("CHECKSUM: ");
        Serial.println((*(burstData + 9)));

        // Report if checksum is good or bad
        Serial.print("CHECKSUM OK? ");
        if (burstChecksum == *(burstData + 9)) 
            Serial.println("YES");
        else
            Serial.println("NO");
       
        // Print scaled temp data
        Serial.print("TEMP: ");
        Serial.println(TEMPS);

#ifdef DEBUG 
        // Print unscaled gyro data
        Serial.print("XGYRO: ");
        Serial.println((*(burstData + 1)));
        Serial.print("YGYRO: ");
        Serial.println((*(burstData + 2)));
        Serial.print("ZGYRO: ");
        Serial.println((*(burstData + 3)));
      
        // Print unscaled accel data
        Serial.print("XACCL: ");
        Serial.println((*(burstData + 4)));
        Serial.print("YACCL: ");
        Serial.println((*(burstData + 5)));
        Serial.print("ZACCL: ");
        Serial.println((*(burstData + 6)));
        Serial.println(" ");
       
        // Print unscaled temp data
        Serial.print("TEMP: ");
        Serial.println((*(burstData + 7)));
#endif
        printCounter = 0;
        attachInterrupt(22, grabData, RISING);
    }
}

What is the IDE's debug level set at?

Try this to see if you can get prints

#include <ADIS16470.h>
#include <SPI.h>

// Uncomment to enable debug
//#define DEBUG

// Initialize Variables
// Temporary Data Array
uint16_t *burstData;

// Checksum variable
int16_t burstChecksum = 0;

// Accelerometer
float AXS, AYS, AZS = 0;

// Gyro
float GXS, GYS, GZS = 0;

// Control registers
int MSC = 0;
int FLTR = 0;
int DECR = 0;

// Temperature
float TEMPS = 0;

// Delay counter variable
int printCounter = 0;

// Call ADIS16470 Class
ADIS16470 IMU(5,22,21); // Chip Select, Data Ready, Reset Pin Assignments

void setup()
{
    Serial.begin(115200); // Initialize serial output via USB
//    IMU.configSPI(); // Configure SPI communication
//    delay(500); // Give the part time to start up
//    IMU.regWrite(MSC_CTRL, 0xC1);  // Enable Data Ready, set polarity
//    IMU.regWrite(FILT_CTRL, 0x04); // Set digital filter
//    IMU.regWrite(DEC_RATE, 0x00), // Disable decimation
//   
//    // Read the control registers once to print to screen
//    MSC = IMU.regRead(MSC_CTRL);
//    FLTR = IMU.regRead(FILT_CTRL);
//    DECR = IMU.regRead(DEC_RATE);
//
//    attachInterrupt(22, grabData, RISING); // Attach interrupt to pin 2. Trigger on the rising edge
}

// Function used to read register values when an ISR is triggered using the IMU's DataReady output
void grabData()
{
    burstData = {};
    IMU.configSPI(); // Configure SPI before the read. Useful when talking to multiple SPI devices
    burstData = IMU.wordBurst(); // Read data and insert into array
}

// Function used to scale all acquired data (scaling functions are included in ADIS16470.cpp)
void scaleData()
{
    GXS = IMU.gyroScale(*(burstData + 1)); //Scale X Gyro
    GYS = IMU.gyroScale(*(burstData + 2)); //Scale Y Gyro
    GZS = IMU.gyroScale(*(burstData + 3)); //Scale Z Gyro
    AXS = IMU.accelScale(*(burstData + 4)); //Scale X Accel
    AYS = IMU.accelScale(*(burstData + 5)); //Scale Y Accel
    AZS = IMU.accelScale(*(burstData + 6)); //Scale Z Accel
    TEMPS = IMU.tempScale(*(burstData + 7)); //Scale Temp Sensor
}

// Main loop. Print data to the serial port. Sensor sampling is performed in the ISR
void loop()
{
  Serial.println("ponkie pink");
//    printCounter ++;
//    if (printCounter >= 50000) // Delay for writing data to the serial port
//    {
//        detachInterrupt(22); //Detach interrupt to avoid overwriting data
//        scaleData(); // Scale data acquired from the IMU
//        burstChecksum = IMU.checksum(burstData); // Calculate checksum based on data array
//
//        //Clear the serial terminal and reset cursor
//        //Only works on supported serial terminal programs (Putty)
//        Serial.print("\033[2J");
//        Serial.print("\033[H");
//
//        // Print header
//        Serial.println(" ");
//        Serial.println("ADIS16470 Teensy Burst Read Example Program");
//        Serial.println("Juan Chong - November 2017");
//        Serial.println(" ");
//
//        // Print control registers to the serial port
//        Serial.println("Control Registers");
//        Serial.print("MSC_CTRL: ");
//        Serial.println(MSC,HEX);
//        Serial.print("FLTR_CTRL: ");
//        Serial.println(FLTR,HEX);
//        Serial.print("DEC_RATE: ");
//        Serial.println(DECR,HEX);
//        Serial.println(" ");
//        Serial.println("Raw Output Registers");
//       
//        // Print scaled gyro data
//        Serial.print("XGYRO: ");
//        Serial.println(GXS);
//        Serial.print("YGYRO: ");
//        Serial.println(GYS);
//        Serial.print("ZGYRO: ");
//        Serial.println(GZS);
//     
//        // Print scaled accel data
//        Serial.print("XACCL: ");
//        Serial.println(AXS);
//        Serial.print("YACCL: ");
//        Serial.println(AYS);
//        Serial.print("ZACCL: ");
//        Serial.println(AZS);
//        Serial.println(" ");
//
//        Serial.println("Status Registers");
//
//        // Print Status Registers
//        Serial.print("DIAG_STAT: ");
//        Serial.println((*(burstData + 0)));
//        Serial.print("TIME_STMP: ");
//        Serial.println((*(burstData + 8)));
//        Serial.print("CHECKSUM: ");
//        Serial.println((*(burstData + 9)));
//
//        // Report if checksum is good or bad
//        Serial.print("CHECKSUM OK? ");
//        if (burstChecksum == *(burstData + 9))
//            Serial.println("YES");
//        else
//            Serial.println("NO");
//       
//        // Print scaled temp data
//        Serial.print("TEMP: ");
//        Serial.println(TEMPS);
//
//#ifdef DEBUG
//        // Print unscaled gyro data
//        Serial.print("XGYRO: ");
//        Serial.println((*(burstData + 1)));
//        Serial.print("YGYRO: ");
//        Serial.println((*(burstData + 2)));
//        Serial.print("ZGYRO: ");
//        Serial.println((*(burstData + 3)));
//     
//        // Print unscaled accel data
//        Serial.print("XACCL: ");
//        Serial.println((*(burstData + 4)));
//        Serial.print("YACCL: ");
//        Serial.println((*(burstData + 5)));
//        Serial.print("ZACCL: ");
//        Serial.println((*(burstData + 6)));
//        Serial.println(" ");
//       
//        // Print unscaled temp data
//        Serial.print("TEMP: ");
//        Serial.println((*(burstData + 7)));
//#endif
//        printCounter = 0;
//        attachInterrupt(22, grabData, RISING);
//    }
}

Idahowalker,

The debug level was set to 'none'. I tried your code and was able to see your print statement in the serial monitor.

I have found that the ADIS16470 datasheet specifies a maximum clock frequency of 2 MHz for SPI, and the minimum ESP32 CPU frequency is 80 MHz. However, I have an ESP32 currently working with another sensor, ZED F9P GPS, whose max SPI clock frequency is just 5.5 MHz. So I am not sure if clock frequency is the problem, or if I'm heading in the right at all direction with this.

Does anyone know if the ESP32 and ADIS16470 would be compatible at all?

If the debug level was set to None then you'll not get serial prints. Why not set the Debug level to something other than None: Debug would be best.

I set debug level to 'debug' and uncommented the #define DEBUG in the original code, but it still does not print anything. With your code, it was able to print that statement at all debug levels.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.