Calibrator
Before putting the scale to use at your coffee-making station, use a known weight to record the unique resistance characteristics of the load cell sensor. This calibration should only need to be performed once.
The calibration process reads and averages a handful of raw measurement samples then prints the averaged value in the serial output window. The printed raw measurement value that corresponds to a reference weight will be used within the scale's CircuitPython code to calculate the grams and ounces displayed on the scale's screen.
Remember to mount the load cell so that the fixed end is securely fastened and the weighing end is free to flex with no restrictions.
1. To begin the calibration process, remove all weights from the load cell.
2. The next step is to edit code.py to activate the calibrator method. Using Mu or your favorite text editor (Atom is shown in the example), open the code.py file stored in the root directory of the Clue board and also open a serial output window.
3. Remove the left-most comment hashmark and the following space character from line 10 of the file.
4. After making the change to line 10, save the file. The calibration method will automatically run when the code.py file is saved.
A notice that the calibrator is ready will print to the serial output window.
5. Place a reference weight on the measurement end of the load cell. Once a few RAW VALUE measurements are taken, choose one that looks typically like a median value. In this example, the 100 gram reference weight is producing a raw measurement value of approximately 215300.
If you need to re-zero the load cell to get a fresh measurement, remove any weights then press and hold the Clue A button until you hear a confirming beep. Release the button and the calibrator will start the internal zeroing process. You'll hear a confirming tone when zeroing is complete.
6. It's time to edit the code.py file in your editor once again to update the CALIB_RATIO
constant on line 38. The ratio is the reference weight in grams divided by the raw value you noted during calibration. In this example, it's 100 / 215300
.
Don't save the code.py file just yet. There's one more step to go.
7. Place a comment hashmark and a space at the beginning of line 10 to "comment out" the line so that the calibrator method won't be imported the next time code.py executes.
8. Save the file and close the editor. The code.py program will automatically begin. The Clue Coffee Scale is now ready to go!
Calibrator Code Listing
Here's the code listing for the calibrator method. The calibrator is also a good example of a fundamental approach to initiate and read the raw values of a load cell connected to the NAU7802 ADC STEMMA QT board.
# SPDX-FileCopyrightText: 2022 Jan Goolsbey for Adafruit Industries # SPDX-License-Identifier: MIT # # clue_scale_calibrator.py # 2023-01-13 v1.1.1 # # Clue Scale Calibrator - Single Channel Version # Adafruit NAU7802 Stemma breakout example import time import board from adafruit_clue import clue from cedargrove_nau7802 import NAU7802 clue.pixel.brightness = 0.2 # Set NeoPixel brightness clue.pixel[0] = clue.YELLOW # Set status indicator to yellow (initializing) SAMPLE_AVG = 3 # Number of sample values to average DEFAULT_GAIN = 128 # Default gain for internal PGA # Instantiate 24-bit load sensor ADC i2c = board.I2C() # uses board.SCL and board.SDA # i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller nau7802 = NAU7802(i2c, address=0x2A, active_channels=1) def zero_channel(): """Initiate internal calibration and zero the current channel. Use after power-up, a new channel is selected, or to adjust for measurement drift. Can be used to zero the scale with a tare weight.""" nau7802.calibrate("INTERNAL") nau7802.calibrate("OFFSET") def read(samples=100): # Read and average consecutive raw sample values; return average raw value sample_sum = 0 sample_count = samples while sample_count > 0: if nau7802.available(): sample_sum = sample_sum + nau7802.read() sample_count -= 1 return int(sample_sum / samples) # Activate the NAU780 internal analog circuitry, set gain, and calibrate/zero nau7802.enable(True) nau7802.gain = DEFAULT_GAIN # Use default gain zero_channel() # Calibrate and zero print("-----------------------------------") print(" NAU7802 SINGLE CHANNEL CALIBRATOR") print("-----------------------------------") print("Place a calibration weight on the") print("load cell.") print("To re-zero the load cell, remove") print("any weights then press and hold A.") print("-----------------------------------") print("") # Play "welcome" tones clue.play_tone(1660, 0.15) clue.play_tone(1440, 0.15) # Main loop: Read sample and display value while True: clue.pixel[0] = clue.GREEN # Set status indicator to green # Read the raw value; print raw value, gain setting, and % of full-scale value = read(SAMPLE_AVG) print(f"CHAN_{nau7802.channel:1.0f} RAW VALUE: {value:7.0f}") print(f"GAIN: x{DEFAULT_GAIN} full-scale: {(value / ((2**23) - 1)) * 100:3.2f}%") print("===================================") time.sleep(0.1) if clue.button_a: # Zero and recalibrate the NAU780 clue.play_tone(1660, 0.3) # Play "button pressed" tone clue.pixel[0] = clue.RED # Set status indicator to red (stopped) zero_channel() while clue.button_a: # Wait until button is released time.sleep(0.1) print("RECALIBRATED") clue.play_tone(1440, 0.5) # Play "reset completed" tone
Page last edited February 24, 2025
Text editor powered by tinymce.