Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADS1262 - Unable to acquire data #14

Open
NikGreek opened this issue Nov 5, 2021 · 2 comments
Open

ADS1262 - Unable to acquire data #14

NikGreek opened this issue Nov 5, 2021 · 2 comments

Comments

@NikGreek
Copy link

NikGreek commented Nov 5, 2021

Hello, I'm trying to connect the ads1262 with an arduino uno so I can measure voltage with higher precision.
I'm using the same connections you suggest and the same code.
However in serial monitor, I only get the "successful initialization" message and then nothing or I get only zero values of voltage.
I apply the analog signal from a NI ELVIS III breadboard.
Is this something you can help me with ?
Thank you in advance!

@LAWBear
Copy link

LAWBear commented Dec 17, 2021

I remain hopeful for suggestions/guidance on ADS1262 data values from ProtoCentral ADS1262 "1-Simple_Differential.ino". Have upgraded MCU from Feather M0 to Feather M4 Express, and commented sketch "#include <SoftwareSerial.h> since previous comment.

Data "readout voltage/mv" remains 0.00 & 0.00 resp.

I embed logic analyzer image but cannot include *.rar archive of Saleae logic files for analysis. Data only displays intermittently or at interval(s) of ~732ms??

logic_analyzer_view

Analyzer traces self labeled and arranged for clarity of response and issue.

PLEASE advise steps for further testing or diagnositcs.

@LAWBear
Copy link

LAWBear commented Feb 7, 2022

I MAY be getting close to successful configuration of the ADS1262 and the Feather M4 Express as an SD card data acquisition system. This configuration also provides GPS header statements in each file, and fairly large SD cards (32Gb & 64Gb) using Fat32 or ExFat with 32k clusters and 128k clusters resp. I am storing raw binary at up to 38.4 ksps to the SD card with some reasonable success, but still struggling a bit to get the ADS1262 to "start" and/or "sync" with the sample clocks. To the interests of wizards I include my crude sketch. Further, to some other inquiries, I have also successfully "tested" the ProtoCentral on Arduino Uno R3. and the "example" sketch. (currently using pushbutton(s) to start file for selected DURATION)

Comments/Guidance appreciated:

``/Compiled for Feather M4 Express (SAMD51)
Sample rate and ADS1262 tuning done in modified ads1262.cpp
Using data buffer sized for 32Gb Sandisk Extreme SD card
Sketch includes some place-holders for AirLift ESP32 Coprocessor (future work)
/

#include <SPI.h>
#include <SdFat.h>
#include <stdint.h>
#include <Adafruit_GPS.h>
#include <ads1262.h>
//#include <WiFiNINA.h>
#include <stdio.h>

#define SPI_SPEED SD_SCK_MHZ(12)
#define DURATION 10 // RECORDING DURATION
int count1=0;
SdFat SD;
File myFile;
char filename[15];

// name of the GPS hardware serial port?
#define GPSSerial Serial1

// Connect to the GPS on the hardware port
Adafruit_GPS GPS(&GPSSerial);

String NMEA1;
String NMEA2;
char c;

//AirLIft WiFi
const int WIFININA_SLAVESELECT = 13;
const int WIFININA_SLAVERESET = 12;
const int WIFININA_SLAVEREADY = 11;

const int ledStart = A1;
const int ledStop = A2;
const int btnStart = A3;
const int btnStop = A4;
unsigned long startRecTime = 0;
const int sd_cs_pin = 10; //Feather M4 SD card chip-select pin
//const int GPO = ?? //not available until pushbuttons & LED's released for external controls

//Pins used for the connection with the sensor, the others are controlled by the SPI library): (Feather M4 pins assigned in ads1262.h)
//const int ADS1262_DRDY_PIN = 6;
//const int ADS1262_CS_PIN = 9;
//const int ADS1262_START_PIN = 5;
//const int ADS1262_PWDN_PIN = A0;

int recPressed = 0;
int stopPressed = 0;
int flag = 0;

ads1262 PC_ADS1262; //ADS class

//ADS1262 global
#define PGA 1 // Programmable Gain = 1
#define VREF 2.50 // Internal reference of 2.048Vc
#define VFSR VREF/PGA
#define FSR (((long int)1<<23)-1)

#define START1 0x08
#define STOP1 0x0A
#define RDATA1 0x12

//float volt_V=0;
//float volt_mV=0;
volatile int i;
volatile char SPI_RX_Buff[10];
volatile long ads1262_rx_Data[10];
volatile static int SPI_RX_Buff_Count = 0;
volatile char *SPI_RX_Buff_Ptr;
volatile int Responsebyte = false;

unsigned char buffer1[32000];
int newData = 0; // new data from adc?
int index1=0;

void setup()
{
// 9600 baud is the default rate for the Ultimate GPS/Featherwing
GPSSerial.begin(9600);

GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
// Default is 1 Hz update rate
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
delay(1000); //Pause

pinMode(WIFININA_SLAVESELECT,OUTPUT); //AirLift_WiFi_CS_PIN 13
pinMode(WIFININA_SLAVERESET,OUTPUT); //AirLift_WiFi_RST_PIN 12
pinMode(WIFININA_SLAVEREADY ,INPUT); //AirLift_WiFi_DRDY_PIN 11

pinMode(10, OUTPUT); // DON'T change this(10) - Hardware sd_cs_pin pin must be left as output for SD library functions to work correctly
pinMode(ledStart, OUTPUT); //A1 pushbutton,to be replaced with BLE replies later
pinMode(ledStop, OUTPUT); //A2 pushbutton,to be replaced with BLE replies later
pinMode(btnStart, INPUT_PULLUP); //A3 Blue LED,to be replaced with BLE commands later
pinMode(btnStop, INPUT_PULLUP); //A4 Green LED,to be replaced with BLE commands later
pinMode(sd_cs_pin, OUTPUT); //10 SD enable (Feather M4 Express)
// pinMode(GPO,OUTPUT); //?? Used in BLE mode, not available until pushbuttons & LED's released for external controls

// initalize the data ready and chip select pins:
pinMode(ADS1262_DRDY_PIN, INPUT); //data ready input line (Feather M4- pin 6)
pinMode(ADS1262_CS_PIN, OUTPUT); //chip enable output line (Feather M4- pin 9)
pinMode(ADS1262_START_PIN, OUTPUT); // start (Feather M4- pin 5)
pinMode(ADS1262_PWDN_PIN, OUTPUT); // Power down output (Feather M4- pin A0)

digitalWrite(WIFININA_SLAVESELECT, HIGH);

Serial.begin(115200); // Max Baud Rate
SD.begin(); //Start SD card library
// SPI.begin(); // start SPI library
SPI.beginTransaction(SPISettings(SPI_SPEED, MSBFIRST, SPI_MODE1));

digitalWrite(ADS1262_PWDN_PIN,HIGH);
digitalWrite(ADS1262_PWDN_PIN,LOW);
digitalWrite(ADS1262_PWDN_PIN,HIGH); // hold high for operating
delay(10);

digitalWrite(10, HIGH);

if (SD.begin(sd_cs_pin,SPI_SPEED)) {        //testing changes to SPI speed
delay(10);

for (int dloop = 0; dloop < 4; dloop++) {
digitalWrite(ledStart,!digitalRead(ledStart));
delay(100);
}
}
else { // if error, flash LED twice per second, until reset
while(1) {
digitalWrite(ledStart,!digitalRead(ledStart));
delay(500);
}
}
strcpy(filename, "ANALOG00.BIN"); // Template for file name, characters 6 & 7 get set automatically later
SD.ls(LS_R | LS_DATE | LS_SIZE); // list the files

PC_ADS1262.ads1262_Init(); //initialize ads126
delay(10);

// PC_ADS1262.ads1262_SPI_Command_Data(START1);
// delay(10);

}

void loop()
{
if (digitalRead(btnStart) == LOW && recPressed == 0) {
StartRec(); // launch StartRec method
startRecTime = millis();
}
if (digitalRead(btnStop) == LOW) {
StopRec(); // launch StopRec method
}

if(recPressed){
if( (millis() - startRecTime) > 1000)
{
count1++;
if(count1 >= DURATION)
{
StopRec();
count1 =0;
}
startRecTime = millis();
}
}

if((digitalRead(ADS1262_DRDY_PIN)) == LOW)               // monitor Data ready(DRDY pin)
{
SPI_RX_Buff_Ptr = PC_ADS1262.ads1262_Read_Data();  //6Bytes <STATUS|DATA1|DATA2|DATA3|DATA4|CHECKSUM>
Responsebyte = true;
}
if(Responsebyte == true)
{
  for(i = 0; i <5; i++) //Remove STATUS byte?
  {   
  SPI_RX_Buff[SPI_RX_Buff_Count++] = *(SPI_RX_Buff_Ptr + i);              
  }
Responsebyte = false;
}

if(SPI_RX_Buff_Count >= 5)
{
ads1262_rx_Data[0]= (unsigned char)SPI_RX_Buff[1]; // read 4 bytes adc count
ads1262_rx_Data[1]= (unsigned char)SPI_RX_Buff[2];
ads1262_rx_Data[2]= (unsigned char)SPI_RX_Buff[3];
ads1262_rx_Data[3]= (unsigned char)SPI_RX_Buff[4];

for(int i = 0; i < 4 ; i++)
{
  buffer1[index1++] = ads1262_rx_Data[i];
} 

SPI_RX_Buff_Count = 0;
if(index1 >= 32000)
{
  newData =1;
  index1 = 0;
}

}

if(recPressed && (newData == 1) )
{

myFile = SD.open(filename, O_RDWR | O_APPEND);  //re-open file to append buffer data in "loop"
myFile.write(buffer1,32000);

index1 = 0;
myFile.close();
newData = 0;
}

}

void StartRec() // start recording method
{
digitalWrite(ledStart,HIGH);
digitalWrite(ledStop,LOW);

recPressed = 1;
stopPressed = 0;

for (uint8_t i = 0; i < 100; i++) {
filename[6] = '0' + i/10;
filename[7] = '0' + i%10;
//create if does not exist, do not open existing, write, sync after write
if (! SD.exists(filename)) {
  break;
}

}
readGPS(); //This is a function below which reads two NMEA sentences from GPS to create record "header"

myFile = SD.open(filename, FILE_WRITE);

// Serial.println(NMEA1); //Uncomment these lines to display GPGGA on serial monitor, !!! Start loop will not execute if serial monitor is not displayed
// delay(10);
// Serial.println(NMEA2); //Uncomment these lines to display GPRMC on serial monitor, !!! Start loop will not execute if serial monitor is not displayed
// delay(10);

myFile.println(NMEA1); //try to write NMEA1 GGA as file header
myFile.close();
delay(10);
myFile = SD.open(filename, O_RDWR | O_APPEND);  //re-open file to append NMEA2
myFile.println(NMEA2); //try to write NMEA2 RMC as file header
myFile.sync();
delay(10); 

PC_ADS1262.ads1262_SPI_Command_Data(START1);
delay(1);  

}

void StopRec() { // stop recording method

digitalWrite(ledStart,LOW);
digitalWrite(ledStop,HIGH);

myFile.close();
recPressed = 0;

}

void readGPS(){ //This function will read and remember two NMEA sentences from GPS
clearGPS(); //Serial port probably has old or corrupt data, so begin by clearing it all out
while(!GPS.newNMEAreceived()) { //Keep reading characters in this loop until a good NMEA sentence is received
c=GPS.read(); //read a character from the GPS
}
GPS.parse(GPS.lastNMEA()); //Once good NMEA, parse it
NMEA1=GPS.lastNMEA(); //Once parsed, save NMEA sentence into NMEA1

while(!GPS.newNMEAreceived()) { //Go out and get the second NMEA sentence, should be different type than the first one read above.
c=GPS.read();
}
GPS.parse(GPS.lastNMEA());
NMEA2=GPS.lastNMEA();
}

void clearGPS() { //Since between GPS reads, we still have data streaming in, we need to clear the old data by reading a few sentences, and discarding these
while(!GPS.newNMEAreceived()) {
c=GPS.read();
}
GPS.parse(GPS.lastNMEA());
while(!GPS.newNMEAreceived()) {
c=GPS.read();
}
GPS.parse(GPS.lastNMEA());
}
''
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants