{"id":28389034,"url":"https://github.com/perpetualkid/brickpi.uwp","last_synced_at":"2025-06-27T16:31:07.291Z","repository":{"id":99404113,"uuid":"63268488","full_name":"perpetualKid/BrickPi.Uwp","owner":"perpetualKid","description":"Windows 10 IoT Core UWP implementation for Raspberry Pi \u0026 Dexter BrickPi LEGO MINDSTORMS board","archived":false,"fork":false,"pushed_at":"2018-11-24T19:02:29.000Z","size":214,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-06-23T21:00:00.864Z","etag":null,"topics":["brickpi","iot-core","lego-mindstorms","mindstorms","raspberry","raspberry-pi","windows-iot"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/perpetualKid.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-07-13T18:05:24.000Z","updated_at":"2024-07-17T07:38:15.000Z","dependencies_parsed_at":"2023-06-03T02:00:12.409Z","dependency_job_id":null,"html_url":"https://github.com/perpetualKid/BrickPi.Uwp","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/perpetualKid/BrickPi.Uwp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perpetualKid%2FBrickPi.Uwp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perpetualKid%2FBrickPi.Uwp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perpetualKid%2FBrickPi.Uwp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perpetualKid%2FBrickPi.Uwp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/perpetualKid","download_url":"https://codeload.github.com/perpetualKid/BrickPi.Uwp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perpetualKid%2FBrickPi.Uwp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262293022,"owners_count":23288645,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["brickpi","iot-core","lego-mindstorms","mindstorms","raspberry","raspberry-pi","windows-iot"],"created_at":"2025-05-31T00:12:08.713Z","updated_at":"2025-06-27T16:31:07.285Z","avatar_url":"https://github.com/perpetualKid.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BrickPi.Uwp for Windows IoT Core\n\n[Windows 10 IoT Core](https://developer.microsoft.com/en-us/windows/iot) [Universal Windows Platform (UWP)](https://msdn.microsoft.com/en-us/windows/uwp/get-started/universal-application-platform-guide) implementation for [Dexter BrickPi+](https://www.dexterindustries.com/brickpi-tutorials-documentation/) board on [Raspberry Pi](https://www.raspberrypi.org/products/raspberry-pi-2-model-b/) and enabling [LEGO MINDSTORMS](http://www.lego.com/mindstorms/) components to be controlled by Windows 10 IoT Core.\n\n#### Current Status\n\nThe code has been tested on **Raspberry Pi 2 Model B** and **Raspberry Pi 3 Model B** and Windows IoT Core OS from **Version 10.0.14393.0** and onwards (Redstone/Anniversary Update). \n\nLego Mindstorms NXT 2.0 Sensors and Motors are implemented and tested, and many of the [HiTechnic](http://modernroboticsinc.com/hitechnic_products) sensors and port multiplexer:\n\n##### Mindstorms\n- Mindstorms [NXT Touch Sensor](https://shop.lego.com/en-CH/Touch-Sensor-9843)\n- Mindstorms [NXT  Color sensor](http://shop.lego.com/en-CH/Color-Sensor-9694) (see also [Known Issues](#Known-Issues) section )\n- Mindstorms [NXT Ultrasonic Sensor](http://shop.lego.com/en-US/Ultrasonic-Sensor-9846)\n- Mindstorms [EV3 Touch Sensor](http://shop.lego.com/en-US/EV3-Touch-Sensor-45507) (untested)\n\n##### HiTechnic\n- HiTechnic NXT [Touch Sensor Multiplexer](http://modernroboticsinc.com/hitechnic-nxt-touch-sensor-multiplexer)\n- HiTechnic [Angle Sensor](http://modernroboticsinc.com/hitechnic-nxt-angle-sensor)\n- HiTechnic [Compass Sensor](http://modernroboticsinc.com/hitechnic-nxt-compass-sensor)\n- HiTechnic [Gyro Sensor (legacy)](http://www.hitechnic.com/cgi-bin/commerce.cgi?preadd=action\u0026key=NGY1044)\n- HiTechnic [EOPD Sensor](http://modernroboticsinc.com/hitechnic-nxt-eopd)\n- HiTechnic [Acceleration \u0026 Tilt Sensor](http://modernroboticsinc.com/hitechnic-nxt-acceleration-tilt-sensor)\n- HiTechnic [IR Seeker V2 Sensor](http://modernroboticsinc.com/hitechnic-nxt-irseeker-v2)\n\n## Getting Started\n\n#### Setting up a new project\n\nThe application uses the Background Application template for Windows IoT Core. \n\n \u003cimg src=\"./media/image001.png\" /\u003e\n\nAdd a reference to the BrickPi.Uwp library to your project. You can either use the source code version by cloning and compiling this Github repository, or use the [**BrickPi UWP Windows IoT Core Nuget package**](https://www.nuget.org/packages/BrickPi.UWP/).\n\nTo install BrickPi UWP Windows IoT Core, run the following command in the Package Manager Console \n`Install-Package BrickPi.UWP` or run the Package Manager UI:\n\n \u003cimg src=\"./media/image002.png\" /\u003e\n\n Search for \"BrickPi.UWP\" package:\n\n \u003cimg src=\"./media/image003.png\" /\u003e\n\n Enable the package in the current project\n\n  \u003cimg src=\"./media/image004.png\" /\u003e\n\n\nOnce the project is created, you need to enable support for serial port capabilities. This can't be done in the UI Manifest editor, so you'll need to text edit the Package.appmanifest file and add (there will be an internetClient capability by default):\n\n```XML\n  \u003cCapabilities\u003e\n\t\u003cCapability Name=\"internetClient\" /\u003e\n\t\u003cDeviceCapability Name=\"serialcommunication\"\u003e\n\t  \u003cDevice Id=\"any\"\u003e\n\t\t\u003cFunction Type=\"name:serialPort\" /\u003e\n\t  \u003c/Device\u003e\n\t\u003c/DeviceCapability\u003e\n  \u003c/Capabilities\u003e\n```\n\nFirst you need to implement a \ndeferal for the background task instance\n\n```C#\npublic sealed class StartupTask : IBackgroundTask\n{\n\tBackgroundTaskDeferral deferal;\n\n\tpublic async void Run(IBackgroundTaskInstance taskInstance)\n\t{\n\t\tdeferal = taskInstance.GetDeferral();\n\t\t//....\n\t}\n}\n```\nMore details about this can be found in the \n[Developing Background Applications](https://developer.microsoft.com/en-us/windows/iot/win10/backgroundapplications) guide.\n\n\n### BrickPi\n\nNext you need to get a reference to the BrickPi instance. The BrickPi is connected to an UART port on the Raspberry, which is referenced by name like \"UART0\". As current Raspberry Pi only have one UART available, name parameter could be dropped and the first available UART is used\n\n\n```C#\n//Need a brick and a serial port\nBrick brick = await Brick.InitializeInstance(\"Uart0\");\n```\n\nTo check basic comnunication with the BrickPi works, and see if a correct firmware version is installed on the BrickPi itself, call the `GetBrickVersion()` like this:\n```C#\nint version = await brick.GetBrickVersion();\nDebug.WriteLine(string.Format(\"Brick Version: {0}\", version));\n```\n\nThe BrickPi should always return version **2**. You should always call `GetBrickVersion()` before you configure any sensors, as this resets any sensor information. This is due to the fact how the firmware version is queried internally by setting all sensors to a specific (non-existing) sensor type.\n\nInternally, the BrickPi runs two Arduinos on the board. Each Arduino has a tiny blue LED connected, which can be controlled on corresponding GPIO-pins from the RaspBerry Pi. Arduino1 Led is connected to GPIO port 18, corresponding to pin 12 on the RaspBerry Pi 40-pin header, and Arduino2 Led is connected on GPIO port 27, corresponding to pin 13 on the RaspBerry Pi 40-pin header. Further details on GPIO pin mappings can be found at the [Raspberry Pi 2 \u0026 3 Pin Mappings](https://developer.microsoft.com/en-us/windows/iot/win10/samples/pinmappingsrpi2) overview.\n\nTo use the LED in code, you can either set the status (ON or OFF) explicitely, or just toggle from current status\n\n```C#\nbrick.Arduino1Led.Toggle();\t//change status from ON to OFF or vice versa\nbrick.Arduino2Led.Light= true;\t//explicitely set status to ON\n```\n\n### Motors\n\nMotors ([Standard NXT Motors](http://shop.lego.com/en-US/Interactive-Servo-Motor-9842)) do not need specific configuration, instances are preinitialized and can be referred through the BrickPi.Motors collection:\n\n```C#\nMotor motorA = brick.Motors[MotorPort.Port_MA];\nMotor motorD = brick.Motors[MotorPort.Port_MD];\n\n```\n\nUsing the reference, motors can be enabled and a velocity set. Velocity can be positive or negative to indicate the direction to run.\n\n```C#\nmotorA.Velocity = -50;\nmotorA.Enabled = true;\n//...\t\nmotorA.Enabled = false;\t//set the motor to float\n//...\nmotorA.Velocity = 0;\t//set the motor to hold at current position\n\n````\n\n#### Motor Encoders\n\nEncoders are part of motors and count motor rotation with 0.5 degree precision (720 ticks per revolution). To set custom encoder count, or reset the encoder, the EncoderOffset property can be used. Setting the EncoderOffset equal to current Encoder count, will reset the Encoder.\n\n```C#\nint encoderTicks = motorA.Encoder;\n//reset the Encoder\nmotorA.EncoderOffset = motorA.Encoder;\n```\n\n### Sensors\n\nSensor ports need to be initialized with the specific sensor type, as different sensors have different response data format. If not explicitely set, each sensor port is initialized as a RawSensor (technically sending a 10-bit response value), which most analog sensors are using. \n\nInstances of the specific sensor type need to be created, and attached to the Brick.Sensors collection. If multiple sensors will be attached, initialization can be hold until all sensors are created and added to the collection.\n\n```C#\nNXTTouchSensor touch = new NXTTouchSensor(SensorPort.Port_S1, SensorType.TOUCH_DEBOUNCE);\nawait brick.Sensors.Add(touch, true); //true to hold initialization until all sensors are attached\n\nNXTUltraSonicSensor ultrasonic = new NXTUltraSonicSensor(SensorPort.Port_S2, SensorType.ULTRASONIC_CONT);\nawait brick.Sensors.Add(ultrasonic, true);\n//...\nif (!await brick.InitializeSensors())\t\t//now explicitely call sensor initialization\n\tDebug.WriteLine(\"Something went wrong initializing sensors\");\n```\n\nSensor data actively needs to be polled from the BrickPi. This can be done in a single shot using `brick.UpdateValues()`. More typically, a continuous loop running polls sensor data and motor encoder data continously. Such loop can be started by calling `brick.Start()`\n\n#### Sensor Data\n\nSensor's internal data buffer will be updated either through single or continuous sensor data polling (see above). In the application, sensor data can than be accessed through the various sensor properties, i.e. the UltraSonic sensor has a property for Distance, or Touch Sensor a boolean property indicating if the button is pressed:\n```C#\nDebug.WriteLine(string.Format(\"NXT Ultrasonic, Distance: {0}, \", ultrasonic.Distance)); //distance in cm\nDebug.WriteLine(string.Format(\"NXT Touch, Is Pressed: {0}, \", touch.Pressed)); //true if pressed\n```\n\nInternally, sensor data is held as RawValue, such as 0 or 1 for touch sensor, or different color values for Color Sensor\n```C#\nDebug.WriteLine(string.Format(\"NXT Color, Raw: {0}\", color.RawValue));\n```\n\n#### Sensor Events\n\nSensors will also raise events if sensor values change\n\n```C#\ntouch.OnPressed += Touch_OnPressed;\ntouch.OnReleased += Touch_OnReleased;\ntouch.OnChanged += Touch_OnChanged;\n//...\n\nprivate void Touch_OnChanged(object sender, SensorEventArgs e)\n{\n\tif ((e as TouchSensorEventArgs).Pressed)\n\t{\n\t\tbrick.Arduino2Led.Light= true;\n\t}\n\telse\n\t{\n\t\tbrick.Arduino2Led.Light = false;\n\t}\n} \n\nprivate void Touch_OnPressed(object sender, SensorEventArgs e)\n{\n\tbrick.Arduino1Led.Light= true;\n}\n\nprivate void Touch_OnReleased(object sender, SensorEventArgs e)\n{\n\tbrick.Arduino1Led.Light= false;\n}\n\n```\n\nTo avoid raising events on noisy data, ie. where ambient light floats, or ultrasonic distance may vary by few cm, a Threshold could be set with some sensors, which means no event will be raised if the change is less than the threshold value.\n\n```C#\nultrasonic.Threshold = 5;\n```\n\n### Voltage\n\nThe BrickPi+ has an onboard MCP3031 chip, connected to the Raspberry I2C bus. This chip can be used to read the current voltage supplied to the Raspberry/BrickPi stack, i.e. to monitor power supply from battery.\n\nSimple read the brick's Voltage property.\n\n```C#\nDebug.WriteLine($\"Voltage {brick.Voltage}V\");\n```\n\n### Known Issues\n\nThere is an issue using the Mindstorms [NXT 2.0 Color sensor](http://shop.lego.com/en-US/Color-Sensor-9694) as reported multiple times in BrickPi forum [here](http://www.dexterindustries.com/topic/has-anyone-got-the-colour-sensor-to-work/), [here](http://www.dexterindustries.com/topic/brickpi-colour-sensor/) or [here](http://www.dexterindustries.com/topic/problems-with-lego-color-sensor/), where the sensor does not initialize correctly if running in `SensorType.COLOR_FULL` (all colors enabled).\nTo work around, one has to attach the sensor at the first port of a given Arduino (`SensorPort.Port_S1` or `SensorPort.Port_S3`) and leave the next Port unconnected (`SensorPort.Port_S2` or `SensorPort.Port_S4`), but initialize the same color sensor on both ports\n\n```C#\n//adding NXTColorSensor twice, on S3 and S4, to work around BrickPi issue. Order (S3 or S4 first) does not matter.\nNXTColorSensor color = new NXTColorSensor(SensorPort.Port_S4, SensorType.COLOR_FULL);\nawait brick.Sensors.Add(color, true);\ncolor = new NXTColorSensor(SensorPort.Port_S3, SensorType.COLOR_FULL);\nawait brick.Sensors.Add(color, true);\n\n```\n_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperpetualkid%2Fbrickpi.uwp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fperpetualkid%2Fbrickpi.uwp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperpetualkid%2Fbrickpi.uwp/lists"}