Serial Read Sample Rate too Slow

Hello,

I'm using a Arduino Nano BLE 33 board with an amplified (HX711) load cell (FX1901-0001-0010) and position sensor (VL6180X). I'm taking readings from the load cell, position sensor and the onboard triaxial accelerometer and printing them to the serial line to be read in Python and stored in an excel workbook.

I seem to constantly get a sample rate of 11Hz regardless of whether I change my delay or baud rate. I need to get a higher sample rate - more like 25Hz. Please help me understand what is my limitation here.

Arduino code:

// Include the necessary libraries
#include <HX711.h> // for the amplifier
#include <Arduino_LSM9DS1.h> // for the IMU data
#include <Wire.h> // for the position sensor
#include <VL6180X.h> // for the position sensor

// Define the pins - these have been soldered so are fixed
const int HX711_dout = 6; // changed to D6
const int HX711_sck = 3;

// Create the HX711 and VL6180X type objects
HX711 loadcell;
VL6180X sensor;


void setup() {
  // Initialise the serial communication
  Serial.begin(2000000);  // 38400
  while (!Serial);

  // Initialise the IMU chip
  if (!IMU.begin()) {
    //Serial.println("Failed to initialize IMU!");
    while (1);
    }

  // Initialise the HX711 object by inputting the data output pin, clock
  // input pin and gain factor - a gain of 32 automatically selects channel B
  // Default is 128 - channel A
  loadcell.begin(HX711_dout, HX711_sck, 32);
  int data = loadcell.read_average(20);
  //Serial.println(data);
  //Serial.println("started");

    // Initialise the position sensor
    Wire.begin();
    sensor.init();
    sensor.configureDefault();

    bool record = false;

  // Zero the load cell
 // loadcell.set_scale();
  //loadcell.tare(); 

}

void loop() {
    // Define the Accelerometer data variables
    float x1, y1, z1;
  
    // Sample and print the time to the serial line
    Serial.print(micros());
    Serial.print(',');
  
    // Sample the IMU data
    if (IMU.accelerationAvailable()) {
        IMU.readAcceleration(x1, y1, z1);
  
        Serial.print(x1);
        Serial.print(',');
        Serial.print(y1);
        Serial.print(',');
        Serial.print(z1);
        Serial.print(',');
    }

    // Sample and print out the position reading
    Serial.print(sensor.readRangeSingleMillimeters());
    Serial.print(',');
  
    // Sample and print out the force data to the serial line
    Serial.println(loadcell.read());
 
  
    delay(10);
}     

Snippet of python code used to read and decode - the data is stored in a raw_data list during collection and then decoded line by line afterwards:

ser = serial.Serial("/dev/cu.usbmodem1421", 2000000, timeout=1)   # 38400

# Clear the serial queue
ser.flushInput()
curr_line = ser.readline()
raw_data.append(curr_line)

curr_data = (raw_data[ii][0:-2]).decode("utf-8", "strict").split(',')

I2C will slow you up, SPi is faster.

I want faster but I will use a delay. Strange.

I've tried excluding this and purely printing out the time stamp and force reading to the serial line and I'm still getting a sample rate of 11Hz?

I added in the delay to test changing the sample rate.

Have you looked into the maximum data transfer rate of I2C vs SPI?

If I2C is limited to a certain data rate then that will be the maximum data transfer rate under the most ideal conditions. I2C is not fast.

I realised that it was an issue with the HX711 amplifier - it has a sampling rate of 10Hz or 80Hz and it was set to 10Hz

Thanks for the help.

delay (10); limits to a sample rate of 100 Hz. Or reduces 12,5 Hz (80ms) to 90ms=11Hz. And assures Serial is not the next limit.
However, a test version with mockup values should clearly show the actual bottleneck(s).

Would it help to lower this into

 int data = loadcell.read_average(10)

?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.