Package com.tinkerforge
Class BrickletLoadCell
- java.lang.Object
-
- com.tinkerforge.DeviceBase
-
- com.tinkerforge.Device
-
- com.tinkerforge.BrickletLoadCell
-
public class BrickletLoadCell extends Device
Measures weight with a load cell
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
BrickletLoadCell.Configuration
class
BrickletLoadCell.WeightCallbackThreshold
static interface
BrickletLoadCell.WeightListener
This listener is triggered periodically with the period that is set bysetWeightCallbackPeriod(long)
.static interface
BrickletLoadCell.WeightReachedListener
This listener is triggered when the threshold as set bysetWeightCallbackThreshold(char, int, int)
is reached.-
Nested classes/interfaces inherited from class com.tinkerforge.Device
Device.Identity
-
-
Field Summary
-
Constructor Summary
Constructors Constructor Description BrickletLoadCell(java.lang.String uid, IPConnection ipcon)
Creates an object with the unique device ID \c uid.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addWeightListener(BrickletLoadCell.WeightListener listener)
Adds a Weight listener.void
addWeightReachedListener(BrickletLoadCell.WeightReachedListener listener)
Adds a WeightReached listener.void
calibrate(long weight)
To calibrate your Load Cell Bricklet you have to * empty the scale and call this function with 0 and * add a known weight to the scale and call this function with the weight.BrickletLoadCell.Configuration
getConfiguration()
Returns the configuration as set bysetConfiguration(short, short)
.long
getDebouncePeriod()
Returns the debounce period as set bysetDebouncePeriod(long)
.Device.Identity
getIdentity()
Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.short
getMovingAverage()
Returns the length moving average as set bysetMovingAverage(short)
.int
getWeight()
Returns the currently measured weight.long
getWeightCallbackPeriod()
Returns the period as set bysetWeightCallbackPeriod(long)
.BrickletLoadCell.WeightCallbackThreshold
getWeightCallbackThreshold()
Returns the threshold as set bysetWeightCallbackThreshold(char, int, int)
.boolean
isLEDOn()
Returns *true* if the led is on, *false* otherwise.void
ledOff()
Turns the LED off.void
ledOn()
Turns the LED on.void
removeWeightListener(BrickletLoadCell.WeightListener listener)
Removes a Weight listener.void
removeWeightReachedListener(BrickletLoadCell.WeightReachedListener listener)
Removes a WeightReached listener.void
setConfiguration(short rate, short gain)
The measurement rate and gain are configurable.void
setDebouncePeriod(long debounce)
Sets the period with which the threshold listener *BrickletLoadCell.WeightReachedListener
is triggered, if the threshold *setWeightCallbackThreshold(char, int, int)
keeps being reached.void
setMovingAverage(short average)
Sets the length of a `moving averaging <https://en.wikipedia.org/wiki/Moving_average>`__ for the weight value.void
setWeightCallbackPeriod(long period)
Sets the period with which theBrickletLoadCell.WeightListener
listener is triggered periodically.void
setWeightCallbackThreshold(char option, int min, int max)
Sets the thresholds for theBrickletLoadCell.WeightReachedListener
listener.void
tare()
Sets the currently measured weight as tare weight.-
Methods inherited from class com.tinkerforge.DeviceBase
getAPIVersion, getResponseExpected, setResponseExpected, setResponseExpectedAll
-
-
-
-
Field Detail
-
DEVICE_IDENTIFIER
public static final int DEVICE_IDENTIFIER
- See Also:
- Constant Field Values
-
DEVICE_DISPLAY_NAME
public static final java.lang.String DEVICE_DISPLAY_NAME
- See Also:
- Constant Field Values
-
FUNCTION_GET_WEIGHT
public static final byte FUNCTION_GET_WEIGHT
- See Also:
- Constant Field Values
-
FUNCTION_SET_WEIGHT_CALLBACK_PERIOD
public static final byte FUNCTION_SET_WEIGHT_CALLBACK_PERIOD
- See Also:
- Constant Field Values
-
FUNCTION_GET_WEIGHT_CALLBACK_PERIOD
public static final byte FUNCTION_GET_WEIGHT_CALLBACK_PERIOD
- See Also:
- Constant Field Values
-
FUNCTION_SET_WEIGHT_CALLBACK_THRESHOLD
public static final byte FUNCTION_SET_WEIGHT_CALLBACK_THRESHOLD
- See Also:
- Constant Field Values
-
FUNCTION_GET_WEIGHT_CALLBACK_THRESHOLD
public static final byte FUNCTION_GET_WEIGHT_CALLBACK_THRESHOLD
- See Also:
- Constant Field Values
-
FUNCTION_SET_DEBOUNCE_PERIOD
public static final byte FUNCTION_SET_DEBOUNCE_PERIOD
- See Also:
- Constant Field Values
-
FUNCTION_GET_DEBOUNCE_PERIOD
public static final byte FUNCTION_GET_DEBOUNCE_PERIOD
- See Also:
- Constant Field Values
-
FUNCTION_SET_MOVING_AVERAGE
public static final byte FUNCTION_SET_MOVING_AVERAGE
- See Also:
- Constant Field Values
-
FUNCTION_GET_MOVING_AVERAGE
public static final byte FUNCTION_GET_MOVING_AVERAGE
- See Also:
- Constant Field Values
-
FUNCTION_LED_ON
public static final byte FUNCTION_LED_ON
- See Also:
- Constant Field Values
-
FUNCTION_LED_OFF
public static final byte FUNCTION_LED_OFF
- See Also:
- Constant Field Values
-
FUNCTION_IS_LED_ON
public static final byte FUNCTION_IS_LED_ON
- See Also:
- Constant Field Values
-
FUNCTION_CALIBRATE
public static final byte FUNCTION_CALIBRATE
- See Also:
- Constant Field Values
-
FUNCTION_TARE
public static final byte FUNCTION_TARE
- See Also:
- Constant Field Values
-
FUNCTION_SET_CONFIGURATION
public static final byte FUNCTION_SET_CONFIGURATION
- See Also:
- Constant Field Values
-
FUNCTION_GET_CONFIGURATION
public static final byte FUNCTION_GET_CONFIGURATION
- See Also:
- Constant Field Values
-
FUNCTION_GET_IDENTITY
public static final byte FUNCTION_GET_IDENTITY
- See Also:
- Constant Field Values
-
THRESHOLD_OPTION_OFF
public static final char THRESHOLD_OPTION_OFF
- See Also:
- Constant Field Values
-
THRESHOLD_OPTION_OUTSIDE
public static final char THRESHOLD_OPTION_OUTSIDE
- See Also:
- Constant Field Values
-
THRESHOLD_OPTION_INSIDE
public static final char THRESHOLD_OPTION_INSIDE
- See Also:
- Constant Field Values
-
THRESHOLD_OPTION_SMALLER
public static final char THRESHOLD_OPTION_SMALLER
- See Also:
- Constant Field Values
-
THRESHOLD_OPTION_GREATER
public static final char THRESHOLD_OPTION_GREATER
- See Also:
- Constant Field Values
-
RATE_10HZ
public static final short RATE_10HZ
- See Also:
- Constant Field Values
-
RATE_80HZ
public static final short RATE_80HZ
- See Also:
- Constant Field Values
-
GAIN_128X
public static final short GAIN_128X
- See Also:
- Constant Field Values
-
GAIN_64X
public static final short GAIN_64X
- See Also:
- Constant Field Values
-
GAIN_32X
public static final short GAIN_32X
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BrickletLoadCell
public BrickletLoadCell(java.lang.String uid, IPConnection ipcon)
Creates an object with the unique device ID \c uid. and adds it to the IP Connection \c ipcon.
-
-
Method Detail
-
getWeight
public int getWeight() throws TinkerforgeException
Returns the currently measured weight. If you want to get the weight periodically, it is recommended to use theBrickletLoadCell.WeightListener
listener and set the period withsetWeightCallbackPeriod(long)
.- Throws:
TinkerforgeException
-
setWeightCallbackPeriod
public void setWeightCallbackPeriod(long period) throws TinkerforgeException
Sets the period with which theBrickletLoadCell.WeightListener
listener is triggered periodically. A value of 0 turns the listener off. TheBrickletLoadCell.WeightListener
listener is only triggered if the weight has changed since the last triggering.- Throws:
TinkerforgeException
-
getWeightCallbackPeriod
public long getWeightCallbackPeriod() throws TinkerforgeException
Returns the period as set bysetWeightCallbackPeriod(long)
.- Throws:
TinkerforgeException
-
setWeightCallbackThreshold
public void setWeightCallbackThreshold(char option, int min, int max) throws TinkerforgeException
Sets the thresholds for theBrickletLoadCell.WeightReachedListener
listener. The following options are possible: \verbatim "Option", "Description" "'x'", "Listener is turned off" "'o'", "Listener is triggered when the weight is *outside* the min and max values" "'i'", "Listener is triggered when the weight is *inside* the min and max values" "'<'", "Listener is triggered when the weight is smaller than the min value (max is ignored)" "'>'", "Listener is triggered when the weight is greater than the min value (max is ignored)" \endverbatim- Throws:
TinkerforgeException
-
getWeightCallbackThreshold
public BrickletLoadCell.WeightCallbackThreshold getWeightCallbackThreshold() throws TinkerforgeException
Returns the threshold as set bysetWeightCallbackThreshold(char, int, int)
.- Throws:
TinkerforgeException
-
setDebouncePeriod
public void setDebouncePeriod(long debounce) throws TinkerforgeException
Sets the period with which the threshold listener *BrickletLoadCell.WeightReachedListener
is triggered, if the threshold *setWeightCallbackThreshold(char, int, int)
keeps being reached.- Throws:
TinkerforgeException
-
getDebouncePeriod
public long getDebouncePeriod() throws TinkerforgeException
Returns the debounce period as set bysetDebouncePeriod(long)
.- Throws:
TinkerforgeException
-
setMovingAverage
public void setMovingAverage(short average) throws TinkerforgeException
Sets the length of a `moving averaging <https://en.wikipedia.org/wiki/Moving_average>`__ for the weight value. Setting the length to 1 will turn the averaging off. With less averaging, there is more noise on the data.- Throws:
TinkerforgeException
-
getMovingAverage
public short getMovingAverage() throws TinkerforgeException
Returns the length moving average as set bysetMovingAverage(short)
.- Throws:
TinkerforgeException
-
ledOn
public void ledOn() throws TinkerforgeException
Turns the LED on.- Throws:
TinkerforgeException
-
ledOff
public void ledOff() throws TinkerforgeException
Turns the LED off.- Throws:
TinkerforgeException
-
isLEDOn
public boolean isLEDOn() throws TinkerforgeException
Returns *true* if the led is on, *false* otherwise.- Throws:
TinkerforgeException
-
calibrate
public void calibrate(long weight) throws TinkerforgeException
To calibrate your Load Cell Bricklet you have to * empty the scale and call this function with 0 and * add a known weight to the scale and call this function with the weight. The calibration is saved in the EEPROM of the Bricklet and only needs to be done once. We recommend to use the Brick Viewer for calibration, you don't need to call this function in your source code.- Throws:
TinkerforgeException
-
tare
public void tare() throws TinkerforgeException
Sets the currently measured weight as tare weight.- Throws:
TinkerforgeException
-
setConfiguration
public void setConfiguration(short rate, short gain) throws TinkerforgeException
The measurement rate and gain are configurable. The rate can be either 10Hz or 80Hz. A faster rate will produce more noise. It is additionally possible to add a moving average (seesetMovingAverage(short)
) to the measurements. The gain can be 128x, 64x or 32x. It represents a measurement range of ±20mV, ±40mV and ±80mV respectively. The Load Cell Bricklet uses an excitation voltage of 5V and most load cells use an output of 2mV/V. That means the voltage range is ±15mV for most load cells (i.e. gain of 128x is best). If you don't know what all of this means you should keep it at 128x, it will most likely be correct. The configuration is saved in the EEPROM of the Bricklet and only needs to be done once. We recommend to use the Brick Viewer for configuration, you don't need to call this function in your source code.- Throws:
TinkerforgeException
-
getConfiguration
public BrickletLoadCell.Configuration getConfiguration() throws TinkerforgeException
Returns the configuration as set bysetConfiguration(short, short)
.- Throws:
TinkerforgeException
-
getIdentity
public Device.Identity getIdentity() throws TinkerforgeException
Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier. The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port). A Bricklet connected to an :ref:`Isolator Bricklet <isolator_bricklet>` is always at position 'z'. The device identifier numbers can be found :ref:`here <device_identifier>`. |device_identifier_constant|- Specified by:
getIdentity
in classDevice
- Throws:
TinkerforgeException
-
addWeightListener
public void addWeightListener(BrickletLoadCell.WeightListener listener)
Adds a Weight listener.
-
removeWeightListener
public void removeWeightListener(BrickletLoadCell.WeightListener listener)
Removes a Weight listener.
-
addWeightReachedListener
public void addWeightReachedListener(BrickletLoadCell.WeightReachedListener listener)
Adds a WeightReached listener.
-
removeWeightReachedListener
public void removeWeightReachedListener(BrickletLoadCell.WeightReachedListener listener)
Removes a WeightReached listener.
-
-