Documentation

Overview

Measures CO2 concentration, temperature and humidity.

See also the documentation here: https://www.tinkerforge.com/en/doc/Software/Bricklets/CO2V2_Bricklet_Go.html.

Index

Constants

View Source
const DeviceDisplayName = "CO2 Bricklet 2.0"
View Source
const DeviceIdentifier = 2147

Variables

This section is empty.

Functions

This section is empty.

Types

type BootloaderMode

type BootloaderMode = uint8
const (
	BootloaderModeBootloader                    BootloaderMode = 0
	BootloaderModeFirmware                      BootloaderMode = 1
	BootloaderModeBootloaderWaitForReboot       BootloaderMode = 2
	BootloaderModeFirmwareWaitForReboot         BootloaderMode = 3
	BootloaderModeFirmwareWaitForEraseAndReboot BootloaderMode = 4
)

type BootloaderStatus

type BootloaderStatus = uint8
const (
	BootloaderStatusOK                        BootloaderStatus = 0
	BootloaderStatusInvalidMode               BootloaderStatus = 1
	BootloaderStatusNoChange                  BootloaderStatus = 2
	BootloaderStatusEntryFunctionNotPresent   BootloaderStatus = 3
	BootloaderStatusDeviceIdentifierIncorrect BootloaderStatus = 4
	BootloaderStatusCRCMismatch               BootloaderStatus = 5
)

type CO2V2Bricklet

type CO2V2Bricklet struct {
	// contains filtered or unexported fields
}

func New

Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ipcon` is connected.

func (*CO2V2Bricklet) DeregisterAllValuesCallback

func (device *CO2V2Bricklet) DeregisterAllValuesCallback(registrationId uint64)

Remove a registered All Values callback.

func (*CO2V2Bricklet) DeregisterCO2ConcentrationCallback

func (device *CO2V2Bricklet) DeregisterCO2ConcentrationCallback(registrationId uint64)

Remove a registered CO2 Concentration callback.

func (*CO2V2Bricklet) DeregisterHumidityCallback

func (device *CO2V2Bricklet) DeregisterHumidityCallback(registrationId uint64)

Remove a registered Humidity callback.

func (*CO2V2Bricklet) DeregisterTemperatureCallback

func (device *CO2V2Bricklet) DeregisterTemperatureCallback(registrationId uint64)

Remove a registered Temperature callback.

func (*CO2V2Bricklet) GetAPIVersion

func (device *CO2V2Bricklet) GetAPIVersion() [3]uint8

Returns the version of the API definition (major, minor, revision) implemented by this API bindings. This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.

func (*CO2V2Bricklet) GetAirPressure

func (device *CO2V2Bricklet) GetAirPressure() (airPressure uint16, err error)

Returns the ambient air pressure as set by SetAirPressure.

func (*CO2V2Bricklet) GetAllValues

func (device *CO2V2Bricklet) GetAllValues() (co2Concentration uint16, temperature int16, humidity uint16, err error)

Returns all values measured by the CO2 Bricklet 2.0.

If you want to get the values periodically, it is recommended to use the RegisterAllValuesCallback callback. You can set the callback configuration with SetAllValuesCallbackConfiguration.

Note

The sensor is able to messure up to 120 °C. However it is only specified up to 70 °C.
Exposing the Bricklet to higher temperatures might result in permanent damage.

func (*CO2V2Bricklet) GetAllValuesCallbackConfiguration

func (device *CO2V2Bricklet) GetAllValuesCallbackConfiguration() (period uint32, valueHasToChange bool, err error)

Returns the callback configuration as set by SetAllValuesCallbackConfiguration.

func (*CO2V2Bricklet) GetBootloaderMode

func (device *CO2V2Bricklet) GetBootloaderMode() (mode BootloaderMode, err error)

Returns the current bootloader mode, see SetBootloaderMode.

Associated constants:

* BootloaderModeBootloader
* BootloaderModeFirmware
* BootloaderModeBootloaderWaitForReboot
* BootloaderModeFirmwareWaitForReboot
* BootloaderModeFirmwareWaitForEraseAndReboot

func (*CO2V2Bricklet) GetCO2Concentration

func (device *CO2V2Bricklet) GetCO2Concentration() (co2Concentration uint16, err error)

Returns CO2 concentration.

If you want to get the value periodically, it is recommended to use the RegisterCO2ConcentrationCallback callback. You can set the callback configuration with SetCO2ConcentrationCallbackConfiguration.

func (*CO2V2Bricklet) GetCO2ConcentrationCallbackConfiguration

func (device *CO2V2Bricklet) GetCO2ConcentrationCallbackConfiguration() (period uint32, valueHasToChange bool, option ThresholdOption, min uint16, max uint16, err error)

Returns the callback configuration as set by SetCO2ConcentrationCallbackConfiguration.

Associated constants:

* ThresholdOptionOff
* ThresholdOptionOutside
* ThresholdOptionInside
* ThresholdOptionSmaller
* ThresholdOptionGreater

func (*CO2V2Bricklet) GetChipTemperature

func (device *CO2V2Bricklet) GetChipTemperature() (temperature int16, err error)

Returns the temperature as measured inside the microcontroller. The value returned is not the ambient temperature!

The temperature is only proportional to the real temperature and it has bad accuracy. Practically it is only useful as an indicator for temperature changes.

func (*CO2V2Bricklet) GetHumidity

func (device *CO2V2Bricklet) GetHumidity() (humidity uint16, err error)

Returns relative humidity.

If you want to get the value periodically, it is recommended to use the RegisterHumidityCallback callback. You can set the callback configuration with SetHumidityCallbackConfiguration.

func (*CO2V2Bricklet) GetHumidityCallbackConfiguration

func (device *CO2V2Bricklet) GetHumidityCallbackConfiguration() (period uint32, valueHasToChange bool, option ThresholdOption, min uint16, max uint16, err error)

Returns the callback configuration as set by SetHumidityCallbackConfiguration.

Associated constants:

* ThresholdOptionOff
* ThresholdOptionOutside
* ThresholdOptionInside
* ThresholdOptionSmaller
* ThresholdOptionGreater

func (*CO2V2Bricklet) GetIdentity

func (device *CO2V2Bricklet) GetIdentity() (uid string, connectedUid string, position rune, hardwareVersion [3]uint8, firmwareVersion [3]uint8, deviceIdentifier uint16, err error)

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 `Isolator Bricklet <isolator_bricklet>` is always at position 'z'.

The device identifier numbers can be found `here <device_identifier>`. |device_identifier_constant|

func (*CO2V2Bricklet) GetResponseExpected

func (device *CO2V2Bricklet) GetResponseExpected(functionID Function) (bool, error)

Returns the response expected flag for the function specified by the function ID parameter. It is true if the function is expected to send a response, false otherwise.

For getter functions this is enabled by default and cannot be disabled, because those functions will always send a response. For callback configuration functions it is enabled by default too, but can be disabled by SetResponseExpected. For setter functions it is disabled by default and can be enabled.

Enabling the response expected flag for a setter function allows to detect timeouts and other error conditions calls of this setter as well. The device will then send a response for this purpose. If this flag is disabled for a setter function then no response is sent and errors are silently ignored, because they cannot be detected.

See SetResponseExpected for the list of function ID constants available for this function.

func (*CO2V2Bricklet) GetSPITFPErrorCount

func (device *CO2V2Bricklet) GetSPITFPErrorCount() (errorCountAckChecksum uint32, errorCountMessageChecksum uint32, errorCountFrame uint32, errorCountOverflow uint32, err error)

Returns the error count for the communication between Brick and Bricklet.

The errors are divided into

* ACK checksum errors, * message checksum errors, * framing errors and * overflow errors.

The errors counts are for errors that occur on the Bricklet side. All Bricks have a similar function that returns the errors on the Brick side.

func (*CO2V2Bricklet) GetStatusLEDConfig

func (device *CO2V2Bricklet) GetStatusLEDConfig() (config StatusLEDConfig, err error)

Returns the configuration as set by SetStatusLEDConfig

Associated constants:

* StatusLEDConfigOff
* StatusLEDConfigOn
* StatusLEDConfigShowHeartbeat
* StatusLEDConfigShowStatus

func (*CO2V2Bricklet) GetTemperature

func (device *CO2V2Bricklet) GetTemperature() (temperature int16, err error)

Returns temperature.

Note

The sensor is able to messure up to 120 °C. However it is only specified up to 70 °C.
Exposing the Bricklet to higher temperatures might result in permanent damage.

If you want to get the value periodically, it is recommended to use the RegisterTemperatureCallback callback. You can set the callback configuration with SetTemperatureCallbackConfiguration.

func (*CO2V2Bricklet) GetTemperatureCallbackConfiguration

func (device *CO2V2Bricklet) GetTemperatureCallbackConfiguration() (period uint32, valueHasToChange bool, option ThresholdOption, min int16, max int16, err error)

Returns the callback configuration as set by SetTemperatureCallbackConfiguration.

Associated constants:

* ThresholdOptionOff
* ThresholdOptionOutside
* ThresholdOptionInside
* ThresholdOptionSmaller
* ThresholdOptionGreater

func (*CO2V2Bricklet) GetTemperatureOffset

func (device *CO2V2Bricklet) GetTemperatureOffset() (offset uint16, err error)

Returns the temperature offset as set by SetTemperatureOffset.

func (*CO2V2Bricklet) ReadUID

func (device *CO2V2Bricklet) ReadUID() (uid uint32, err error)

Returns the current UID as an integer. Encode as Base58 to get the usual string version.

func (*CO2V2Bricklet) RegisterAllValuesCallback

func (device *CO2V2Bricklet) RegisterAllValuesCallback(fn func(uint16, int16, uint16)) uint64

This callback is triggered periodically according to the configuration set by SetAllValuesCallbackConfiguration.

The parameters are the same as GetAllValues.

Note

The sensor is able to messure up to 120 °C. However it is only specified up to 70 °C.
Exposing the Bricklet to higher temperatures might result in permanent damage.

func (*CO2V2Bricklet) RegisterCO2ConcentrationCallback

func (device *CO2V2Bricklet) RegisterCO2ConcentrationCallback(fn func(uint16)) uint64

This callback is triggered periodically according to the configuration set by SetCO2ConcentrationCallbackConfiguration.

The parameter is the same as GetCO2Concentration.

func (*CO2V2Bricklet) RegisterHumidityCallback

func (device *CO2V2Bricklet) RegisterHumidityCallback(fn func(uint16)) uint64

This callback is triggered periodically according to the configuration set by SetHumidityCallbackConfiguration.

The parameter is the same as GetHumidity.

func (*CO2V2Bricklet) RegisterTemperatureCallback

func (device *CO2V2Bricklet) RegisterTemperatureCallback(fn func(int16)) uint64

This callback is triggered periodically according to the configuration set by SetTemperatureCallbackConfiguration.

The parameter is the same as GetTemperature.

func (*CO2V2Bricklet) Reset

func (device *CO2V2Bricklet) Reset() (err error)

Calling this function will reset the Bricklet. All configurations will be lost.

After a reset you have to create new device objects, calling functions on the existing ones will result in undefined behavior!

func (*CO2V2Bricklet) SetAirPressure

func (device *CO2V2Bricklet) SetAirPressure(airPressure uint16) (err error)

The CO2 concentration depends (among other things) on the ambient air pressure.

To increase the accuracy of the CO2 Bricklet 2.0 you can set the current air pressure. You use the `Barometer Bricklet 2.0 <barometer_v2_bricklet>` or the `Air Quality Bricklet <air_quality_bricklet>` to get the current air pressure.

By default air pressure compensation is disabled. Once you set a value it will be used for compensation. You can turn the compensation off again by setting the value to 0.

It is sufficient to update the value every few minutes.

func (*CO2V2Bricklet) SetAllValuesCallbackConfiguration

func (device *CO2V2Bricklet) SetAllValuesCallbackConfiguration(period uint32, valueHasToChange bool) (err error)

The period is the period with which the RegisterAllValuesCallback callback is triggered periodically. A value of 0 turns the callback off.

If the `value has to change`-parameter is set to true, the callback is only triggered after at least one of the values has changed. If the values didn't change within the period, the callback is triggered immediately on change.

If it is set to false, the callback is continuously triggered with the period, independent of the value.

func (*CO2V2Bricklet) SetBootloaderMode

func (device *CO2V2Bricklet) SetBootloaderMode(mode BootloaderMode) (status BootloaderStatus, err error)

Sets the bootloader mode and returns the status after the requested mode change was instigated.

You can change from bootloader mode to firmware mode and vice versa. A change from bootloader mode to firmware mode will only take place if the entry function, device identifier and CRC are present and correct.

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

Associated constants:

* BootloaderModeBootloader
* BootloaderModeFirmware
* BootloaderModeBootloaderWaitForReboot
* BootloaderModeFirmwareWaitForReboot
* BootloaderModeFirmwareWaitForEraseAndReboot
* BootloaderStatusOK
* BootloaderStatusInvalidMode
* BootloaderStatusNoChange
* BootloaderStatusEntryFunctionNotPresent
* BootloaderStatusDeviceIdentifierIncorrect
* BootloaderStatusCRCMismatch

func (*CO2V2Bricklet) SetCO2ConcentrationCallbackConfiguration

func (device *CO2V2Bricklet) SetCO2ConcentrationCallbackConfiguration(period uint32, valueHasToChange bool, option ThresholdOption, min uint16, max uint16) (err error)

The period is the period with which the RegisterCO2ConcentrationCallback callback is triggered periodically. A value of 0 turns the callback off.

If the `value has to change`-parameter is set to true, the callback is only triggered after the value has changed. If the value didn't change within the period, the callback is triggered immediately on change.

If it is set to false, the callback is continuously triggered with the period, independent of the value.

It is furthermore possible to constrain the callback with thresholds.

The `option`-parameter together with min/max sets a threshold for the RegisterCO2ConcentrationCallback callback.

The following options are possible:

Option| Description
--- | ---
'x'|    Threshold is turned off
'o'|    Threshold is triggered when the value is *outside* the min and max values
'i'|    Threshold is triggered when the value is *inside* or equal to the min and max values
'<'|    Threshold is triggered when the value is smaller than the min value (max is ignored)
'>'|    Threshold is triggered when the value is greater than the min value (max is ignored)

If the option is set to 'x' (threshold turned off) the callback is triggered with the fixed period.

Associated constants:

* ThresholdOptionOff
* ThresholdOptionOutside
* ThresholdOptionInside
* ThresholdOptionSmaller
* ThresholdOptionGreater

func (*CO2V2Bricklet) SetHumidityCallbackConfiguration

func (device *CO2V2Bricklet) SetHumidityCallbackConfiguration(period uint32, valueHasToChange bool, option ThresholdOption, min uint16, max uint16) (err error)

The period is the period with which the RegisterHumidityCallback callback is triggered periodically. A value of 0 turns the callback off.

If the `value has to change`-parameter is set to true, the callback is only triggered after the value has changed. If the value didn't change within the period, the callback is triggered immediately on change.

If it is set to false, the callback is continuously triggered with the period, independent of the value.

It is furthermore possible to constrain the callback with thresholds.

The `option`-parameter together with min/max sets a threshold for the RegisterHumidityCallback callback.

The following options are possible:

Option| Description
--- | ---
'x'|    Threshold is turned off
'o'|    Threshold is triggered when the value is *outside* the min and max values
'i'|    Threshold is triggered when the value is *inside* or equal to the min and max values
'<'|    Threshold is triggered when the value is smaller than the min value (max is ignored)
'>'|    Threshold is triggered when the value is greater than the min value (max is ignored)

If the option is set to 'x' (threshold turned off) the callback is triggered with the fixed period.

Associated constants:

* ThresholdOptionOff
* ThresholdOptionOutside
* ThresholdOptionInside
* ThresholdOptionSmaller
* ThresholdOptionGreater

func (*CO2V2Bricklet) SetResponseExpected

func (device *CO2V2Bricklet) SetResponseExpected(functionID Function, responseExpected bool) error

Changes the response expected flag of the function specified by the function ID parameter. This flag can only be changed for setter (default value: false) and callback configuration functions (default value: true). For getter functions it is always enabled.

Enabling the response expected flag for a setter function allows to detect timeouts and other error conditions calls of this setter as well. The device will then send a response for this purpose. If this flag is disabled for a setter function then no response is sent and errors are silently ignored, because they cannot be detected.

func (*CO2V2Bricklet) SetResponseExpectedAll

func (device *CO2V2Bricklet) SetResponseExpectedAll(responseExpected bool)

Changes the response expected flag for all setter and callback configuration functions of this device at once.

func (*CO2V2Bricklet) SetStatusLEDConfig

func (device *CO2V2Bricklet) SetStatusLEDConfig(config StatusLEDConfig) (err error)

Sets the status LED configuration. By default the LED shows communication traffic between Brick and Bricklet, it flickers once for every 10 received data packets.

You can also turn the LED permanently on/off or show a heartbeat.

If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.

Associated constants:

* StatusLEDConfigOff
* StatusLEDConfigOn
* StatusLEDConfigShowHeartbeat
* StatusLEDConfigShowStatus

func (*CO2V2Bricklet) SetTemperatureCallbackConfiguration

func (device *CO2V2Bricklet) SetTemperatureCallbackConfiguration(period uint32, valueHasToChange bool, option ThresholdOption, min int16, max int16) (err error)

The period is the period with which the RegisterTemperatureCallback callback is triggered periodically. A value of 0 turns the callback off.

If the `value has to change`-parameter is set to true, the callback is only triggered after the value has changed. If the value didn't change within the period, the callback is triggered immediately on change.

If it is set to false, the callback is continuously triggered with the period, independent of the value.

It is furthermore possible to constrain the callback with thresholds.

The `option`-parameter together with min/max sets a threshold for the RegisterTemperatureCallback callback.

The following options are possible:

Option| Description
--- | ---
'x'|    Threshold is turned off
'o'|    Threshold is triggered when the value is *outside* the min and max values
'i'|    Threshold is triggered when the value is *inside* or equal to the min and max values
'<'|    Threshold is triggered when the value is smaller than the min value (max is ignored)
'>'|    Threshold is triggered when the value is greater than the min value (max is ignored)

If the option is set to 'x' (threshold turned off) the callback is triggered with the fixed period.

Associated constants:

* ThresholdOptionOff
* ThresholdOptionOutside
* ThresholdOptionInside
* ThresholdOptionSmaller
* ThresholdOptionGreater

func (*CO2V2Bricklet) SetTemperatureOffset

func (device *CO2V2Bricklet) SetTemperatureOffset(offset uint16) (err error)

Sets a temperature offset. A offset of 10 will decrease the measured temperature by 0.1 °C.

If you install this Bricklet into an enclosure and you want to measure the ambient temperature, you may have to decrease the measured temperature by some value to compensate for the error because of the heating inside of the enclosure.

We recommend that you leave the parts in the enclosure running for at least 24 hours such that a temperature equilibrium can be reached. After that you can measure the temperature directly outside of enclosure and set the difference as offset.

This temperature offset is used to calculate the relative humidity and CO2 concentration. In case the Bricklet is installed in an enclosure, we recommend to measure and set the temperature offset to improve the accuracy of the measurements.

It is sufficient to set the temperature offset once. The offset is saved in non-volatile memory and is applied again after a power loss.

func (*CO2V2Bricklet) SetWriteFirmwarePointer

func (device *CO2V2Bricklet) SetWriteFirmwarePointer(pointer uint32) (err error)

Sets the firmware pointer for WriteFirmware. The pointer has to be increased by chunks of size 64. The data is written to flash every 4 chunks (which equals to one page of size 256).

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

func (*CO2V2Bricklet) WriteFirmware

func (device *CO2V2Bricklet) WriteFirmware(data [64]uint8) (status uint8, err error)

Writes 64 Bytes of firmware at the position as written by SetWriteFirmwarePointer before. The firmware is written to flash every 4 chunks.

You can only write firmware in bootloader mode.

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

func (*CO2V2Bricklet) WriteUID

func (device *CO2V2Bricklet) WriteUID(uid uint32) (err error)

Writes a new UID into flash. If you want to set a new UID you have to decode the Base58 encoded UID string into an integer first.

We recommend that you use Brick Viewer to change the UID.

type Function

type Function = uint8
const (
	FunctionGetAllValues                             Function = 1
	FunctionSetAirPressure                           Function = 2
	FunctionGetAirPressure                           Function = 3
	FunctionSetTemperatureOffset                     Function = 4
	FunctionGetTemperatureOffset                     Function = 5
	FunctionSetAllValuesCallbackConfiguration        Function = 6
	FunctionGetAllValuesCallbackConfiguration        Function = 7
	FunctionGetCO2Concentration                      Function = 9
	FunctionSetCO2ConcentrationCallbackConfiguration Function = 10
	FunctionGetCO2ConcentrationCallbackConfiguration Function = 11
	FunctionGetTemperature                           Function = 13
	FunctionSetTemperatureCallbackConfiguration      Function = 14
	FunctionGetTemperatureCallbackConfiguration      Function = 15
	FunctionGetHumidity                              Function = 17
	FunctionSetHumidityCallbackConfiguration         Function = 18
	FunctionGetHumidityCallbackConfiguration         Function = 19
	FunctionGetSPITFPErrorCount                      Function = 234
	FunctionSetBootloaderMode                        Function = 235
	FunctionGetBootloaderMode                        Function = 236
	FunctionSetWriteFirmwarePointer                  Function = 237
	FunctionWriteFirmware                            Function = 238
	FunctionSetStatusLEDConfig                       Function = 239
	FunctionGetStatusLEDConfig                       Function = 240
	FunctionGetChipTemperature                       Function = 242
	FunctionReset                                    Function = 243
	FunctionWriteUID                                 Function = 248
	FunctionReadUID                                  Function = 249
	FunctionGetIdentity                              Function = 255
	FunctionCallbackAllValues                        Function = 8
	FunctionCallbackCO2Concentration                 Function = 12
	FunctionCallbackTemperature                      Function = 16
	FunctionCallbackHumidity                         Function = 20
)

type StatusLEDConfig

type StatusLEDConfig = uint8
const (
	StatusLEDConfigOff           StatusLEDConfig = 0
	StatusLEDConfigOn            StatusLEDConfig = 1
	StatusLEDConfigShowHeartbeat StatusLEDConfig = 2
	StatusLEDConfigShowStatus    StatusLEDConfig = 3
)

type ThresholdOption

type ThresholdOption = rune
const (
	ThresholdOptionOff     ThresholdOption = 'x'
	ThresholdOptionOutside ThresholdOption = 'o'
	ThresholdOptionInside  ThresholdOption = 'i'
	ThresholdOptionSmaller ThresholdOption = '<'
	ThresholdOptionGreater ThresholdOption = '>'
)