3/18/25, 1:28 PM High-Precision AD HAT - Waveshare Wiki
High-Precision AD HAT
From Waveshare Wiki
Jump to: navigation, search
Overview High-Precision AD HAT
High-Precision AD HAT For Raspberry Pi, ADS1263 10-Ch
32-Bit ADC.
Specification
Resolution (Bits): 32
Input channels: 10
Sample rate (MAX): 38 kSPS ([Link]
PGA Magnification (MAX): 32
BUS: SPI Raspberry Pi AD Expansion
Structure: Delta-Sigma
Input type: Differential, Single-end
Reference voltage: Internal, External
Input voltage range (MAX): 2.5V, 5V
Input voltage range (MIN): -2.5V, 0V
Fatures
Adopts ADS1263 chip, low noise, low-temperature drift, 10-ch 32-bit high precision ADC (5-ch
differential input), 38.4kSPS Max sampling rate.
with embedded 24-bit auxiliary ADC, internal ADC test signal, IDAC, 2.5V internal reference
voltage, 8 x multiplexing GPIO, PGA (32 times Max).
Onboard AD header input, compatible with Waveshare sensor pinout, for connecting sorts of
sensor modules.
Onboard AD screw terminal input, allows connecting analog signal and analog power supply,
general-purpose interface.
Onboard control header, make it easy to control the module by other hosts in addition to Raspberry
Pi.
Three-wire RTD (resistor temperature detector) circuit, enabled by soldering 0R resistor.
Pinout
PIN Raspberry Pi(BCM) Raspberry Pi(WiringPi) Description
DRDY P17 P0 ADS1263 data output ready, low active
RESET P18 P1 ADS1263 reset input
CS P22 P3 ADS1263 chip select, low active
DIN P10 P12 SPI data input
DOUT P9 P13 SPI data output
[Link] 1/16
3/18/25, 1:28 PM High-Precision AD HAT - Waveshare Wiki
SCK P11 P14 SPI clock
SCK P11 P14 SPI clock
DIN0 D6 P22 Digits input signal
DIN1 D13 P23 Digits input signal
DIN2 D19 P24 Digits input signal
DIN3 D26 P25 Digits input signal
Hardware Configuration
PS: If you use other controllers (i.e., use the 8Pin SMD connector to input control
signals), AVDD must also be connected to the power supply (5V), otherwise the chip
does not work.
Configure Single-end
This board is set to single-end mode by default. That is AVDD is connected to 5V, AVSS is connected
to GND, and COM is connected to GND and set as negative end input.
You can connect the GND (or COM) and any IN pin to the target device for measuring.
Configure Differential
(Optional) Adapting the GND pin (or COM port) of the AD HAT for connecting to the GND pin of the
target board.
Connect your differential signal to the differential signal input port of the AD HAT. (IN0 & IN1 or
one of the differential signal input ports in the other four groups).
(Optional) if the signal that you want to test is so small, you can use PGA. You need to
set the reference voltage as the internal ±2.5V in the demo (AVDD-AVSS is single-end and does
not support PGA by default). Also, You should modify the REF value to 2.5 in the main.c file and
adjust the PGA according to the actual situation.
#Modify the internal REF voltage
#Change the define in the ADS1263_ConfigADC1() of ADS1263.c from
UBYTE REFMUX = 0x24;
#to
UBYTE REFMUX = 0x00;
Use the differential mode for measuring.
#Modify line 33 of main.c (Python code also has the function of the same name)
#change
ADS1263_SetMode(0);
#to
ADS1263_SetMode(1);
[Link] 2/16
3/18/25, 1:28 PM High-Precision AD HAT - Waveshare Wiki
Note: The channel number for Differential measuring should be smaller than 5. You can change it
according to the actual situation.
Configure RTD
If you need to use the RTD function, please configure it as below:
Solder four 0ohm resistors on the "RTD 0R" pads which is on the backside.
(/wiki/File:High_AD_HAT_RTD1.png)
Remove the jumpers of COM-GND.
(/wiki/File:High_AD_HAT_Jump1.png)
Connect the positive end of the three-wire RTD module to IN7 and the less two to IN6 and IN4.
(/wiki/File:High_AD_HAT_RTD2.png)
Modify the codes.
Communication Protocol
SPI Protocol
The AD HAT uses an SPI interface, for more information about the protocol, you can refer to
datasheet Pages 11-12.
SPI timing:
[Link] 3/16
3/18/25, 1:28 PM High-Precision AD HAT - Waveshare Wiki
(/wiki/File:High_AD_HAT_SPI_0.png)
(/wiki/File:High_AD_HAT_SPI.png)
CS is chip select. The chip is active when the CS is low;
SCLK is the clock pin of SPI;
DIN is the data input pin, that is MOSI, master output, and slave input;
DOUT is the data output pin, that is MISO, master input, and slave output;
DRDY is the data ready output pin, when the data of ADC1 is ready to output, it is low.
SPI communication has data transfer timing, which is combined by CPHA and CPOL.
CPOL determines the level of the serial synchronous clock at the idle state. When CPOL = 0, the
level is Low. However, CPOL has little effect on transmission.
CPHA determines whether data is collected at the first clock edge or at the second clock edge of
the serial synchronous clock; when CPHL = 0, data is collected at the first clock edge.
There are 4 SPI communication modes. SPI0 is commonly used, in which CPHL = 0, CPOL = 0.
As you can see from the figure above, data transmission starts at the first falling edge of SCLK, and
8 bits of data are transferred in one clock cycle. Here, SPI0 is in use, and data is transferred by bits,
MSB first.
[Link] 4/16
3/18/25, 1:28 PM High-Precision AD HAT - Waveshare Wiki
C examples and Python examples are provided for quick starting.
Configure interface
Enable SPI interface
PS: If you are using a system with a Bullseye branch, you need to change "apt-get" to "apt", and
the system of the Bullseye branch only supports Python3.
Open the terminal, and use the command to enter the configuration page.
sudo raspi-config
Choose Interfacing Options -> SPI -> Yes to enable the SPI interface
(/wiki/File:RPI_open_spi.png)
Reboot Raspberry Pi
sudo reboot
[Link] 5/16
3/18/25, 1:28 PM High-Precision AD HAT - Waveshare Wiki
Make sure that the SPI is not occupied by other devices, you can check in the middle of the
/boot/config .txt.
Check /boot/[Link], and you can see 'dtparam=spi=on' was written in.
(/wiki/File:Raspberry_Pi_Guides_for_4.37_e-[Link])
To make sure SPI is not occupied, it is recommended to close other drivers' coverage. You can use
ls /dev/spi* to check whether SPI is occupied. If the terminal outputs /dev/spidev0.1 and
/dev/spidev0.1, SPI is not occupied.
(/wiki/File:Raspberry_Pi_Guides_for_4.37_e-[Link])
Install Library
If you use bookworm system, only the lgpio library is available, bcm2835
and wiringPi libarary cannot be installed or used. Please note that the
python library does not need to install, you can directly run the demo.
BCM2835
#Open the Raspberry Pi terminal and run the following command
wget [Link]
tar zxvf [Link]
cd bcm2835-1.71/
sudo ./configure && sudo make && sudo make check && sudo make install
# For more, you can refer to the official website at: [Link]
kem/bcm2835/
WiringPi
#Open the Raspberry Pi terminal and run the following command
cd
sudo apt-get install wiringpi
#For Raspberry Pi systems after May 2019 (earlier than that can be executed witho
ut), an upgrade may be required:
wget [Link]
sudo dpkg -i [Link]
gpio -v
# Run gpio -v and version 2.52 will appear, if it doesn't it means there was an i
nstallation error
# Bullseye branch system using the following command:
[Link] 6/16
3/18/25, 1:28 PM High-Precision AD HAT - Waveshare Wiki
git clone [Link]
cd WiringPi
. /build
gpio -v
# Run gpio -v and version 2.70 will appear, if it doesn't it means there was an i
nstallation error
lgpio
wget [Link]
unzip [Link]
cd lg-master
sudo make install
#for more details, you can refer to [Link]
python
sudo apt-get update
sudo apt-get install ttf-wqy-zenhei
sudo apt-get install python-pip
sudo pip install [Link]
sudo pip install spidev
# bookworm system
sudo apt-get install python3-spidev
sudo apt-get install [Link]
Download Demo Codes
Open a terminal and run the following commands to download demo codes:
cd ~
git clone [Link]
Examples
Compile the codes:
cd ~/High-Pricision_AD_HAT_Code/c
sudo make clean
sudo make
In Jetson Nano:
[Link] 7/16
3/18/25, 1:28 PM High-Precision AD HAT - Waveshare Wiki
cd ~/High-Precision_AD_HAT_Code/c
sudo make clean
sudo make JETSON
If you want to use other libraries, you need to modify the Makefile file.
sudo vim Makefile
Change USELIB_RPIwhich is on line 13-15
main file is generated after compiling, then you can run the file:
sudo ./main
For this demo, you can also make some modifications to achieve different functions. For the
details, please refer to the following part "Function Introduction".
Python
Open a terminal and run the Python codes:
cd ~/High-Pricision_AD_HAT_Code/python
sudo python [Link]
or
sudo python3 [Link]
If you use the Jetson Nano, you should enable the SPI first:
sudo /opt/nvidia/jetson-io/[Link]
The GPIO tools menu will pop up, select "Configure 40-pin expansion header" and p
ress "Enter" to enter the secondary menu.
Then check spi1 and return to the upper menu, and finally select "Save and reboot
to reconfigure pins" to make the device reboot configuration take effect.
sudo apt install python-pip
sudo pip install spidev
If you fail to enable the SPI, you can refer to NVIDIA Jetson Linux Developer Guide ([Link]
[Link]/jetson/archives/r34.1/DeveloperGuide/[Link]#page/Tegra%20Linux%20Driver%20P
ackage%20Development%20Guide/hw_setup_jetson_io.html).
[Link] 8/16
3/18/25, 1:28 PM High-Precision AD HAT - Waveshare Wiki
For this demo, you can also make some modifications to achieve different functions. For the
details, please refer to the following part "Function Introduction".
Function Introduction
Hardware section
The ADC of this module used is ADS1263 using the SPI communication, which needs to pay
attention to those three parameters: mode (mode 1), rate (maximum 8M), data format (MSB).
It is mainly used to send commands and read/write registers: The commands are used to
start/end ADC conversion, read/write registers, restart, etc; The registers are mainly used to write
the configuration parameters, and the core of the demo is to read and write the registers.
The Read/Write register is a special command, which is different from an ordinary command(a
single byte), it uses multi-byte(read/write register command + data to be written/received).
Software section
Because the functions of the C code and the Python code are the same, the following takes the
code of ADS1263.c as an example, the corresponding function can also be found in [Link]:
Reset function, DEV_RST_PIN is the IC reset pin, low level active. The reset operation is required
before each use, and then the register configuration will be restored to the default value after
reset and it needs to be reconfigured for the next use.
static void ADS1263_reset(void)
Data read and write functions, these are three functions: write command, write register, read
register. Each SPI operation needs to pull down the DEV_CS_PIN (chip select, CS) pin, read and
write registers will send 0x00 once because the command is two bytes.
static void ADS1263_WriteCmd(UBYTE Cmd)
static void ADS1263_WriteReg(UBYTE Reg, UBYTE data)
static UBYTE ADS1263_Read_data(UBYTE Reg)
Data check function——Sum Check function, the read data of this demo uses Sum Check, you can
also configure to use CRC Check through the register.
The main principle of the Sum Check is to add the low eight bits of the data, and finally add a fixed
parameter. Use the low eight bits of this final sum XOR with the check byte which is read. If the
data is read correctly, it will return 0.
static UBYTE ADS1263_Checksum(UDOUBLE val, UBYTE byt)
Data waiting function, DEV_DRDY_PIN is the DRDY pin, which is valid when ADC1 performs data
conversion and sends a low level after the data is ready.
Note ADC2 is not applicable to this function.
[Link] 9/16
3/18/25, 1:28 PM High-Precision AD HAT - Waveshare Wiki
static void ADS1263_WaitDRDY(void)
Chip Read function, if the return value is 1, which means the IC is ADS1263, and return 0 for
ADS1262.
UBYTE ADS1263_ReadChipID(void)
Mode setting function, set to 1 for the differential mode, the default value is 0 for single-ended
mode
void ADS1263_SetMode(UBYTE Mode)
ADC config function, which can set the ADC rate, PGA gain multiple, reference voltage, etc.
The information on the register you can check in the ADS1263 ([Link]
2/2a/[Link]). If you need to configure other registers, it is better to read and verify after each
writing according to the routine manner.
In order to ensure data stability and reduce crosstalk between multiple channels and two ADCs, the
data conversion delay used by the demo is relatively large and the conversion rate is relatively slow.
But you can modify it if you need to increase the speed.
Note It is not recommended to turn on PGA when using single-ended measurement for ADC1.
The PGA is off by default.
void ADS1263_ConfigADC1(ADS1263_GAIN gain, ADS1263_DRATE drate)
void ADS1263_ConfigADC2(ADS1263_ADC2_GAIN gain, ADS1263_ADC2_DRATE drate)
Chip initialization functions, including resetting, verifying, and configuring the ADC device.
UBYTE ADS1263_init(void)
Select the channel function, and call this function before switching the ADC channel.
static void ADS1263_SetChannal(UBYTE Channal)
static void ADS1263_SetChannal_ADC2(UBYTE Channal)
void ADS1263_SetDiffChannal(UBYTE Channal)
void ADS1263_SetDiffChannal_ADC2(UBYTE Channal)
Read ADC data function, the return value of ADC1 is 32-bit data, and for ADC2 is 24-bit data.
static UDOUBLE ADS1263_Read_ADC1_Data(void)
static UDOUBLE ADS1263_Read_ADC2_Data(void)
Obtain the data of the specified channel, there will be different effects depending on the mode.
[Link] 10/16
3/18/25, 1:28 PM High-Precision AD HAT - Waveshare Wiki
UDOUBLE ADS1263_GetChannalValue(UBYTE Channel)
UDOUBLE ADS1263_GetChannalValue_ADC2(UBYTE Channel)
Obtain the data of all channels, encapsulate it for other files to call, and get the data cyclically
of a specified number of channels.
To obtain 32-bit or 24-bit raw data, and then use this data by the maximum range and then multiply
it by the reference voltage, you can get the voltage data. For example, the voltage of Raspberry Pi
used with the demo is 5V (measured 5.08V), so the final voltage data is: ADC[i]/0x7fffffff*REF, the
same applies to the negative voltage.
void ADS1263_GetAll(UDOUBLE *ADC_Value)
void ADS1263_GetAll_ADC2(UDOUBLE *ADC_Value)
RTD test function, including the RTD register configuration, the data conversion, and the reading
of ADC1.
To get temperature data
You need to calculate the resistance of the thermal resistance first. According to R=U/I, divide the
two resistances (thermal resistance, reference resistance):
R(thermal resistance)/R(reference resistance) = U (thermal resistance) * U (reference resistance) *
2
So, RES = (ADC[0] / 0x7fffffff * 1) * 1 * 2 * 2000
Finally, the temperature can be obtained according to the thermal resistance formula, and the
thermal resistance of the demo uses Pt100.
So the TEMP = (RES/100-1) / 0.00385
UDOUBLE ADS1263_RTD(ADS1263_DELAY delay, ADS1263_GAIN gain, ADS1263_DRATE drate)
DAC test function, used for the voltage setting, output pin setting (positive and negative
polarity), open or close the DAC output.
void ADS1263_DAC(ADS1263_DAC_VOLT volt, UBYTE isPositive, UBYTE isOpen)
[Link] 11/16
3/18/25, 1:28 PM High-Precision AD HAT - Waveshare Wiki
Note In the main file, you can modify the macro definition to quickly convert the required
test(ADC/RTD). The REF is the reference voltage, you may need to modify it according to the actual
situation for measuring accurately.
Resource
Documents
Schematic ([Link]
Demo codes
Github ([Link]
Datasheet
ADS1263 ([Link]
Software
Panasonic SDFormatter ([Link]
Win32DiskImager ([Link]
PuTTY ([Link]
wiringPi & bcm2835 C LIB ([Link]
bcm2835-1.45 ([Link]
CP2102 driver ([Link]
FAQ
Question:Introduced that the module has a sampling rate of 30ksps, why
the AD test cannot reach this rate;
Answer:
The sample program turns on 8-channel high-precision ADC by default. In order to ensure
stability and accuracy, the program adds a delay when reading and processing data. If a higher
rate is required, the delay can be commented out. The demo for optimizing the input is as
follows:30K_High-Precision_AD_HAT_Code ([Link]
[Link] 12/16
3/18/25, 1:28 PM High-Precision AD HAT - Waveshare Wiki
recision_AD_HAT_Code.zip)
(/wiki/File:34K_high.png)
Question:After running the program, the error shown in the figure below
appeared, IOError:[Errno 2]No such file or directory
Answer:
(/wiki/File:High-Precision_AD_HAT01.png)
Check the [Link] file, confirm that the SPI is turned on, and comment out other SPI devices.
After the configuration is complete, restart and run:
sudo nano /boot/[Link]
[Link] 13/16
3/18/25, 1:28 PM High-Precision AD HAT - Waveshare Wiki
(/wiki/File:High-Precision_AD_HAT02.png)
Question:What should I do to improve during measurement?
Answer:
The following are some possible reasons and ways to improve them:
The sampling rate is too high, you can try to reduce the rate.
Single-ended mode is easy to be interfered with, the use of differential mode can be reduced to
a certain extent.
Switching channels may introduce noise, reducing channel switching when measuring can
improve the results to some extent.
The reference voltage is unstable, using a stable external reference voltage (AVDD-AVSS) can
reduce noise and improve stability.
Reference voltage calibration: different adapters supplies power to the Raspberry Pi, the
reference voltage may be different, let's say if the adapter you use is 5.15V, please change the
voltage here to 5.15V for comparison test:
[Link] 14/16
3/18/25, 1:28 PM High-Precision AD HAT - Waveshare Wiki
(/wiki/File:[Link])
Question:After running the program, why do they all show 5V?
Answer:
Unconnected idle channel shows 5.08V; chip internal structure reasons are a normal
phenomenon.
The default floating voltage is 5.08V, which does not affect the use, if you do not need other
channels, you can turn off the channel or connect GND.
Question:What should I do if the voltage measurement is not accurate?
Answer:
[Link] 15/16
3/18/25, 1:28 PM High-Precision AD HAT - Waveshare Wiki
You can measure the 3.3V pin on the Raspberry Pi to make sure it is 3.3V.
(/wiki/File:HP_AD_FAQ.png)
Support
Technical Support
If you need technical support or have any
feedback/review, please click the Submit Now
Submit Now ([Link]
button to submit a ticket, Our support team will
check and reply to you within 1 to 2 working
[Link]/)
days. Please be patient as we make every effort
to help you to resolve the issue.
Working Time: 9 AM - 6 PM GMT+8 (Monday to
Friday)
Retrieved from "[Link]
([Link]
[Link] 16/16