SEARCH: i2c

I2C sensors

First of all, you must specify a pin for a sensor. It is the SDA pin. Then it would help if you defined the SCL pin. For example, output 4 – BME280, and output 5 – I2C SCL.

I2C configuration for a sensor

If you connect several sensors on one bus (pin), you may define the SCL pin only once.

This image has an empty alt attribute; its file name is img1-4.png
I2C configuration for sensors on one bus

Zigbee: Accepts the “read” and “write” commands on the endpoint for the SDA pin.

Real-time clock (DS3231 or DS1307 RTC)

The firmware supports the most popular RTC chips like DS3231 and DS1307. These battery-powered chips can count time independently with the main module. The firmware reads the time from these chips at the boot time and periodically synchronizes the module’s time with RTC.

RTC chips support the I2C protocol. Therefore, you can add them in a similar way, like other I2C sensors.

⚠️ THIS FEATURE IS AVAILABLE IN THE PREMIUM VERSION

⚠️ This feature is not available on the CC253X router.

RTC clock setup

Zigbee internals

Zigbee cluster: ZCL_CLUSTER_ID_GEN_TIME
Zigbee attributes: ATTRID_TIME_TIME (UTC data type, 32-bit number of seconds since Jan 1, 2000)
Zigbee commands: read, write.

Zigbee2MQTT commands

You should create a custom converter for your device, place it in the “data” folder, and add it to the configuration.

read - immediately reads the current time.
Topic: zigbee2mqtt/[friedly_name]/get/[channel]
Channel: l1, l2, l3 … l16
Payload: 1
Returns: The counter value {"[channel]": float_value}
write - this command allows you to synchronize time with the host. It is not recommended to call it directly because the device expects an encoded value. The custom converter gets the current host's time and calculates the correct value automatically.
Command example:
const values = {timeStatus: 3, time: time};
endpoint.write('genTime', values);

Rotary encoder

A rotary encoder is a type of position sensor used to determine the angular position of a rotating shaft. It generates an electrical signal, either analog or digital, according to the rotational movement (more info).

Digital rotary encoder
Digital rotary encoder

The firmware counts impulses in the 500 ms interval and sends a positive value for CW rotations and a negative value for CCW rotations. Optionally, the firmware can handle and send an event for a click button.

Wiring

Output 1 → S1
Output 2 → S2
Input 2 → Key
GND → GND
3.3V → VCC

Firmware configuration

Firmware configuration for digital rotary encoder
Firmware configuration

The image above is an example. You can connect signals to any pins and place them on any input and output. The I2C SCL line should be defined immediately after the “Rotary encoder.”

Ultrasonic sensors (US100, HC-SR04 or similar)

These ultrasonic sonar distance sensors are really common in robotics projects, but they can also be used for automation, interactive art, and motion sensing. They work at about 2cm to 450cm away, but we think 10cm-250cm will get you the best results. Sensors look very similar and have a pair of flippers.

US-100 ultrasonic sensor

The US-100 is very similar to the popular HC-SR04 ultrasonic sensor and even looks the same, but it can work in the UART mode and provide more precise measurements.

Compatible sensors are: HY-SRF05, HC-SR04, HC-SR04 3-5V, US-100, HC-SR04P, US-015, US-016, HC-SR04+, US-026, IOE-SR05, RCWL-1601, AJ-SR04M

Zigbee firmware configuration for US100

It would be best if you used the jumper is on the board to select the UART mode.

The firmware configuration for US100

Connections

P02 (UART RX) → Tx
P03 (UART TX) → Rx
GND → GND
3.3V → VCC
Do not forget about the jumper. If you do not receive data from this sensor, try to swap Rx and Tx wires.

Zigbee firmware configuration for HC-SR04 compatible sensors

This sensor requires a trigger signal to start a measurement, and the firmware uses the “I2C SCL” signal for it. It would be best if you defined it immediately after the HC-SR04 sensor.

Note: the firmware cannot measure a signal width with precision in microseconds. Therefore, the measured distance is rounded to about 15 centimeters. If you need better accuracy, use US100 instead.

The firmware configuration for HC-SR04

Connections

I2C SCL → Trig
HC-SR04 → Echo
GND → GND
3.3V → VCC

Interval

If the value in the “Interval” field is not zero, the firmware executes measurement every N seconds. It sends a new value to a coordinator only if a distance value changes. But the firmware always sends the latest measured value with a periodic report.

16-channel Zigbee PWM controller (PCA9685)

The PCA9685 is an I2C-bus controlled 16-channel LED controller optimized for Red/Green/Blue/Amber (RGBA) color backlighting applications. Each LED output has its own 12-bit resolution (4096 steps) fixed frequency individual PWM controller that operates at a programmable frequency from a typical of 24 Hz to 1526 Hz with a duty cycle that is adjustable from 0% to 100 % to allow the LED to be set to a specific brightness value. All outputs are set to the same PWM frequency.

PCA9685. Typical configuration
Fig. 1. PCA9685. Typical configuration

The configuration above is for 8 channels on a controller connected to P15 (SDA) and P13 (SCL) pins.

Address – it is the I2C address. The default value is 0x70 (hex) or 112 (dec).

Inversed – if this option is enabled and the PWM channel is off, the output will have the HIGH level. Otherwise, the output will change the LOW level.

Frequency – PWM frequency. The firmware uses a value from the first defined channel (in this example, Output 1).

Channel – PWM channel number from 0 to 15.

Type – the PWM output type (fig. 2).

PWM output type
Fig. 2. PWM output type

Zigbee2MQTT commands

on/off - Look for commands and examples for GPIO outputs.
write - sets the PWM duty cycle.
Topic: zigbee2mqtt/[friedly_name]/[channel]/set/brightness
Channel: l1, l2, l3 … l16
Payload: value (0..254)
Topic: zigbee2mqtt/[friedly_name]/set/[channel]
Channel: l1, l2, l3 … l16
Payload: {"brightness": value, "transition": 3}
value: 0 .. 254.
transition: (optional) the transition time in seconds between states.
read - reads the current value
Topic: zigbee2mqtt/[friedly_name]/[channel]/get/brightness
Payload: none
Returns: {"brightness_[channel]": value}

Changelog

2022-05-04

[+] Added the ability to link the same virtual pin to several outputs if required.
[*] [CC2652] Now a router can report the LQI value for child devices (#112).
[+] [CC2652] changed to the latest SDK 6.10, which in theory should solve the problem froze routers.
[*] [CC2652] [PSM] The device did not go to sleep when communication with the coordinator was lost (#115).

2021-08-05

  • Added support for CC2652R1, CC2652RB, CC2652P, CC1352P2 chips 🔥🔥🔥.
  • Improved external wake-up buttons handling in the PSM mode.
  • Improved the 16-channel version.
  • Minor bug fixes and improvements.

2021-04-27

  • Few improvements in PWM. Now, you can set a transition time between states and select a linked button’s mode.
  • Improved the power-saving mode. I’ve confirmed that a sensor may consume 1 µa and 0.4µa if there are no periodic reports.
  • UART allows you to set a custom data packet’s delimiter.
  • Fixed a bug in Pulse Switch.
  • Improved an RF signal level in chips without an amplifier.

2021-04-05

  • Added the Uptime virtual sensor.
  • Improved the switch mode for GPIO inputs in the power-saving mode.
  • Fixed problem with inputs with the pull-down resistor the power saving mode.
  • Added an option to disable resetting by a power on/off cycle.
  • A small improvement in a custom converter for SenseAir S8.
  • Fixed a bug with UART on output 2.

2021-03-29

  • Added a low-power counter with nonvolatile memory PCF8583 (Premium).
  • Added 16-channel PWM controller PCA9685 (Premium).
  • Small interface improvements.

2021-03-22

  • Added sensors HTU21D, HDC1080, SHT20, SHT30, SHTC3.
  • Improved the I2C interface
  • Counter: added options to select a debounce interval for fast and slow counters.
  • Counter: you can set any initial value remotely.
  • Added virtual pins (P30-P37) that you can use in your configuration (for example, for internal temperature or voltage sensors). Therefore, you can use real pins on a chip for other purposes.
  • Fixed problem with a wrong internal temperature in PSM.

2021-03-07 Added the power saving mode for battery-powered devices to the Premium version.

2021-03-02 Added the Premium version with 16 channels. Added creating of external converters for Zigbee2MQTT with the necessary Exposes.

2021-02-21 Improved compatibility with BMx280 sensors.

2021-02-15 Improved code for INA219, INA3221 sensors. Added the inverted mode for hardware PWM.

2021-01-14 Added ACS758. Control of PWM outputs with switch inputs. Status LED modes. Added a scale factor for ADC. Minor bugfixes.

2020-12-25 Christmas Edition :-). I’ve fixed a problem with the ‘trigger.’ The old trigger cannot wait for more than 60 seconds. Now, the firmware firstly initializes GPIO outputs to minimize an interval of undefined state after power on.

2020-12-20 Fixed minor bugs (bistable relays). Added the pulse switch mode. Now the firmware immediately reports about a state when it gets a command from a bound device.

2020-12-07 Added reading of simple MODBUS RTU sensors. Fixed problem with connection losing in the router mode.

2020-11-09 Added a virtual group switch.

2020-10-29 Added firmware for end devices (without routing).

2020-10-18 Added support of Sensirion SPS30 (Particulate Matter Sensor), PZEM-004T (Energy Monitor Sensor), BH1750 (Ambient Light Sensor), INA219 (DC Voltage/Current Sensor), INA3221 (3-channel DC Voltage/Current Sensor).

2020-08-14 Fixed problem with unexpected behavior of the P14 pin when it is configured as a GPIO output.

2020-08-10 Added ACS712 sensor.

2020-07-10 Fixed problem with losing connection after power loss.

2020-06-26 Tested SI7021 & CCS811.

2020-06-24 Fixed problem with switch buttons linked to relays. Added the toggle mode for a switch input (works like Aqara).

2020-06-16 Improved hardware PWM (added frequency selection up to 32 kHz).

2020-05-26 Fixed interview problems in some configurations.

2020-05-21 Increased number of inputs to 8. Configurable TXEN and RXEN pins for the RFX2401 power amplifier. Ability to assign the DS18B20 sensor to an endpoint.

2020-05-03 Added the “Inverse” option for inputs and outputs. Added PWM.

2020-04-22 Fixed internal temperature measurement.

2020-04-20: Fixed problem with a pull-up/down mode. Added checks for pull-up/down settings in the configurator.

2020-04-19: Fixed problem with empty endpoints that may cause problems with joining. Fixed a bug with ADC.

2020-04-14: Fixed a problem with ADC.

Zigbee Configurable Firmware Features

CCS811

The sensor requires environmental temperature and humidity for better results. The example above shows that several I2C sensors are connected on the same bus. They provide the necessary data. These sensors should be defined first. If they are defined after CCS811, environmental info will be ignored by CCS811.

You may also send temperature and humidity from a higher system.

Analog value: 65NNN where NNN is a humidity value, for example, 65050 for 50%. Humidity range: 0 … 50.
Analog value: 64NNN where NNN is a temperature value, shifted by 25. For example, 64000 for -25C, 64025 for 0C, 64050 for 25C. Temperature range: -25 … 100.
Analog value: 0 .. 63999 – baseline value (see docs for CCS811).

write - set the baseline value.
Topic: zigbee2mqtt/[friedly_name]/set
Payload: {"[channel]": 123}
Channel: l1, l2, l3 … l16
write - set the temperature value 25C.
Topic: zigbee2mqtt/[friedly_name]/set
Payload: {"[channel]": 64050}
Channel: l1, l2, l3 … l16
write - set the humidity value 50%.
Topic: zigbee2mqtt/[friedly_name]/set
Payload: {"[channel]": 65050}
Channel: l1, l2, l3 … l16

Analog input with ADS1115 in Python

Python has the pretty good library “WiringPi-Python“, but it depends on WiringPi2 for Raspberry Pi and cannot be installed automatically through pip. Here is a solution.

In my project I want to control a battery voltage and a charging state for my LiPo battery. Therefore I’ve added the ADS1115 board.

I’ve installed WiringPi2 for BPi and tried to read analog inputs through the gpio command line utility.

1
$ gpio -x ads1115:200:0x48 aread 200

The main disadvantage of this method for me is the default analog reading settings: 128 samples per second and +/-4.096V range (my battery voltage is 4.2V). You cannot change these setting in the command line utility.

There are no more results.