Input for Audio Shield

Status
Not open for further replies.
Hi All!
First of all thank you for your kind answers.
Some update about the project: I'm not able to work with the Audio library, because I am a total newbie in audio, so I've decided to do not use anymore the Audio shield and I'm sending the manipulated data out through the DAC, without any filtering (only the offset removal due the position).

I'm getting some results but my main problem here is that the analogWrite() function is super slow and I'm losing samples in output.

WhatsApp Image 2020-02-20 at 18.52.07.jpg

I'm acquiring the Sensor via SPI and I've modified the library (Adafruit_LIS3DH.h) to speed up to 1Mhz. How I can get a smoother output via DAC?
here is my code:

Code:
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Adafruit_LIS3DH.h>
#include <Adafruit_Sensor.h>

//Pin per SPI del LIS3DH, versione Teensy 3.6
#define LIS3DH_CLK 32
#define LIS3DH_MISO 1
#define LIS3DH_MOSI 0
#define LIS3DH_CS 31

#define DAC (A21)
#define ZERO_DAC 2048

#define GAIN_X (float)(0.3)
#define GAIN_Y (float)(0.3)
#define GAIN_Z (float)(0.8)
#define GAIN_TOT (float)(0.5)

Adafruit_LIS3DH lis = Adafruit_LIS3DH(LIS3DH_CS, LIS3DH_MOSI, LIS3DH_MISO, LIS3DH_CLK);

int16_t sens_fusion_out = 0;
int16_t sens_fusion_filt = 0;
int16_t sens_fusion_prev = 0;

void setup() 
{
  Serial.begin(9600);
  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_2_G);   // 2, 4, 8 or 16 G!
  
  Serial.print("Range = "); Serial.print(2 << lis.getRange());  
  Serial.println("G");
  analogWriteResolution(12);
}

void loop() 
{
  lis.read();
  sens_fusion_out = ((lis.x * GAIN_X) + (lis.y * GAIN_Y) + (lis.z * GAIN_Z)) * GAIN_TOT;
  sens_fusion_filt = (sens_fusion_out - sens_fusion_prev);
  sens_fusion_prev = sens_fusion_out;
 
  Serial.print("FILT: "); Serial.println(sens_fusion_filt);
  analogWrite(DAC, (sens_fusion_filt * 0.25) + ZERO_DAC);
}

Thanks a lot for the help, you have been super kind,

Paul.
 
Hi All!
I'm acquiring the Sensor via SPI and I've modified the library (Adafruit_LIS3DH.h) to speed up to 1Mhz.
I don't understand what that means given the device tops out with a data rate of "5 KHz" per the datasheet. I assume that means 5 Ksamples / second.
 
Status
Not open for further replies.
Back
Top