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(',')