nanoFramework.Iot.Device.Charlieplex
1.2.696
Prefix Reserved
dotnet add package nanoFramework.Iot.Device.Charlieplex --version 1.2.696
NuGet\Install-Package nanoFramework.Iot.Device.Charlieplex -Version 1.2.696
<PackageReference Include="nanoFramework.Iot.Device.Charlieplex" Version="1.2.696" />
paket add nanoFramework.Iot.Device.Charlieplex --version 1.2.696
#r "nuget: nanoFramework.Iot.Device.Charlieplex, 1.2.696"
// Install nanoFramework.Iot.Device.Charlieplex as a Cake Addin #addin nuget:?package=nanoFramework.Iot.Device.Charlieplex&version=1.2.696 // Install nanoFramework.Iot.Device.Charlieplex as a Cake Tool #tool nuget:?package=nanoFramework.Iot.Device.Charlieplex&version=1.2.696
Charlieplex Segment binding
Charliplexing is a multiplexing scheme that enables controlling a significantly larger number of LEDs or other load or sensor than a more traditional wiring scheme would allow. Charlieplexing enables addressing up to n^2-n
LEDs where n is the number of pins available. For example, 3 pins can be used to address up to 6 LEDs, 4 pins can address 12, and 5 pins can address 20. That sounds great, however charlieplexed circuits are hard to wire due to their complexity.
An even bigger challenge is that the scheme (at least in its basic form) only allows for lighting a single LED at once. On the face of it, that would seem to be a big problem. Don't worry. The LEDs change very quickly such that the eye is tricked into thinking multiple LEDs are lit at the same time. This means that your code that cannot be doing something else while the LEDs are lit. This is why the API accepts timing information. This is not what you'd expect if you are used to lighting LEDs directly from GPIO pins or via a shift register.
Show dotnet: Animating 40 LEDs with charlieplexing demonstrates using this binding.
Usage
The following code sample demonstrates addressing 6 LEDs with 3 pins.
var pins = new int[] { 6, 13, 19 };
var ledCount = 6;
var charlie = new CharlieplexSegment(pins, ledCount);
for (int i = 0; i < ledCount; i++)
{
// will keep lit for 500ms
charlie.Write(i, 1, 500);
charlie.Write(i, 0);
}
The charlieplex-test sample exercises a broader use of the API.
Using with LEDs
The following image demonstrates a 3-pin charlieplex circuit, which is the starting point for charlieplexing. There are 6 LEDs in the circuit in groups of two. In each group of two, the LEDs connect to the same two GPIO pins, but with the opposite polarity (anode and cathodes are switched).
Using with an LED bar graph
The image above demonstrates using LEDs within a charlieplex circuit. LEDs are straightforward to use since you can switch their anode/cathode orientation. You cannot do that with an LED bar graph since the anode and cathode legs are fixed. Instead, you need to create your own circuit on a breadboard, and then feed that to the appropriate legs. That's what you see happening in the image below.
Circuit addressing scheme
The CharlieplexSegment type uses an addressing scheme that can be thought of as depth then breadth. Between each pair of pins, there are a pair of LEDs or other loads. The first LED is placed anode-first and the second is placed cathode-first. You start with the first two pins for the first pair of LEDs, and then the second and third pins for the second pair. This continues until you run out of pins. After that, you start from the first pin again, but this time pair with the third pin. This pattern continues until you reach the desired number of LEDs or run out of pins.
It is critical to understand the difference between anode (typically longer) and cathode legs of LEDs. You will be checking these with each placement.
The binding includes an API that returns a description of the circuit you need to use. The sample calls this API and prints this information to the terminal, using the same pins as the code example above. This information is very helpful to have to configure the circuit correctly.
Node 0 -- Anode: 6; Cathode: 13
Node 1 -- Anode: 13; Cathode: 6
Node 2 -- Anode: 13; Cathode: 19
Node 3 -- Anode: 19; Cathode: 13
Node 4 -- Anode: 6; Cathode: 19
Node 5 -- Anode: 19; Cathode: 6
The tests in CharlieplexLayout.cs call this same API and demonstrate the circuit address scheme with varying numbers of pins.
Given a 6 LED circut, charlie.Write(5,1)
will light LED6 in the diagram. The API uses a 0-based scheme. As a result, charlie.Write(6,1)
will throw an exception.
This image demonstrates a 2-pin circuit. There isn't any reason to use a 2-pin charlieplex circuit other than as a learning exercise.
This image demonstrates a 3-pin circuit.
This image demonstrates a 6-pin circuit.
The Controlling 20 Led's From 5 Arduino Pins Using Charlieplexing includes larger wiring diagrams that match the scheme used by this binding.
Alternatives
The alternative to a charlieplex circuit is a shift register. See SN74HC595 -- 8-Bit Shift Register. A shift register is even more efficient at using pins than a charlieplex circuit, and is simpler to configure.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net is compatible. |
-
- nanoFramework.CoreLibrary (>= 1.15.5)
- nanoFramework.Iot.Device.Multiplexing (>= 1.2.693)
- nanoFramework.Runtime.Events (>= 1.11.18)
- nanoFramework.System.Device.Gpio (>= 1.1.41)
- nanoFramework.System.Diagnostics.Stopwatch (>= 1.2.693)
- nanoFramework.System.Math (>= 1.5.43)
- nanoFramework.System.Threading (>= 1.1.32)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.2.696 | 73 | 12/16/2024 |
1.2.673 | 87 | 10/23/2024 |
1.2.662 | 96 | 10/11/2024 |
1.2.631 | 99 | 8/28/2024 |
1.2.590 | 103 | 7/17/2024 |
1.2.570 | 113 | 6/14/2024 |
1.2.560 | 115 | 5/29/2024 |
1.2.552 | 115 | 5/17/2024 |
1.2.548 | 119 | 5/15/2024 |
1.2.536 | 117 | 4/15/2024 |
1.2.514 | 135 | 3/22/2024 |
1.2.436 | 225 | 11/10/2023 |
1.2.416 | 110 | 11/8/2023 |
1.2.329 | 149 | 5/26/2023 |
1.2.313 | 136 | 5/12/2023 |
1.2.308 | 142 | 5/11/2023 |
1.2.302 | 157 | 5/10/2023 |
1.2.297 | 162 | 5/3/2023 |
1.2.273 | 219 | 3/17/2023 |
1.2.212 | 319 | 1/5/2023 |
1.2.208 | 316 | 1/3/2023 |
1.2.203 | 312 | 12/28/2022 |
1.2.159 | 354 | 11/14/2022 |
1.2.153 | 386 | 11/5/2022 |
1.2.141 | 380 | 10/25/2022 |
1.2.128 | 377 | 10/22/2022 |
1.2.122 | 431 | 10/12/2022 |
1.2.114 | 383 | 10/8/2022 |
1.2.95 | 439 | 9/22/2022 |
1.2.87 | 496 | 9/15/2022 |
1.2.73 | 412 | 9/8/2022 |
1.1.116.8772 | 436 | 6/24/2022 |
1.1.113.2032 | 455 | 6/23/2022 |
1.1.3 | 502 | 4/15/2022 |
1.1.1 | 442 | 4/14/2022 |
1.0.300 | 458 | 3/31/2022 |
1.0.288-preview.114 | 137 | 3/25/2022 |
1.0.288-preview.113 | 124 | 3/25/2022 |
1.0.288-preview.100 | 133 | 3/19/2022 |
1.0.288-preview.99 | 128 | 3/18/2022 |
1.0.288-preview.98 | 121 | 3/18/2022 |
1.0.288-preview.94 | 132 | 3/15/2022 |
1.0.288-preview.93 | 131 | 3/15/2022 |
1.0.288-preview.90 | 119 | 3/11/2022 |
1.0.288-preview.87 | 123 | 3/10/2022 |
1.0.288-preview.86 | 137 | 3/8/2022 |
1.0.288-preview.65 | 124 | 2/18/2022 |
1.0.288-preview.48 | 150 | 2/4/2022 |
1.0.288-preview.41 | 151 | 1/31/2022 |
1.0.288-preview.29 | 142 | 1/28/2022 |
1.0.288-preview.20 | 143 | 1/27/2022 |
1.0.288-preview.19 | 143 | 1/27/2022 |
1.0.288-preview.5 | 150 | 1/24/2022 |
1.0.288-preview.3 | 137 | 1/21/2022 |
1.0.288-preview.1 | 139 | 1/21/2022 |
1.0.272 | 177 | 1/10/2022 |
1.0.259 | 328 | 12/9/2021 |
1.0.218 | 211 | 10/18/2021 |
1.0.195 | 341 | 10/1/2021 |
1.0.136 | 247 | 7/17/2021 |
1.0.135 | 178 | 7/16/2021 |
1.0.134 | 191 | 7/15/2021 |
1.0.133 | 202 | 7/14/2021 |
1.0.131 | 183 | 7/8/2021 |
1.0.121 | 230 | 6/29/2021 |
1.0.120 | 202 | 6/29/2021 |
1.0.119 | 244 | 6/28/2021 |
1.0.118 | 218 | 6/20/2021 |
1.0.112 | 217 | 6/16/2021 |
1.0.110 | 249 | 6/9/2021 |
1.0.109 | 180 | 6/8/2021 |
1.0.106 | 210 | 6/1/2021 |
1.0.104 | 280 | 5/29/2021 |
1.0.63 | 191 | 5/26/2021 |
1.0.40 | 202 | 5/24/2021 |