nanoFramework.MagicBit 1.2.196

Prefix Reserved
dotnet add package nanoFramework.MagicBit --version 1.2.196
                    
NuGet\Install-Package nanoFramework.MagicBit -Version 1.2.196
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="nanoFramework.MagicBit" Version="1.2.196" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="nanoFramework.MagicBit" Version="1.2.196" />
                    
Directory.Packages.props
<PackageReference Include="nanoFramework.MagicBit" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add nanoFramework.MagicBit --version 1.2.196
                    
#r "nuget: nanoFramework.MagicBit, 1.2.196"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package nanoFramework.MagicBit@1.2.196
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=nanoFramework.MagicBit&version=1.2.196
                    
Install as a Cake Addin
#tool nuget:?package=nanoFramework.MagicBit&version=1.2.196
                    
Install as a Cake Tool

Quality Gate Status Reliability Rating License NuGet #yourfirstpr Discord

nanoFramework logo


Welcome to the .NET nanoFramework MagicBit Library repository

Build status

Component Build Status NuGet Package
MagicBit Build Status NuGet

Usage

This nuget can be used with the great MagicBit board.

It does bring support for almost all the sensors and the robot elements. Still, some are not natively in this nuget as they are part of the existing IoT.Device bindings. See the known limitations as well.

You just need to make sure your MagicBit is flashed like this:

# Replace the com port number by your COM port
nanoff --platform esp32 --update --preview --serialport COM3

A detailed example is available in the Test application as well.

Screen

The only thing you need to do to access the screen is to initialize it:

MagicBit.InitializeScreen();

Once you've initialized it, you can access both a Screen static class and a Console static class.

The Screen one brings primitives to write directly on the screen points, select colors as well as writing a text.

For example, you can write a small buffer square of 8x8 at the position 0, 26 with a width of 8 like this:

byte[] _heart = new byte[] {
            0b0100_0010,
            0b0110_0110,
            0b1111_1111,
            0b1111_1111,
            0b1111_1111,
            0b0011_1100,
            0b0011_1100,
            0b0001_1000,
        };
Screen.DrawBitmap(0, 26, 8, _heart);

Note that only multiple of 8 are possible for the width, the buffer should be a multiple of the width / 8. Each bit is representing a pixel. This is the way you can display images.

The screen provides as well other primitives, here is a quick example:

// You can use the Screen primitives like this:
Screen.Clear();
Screen.Write(2, 0, "MagicBit", 2);
Screen.Write(2, 26, "loves .NET", 1, true);
Screen.Write(2, 40, "nanoFramework", 1, true);
Screen.Write(2, 50, "Clk right button", 1, false);
Screen.DrawBitmap(0, 26, 8, _heart);
Screen.DrawBitmap(Screen.Width - 9, 26, 8, _heart);
// You should make sure that you call Display
Screen.Display();

And you will get even more thru Screen.Device.

The Console class works in a similar way as the classic System.Console:

Console.Clear();
Console.WriteLine("Motors");
Console.CursorTop = 2;
Console.WriteLine("Motors will run reverse then rotate both direction");

Note: You can change the default font as well, you need to provide it as a property. The Cursor positions are calculated with the width of the font.

Buttons

The 2 buttons are exposed.

They are called ButtonLeft and ButtonRight. You can get access to the events as well. For example:

MagicBit.ButtonLeft.Press += (sender, e) =>
{
    Console.CursorLeft = 0;
    Console.CursorTop = 0;
    Console.Write($"Left Pressed  ");
};

// Simple way of getting the button status
while (!MagicBit.ButtonRight.IsPressed)
{
    Thread.Sleep(20);
}

Another sample with events:

MagicBit.ButtonRight.IsHoldingEnabled = true;
MagicBit.ButtonRight.Holding += (sender, e) =>
{
    Console.Write("ButtonRight hold long.");
};

Motors

The MagicBit has a driver allowing to control 2 DC motors. If you have the robot kit, you'll be able to control them. If you don't have the robot kit, you still can use your own if you plug them on the correct pins.

Console.Clear();
Console.WriteLine("Motors");
Console.CursorTop = 2;
Console.WriteLine("Motors will run reverse then rotate both direction");
var motor1 = MagicBit.Motor1;
var motor2 = MagicBit.Motor2;
motor1.Speed = -0.5;
motor2.Speed = -0.5;
Thread.Sleep(2000);
motor1.Speed = +0.5;
motor2.Speed = -0.5;
Thread.Sleep(2000);
motor1.Speed = -0.5;
motor2.Speed = +0.5;
Thread.Sleep(2000);
motor1.Speed = 0;
motor2.Speed = 0;

Buzzer

It's of course possible to use the buzzer. Here is an example playing tones:

var buzz = MagicBit.Buzzer;
for (int i = 0; i < 10; i++)
{
    buzz.PlayTone(500 + i * 25, 1000);
}

Potentiometer and Luminosity

Those 2 embedded sensors can be directly accessed and used. Here is a complete example reading them, displaying the value on the screen and interrupting them when the left button is pressed:

CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
MagicBit.ButtonLeft.Press += (sender, e) =>
{
    cancellationTokenSource.Cancel();
};

Console.Clear();
Console.WriteLine("Sensors");
Console.CursorTop = 2;
Console.WriteLine("Clk left button to stop");

while (!cancellationTokenSource.Token.IsCancellationRequested)
{
    // Read the potentiometer ratio, from 0.0 to 1.0
    var ratio = MagicBit.Potentiometer.ReadRatio();
    // Read the luminosity sensor ratio from 0.0 (full dark) to 1.0 (full light)
    var lumi = MagicBit.Luminosity.ReadRatio();
    Console.CursorTop = 4;
    Console.CursorLeft = 0;
    Console.WriteLine($"Pot: {ratio * 100:N2}%  ");
    Console.CursorTop = 5;
    Console.CursorLeft = 0;
    Console.WriteLine($"lum: {lumi * 100:N2}%  ");
    cancellationTokenSource.Token.WaitHandle.WaitOne(200, true);
}

Servo motor

Servo motor can be attached to. So far, you have a direct and easy way on the blue pin. This full sample shows how to change the angle from 0 to 180 degrees, displays the next angle and wait for the left button to be pressed to stop:

CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
MagicBit.ButtonLeft.Press += (sender, e) =>
{
    cancellationTokenSource.Cancel();
};

Console.Clear();
Console.WriteLine("Servo");
Console.CursorTop = 2;
Console.WriteLine("Clk left button to stop");

// The servo can be different and you can adjust the values as needed
var servo = MagicBit.GetServoPinBlue(180, 500, 2400);
// This is needed to start the servo
servo.Start();
int angle = 0;
while (!cancellationTokenSource.Token.IsCancellationRequested)
{
    servo.WriteAngle(angle);
    angle = angle == 0 ? 180 : 0;
    Console.CursorTop = 4;
    Console.CursorLeft = 0;
    Console.WriteLine($"Angle: {angle}deg  ");
    cancellationTokenSource.Token.WaitHandle.WaitOne(3000, true);
}

// Don't forget to stop it at the end.
servo.Stop();

Note: it is technically possible to use any available pin to plug a servo motor. The board package will make your life easy if you are using the blue pin. Otherwise, you'll have to set up the Servo motor yourself.

Leds

The 4 embedded leds are available.

MagicBit.LedBlue.Write(PinValue.High);

Important: You cannot use them with the motors as they are using the same pins.

I2C Device

By default you can get an I2C Device thorough the red pins. You can either use GetRed or GetI2cDevice. For example if you wan to create an I2C Device with the address 0x42, just do:

var myI2cDevice = MagicBit.GetI2cDevice(0x42);

Black left and right pins

You can get a GPIO Pin, so a pin you can use a single output or input from the Black pins directly. Both GetPinBlackLeft and GetPinBlackRight will give it to you:

// This will create an output mode pint, you can for example attach a led
var myPin = MagicBit.GetPinBlackLeft(PinMode.Output);
// This will change the pin to high
myPin.Write(PinValue.High);

Blue pin

The blue pin is setup by default to be used as PWM. When getting it, you'll get a PWM Channel:

var myPwm = MagicBit.GetPinBlue();

Changing default pin behavior

This is a more advance scenario but you can change the function of any pin if you did not use the default function before. For example, you can from the black left pin create a PWM chanel as well:

Configuration.SetPinFunction(32, DeviceFunction.PWM11);
var myBlackPwm = PwmChannel.CreateFromPin(32);

Even if the blue pin default behavior is PWM, if you do not ask for it, you can use it in a different way. For example as a simple input:

var myBluePin = MagicBit.GpioController.Open(26, PinMode.Input);

Known limitations

There are few sensors that will not work, see the list below, the reasons and possible mitigation:

  • DHT sensor is not supported yet on ESP32 .NET managed code. You can use one of the other supported temperature and humidity sensor. See here.
  • The HCSR04 which is on the robot is not yet supported as it's using the same pin for emission and reception of the signal. This is work in progress to find a solution. The one sold separately, when used with the red port will perfectly work.
  • The QRT Sensors are not yet supported as a group, this is work in progress. In the mean time, you can read them as analog sensors individually.

Feedback and documentation

For documentation, providing feedback, issues and finding out how to contribute please refer to the Home repo.

Join our Discord community here.

Credits

The list of contributors to this project can be found at CONTRIBUTORS.

License

The nanoFramework Class Libraries are licensed under the MIT license.

Code of Conduct

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behaviour in our community. For more information see the .NET Foundation Code of Conduct.

.NET Foundation

This project is supported by the .NET Foundation.

Product Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.196 434 12/11/2025
1.2.195 295 11/13/2025
1.2.193 203 10/6/2025
1.2.191 171 7/31/2025
1.2.190 196 7/28/2025
1.2.189 301 4/10/2025
1.2.188 273 4/3/2025
1.2.187 250 4/2/2025
1.2.186 260 4/2/2025
1.2.185 244 3/13/2025
1.2.184 263 3/10/2025
1.2.183 268 3/10/2025
1.2.181 206 2/26/2025
1.2.180 209 2/25/2025
1.2.179 185 2/25/2025
1.2.178 204 2/4/2025
1.2.177 228 2/4/2025
1.2.176 217 2/4/2025
1.2.175 187 2/3/2025
1.2.174 201 1/31/2025
1.2.173 197 1/31/2025
1.2.169 219 1/30/2025
1.2.168 197 1/23/2025
1.2.167 191 1/20/2025
1.2.166 189 1/16/2025
1.2.164 251 1/2/2025
1.2.163 198 12/30/2024
1.2.162 224 12/26/2024
1.2.161 196 12/19/2024
1.2.159 202 12/5/2024
1.2.158 234 10/24/2024
1.2.157 207 10/21/2024
1.2.156 218 10/7/2024
1.2.155 246 9/30/2024
1.2.154 190 9/9/2024
1.2.153 225 9/5/2024
1.2.152 207 8/29/2024
1.2.151 235 8/26/2024
1.2.150 233 8/12/2024
1.2.149 195 8/8/2024
1.2.148 168 7/29/2024
1.2.147 207 7/22/2024
1.2.146 219 7/18/2024
1.2.145 253 7/15/2024
1.2.144 219 7/11/2024
1.2.142 257 6/20/2024
1.2.140 197 6/17/2024
1.2.137 228 5/30/2024
1.2.135 242 5/20/2024
1.2.133 230 5/16/2024
1.2.130 235 4/18/2024
1.2.128 222 4/8/2024
1.2.126 229 3/25/2024
1.2.124 260 3/18/2024
1.2.122 231 3/14/2024
1.2.120 254 2/29/2024
1.2.118 219 2/26/2024
1.2.116 241 1/26/2024
1.2.103 327 11/13/2023
1.2.101 209 11/9/2023
1.2.98 185 11/9/2023
1.2.96 274 10/9/2023
1.2.94 233 10/5/2023
1.2.92 215 9/28/2023
1.2.90 238 9/18/2023
1.2.88 227 9/7/2023
1.2.86 254 9/4/2023
1.2.84 282 8/17/2023
1.2.82 250 8/14/2023
1.2.80 279 8/3/2023
1.2.78 264 7/31/2023
1.2.76 259 7/27/2023
1.2.74 246 7/24/2023
1.2.72 286 7/20/2023
1.2.70 275 7/17/2023
1.2.68 285 7/13/2023
1.2.66 327 6/22/2023
1.2.64 267 6/19/2023
1.2.62 260 6/15/2023
1.2.60 303 6/12/2023
1.2.58 329 6/8/2023
1.2.56 274 6/5/2023
1.2.54 298 5/29/2023
1.2.52 314 5/25/2023
1.2.50 307 5/22/2023
1.2.46 317 5/15/2023
1.2.44 324 5/11/2023
1.2.42 299 5/8/2023
1.2.40 345 4/3/2023
1.2.38 372 3/27/2023
1.2.36 381 3/23/2023
1.2.34 409 3/20/2023
1.2.32 399 3/16/2023
1.2.30 382 3/13/2023
1.2.28 405 3/9/2023
1.2.26 393 3/2/2023
1.2.24 417 2/27/2023
1.2.22 424 2/23/2023
1.2.20 405 2/20/2023
1.2.18 424 2/16/2023
1.2.16 441 2/6/2023
1.2.13 489 1/16/2023
1.2.2.16170 473 12/25/2022
1.1.0.96 558 11/15/2022
1.1.0.94 539 11/14/2022
1.1.0.92 542 11/6/2022
1.1.0.90 557 11/4/2022
1.1.0.88 526 11/3/2022
1.1.0.86 538 11/1/2022
1.1.0.84 600 10/27/2022
1.1.0.82 603 10/26/2022
1.1.0.80 569 10/25/2022
1.1.0.78 603 10/24/2022
1.1.0.76 592 10/23/2022
1.1.0.74 587 10/22/2022
1.1.0.72 609 10/13/2022
1.1.0.70 592 10/12/2022
1.1.0.68 600 10/9/2022
1.1.0.65 634 9/23/2022
1.1.0.63 630 9/22/2022
1.1.0.61 675 9/16/2022
1.1.0.59 666 9/15/2022
1.1.0.57 635 9/9/2022
1.1.0.55 591 9/8/2022
1.1.0.53 581 9/5/2022
1.1.0.51 633 8/16/2022
1.1.0.49 609 8/15/2022
1.1.0.47 632 8/7/2022
1.1.0.45 638 8/6/2022
1.1.0.43 619 8/5/2022
1.1.0.41 605 8/4/2022
1.1.0.39 622 8/3/2022
1.1.0.37 604 8/2/2022
1.1.0.34 640 7/25/2022
1.1.0.32 610 7/24/2022
1.1.0.30 647 7/23/2022
1.1.0.28 677 7/10/2022
1.1.0.26 645 7/9/2022
1.1.0.24 659 7/8/2022
1.1.0.22 665 7/1/2022
1.1.0.20 625 6/30/2022
1.1.0.18 655 6/29/2022
1.1.0.16 665 6/27/2022
1.1.0.14 633 6/25/2022
1.1.0.12 636 6/24/2022
1.1.0.10 663 6/16/2022
1.1.0.8 621 6/15/2022
1.1.0.6 644 6/14/2022
1.1.0.4 618 6/1/2022
1.0.1-preview.101 251 3/26/2022
1.0.1-preview.99 266 3/25/2022
1.0.1-preview.97 278 3/22/2022
1.0.1-preview.95 275 3/21/2022
1.0.1-preview.93 263 3/20/2022
1.0.1-preview.91 257 3/18/2022
1.0.1-preview.89 270 3/18/2022
1.0.1-preview.87 282 3/17/2022
1.0.1-preview.85 258 3/16/2022
1.0.1-preview.83 255 3/14/2022
1.0.1-preview.81 280 3/14/2022
1.0.1-preview.79 263 3/12/2022
1.0.1-preview.77 248 3/9/2022
1.0.1-preview.75 257 3/7/2022
1.0.1-preview.73 256 3/4/2022
1.0.1-preview.71 260 3/3/2022
1.0.1-preview.69 264 2/28/2022
1.0.1-preview.67 255 2/27/2022
1.0.1-preview.65 290 2/26/2022
1.0.1-preview.63 269 2/19/2022
1.0.1-preview.61 257 2/18/2022
1.0.1-preview.57 306 2/17/2022
1.0.1-preview.55 297 2/16/2022
1.0.1-preview.53 278 2/13/2022
1.0.1-preview.51 264 2/12/2022
1.0.1-preview.49 264 2/11/2022
1.0.1-preview.47 262 2/10/2022
1.0.1-preview.45 283 2/9/2022
1.0.1-preview.43 293 2/5/2022
1.0.1-preview.41 285 2/1/2022
1.0.1-preview.39 284 1/28/2022
1.0.1-preview.37 280 1/28/2022
1.0.1-preview.35 270 1/28/2022
1.0.1-preview.33 297 1/28/2022
1.0.1-preview.31 309 1/27/2022
1.0.1-preview.29 278 1/25/2022
1.0.1-preview.27 268 1/22/2022
1.0.1-preview.25 273 1/21/2022
1.0.1-preview.24 292 4/16/2022
1.0.1-preview.23 316 1/21/2022
1.0.1-preview.22 293 4/15/2022
1.0.1-preview.21 278 1/21/2022
1.0.1-preview.20 260 4/6/2022
1.0.1-preview.19 277 1/21/2022
1.0.1-preview.18 258 4/3/2022
1.0.1-preview.17 272 1/20/2022
1.0.1-preview.16 250 3/31/2022
1.0.1-preview.15 271 1/17/2022
1.0.1-preview.13 269 1/11/2022
1.0.1-preview.10 351 11/10/2021