Netduino, Visual Basic and PWM to drive a DC motor

Today was yet another rainy day. I was looking forward to doing some work outside but it wasn’t meant to be. I don’t like rain and mud so I blew the dust of my Netduino board that I’ve come to hate. I hadn’t touched it in almost a year.

Last year I broke my teeth on getting a RFID card reader to work over I²C for a school project. It turns out that all I did was probably good. To make sure I bought a I²C real time clock to test my own hardware and code. I was able to address that I²C device. But the RFID reader I got for free is probably either broken or not following the I²C standards. The emails I sent for support to the owner of the small company remain unanswered and the firm’s website is down long since so I guess they’re out of business. I questioned myself and all my own hardware and even the Netduino soft- and firmware but not the RFID reader that was given to me by a company making commercial products with it. But the harm was done and I was disgusted by the Netduino board and technology in general. Remember?

A while later I pulled myself together and looked online for code to adapt to communicate over TCP/IP. I needed to straighten that out to help one of my students in a school project. When I pulled that off in a January weekend, I moved the box with all the development stuff upstairs and haven’t touched it until today. Nevertheless two years ago I had wild ham radio related plans with it when I bought it. I even bought a lot of parts for those projects. Maybe later?

Since VB support on the official forum is a bit substandard or at least sub-my-standard I recently began writing small bits of code to master the basic I/O operations like digital I/O, analogue input, interrupts, time synch over NTP and now basic PWM for a DC motor speed control. It’s a work in progress since I get many interrupts myself hogging my scarce free time.

Together with the board I bought a small experimenter’s kit. Very convenient. So today I wrote the PWM code and made the circuit on the breadboard. A resistor, a fly back diode to put across the motor terminals and a small NPN transistor are part of the kit. It’s a 2N2222 transistor. PWM duty cycle is controlled by a varying DC voltage to an analog input. I make a voltage divider with a small potmeter whose wiper I connect to the ADC. Very simple stuff, the hardware as well as the software. Yet it didn’t work. Drives me crazy. Just my luck. What’s up with this freakin’ board and all I try to do with it?

I triple checked the circuit but that seemed OK. I converted the PWM output to a simple on/off circuit. That’s just SMOP reconfiguring the output’s behaviour. Still no luck. Voltages measured pointed to a transistor that just didn’t want to conduct. A brand new 2N2222 that came with the kit. I replaced it with a BC547 out of my own stock and the on/off circuit worked right away. Why do I always end up with broken parts although they’re new out of the box?

Back to making a PWM – that turned out to be fairly easy yet I keep messing with the board. It loses connection with the computer over USB and needs a lot of unplugging/reconnecting. Is it me or does the board’s system design have some flaws?

I lost quite some time before accepting that the transistor was broken and I was missing a reference to a DLL. That took me some time to figure out too. But now I figured out basic PWM for a simple DC motor.

One day I hope to use all this preparatory work in a ham radio project. The schematics are in the PDF. If you want code, just ask. Pictures and movies take too much time to get from the camera, process and embed here.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.