GY-63_MS5611/libraries/HC4052/README.md

130 lines
4.0 KiB
Markdown
Raw Normal View History

2023-01-26 06:34:18 -05:00
[![Arduino CI](https://github.com/RobTillaart/HC4052/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/HC4052/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/HC4052/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/HC4052/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/HC4052/actions/workflows/jsoncheck.yml)
2023-11-04 09:20:20 -04:00
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/HC4052.svg)](https://github.com/RobTillaart/HC4052/issues)
2023-01-26 06:34:18 -05:00
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/HC4052/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/HC4052.svg?maxAge=3600)](https://github.com/RobTillaart/HC4052/releases)
2023-11-04 09:20:20 -04:00
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/HC4052.svg)](https://registry.platformio.org/libraries/robtillaart/HC4052)
2023-01-26 06:34:18 -05:00
# HC4052
2023-11-24 10:47:45 -05:00
HC4052 is an Arduino library for a HC4052 4 x 2 channel multiplexer.
2023-01-26 06:34:18 -05:00
## Description
2023-11-24 10:47:45 -05:00
HC4052 is a library to control the CD74HC4052 4 x 2 channels
2023-01-26 06:34:18 -05:00
multiplexer / demultiplexer and compatible devices.
2023-11-24 09:51:39 -05:00
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.
2023-11-24 10:47:45 -05:00
Or to switch audio channels (not tested) etc.
2023-01-26 06:34:18 -05:00
2023-11-24 10:47:45 -05:00
The channel selection is done with two select lines **A, B** or **s0, s1**.
2023-01-26 06:34:18 -05:00
2023-11-24 10:47:45 -05:00
The device can be enabled/disabled by the enable line **INH** or **E**.
2023-01-26 06:34:18 -05:00
#### Compatibles
2023-11-24 09:51:39 -05:00
- https://assets.nexperia.com/documents/data-sheet/74HC_HCT4052.pdf
- 74HC4052 (CMOS level)
- 74HCT4052 (TTL level)
To elaborate.
2023-01-26 06:34:18 -05:00
#### Related to
- https://github.com/RobTillaart/HC4051 (1x8 mux)
2023-11-04 09:20:20 -04:00
- https://github.com/RobTillaart/HC4052 (2x4 mux)
2023-01-26 06:34:18 -05:00
- https://github.com/RobTillaart/HC4053 (3x2 mux)
- https://github.com/RobTillaart/HC4067 (1x16 mux)
## Hardware connection
2023-11-24 10:47:45 -05:00
Typical connection is to connect the two **select pins** to two IO Pins of your board.
2023-01-26 06:34:18 -05:00
2023-11-24 10:47:45 -05:00
The optional **enablePin(INH)** must be connected to GND if not used.
2023-01-26 06:34:18 -05:00
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
```cpp
#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.
2023-11-24 10:47:45 -05:00
- **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
2023-01-26 06:34:18 -05:00
- **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
2023-11-24 09:51:39 -05:00
#### Must
2023-01-26 06:34:18 -05:00
- keep in sync with HC4067 et.al.
2023-11-24 09:51:39 -05:00
#### Should
#### Could
- add examples
- i2c scan ?
- performance
#### Wont
2023-11-04 09:20:20 -04:00
## 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,