This project showcases how to use Windows 10 IoT Core on a Raspberry Pi 3 to spin a motor by providing input to a motor controller and then measuring the speed of the spinning motor using a digital encoder. We use the digital encoder feedback in a PID loop to control the speed of the motor and by doing this, we created a closed loop control system!
In addition, it demonstrates the Windows 10 IoT Core's capabilities to provide and interact with a Remote UI and sensors.
After doing this, we began using the T-Nuts and Corner Brackets to solidify a framing using 90 degree angles and then attached the perforated polycarbonate sheet.
Once the framing has been created, the next step was to attach the Aluminum Base Mount for the Ball Bearings for 3/8" shaft diameter.
Then attached the wheel to pieces of 3/8" shaft using the 375 Key Hub, 3/32" Key Stock, set screw shaft collar, screws, and nuts.
Then we mounted the CIMple Gearbox which had been assembled with the motor, PID controller and the proper gears and shafts.
After which we attached the CIMple Gearbox shaft to the 3/8" shaft using a custom bored reduction coupler (custom bored to reduce from 1/2" to 3/8").
Then we mounted and hooked up the motor controller, fuse, and circuit breaker to the motor and battery.
Hook up the pins for the digital encoder and motor controller to the PWM/Servo HAT:
Then we hooked up the Touchscreen - follow this guide by the manufacturer.
Like all other Windows 10 IoT Applications, deployment happens through Visual Studio, but you will need to install the latest Windows 10 IoT Core Insider Preview image and follow the setup instructions.
Then download the repository containing the code for the project (Coming soon).
Open up the Visual Studio project.
Then deploy it to your Raspberry Pi 3 (more info on deployment can be found here).
This project is a great example of how writing Universal Windows applications allows you to seamlessly operate in a mixed mode of using both C++ and C# components that can run across devices. In addition it utilizes both Arduino Wiring and the Lightning Providers which make use of a direct memory-mapped driver that offers high performance GPIO.
There are four main components.
The DemoApp project contains the main UI for the demo and includes the Motor and PidController projects. The demo can run in two modes.
In throttle mode the slider will adjust the throttle of the motor between 0 and 100%. While the motor controllers used are capable of driving the motor in reverse, this project doesn't use that functionality but it can easily be achieved by setting a negative percentage as the motor throttle.
In closed-loop mode the application will control the motor throttle to achieve the desired RPM which is again set with the slider control.
The Motor project contains the logic for getting the RPM of the motor shaft and controlling the motor throttle. It is written in C++ and uses Arduino Wiring as well as our Lightning Providers. Throttle is controlled using a PWM-controlled motor controller which is attached to an Adafruit PWM Servo Hat. The RPM value is calculated using Lightning and an optical encoder. This is as easy as using the Arduino Wiring attachInterrupt syntax you're already familiar with in C++. This is where the high performance of the Lightning direct memory-mapped driver is necessary so we can process the encoder interrupts at an acceptable rate. Knowing the pulses per revolution value of the encoder along with the elapsed time between interrupts we can easily calculate the RPM. This results in the RPM being calculated hundreds of times a second which can lead to a very noisy output so we used an exponential moving average to smooth it out.
Note: For the Lightning Providers to work you need to enable the direct memory-mapped driver. Directions for doing that can be found here.
The PID Controller project is a Universal Windows Runtime Component written in C# that implements a very simple proportional-integral-derivative controller that can be reused in any project the requires closed-loop control.
We will continue to update this post as new functionality is released via the Windows Insider Program. Here are some things to look forward to in the coming months.
Did you replicate this project? Share it!I made one
Love this project? Think it could be improved? Tell us what you think!