element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi Projects
  • Products
  • Raspberry Pi
  • Raspberry Pi Projects
  • More
  • Cancel
Raspberry Pi Projects
Blog Continuous sampling with the Data Acquisition Board for Pi Pico
  • Blog
  • Documents
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi Projects to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 25 Nov 2023 4:09 PM Date Created
  • Views 2182 views
  • Likes 10 likes
  • Comments 12 comments
  • ADC (Analog-to-Digital Converter)
  • pico
  • data acquisition
  • ads1115
  • rp2040
  • daq
  • pico-eurocard
  • raspberry_pi_projects
  • adc
  • test&measurement
Related
Recommended

Continuous sampling with the Data Acquisition Board for Pi Pico

Jan Cumps
Jan Cumps
25 Nov 2023
Continuous sampling with the Data Acquisition Board for Pi Pico

 shabaz designed a Data Acquisition Board for Pi Pico . In this post, I'm using it in continuous sample mode. Goal: get 1 second worth of samples, in 860 samples per second mode.

There are several options to trigger the reading of the samples. You could set up a timer that fires every 1162 µs. Then let it kick off a read. There is a 10% variation though - my device clocks at 850 samples, approx 2% slower. 

I've used another option that isn't dependent on the exact data rate: the ADS1115 has a RDY pin. I've configured it to pulse each time a sample is ready.

image

I modified the PCB, and connected the RDY pin to GP13 with a bodge wire.

image

The RDY pin needs a pull-up. I tested if the RP2040 internal pull-up has enough oomph: yes.

image

In my code, I attached an interrupt to the rising edge of GP13. Each time, it 'll initiate a read over i2c.

image

Highlights of the code (it's attached, with *.uf2 firmware precompiled)

volatile bool rdy = false;

void rdy_callback(uint gpio, uint32_t events) {
    rdy = true;
}

// board initialisation
void
board_init(void) {
    // ...
    
    // listener for ADC RDY
    gpio_init(13);
    gpio_pull_up(13);
    gpio_set_dir(13, false);
    gpio_set_irq_enabled_with_callback(13, GPIO_IRQ_EDGE_RISE, true, &rdy_callback);


    // ...
}

void adc_enable_rdy(uint8_t boardnum) {
    uint8_t buf[3];
    
    buf[0] = ADS1115_REG_LO_THRESH;
    buf[1] = 0x00;
    buf[2] = 0x00; //Lo_thresh MS bit must be 0
    i2c_write_blocking(i2c_port, adc_addr[boardnum], buf, 3, false);

    buf[0] = ADS1115_REG_HI_THRESH;
    buf[1] = 0x80;
    buf[2] = 0x00; //Hi_thresh  MS bit must be 1
    i2c_write_blocking(i2c_port, adc_addr[boardnum], buf, 3, false);
}

// ************ main function *******************
int main(void) {
    stdio_init_all();

    board_init();

    build_data_rate(BOARD0, DR_860);
    build_gain(BOARD0, AIN1, GAIN_2_048); // +- 2.048V

    #define SAMPLES 860

    uint16_t buf[SAMPLES];
    
    build_cont_conversion(0);
    adc_set_mux(BOARD0,0,false);
    adc_enable_rdy(0);

    uint8_t* buf8_ptr = (uint8_t*)buf;
    *buf8_ptr = ADS1115_REG_CONVERSION;
    i2c_write_blocking(i2c_port, adc_addr[BOARD0], buf8_ptr, 1, false);

    uint8_t* buf8_end_ptr = ((uint8_t*)buf) + (sizeof buf);
    rdy = false;

    while (buf8_ptr < buf8_end_ptr) {
        if (rdy) {
            rdy = false;
            i2c_read_blocking(i2c_port, adc_addr[BOARD0], buf8_ptr, 2, false);
            buf8_ptr += 2;
        }
    }

    uint16_t* buf16_ptr = buf;
    uint16_t* buf16_end_ptr = buf + (sizeof buf) / 2;
    
    while (buf16_ptr < buf16_end_ptr) {
        *buf16_ptr = *buf16_ptr >> 8 | *buf16_ptr << 8; // swap bytes
        printf("AIN1 = %.3f V\n", to_volts(BOARD0, 0, *buf16_ptr));
        buf16_ptr++;
    }

    while (FOREVER) {}
}

I didn't include the definitions and functions of shabaz ' source code example. They are available in the download.

The data collection loop is made as short as possible. I set the i2c baud rate to 1 MM. And removed the bit swapping and voltage conversion from the sample loop. I made a second loop that does these conversion activities once all data is collected.
This isn't needed for timekeeping. There's enough time for slower i2c , and to do bit swapping and voltage conversion.
What we can gain by taking them out, is to let the controller go low power while waiting for a next pulse. Not implemented, but worth investigating.

image

Enjoy!

Source and firmware: 
adc_board_test_20231125.zip

  • Sign in to reply
  • Jan Cumps
    Jan Cumps over 1 year ago

    OO version follow-up:  OO example for the Data Acquisition Board for Pi Pico: deep dive into the sample data buffer 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 1 year ago

    Object oriented version:  Object Oriented example for the Data Acquisition Board for Pi Pico 

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 1 year ago

    Follow-up:  Min and Max bulk samples from Data Acquisition Board for Pi Pico with C++ STL 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 1 year ago

    Follow-up: Converting bulk samples from Data Acquisition Board for Pi Pico with C++ STL 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 1 year ago

    Follow-up:  Average bulk samples from Data Acquisition Board for Pi Pico with C++ STL 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube