Problem with ADS1256 board

Hi to everybody,

This is my first message to the forum. I've been reading it a lot since I started a year ago working with Arduino for my geology projects, and first, I would like to say thanks for the big community support I always find in the board.

Now I've got one question. Two weeks ago I bought an ADS1256 board (the one of the attached image). I've been struggling to make it work and get some readings, but I didn't succeed. I tried to use the ADS1213 library, and also the ADS1248, but the only values I've got are -1 or 0 with an Arduino UNO board and also with a DUE.

Anybody can help?

Thanks in advance.

for some reason I cannot download your picture. post a link to shop? Show connections & code

I bought this model: http://www.ebay.com/itm/ADS1256-24Bits-ADC-AD-Module-Communication-Modules-Capture-Board-Module-Kit-/151512712677

I was using the code from the ADS1213 library:

// This sketch demonstrates the use of the ADS1213 library by first initializing
// it with the neccesary parameters, then reading it every half second while cycling through the channels.

#include <ADS1213.h>

ADS1213 ADC_ext(16,false,13,11,2,0);
// clock speed MHz, true=offset binary (false=two's complement (can be negative)), SCLK pin, IO pin, DRDY pin, CS pin (0 if not in use)

void setup() {
  Serial.begin(115200);
  ADC_ext.CMRwrite(3,B001,1,1,255);
  // channel 3, mode 001 (self-calibration), gain 1, TMR 1, DR 255
  Serial.println("Done with setup");
}

void loop() {
  static byte Channel=1; // Static makes sure it doesn't get re-initialized every time
  Serial.print(Channel,DEC); Serial.print(" ch ");
  Serial.println(ADC_ext.readSigned(3),DEC); // Read and print the signed value
  Channel += 1;
  if (Channel>4) Channel = 1;
  ADC_ext.channel(Channel); // Set the current (incremented) channel by using the channel() function
  delay(500);
}

The connections were the SCLK to the pin 13, IO to the pin 11, DRDY to the pin 2, and tested the cable select option connected to a pin, and without any connection, but got the same results.

I believe you found library from here.

Chips are very alike, so the lib may work. Choose other pin (than pin 0) for CS
Channel 3 is read in your code. (not full bridge with differential inputs)

I just continue to have readings like -1. When I get my hands close to the Analog pins, the readings change to 0, but nothing else.

Now, using the ADS1213 I got lectures, but only when I put my hands over the geophone, using this code, but the lectures don't make any sense to me.:

#include <ADS1213.h>

ADS1213 ADC_ext(16,true,13,10,3,0);
// clock speed MHz, true=offset binary (false=two's complement (then the output can be negative)), SCLK pin, IO pin, DRDY pin, CS pin (0 if not in use)

void setup() {
  Serial.begin(115200);
  ADC_ext.CMRwrite(3,B001,1,1,50);
  // channel 3, mode 001 (self-calibration), gain, TMR, Decimation Ratio
  Serial.println("Done with setup");
}

const int NoOfSamples = 60; // Warning: if set too high, DeviationSqSum may overflow!
// This will happen sooner when the real standard deviation is higher.
unsigned long Values[NoOfSamples];

void loop() {
  
    double lec=ADC_ext.read(B000,3);
    Serial.println(lec);

  delay(20); // Wait a second to avoid overflowing the serial monitor with data
}

Try using hardware SPI.. pins clk 13, MISO 12 and MOSI 11
I'll download GitHub - Flydroid/ADS12xx-Library: Library for TI ADS1248 and ADS1256 24bit ADC this one and take a peek inside..

There in an .ino-file included.. It tells you to alter the "ads12xx.h"
(I can see it needs to be changed)
In the example, change RDY, CS and Start to match any digital pin (except 11..13)

Knut_ny,

I've tried this library, but the program that is served as an example it doesn't work for me, just gets stuck after selecting any of the commands.

I see also that my board doesn't have a START pin, but I obviously must be doing anything else wrong.

My plan is using this board to get the data from three geophones as differential inputs to get a higher dinamic range than when I use a 16 bit ADC.

Thanks for your help.

The full datasheet has all info needed to program and read the chip.
RDY-line tells when a convertion is done and data can be fetched. If the input is from an ocsillating source it may be difficult to interpret the reading.
Maybe some enveloping can be done before reading. (to read interval peak values)

What kind of signals/levels do you det from the geophones? frequency?

..and take a look at ebay.. HX711 (differential, amplifying inputs 32/64/128 times) @<$3

The problem is that I don't have enough programming background, that is why I tried to use these already made libraries.

I usually read frequencies under 50 Hz, but I use three geophones simultaneously, two horizontal and one vertical. The HX711 only have two differential inputs, but I'm gonna give it a try.

Thanks for the advice!

!! See the HX711 datasheet.. You usually use only one channel as it it related to ampl. factor

hello

ADS1256 register read and write work properly but i have problem to read the data from ads1256 its show garbage value.

i send my code here.

#include <SPI.h>
#define DRDY_PIN 2
#define CS_PIN 7
#define NOP 0xFF
#define MISO_PIN 12
#define MOSI_PIN 11
#define SCK_PIN 13
#define WREG 0x50
#define RREG 0x10
#define RDATA 0x01 //Read data once
#define RDATAC 0x03 //Read data continously
#define SDATAC 0x0F //Stop reading data continously
#define WAKEUP 0x00 //Exit Sleep Mode
#define SYNC 0xFC
#define NOP 0xFF
#define ORDER_MSB // Most significant Bit first (default)
#define SPI_SPEED 4800000
#define PGA 1 // Programmable Gain = 1
#define VREF 2.5 // Internal reference of 2.048V
#define VFSR VREF*2/PGA
#define FSR (((long int)1<<23)-1)

//const int dataReadyPin = 6;
volatile byte MSB;
volatile byte data;
volatile byte LSB;
//volatile char SPI_RX_Buff[3];
//volatile byte *SPI_RX_Buff_Ptr;
uint8_t CONFIG_REG0_ADDRESS;
uint8_t CONFIG_REG1_ADDRESS;
uint8_t CONFIG_REG2_ADDRESS;
uint8_t CONFIG_REG3_ADDRESS;
uint8_t CONFIG_REG4_ADDRESS;
uint8_t CONFIG_REG5_ADDRESS;
uint8_t CONFIG_REG6_ADDRESS;
uint8_t CONFIG_REG7_ADDRESS;
uint8_t CONFIG_REG8_ADDRESS;
uint8_t CONFIG_REG9_ADDRESS;
uint8_t CONFIG_REG10_ADDRESS;
uint8_t Config_Reg0 ;
uint8_t Config_Reg1 ;
uint8_t Config_Reg2;
uint8_t Config_Reg3 ;
uint8_t Config_Reg4 ;
uint8_t Config_Reg5 ;
uint8_t Config_Reg6;
uint8_t Config_Reg7 ;
uint8_t Config_Reg8 ;
uint8_t Config_Reg9;
uint8_t Config_Reg10 ;

volatile int DRDY_state;

void setup()
{
delayMicroseconds(500);
delayMicroseconds(500);
pinMode(MOSI_PIN, OUTPUT);
pinMode(MISO_PIN, INPUT);
pinMode(CS_PIN, OUTPUT);
pinMode(DRDY_PIN, INPUT);
pinMode(SCK_PIN, INPUT);
digitalWrite(CS_PIN, HIGH);
digitalWrite(SCK_PIN, LOW);
volatile int DRDY_state = HIGH;
SPI.begin();
Serial.begin(9600);
void writeRegister(uint8_t address, uint8_t value);
uint8_t readRegister(uint8_t address);
SPI.beginTransaction(SPISettings(SPI_SPEED, MSBFIRST, SPI_MODE1));
void DRDY_Interuppt();
attachInterrupt(digitalPinToInterrupt(DRDY_PIN), DRDY_Interuppt,FALLING);
CONFIG_REG0_ADDRESS=0x00;
CONFIG_REG1_ADDRESS=0x01;
CONFIG_REG2_ADDRESS=0x02;
CONFIG_REG3_ADDRESS=0x03;
CONFIG_REG4_ADDRESS=0x04;
CONFIG_REG5_ADDRESS=0x05;
CONFIG_REG6_ADDRESS=0x06;
CONFIG_REG7_ADDRESS=0x07;
CONFIG_REG8_ADDRESS=0x08;
CONFIG_REG9_ADDRESS=0x09;
CONFIG_REG10_ADDRESS=0x0A;
delay(100);
writeRegister(0x00, 0x01);
delayMicroseconds(50);
writeRegister(0x01, 0x0F);
delayMicroseconds(50);
writeRegister(0x02, 0x20);
delayMicroseconds(50);
writeRegister(0x03, 0xA2);
delayMicroseconds(50);
writeRegister(0x04, 0xE0);
delayMicroseconds(50);
writeRegister(0x05, 0x00);
delayMicroseconds(50);
writeRegister(0x06, 0x00);
delayMicroseconds(50);
writeRegister(0x07, 0x00);
delayMicroseconds(50);
writeRegister(0x08, 0x00);
delayMicroseconds(50);
writeRegister(0x09, 0x00);
delayMicroseconds(50);
writeRegister(0x0A, 0x00);
delayMicroseconds(50);
// digitalWrite(CS_PIN,HIGH); //release chip, signal end transfer

Config_Reg0 = readRegister(CONFIG_REG0_ADDRESS);
delayMicroseconds(50);
Config_Reg1 = readRegister(CONFIG_REG1_ADDRESS);
delayMicroseconds(50);
Config_Reg2 = readRegister(CONFIG_REG2_ADDRESS);
delayMicroseconds(50);
Config_Reg3 = readRegister(CONFIG_REG3_ADDRESS);
delayMicroseconds(50);
Config_Reg4 = readRegister(CONFIG_REG4_ADDRESS);
delayMicroseconds(50);
Config_Reg5 = readRegister(CONFIG_REG5_ADDRESS);
delayMicroseconds(50);
Config_Reg6 = readRegister(CONFIG_REG6_ADDRESS);
delayMicroseconds(50);
Config_Reg7 = readRegister(CONFIG_REG7_ADDRESS);
delayMicroseconds(50);
Config_Reg8 = readRegister(CONFIG_REG8_ADDRESS);
delayMicroseconds(50);
Config_Reg9 = readRegister(CONFIG_REG9_ADDRESS);
delayMicroseconds(50);
Config_Reg10 = readRegister(CONFIG_REG10_ADDRESS);
delayMicroseconds(50);
delay(100);

Serial.println("Config_Reg : ");
Serial.println(Config_Reg0,HEX);
Serial.println(Config_Reg1,HEX);
Serial.println(Config_Reg2,HEX);
Serial.println(Config_Reg3,HEX);
Serial.println(Config_Reg4,HEX);
Serial.println(Config_Reg5,HEX);
Serial.println(Config_Reg6,HEX);
Serial.println(Config_Reg7,HEX);
Serial.println(Config_Reg8,HEX);
Serial.println(Config_Reg9,HEX);
Serial.println(Config_Reg10,HEX);
Serial.println(" ");
delay(200);
digitalWrite(CS_PIN, HIGH);

}

void loop()
{

delayMicroseconds(50);
delayMicroseconds(50);
long int bit32;
long int bit24;
byte *config_reg;
long int regData;

if((digitalRead(DRDY_PIN)) == LOW) // Wait for DRDY to transition low

{
long int regData;
digitalWrite(CS_PIN, LOW); //Pull SS Low to Enable Communications with ADS1247
delayMicroseconds(10);
// RD: Wait 25ns for ADC12xx to get ready
// SPI.transfer(0x51);
//SPI.transfer(0x00);
// SPI.transfer(0x0F);
// writeRegister(0x01,0x43);
//Issue RDATA
SPI.transfer(SDATAC);
SPI.transfer(SYNC);
SPI.transfer( WAKEUP);
SPI.transfer( RDATAC);
delayMicroseconds(1);
bit24 |= SPI.transfer(NOP);
delayMicroseconds(1);
bit24 <<= 8;
bit24 |= SPI.transfer(NOP);
delayMicroseconds(1);
bit24 <<= 8;
bit24 |= SPI.transfer(NOP);
delayMicroseconds(1);
//Serial.println(regData,HEX);
bit24= ( bit24 << 8 );
bit32 = ( bit24 >> 8 );
// Converting 24 bit two's complement to 32 bit two's complement
delayMicroseconds(10);
//Serial.println(bit24,HEX);

float Vout = (float)((bit32VFSR1000)/FSR); //In mV

delay(300);

Serial.print("Vout in mV : ");
Serial.print(Vout);
Serial.print(" 32bit HEX : ");
Serial.println(bit32,HEX);

}
}

void writeRegister(uint8_t address, uint8_t value)
{
delayMicroseconds(10);
// waitforDRDY();
//SPI.beginTransaction(SPISettings(SPI_SPEED, MSBFIRST, SPI_MODE1)); // initialize SPI with SPI_SPEED, MSB first, SPI Mode1
digitalWrite(CS_PIN, LOW);
delayMicroseconds(10);
SPI.transfer(WREG | address); // send 1st command byte, address of the register
SPI.transfer(0x00); // send 2nd command byte, write only one register
SPI.transfer(value); // write data (1 Byte) for the register
delayMicroseconds(10);
digitalWrite(CS_PIN, HIGH);
}

uint8_t readRegister(uint8_t address)
{
uint8_t data;
// waitforDRDY();
// SPI.beginTransaction(SPISettings(SPI_SPEED, MSBFIRST, SPI_MODE1)); // initialize SPI with 4Mhz clock, MSB first, SPI Mode0
digitalWrite(CS_PIN, LOW);
delayMicroseconds(10);
SPI.transfer(RREG | address); // send 1st command byte, address of the register
SPI.transfer(0x00); // send 2nd command byte, read only one register
delayMicroseconds(10);
data = SPI.transfer(NOP); // read data of the register
delayMicroseconds(10);
digitalWrite(CS_PIN, HIGH);
//digitalWrite(_START, LOW);
// SPI.endTransaction();
return data;

}

void waitforDRDY()
{
while (DRDY_state)
{
continue;
}
noInterrupts();
DRDY_state = HIGH;
interrupts();
}

//Interrupt function
void DRDY_Interuppt()
{
DRDY_state = !DRDY_state;
// state = !state;
}

output on serial is

so garbage value is come......

so i not able to understand where i did mistake......

Read PM. - continue here with code and results

Hi,
The library ADS12xx.h doesn't work for me; my board haven't the pin START;

I sent this to "nchazarra".
Compare with datasheet and other libs.
The speed_setting 14MHz may be incorrect for the UNO.

/* ADS1256, datasheet: http://www.ti.com/lit/ds/sbas288j/sbas288j.pdf
compare: https://github.com/Flydroid/ADS12xx-Library/blob/master/ads12xx.cpp
    connections to Atmega328 (UNO)

    CLK  - pin 13
    DIN  - pin 11 (MOSI)
    DOUT - pin 12 (MISO)
    CS   - pin 10
    DRDY - pin 9
    RESET- pin 8 (or tie HIGH?)
    DVDD - 3V3

    Analog ch0 (input 0,1)
    Analog ch1 (input 2,3)
    Analog ch2 (input 4,5)
    (Analog ch3 (input 6,7))
*/

#define cs 10 // chip select
#define rdy 9 // data ready, input
#define rst 8 // may omit

// ** asd1256 Register map and data to write **
#define status_reg 0   // address (datasheet p. 30)
#define status_data 0x01 // default contents after reset (no need to write this)

#define mux_reg 1
//  mux_data to be changed while running, to select input ports

#define adcon_reg 2
#define adcon_data 0x24 // 0 01 00 100 => clk_out(default), sensor detect OFF, gain 16 (p.31)

#define drate_reg 3
#define drate_data 0x82 // => 100 SPS (samples/secons)

#include <SPI.h>

byte i; // general use

void setup()
{
  SPI.begin(); //start the spi-bus
  pinMode(cs, OUTPUT);
  digitalWrite(cs, LOW); // tied low is also OK.
  pinMode(rdy, INPUT);
  pinMode(rst, OUTPUT);
  Serial.begin(115200);
  digitalWrite(rst, LOW);
  delay(1); // LOW at least 4 clock cycles of onboard clock. 100 microsecons is enough
  digitalWrite(rst, HIGH); // now reset to deafult values
  delay(1); // unsure if needed
  // now set working parameters
  writereg(status_reg, status_data); // parameters defined on top
  writereg(adcon_reg, adcon_data);
  writereg(drate_reg, drate_data);
}

void writereg(byte reg_num, byte data) // write to a single register
{
  // digitalWrite(cs, LOW);
  while (rdy) {}  // wait for ready_line to go low
  SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE1)); // start SPI
  delayMicroseconds(10);
  SPI.transfer(0x50 | reg_num); // dataseheet p.34
  SPI.transfer(0x00);   // 2nd command byte
  SPI.transfer(data);   // write tge databyte to the register
  delayMicroseconds(10);
  SPI.endTransaction();
  // digitalWrite(cs, HIGH);
}

byte readreg(byte reg_num)  // read from a single register
{
  // digitalWrite(cs, LOW);  // cs is tied low for now? Theese two lines may be added if other components uses SPI-bus
  while (rdy) {}  // wait for ready_line to go low
  SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE1)); // start SPI
  byte bufr;
  while (rdy) {}  // wait for ready_line to go low
  delayMicroseconds(10);
  SPI.transfer(0x10 | reg_num); // send 1st command byte, address of the register
  SPI.transfer(0);  // one byte only
  delayMicroseconds(10);
  bufr = SPI.transfer(0xff); // read data from register (dummy parameter)
  delayMicroseconds(10);
  SPI.endTransaction();
  // digitalWrite(cs, HIGH);
  return bufr;
}

void loop()
{
  long adc_val; // store reading
  //Read 4 channels from ads1256
  for (i = 0; i < 5; i += 2)
  {
    // digitalWrite(cs, LOW);
    adc_val = 0;
    while (rdy) {} ;
    // send command - select ADC-channel 0000 0001 / 0010 0011 / 0100 0101
    SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE1)); // start SPI
    delayMicroseconds(10);
    writereg(mux_reg, i << 4 | i + 1 ); // positive to analog 0,2,4,6, Neg to 1,3,5,7
    while (rdy) {} ;
    SPI.transfer(1); // command for: READ DATA  (p.34)
    delayMicroseconds(10);// read three bytes (adc-value)
    adc_val = SPI.transfer(0)<<8;
    //delayMicroseconds(10); // needed ?
    adc_val |= SPI.transfer(0);
    //delayMicroseconds(10); // ??
    adc_val <<= 8;
    adc_val |= SPI.transfer(0);
    delayMicroseconds(10);
    // digitalWrite(_CS, HIGH);
    SPI.endTransaction();
    Serial.print(adc_val);
    Serial.print(" / ");
    // digitalWrite(cs, HIGH);
  }
  Serial.println();
}

Hi,

I have the same board in the picture of the first post and I am trying to make this last code work.

I am puzzled a bit by it.
First, I thing that the while(rdy) should really be while (digitalRead(rdy)).
Second, I don't understand the for loop.
It says it wants to read 4 channels, but it iterates only 3 times and I don't know why exactly that choice of values..

Can you make it a bit more explicit?

Thanks!

Thanks..

First, I thing that the while(rdy) should really be while (digitalRead(rdy)).

Of course it shall be..

If you read the compete post, u'll se that OP has only 3 channels used.
I have never seen that sensor, but belive that the code may be a good start..

Knut

Thanks Knut.

I am reading the data sheet and the code is starting to make sense now.

In my case I need to convert a single-ended input, not a differential input.
As far as I understand it, I need to set the multiplex register to 8, which means selecting:
0000 (AIN0) 1000 (AINCOM)

I am not sure if I have got this right.

BTW, there is no AINCOM pin on the board, which makes me think that it is tied to some reference.

With the code as it is now, I get very unstable readings.

Here's an example of readings with AIN0 put to VCC (5V in my case):

16777198
16776701
16777200
0
0
16777200
16777200
16777199
16777202
16776701
16776701
16777200
16777200
0
8388608
16776701
16777198
0
8388608

any suggestion is more than welcome!

AINCOM = Analog Common => reference voltage for ALL inputs

If you've got max 4 analog values to read, you can use the differental setting. This allows for separate ref. voltage for all 4 inputs

A close look at your reading:
chech the binary pattern. compare with 2s compl. zero is 2^23

Guys,

I think I've got it working!!

It's been a hard work of reverse engineering from different sources, schematics, and chinese strange documentations.

I am now finally able to measure the voltage at AIN0 (no differential, just voltage between 0 and 5V). The main problem with Knut's code was the SPI speed, it is way too high, I have brought it down to 1.2 MHz. Also, you need to do the 2's complement of the measured value.

I have done some tests with potentiometers and the values make sense.

Some things I have discovered:

  • I think that the second row of pins, close to the AINx pins is the AINCOM. I don't know how to use it really, so I am leaving it floating.
  • The DVDD and DGND pins should be connected to GND and 3.3V, but if you leave them floating it also seem to work.

Here's the code:

/* ADS1256, datasheet: http://www.ti.com/lit/ds/sbas288j/sbas288j.pdf
  compare: https://github.com/Flydroid/ADS12xx-Library/blob/master/ads12xx.cpp
    connections to Atmega328 (UNO)

    CLK  - pin 13
    DIN  - pin 11 (MOSI)
    DOUT - pin 12 (MISO)
    CS   - pin 10
    DRDY - pin 9
    RESET- pin 8 (or tie HIGH?)
    DVDD - 3V3
    DGND - GND
*/

#define cs 10 // chip select
#define rdy 9 // data ready, input
#define rst 8 // may omit

#define SPISPEED 1250000
              // 1700000

#include <SPI.h>

void setup()
{
  Serial.begin(115200);
  
  pinMode(cs, OUTPUT);
  digitalWrite(cs, LOW); // tied low is also OK.
  pinMode(rdy, INPUT);
  pinMode(rst, OUTPUT);
  digitalWrite(rst, LOW);
  delay(1); // LOW at least 4 clock cycles of onboard clock. 100 microsecons is enough
  digitalWrite(rst, HIGH); // now reset to deafult values
  
  delay(500);
  SPI.begin(); //start the spi-bus
  delay(500);

  //init

  // digitalWrite(cs, LOW);
  while (digitalRead(rdy)) {}  // wait for ready_line to go low
  SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_MODE1)); // start SPI
  delayMicroseconds(10);

  //Reset to Power-Up Values (FEh)
  SPI.transfer(0xFE);
  delayMicroseconds(100);
  
  byte status_reg = 0 ;  // address (datasheet p. 30)
  //PGA SETTING
  //1 ±5V
  //2 ±2.5V
  //4 ±1.25V
  //8 ±0.625V
  //16 ±312.5mV
  //32 ±156.25mV
  //64 ±78.125mV
  byte status_data = 0x01; //status: Most Significant Bit First, Auto-Calibration Disabled, Analog Input Buffer Disabled 
  SPI.transfer(0x50 | status_reg);
  SPI.transfer(0x00);   // 2nd command byte, write one register only
  SPI.transfer(status_data);   // write the databyte to the register
  delayMicroseconds(10);
  

  byte adcon_reg = 2; //A/D Control Register (Address 02h)
  byte adcon_data = 0x20; // 0 01 00 000 => Clock Out Frequency = fCLKIN, Sensor Detect OFF, gain 1
  SPI.transfer(0x50 | adcon_reg);
  SPI.transfer(0x00);   // 2nd command byte, write one register only
  SPI.transfer(adcon_data);   // write the databyte to the register
  delayMicroseconds(10);
  
// digitalWrite(cs, HIGH);
  
  Serial.println("configured, starting");
}


void loop()
{
  unsigned long adc_val =0; // store reading

  // digitalWrite(cs, LOW);
  SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_MODE1)); // start SPI
  delayMicroseconds(10);
  //The most efficient way to cycle through the inputs is to
  //change the multiplexer setting (using a WREG command
  //to the multiplexer register MUX) immediately after DRDY
  //goes low. Then, after changing the multiplexer, restart the
  //conversion process by issuing the SYNC and WAKEUP
  //commands, and retrieve the data with the RDATA
  //command. 
  while (digitalRead(rdy)) {} ;

  byte channel = 0;
  byte data = (channel << 4) | (1 << 3); //AIN-channel and AINCOM
  SPI.transfer(0x50 | 1); // MUX register
  SPI.transfer(0x00);   // 2nd command byte, write one register only
  SPI.transfer(data);   // write the databyte to the register
  delayMicroseconds(10);

  //SYNC command 1111 1100
  SPI.transfer(0xFC);
  delayMicroseconds(10);
  
  //WAKEUP 0000 0000
  SPI.transfer(0x00);
  delayMicroseconds(10);
    
  SPI.transfer(0x01); // Read Data 0000  0001 (01h)
  delayMicroseconds(10);
  
  adc_val = SPI.transfer(0);
  adc_val <<= 8; //shift to left
  adc_val |= SPI.transfer(0);
  adc_val <<= 8;
  adc_val |= SPI.transfer(0);
  
  delayMicroseconds(10);
  
  // digitalWrite(cs, HIGH);
  SPI.endTransaction();

  //The ADS1255/6 output 24 bits of data in Binary Two’s
  //Complement format. The LSB has a weight of
  //2VREF/(PGA(223 − 1)). A positive full-scale input produces
  //an output code of 7FFFFFh and the negative full-scale
  //input produces an output code of 800000h. 
  if(adc_val > 0x7fffff){ //if MSB == 1
    adc_val = (16777215ul - adc_val) + 1; //do 2's complement
  }
  Serial.println(adc_val);

  delay(500);
  // digitalWrite(cs, HIGH);
}