Nut/OS LED Tutorial - Step 2
A word of caution first. As stated in the Hardware Manual, the Ethernut board is highly sensitive to static electricity Never handle the bare board without proper precautions.
Four simple electronic hardware parts are required for this tutorial:
- 1 Resistor
- 1 LED
- 2 female pinhead sockets
The resistor will be connected in series with the LED to limit the current. Without this resistor, a very high current would flow through the LED and destroy not only the LED, but also the Ethernut Board. According to Ohm's Law
R = U / I
A typical standard LED requires a current of 20 mA to lit up with full brightness. However, even at a much lower current it will emit some light. When connecting any electronic circuit to the [[../hardware/expansion.html|Ethernut expansion port]] , we need to make sure, that the port bit we are using is able to supply enough current. The absolute maximum can be found in the datasheet of the Ethernut CPU. On Ethernut 1 and 2 the ATmega128 is used and the datasheet states a maximum rating of 40 mA. But note, that this value is the absolute maximum and should never be reached. Let's start with 2 mA. The voltage used on the Ethernut 1 and 2 expansion port is 5 Volts. Most LEDs got a voltage drop of about 1.4 V to 2.1V. Thus, the voltage at the resistor may reach 3.6 V.
R = 3.6 V / 0.002 A
result in a resistor value of 1800 V/A, or 1.8 kΩ. For 20 mA we calculate
R = 3.6 V / 0.02 A
This results in a resistor of 180 Ω. For our hardware we select a value of 1 kΩ, in which case the current is limited to
3.6 V / 1000 Ω = 0.0036 A
Running a normal LED at 3.6 mA won't offer much light unless we use a low power or very high efficiency type. Anyway, it's still sufficient for our tutorial.
Note, that LEDs do have a polarity and typically one of the two leads is longer than the other one. The longer lead is the anode and will be connected to the resistor while the shorter one will be connected to the Ethernut expansion port.
It is of course possible to directly solder the resistor and the LED to the pins of the expansion port, but that would spoil our Ethernut. It's a much better idea to use some kind of connectors. The two shown on the photo had been cut from a single line, female pinhead socket.
Soldering And Mounting
The schematic is quite simple.
We need three solder joints.
- Solder the resistor to one connector.
- Solder the long lead of the LED to the other wire of the resistor.
- Solder the short lead of the LED to the second connector.
The positive pole of the LED will be connected to the Ethernut 5 Volts power supply via the resistor and the negative pole of the LED to one of the port pins. Later on we will switch the port pin from 5 Volts to 0 Volts to lit the LED.
The 5V power supply is available at pins 3 and 4 of the expansion port. The outer first pin on the side with the RS232 connector is pin 1, the inner is pin 2 and, you guessed it, the second outer pin is pin 3. Connect the connector with the resistor to pin 3 of the Ethernut expansion port
Which port pin to use? Port E is the nearest to our power supply pin. However, port bits 0 and 1 are used for RS232 communication. The next available one is Port E bit 2, which is located at pin 41 of the expansion port. Attach the connector with the LED to this pin.