Comments (13)
Hi @hupozhao ,
I was able to achieve almost 2000 SPS. I have described it in the tutorial:
https://wolles-elektronikkiste.de/en/4-channel-24-bit-adc-ads1220
Did you use Serial.println() to display the values? Then this is the bottleneck, because it is very slow.
from ads1220_we.
Thank you for reading
Serial port output is really slow, and level 6 SPS has been set.
I now directly read ADS1220 data and write it into SPIFFS.
Currently, only 30 values can be written per second.
I am trying to use different settings to improve the reading speed.
Do you have any good suggestions?
thank you!
from ads1220_we.
Level 6 is good. Moreover you should use the continuous mode and the turbo mode. I have described this in my tutorial. You need to find the bottleneck. First you could try to just read let's say 2000 values without saving them. You can measure the time needed to get the values using millis(). You may need to do something with the values like adding them or so - otherwise the compiler might eliminate the sampling. As I wrote before I was able to get 2000 values in 1034 ms which is what it should deliver.
In a next step I would try to save 2000 float values on the SPIFFS. So no measured values, but just any values.
Then you see what is the bottleneck. If both processes should be fast then it's something with the the combination of these processes. That's how I would analyse the issue.
You could also publish your code here or send it to me ([email protected]). Then I can have a look in the evening.
from ads1220_we.
Thank you for reading
This is my modified code,My goal is to use the function to get the return value every 10 milliseconds.
#include <ADS1220_WE.h>
#include <SPI.h>
#define ADS1220_CS_PIN 12
#define ADS1220_DRDY_PIN 21
/* Create your ADS1220 object /
ADS1220_WE ads = ADS1220_WE(ADS1220_CS_PIN, ADS1220_DRDY_PIN);
/ Alternatively you can also pass the SPI object as reference */
// ADS1220_WE ads = ADS1220_WE(&SPI, ADS1220_CS_PIN, ADS1220_DRDY_PIN);
void ads_Begin()
{
if (!ads.init())
{
Serial.println("ADS1220 is not connected!");
while (1) ;
}
/* The voltages to be measured need to be between negative VREF + 0.2 V and positive
- VREF -0.2 V if PGA is enabled. For this basic example I disable PGA, to be on the
- safe side. */
ads.setConversionMode(ADS1220_CONTINUOUS);
ads.setOperatingMode(ADS1220_TURBO_MODE );
ads.setDataRate(ADS1220_DR_LVL_1);
// ads.setGain(ADS1220_GAIN_16); // set gain to 8
ads.bypassPGA(true); // redundant, since this is default, but I wanted to highlight this setting.
}
/*
- You set the channels to be measured with setCompareChannels(); You
- can choose the following parameters:
- Parameter Pos. Input Neg. Input Comment
- ADS1220_MUX_0_1 AIN0 AIN1
- ADS1220_MUX_0_2 AIN0 AIN2
- ADS1220_MUX_0_3 AIN0 AIN3
- ADS1220_MUX_1_2 AIN1 AIN2
- ADS1220_MUX_1_3 AIN1 AIN3
- ADS1220_MUX_2_3 AIN2 AIN2
- ADS1220_MUX_1_0 AIN1 AIN0
- ADS1220_MUX_3_2 AIN3 AIN2
- ADS1220_MUX_0_AVSS AIN0 AVSS single-ended
- ADS1220_MUX_1_AVSS AIN1 AVSS single-ended
- ADS1220_MUX_2_AVSS AIN2 AVSS single-ended
- ADS1220_MUX_3_AVSS AIN3 AVSS single-ended
- ADS1220_MUX_REFPX_REFNX_4 REFP0/REFP1 REFN0/REFN1 (REFPX-REFNX)/4; PGA bypassed
- ADS1220_MUX_AVDD_M_AVSS_4 AVDD AVSS (AVDD-AVSS)/4; PGA bypassed
- ADS1220_MUX_AVDD_P_AVSS_2 AVDD AVSS (AVDD+AVSS)/2
- The last three modes use the internal reference (2.048 V) and gain = 1, independent of
- your settings.
*/
String ads_Data()
{
ads.setCompareChannels(ADS1220_MUX_0_1);
float adata = ads.getVoltage_mV();
ads.setCompareChannels(ADS1220_MUX_2_3);
float bdata = ads.getVoltage_mV();
return String(adata, 5)+ "," + String(bdata, 5);
// Serial.println();
// delay(20);
}
from ads1220_we.
Hi @hupozhao ,
I have taken your code snippets and have made the small program below out of it:
#include <ADS1220_WE.h>
#include <SPI.h>
#define ADS1220_CS_PIN 5
#define ADS1220_DRDY_PIN 21
ADS1220_WE ads = ADS1220_WE(ADS1220_CS_PIN, ADS1220_DRDY_PIN);
void setup()
{
ads_Begin();
Serial.begin(115200);
ads.setConversionMode(ADS1220_CONTINUOUS);
ads.setOperatingMode(ADS1220_TURBO_MODE );
ads.setDataRate(ADS1220_DR_LVL_6);
ads.bypassPGA(true);
delay(1000);
String result = "";
unsigned long startingTime = millis();
for(int i=0; i<1000;i++)
{
result = ads_Data();
}
unsigned long durationTime = millis() - startingTime;
Serial.println(durationTime);
Serial.println(result); // just to check
}
void loop(){}
void ads_Begin()
{
if (!ads.init())
{
Serial.println("ADS1220 is not connected!");
while (1) ;
}
}
String ads_Data()
{
ads.setCompareChannels(ADS1220_MUX_0_1);
float adata = ads.getVoltage_mV();
ads.setCompareChannels(ADS1220_MUX_2_3);
float bdata = ads.getVoltage_mV();
return String(adata, 5) + "," + String(bdata, 5);
}
The only relevant parts I changed were:
- I chose GPIO5 as CS, because my ESP32 did not like it when I took the GPIO12
- I changed to level 6
- I added code to measure the time needed for 1000 times performing ads_Data() which equals 2000 measurements.
The time needed (durationTime) was 1290 milliseconds. This is only a bit slower than the maximum data rate, which would be 1000 milliseconds for 2000 measurements. The reason is the time needed for changing channels and all SPI communication.
However, this is much faster than the 30 measurements per seconds that you have found. The bottleneck must be somewhere else in the rest of your code. At least it's not related with the ADS1220 or the library. I recommend to do similar measurements for the other processes in your code. You said you write the results to the SPIFFS. I don't have much experience with SPIFFS, but I know from writing to SD cards that it slows down very much if you open and close the file every time when you write to it . Could it be something like that?
from ads1220_we.
Thank you for reading @wollewald
The chip I used is ESP32S3. I tested ADS1220 and ADXL355 respectively with the code you gave me. Here is the result:
ADS1220_durationTime:28749
ADS1220_result:-0.10425,0.03394
Failed to obtain time
Device found
ADXL355Started
ADXL355_durationTime:2062
ADXL355_result:0.01313,0.00010,1.00263
I just used the pin:
#define ADS1220_CS_PIN 12
#define ADS1220_DRDY_PIN 21
#define MISO 13
#define MOSI 14
#define SCLK 11
#define SS 12
I set the spi pin in the library file:
uint8_t ADS1220_WE::init(){
vRef = 2.048;
gain = 1;
refMeasurement = false;
convMode = ADS1220_SINGLE_SHOT;
_spi->begin(11,13,14,12);//spi.begin( SCK,MISO,MOSI,SS );
pinMode(csPin, OUTPUT);
pinMode(drdyPin, INPUT);
digitalWrite(csPin, HIGH);
mySPISettings = SPISettings(4000000, MSBFIRST, SPI_MODE1);
reset();
start();
spiffs read and write section:
int key1 = 0;
String file_Name;
File file1;
void t1Callback()
{
if (key1 == 0)
{
filename = "/DD202201154414"
file1 = SPIFFS.open(file_Name, "a");
if (file1)
{
key1 = 1;
Serial.println("File_OK");
Serial.println(file_Name);
}
else
{
SPIFFS.format();
}
}
else
{
file1.println( ads_Data() + "," + adx_Data());
if (file1.size() > 250000)
{
Serial.println("Start sending");
file1.close();
key1 = 0;
wifi_Send_File(file_Name);
}
}
}
My hardware has been designed, is my problem with GPIO?
If you modify it, you can read it quickly, but the result is incorrect:
uint32_t ADS1220_WE::readResult(){
uint8_t buf[3];
uint32_t rawResult = 0;
if(convMode == ADS1220_SINGLE_SHOT){
start();
}
//while(digitalRead(drdyPin) == HIGH) {} ←←←←←←←←←←←←←←Shield it here ADS1220_result:-0.00024,-0.00024
_spi->beginTransaction(mySPISettings);
digitalWrite(csPin, LOW);
buf[0] = _spi->transfer(0x00);
buf[1] = _spi->transfer(0x00);
buf[2] = _spi->transfer(0x00);
digitalWrite(csPin, LOW);
_spi->endTransaction();
rawResult = buf[0];
rawResult = (rawResult << 8) | buf[1];
rawResult = (rawResult << 8) | buf[2];
rawResult = (rawResult << 8);
return rawResult;
}
from ads1220_we.
Hi @hupozhao ,
I had problems using GPIO12 as chip select pin and used GPIO5. Maybe you want to try that?
from ads1220_we.
@wollewald
My hardware has been made, so I can't adjust GPIO.I try to add ADS1220_ CS_ PIN, always set to low level.It doesn't seem to work, or I set the wrong place.
from ads1220_we.
@wollewald I'll try flying line test GPIO5,What pin do you use = 18, MISO = 19, MOSI = 23, SS = 5?
from ads1220_we.
Exactly - and good idea to try it at least provisionally. Unfortunately I do not have an ESP32 S3 board available, otherwise I would test it. Good luck!
from ads1220_we.
Thank you for reading
I found the problem. It's not really the problem of the library. The problem is the selection of pins.
from ads1220_we.
Thanks for the update and good to hear that you found the problem. So, we can close the issue?
from ads1220_we.
Since there was no further feedback I close the issue.
from ads1220_we.
Related Issues (4)
- ”ADS1220_WE“ usage HOT 8
- About AIN2 pin HOT 4
- Passing SPIClass in the constructor HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ads1220_we.