"Netduino - Getting Started with *" Series
- Posted: Dec 30, 2011 at 6:00 AM
- 21,050 Views
- 3 Comments
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
The final Hardware Friday post of the year can't just be on one project now can it? Let's get ourselves set for another great year and get set to hit the ground running building some fun Netduino projects with a great set of Getting Started series by Jeroen Swart
If you want to show more output then blinking LED’s, an LCD module is a good and usually affordable option. They come in different sizes, from 2 numeric-only digits to 40x4 alphanumeric dot-matrix modules. You can also get graphic LCD’s, that range from modules with small resolutions (e.g. 122x32 or 240x128 pixels) to more professional LCD screens (e.g. 5” or 7”), but I will stick with alphanumeric LCD’s for this post.
In my previous post, I explained how I used the Adafruit motorshield to control a steppermotor. Since this shield uses a shift register, it needs a lot of I/O-actions. To control the steppermotor without a shift register, I put together part of the motorshield schematic on a breadboard. What remains is a single L293D with a few supporting parts, as shown in the schematic below.
Working with steppermotors is a bit more complex then working with regular DC motors. Apply a voltage to a DC motor and it will rotate. With stepper motors, you need to apply that voltage in a specific pattern.
Instead of using a single coil, as in a DC motor, most steppermotors use two coils. The number of steps is determined by the number of magnetic poles on the rotor. Two common types of steppermotors are unipolar and bipolar steppermotors.
I2C is a serial communication protocol, used for communication between IC's. It uses two wires: one for data (SDA) and one for a clock signal (SCL). For more details on this protocol, check this Wikipedia article.
The Netduino has one I2C port which is available on pin A4 (SDA) and A5 (SCL). The I2C protocol works as a bus, so you can connect more than one slave devices to the one I2C port of the Netduino. For the I2C bus to work properly, you need to add two pull-up resistors to pins A4 and A5, regardless of the number of devices connected to the bus.
A common communication protocol is RS232. This is a serial protocol, which uses two wires to transmit data in both directions one bit at a time. A port using this protocol is usually simply called a serial port, because it’s one of the most commonly used protocols for serial communication.
Connecting two devices using RS232 can be as simple as connecting 3 wires between them: transmitted data (TxD), received data (RxD) and ground. It is also possible to connect up to 6 more wires, which handle the handshake part of the RS232 protocol. Handshaking is used to synchronize the communication between the devices: e.g. to let the other device know data was sent or it’s ready to receive data. With 3 wires, and no handshaking, both sides must agree upon the details of the communication: the speed and the number of data-, start- and stop-bits.
The Netduino Plus has an on-board SD-card slot. It is connected to one of the SPI ports of the microcontroller. Fortunately, you don't need to write code to control the SPI port yourself. The firmware handles this for you, so all you need to do is work with the classes from the System.IO namespace. Do remember that this is the Micro .NET framework and it is not as rich as the full .NET framework, but it does provide enough implementation for working with the SD card.
The Netduino contains several ports (A0 - A5) that are capable of reading an analog signal and changing it into a digital representation of that signal. These ports can be used for digital I/O as well, but can individually be configured to use an internal ADC (Analog to Digital Converter).
PWM (or Pulse Width Modulation) is a technique that basically allows digital circuits to control analog circuits. One of the applications for this is to control the speed of a motor or, as I will show you in a second, the brightness of a LED.
A digital port is either on or off. This is very logical, but not very helpful when controlling an analog device like a motor. The speed of a motor is usually controlled by varying the voltage: if you set the voltage higher, more current will flow and the speed of the motor will increase.
Controlling a LED directly using a port is fine in most cases, because a LED only requires a small current that can be supplied by the Netduino. But when controlling components that require more current (like high-power LED’s, motors, relays, etc.) a transistor is needed. The transistor is controlled by a small current from the MCU and the transistor controls the heavy load. While transistors actually work as amplifiers, they can also be used as switches.
After getting the blinking LED, the next thing to do is experiment with a switch. Besides an on-board LED, the Netduino also comes with an on-board switch, so we can work without extra components.
There are two ways to use a digital input-port. As an InputPort, which requires us to constantly check for an input-value ourselves, or as an InterruptPort, which will provide an event when the value changes. I will show code for each.
Last week I finally received my Netduino, after it had spent almost a week at customs . I didn’t have much time last weekend, but luckily it doesn’t take much time to get started with the Netduino.
I also ordered a breadboard shield and a motor shield. The breadboard shield is very handy for experimenting small projects, but a separate breadboard is even better. And with some wiring you can use them together, of course.
How to install, connect, start coding, deploy and debug your Netduino projects is very well described in this document on the Netduino website. So there is no point in repeating that here. One tip though: use a separate solution for each project. You can add libraries to the solution of course. I started with a single solution with several projects, each representing a different hardware project. Even though I set a specific project as the ‘Startup Project’, Visual Studio still started the first project I added to the solution when I hit F5. A workaround is to select the correct project in the Solution Explorer, open it’s context-menu and select ‘Debug’, then ‘Start new instance’.
Hopefully that will give every Netduino dev something to think about and play with...
Here’s a few more links you might find interesting: