Hello everyone,
I am working on a project and I have recently switched from the Arduino nano to an ESP32. I have the VSPI line working reading data from the accelerometer. I would like to use VSPI for the accelerometer as I plan to use HSPI for an SD card module. How do I change the SPI settings to use the HSPI as well?
//Testing the LIS3DH on the esp32
#include <SPI.h>
#include <Adafruit_LIS3DH.h>
#include <Adafruit_Sensor.h>
//ACCELEROMETER SPI SETUP
// Used for hardware & software SPI
#define LIS3DH_CS 5
// hardware SPI
Adafruit_LIS3DH lis = Adafruit_LIS3DH(LIS3DH_CS);
//ACCELEROMETER DATA COLLECTION SETUP
#define SIZE 2000 //size of array 400 gets 2000 samples/sec ... sadly not anymore
float samples[SIZE][4]; //declare variable for sample storage
//Retrieve the data from the sensor
void getData() {
//Collect data from the sensor
for(int i=0; i<SIZE; i++){
lis.read(); // get X Y and Z data at once
// Then print out the raw data
/*Serial.print("X: "); Serial.print(lis.x);
Serial.print(" \tY: "); Serial.print(lis.y);
Serial.print(" \tZ: "); Serial.print(lis.z);
*/
/* Or....get a new sensor event, normalized */
sensors_event_t event;
lis.getEvent(&event);
/* Display the results (acceleration is measured in m/s^2) */
/*Serial.print("\t\tX: "); Serial.print(event.acceleration.x);
Serial.print(" \tY: "); Serial.print(event.acceleration.y);
Serial.print(" \tZ: "); Serial.print(event.acceleration.z);
Serial.println(" m/s^2 ");
Serial.println();
*/
//collect the data in blocks
samples[i][0] = micros();
samples[i][1] = event.acceleration.x;
samples[i][2] = event.acceleration.y;
samples[i][3] = event.acceleration.z;
}
}
//Write the data to serial
void writeData() {
for(int i=0; i<SIZE; i++) {
Serial.print(samples[i][0]);
Serial.print(",");
Serial.print(samples[i][1]);
Serial.print(",");
Serial.print(samples[i][2]);
Serial.print(",");
Serial.print(samples[i][3]);
Serial.print("\n");
}
}
void setup() {
Serial.begin(115200);
pinMode(LIS3DH_CS, OUTPUT);
delay(4000);
SPI.begin();
//setup the sensor
Serial.println("LIS3DH test!");
if (! lis.begin(0x18)) { // change this to 0x19 for alternative i2c address
Serial.println("Couldnt start");
while (1) yield();
}
Serial.println("LIS3DH found!");
// lis.setRange(LIS3DH_RANGE_4_G); // 2, 4, 8 or 16 G!
Serial.print("Range = "); Serial.print(2 << lis.getRange());
Serial.println("G");
lis.setDataRate(LIS3DH_DATARATE_LOWPOWER_5KHZ);
Serial.print("Data rate set to: ");
switch (lis.getDataRate()) {
case LIS3DH_DATARATE_1_HZ: Serial.println("1 Hz"); break;
case LIS3DH_DATARATE_10_HZ: Serial.println("10 Hz"); break;
case LIS3DH_DATARATE_25_HZ: Serial.println("25 Hz"); break;
case LIS3DH_DATARATE_50_HZ: Serial.println("50 Hz"); break;
case LIS3DH_DATARATE_100_HZ: Serial.println("100 Hz"); break;
case LIS3DH_DATARATE_200_HZ: Serial.println("200 Hz"); break;
case LIS3DH_DATARATE_400_HZ: Serial.println("400 Hz"); break;
case LIS3DH_DATARATE_POWERDOWN: Serial.println("Powered Down"); break;
case LIS3DH_DATARATE_LOWPOWER_5KHZ: Serial.println("5 Khz Low Power"); break;
case LIS3DH_DATARATE_LOWPOWER_1K6HZ: Serial.println("16 Khz Low Power"); break;
}
}
void loop() {
Serial.print("Test");
Serial.println("Test ln");
//getData();
//writeData();
delay(500);
}
Thank you in advance