GY-63_MS5611/libraries/HC4052
2023-11-24 16:47:45 +01:00
..
.github 0.1.0 HC4052 2023-01-26 12:34:18 +01:00
examples 0.1.3 HC4052 2023-11-24 16:47:45 +01:00
test 0.1.0 HC4052 2023-01-26 12:34:18 +01:00
.arduino-ci.yml 0.1.0 HC4052 2023-01-26 12:34:18 +01:00
CHANGELOG.md 0.1.3 HC4052 2023-11-24 16:47:45 +01:00
HC4052.h 0.1.3 HC4052 2023-11-24 16:47:45 +01:00
keywords.txt 0.1.2 HC4052 2023-11-24 15:51:39 +01:00
library.json 0.1.3 HC4052 2023-11-24 16:47:45 +01:00
library.properties 0.1.3 HC4052 2023-11-24 16:47:45 +01:00
LICENSE 0.1.0 HC4052 2023-01-26 12:34:18 +01:00
README.md 0.1.3 HC4052 2023-11-24 16:47:45 +01:00

Arduino CI Arduino-lint JSON check GitHub issues

License: MIT GitHub release PlatformIO Registry

HC4052

HC4052 is an Arduino library for a HC4052 4 x 2 channel multiplexer.

Description

HC4052 is a library to control the CD74HC4052 4 x 2 channels multiplexer / demultiplexer and compatible devices.

The HC4052 allows e.g to multiplex an I2C bus (SDA+SCL) simultaneous to read multiple sensors that have a fixed address. Another application is to switch Serial (UNO has only one HW Serial) between different devices. Or to switch audio channels (not tested) etc.

The channel selection is done with two select lines A, B or s0, s1.

The device can be enabled/disabled by the enable line INH or E.

Compatibles

To elaborate.

Hardware connection

Typical connection is to connect the two select pins to two IO Pins of your board.

The optional enablePin(INH) must be connected to GND if not used. This way the device is continuous enabled.

Example multiplexing analog in.

        processor                      HC4052
     +-------------+              +-------------+
     |             |              |             |
     |           A |------------->| A        X0 |
     |           B |------------->| B        X1 |
     |      enable |------------->| INH      X2 |
     |             |              |          X3 |
     | analog in   |<-------------| X           |
     |             |              |             |
     | analog in   |<-------------| Y        Y0 |
     |             |              |          Y1 |
     |         GND |--------------| GND      Y2 |
     |             |              | VCC      Y3 |
     |             |              |             |
     +-------------+              +-------------+

Interface

#include "HC4052.h"

Core

  • HC4052(uint8_t A, uint8_t B, uint8_t enablePin = 255) constructor. Set the two select pins and optional the enable pin. If the enablePin == 255 it is considered not used.
  • bool setChannel(uint8_t channel) set the current channel. Valid values 0..3, returns false if channel out of range. If the right channel is already set it does not change it
  • uint8_t getChannel() get current channel 0..3.

Enable

These functions work only if enablePin is set in the constructor.

  • void enable() idem.
  • void disable() idem.
  • bool isEnabled() idem. Also returns true if enablePin is not set.

Future

Must

  • keep in sync with HC4067 et.al.

Should

Could

  • add examples
    • i2c scan ?
    • performance

Wont

Support

If you appreciate my libraries, you can support the development and maintenance. Improve the quality of the libraries by providing issues and Pull Requests, or donate through PayPal or GitHub sponsors.

Thank you,