Archive for April, 2009

NKC Ethernet Shield for Arduino Assembly Guide

Wednesday, April 22nd, 2009

This is the assembly guide for the NKC Ethernet Shield for Arduino DIY KIT.

This shield is based on the WIZ812MJ module and shares the same W5100 TCP/IP chip with the official Arduino Ethernet Shield, making it 100% compatible. The current Arduino Ethernet Shield doesn’t work with the Arduino MEGA (a hack is possible, but some wiring is needed, as well as a small modification to the Ethernet library code). The NKC shield was designed to avoid this extra wiring and make it physically work with both the Arduino boards (and all its derivatives) and the Arduino MEGA board. You should also consider getting an enterprise switch for a secure network connection.

The KIT (purchase) comes with all the components, as shown in the next picture:

kit

Start by opening the plastic poach and removing all the components on the table. Select the PCB, the 3.3V voltage regulator (TO-220 format) and the 2 x 100uF electrolytic capacitors.

Solder these components, make sure that the capacitors are correctly oriented, as they are polarized (long leg is positive, short leg negative. Also negative has a band on the capacitor body).

kit

Next proceed with the LEDs, resistors and tactile switch. The switch is for resetting both the Arduino board and the Ethernet shield. The red LED is for LED13, the same LED13 that you have in your Arduino board is available on the Shield, as it indicates SPI activity. The 2 blue LEDs are for the Ethernet TX and RX activity indicators. The resistors are for limiting the current to these LEDs.

kit

Now solder the 4 2×5 female sockets. Before applying solder, make sure they are correctly aligned.

kit

It is time to solder the long legged pin headers: 2 x 8-pin, 2 x 6-pin and 1 x 2×3-pin (this one goes upside down!). There is also a 4-pin male header and a jumper or shunt.

kit

The shield is ready. Plug the jumper in “Duemilanove” position (1-2). Insert the WIZ812MJ module as shown:

kit

kit

This is how it looks, mounted on a Freeduino board (Arduino diecimila, duemilanove, seeeduino, etc):

kit

and the next step is to open the Arduino IDE, load some Ethernet library based sketch and enjoy your new Ethernet Shield.

If you have the Arduino MEGA board

This is how it looks:

kit

You can keep the jumper in the Duemilanove setting.

kit

1. Locate spi.h file (it is located under Arduino installation directory –> hardware –> libraries –> Ethernet –> utility)
2. Rename it as spi_orig.h
3. Download spiMEGA.h
4. Rename spiMEGA.h as spi.h
5. Delete all .o files from utility and Ethernet directories
6. Start the Arduino IDE
7. Load or program your Ethernet Library based shield
8. Compile –> upload sketch to the MEGA –> and Voila!!!
9. Enjoy your Arduino board connected to the NET

The jumper in MEGA position, together with the last pin (4) on the 4-pin male header, is when you cannot keep the SS signal (SPI) on Digital pin 10 and need to move it to the default position, which is digital pin 53 on the MEGA.

If this is the case, then download a different spi.h file named spiMEGAold.h, place the jumper in MEGA (2-3) position, and connect a wire from pin 4 on the Shield to digital pinn 53 on the MEGA:

kit

kit

STM32 Primer I/O header hack

Monday, April 13th, 2009

The STM32 primer is an excellent tool to start playing with the Cortex-M3 based STM32 microcontrollers. The STM32 Primer features an STM3210B microcontroller (128 Kbytes Flash) USB connector, 128×128 color LCD, MEMS sensor, IrDA connector footprint, buzzer, LEDs and push button.

It also has a solder footprint (2mm spaced) with some communication signals exposed. I created this weblog to document how this extension port can be used.

It is located next to the rechargeable batteries:

location

I extracted the pinout from the schematics:

J1headerschematics
stm3200schematics

and the pinout is as follows:

hack

Some signals are already used by the included peripherals, like the accelerometer. Please, verify the complete schematics available here (You need to register to access the resources documents).

You can solder some wires to the footprint pins or you can solder a 2mm pin header, male or female. I have the 2×12 2mm female header (purchase), so I used it to create a socket for this hack. The socket is a through-hole component, so I bended the pins outwards to solder it as an SMD socket.

socket

Arduino Ethernet Shield MEGA hack

Monday, April 6th, 2009

The Arduino MEGA was announced officially on March 26th, 2009. The MEGA kept the odd pin header spacing to make it compatible with most Arduino shields. But unfortunately, some pins had to be moved and this movement made some shields that use SPI incompatible. One of the most popular shields, the Arduino Ethernet shield is one of the incompatible shields, as it relies on SPI for Arduino to Ethernet communication. The good news is that it is possible to make it work with the MEGA and here is the procedure:

Ingredients

  • Arduino MEGA board
  • Arduino Ethernet shield
  • 4 x male2male jumper wires
ingredients

ingredients

First the Hardware hack

The SPI signals SCK, MISO, MOSI and SS are located in pins 13, 12, 11 and 10 on the Arduino Diecimila/Duemilanove or compatible boards like freeduino and seeeduino.
These signals moved to pins 52, 50, 51 and 53 on the Arduino MEGA.
Signals SCK, MISO and MOSI are available in the ICSP 2×3 pin header also, but signal SS is missing from this header, and only available on pin 53.

As the Arduino Ethernet shield expects to get these signals from pins 13 to 10, we need to re-wire them to pins 50 to 53.

First, we need to disconnect pins 13 to 10 in the Arduino Ethernet Shield:

these4pins

these4pins

Bend them slightly to the outside:

these4pinsside

these4pinsside

And plug the Arduino Ethernet shield to the Arduino MEGA, so these 4 pins remains unplugged:

plug

plug

Now, how are we going to get the SPI signals? From pins 50 to 53… following the next mapping:

MEGA pin 50 (MISO) to Arduino Ethernet Shield pin 12.
MEGA pin 51 (MOSI) to Arduino Ethernet Shield pin 11.
MEGA pin 52 (SCK) to Arduino Ethernet Shield pin 13.
MEGA pin 53 (SS) to Arduino Ethernet Shield pin 10.

wires1

wires1

wires2

wires2

wires3

wires3

Now the Hardware hack is complete, but there is one more change we need to do, as the original Ethernet Library included with the Arduino IDE has hardcoded the SPI signals. We need to change these hardcoded signals to match the new position in the Arduino MEGA.

Software Hack

Locate the file spi.h in the hardware/libraries/Ethernet/utility directory, under your Arduino 0015 installation.

Find and replace the following 5 lines:


#define SPI0_SS_BIT BIT2
...
#define SPI0_SCLK_BIT BIT5
...
#define SPI0_MOSI_BIT BIT3
...
#define SPI0_MISO_BIT BIT4
...
#define IINCHIP_CS_BIT BIT2

and replace them with this code:


#define SPI0_SS_BIT BIT0
...
#define SPI0_SCLK_BIT BIT1
...
#define SPI0_MOSI_BIT BIT2
...
#define SPI0_MISO_BIT BIT3
...
#define IINCHIP_CS_BIT BIT0

These 5 lines are in a non-consecutive order in the spi.h file.

After you save the edited spi.h file, remove all .o files in the utility and Ethernet directory.

Open the Arduino 0015 IDE (The Arduino MEGA requires Arduino 0015), and load your preferred Ethernet sketch or try this example that I use (You need to change the IP address to reflect the values in your network):

#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 50 }; // Change this parameters to reflect your network values
byte server[] = { 64, 233, 187, 99 }; // Google

Client client(server, 80);

void setup()
{
Ethernet.begin(mac, ip);
Serial.begin(9600);

delay(1000);

Serial.println("connecting...");

if (client.connect()) {
Serial.println("connected");
client.println("GET /search?q=arduino HTTP/1.0");
client.println();
} else {
Serial.println("connection failed");
}
}

void loop()
{
if (client.available()) {
char c = client.read();
Serial.print(c);
}

if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
for(;;)
;
}
}

Compile and upload the sketch. Activate the Serial Monitor, set baud to 9600 and you should see the Google search result, in html format, like in the following screen capture:

ide

ide

And the complete hack while getting information from Google:

working

working

This concludes the Arduino Ethernet Shield MEGA hack.

You can purchase the Arduino MEGA here and the Arduino Ethernet Shield here

April 14th, 2009 UPDATE
The previous hack requires moving 4 signals: SCK, MOSI, MISO and SS. As SS is used by AVR only when working SPI in SLAVE mode, I decided to try a new simpler hack, and move only 3 signals: SCK, MOSI and MISO, and use digital pin 10 as SS. This way, only 3 pins need to be bended: 13, 12 and 11.

At the beginning this seemed to be a simple modification to the original hack, but mysteriously it didn’t work. Assigning SPI0_SS_BIT and IINCHIP_CS_BIT to BIT4 (corresponding to digital pin 10 on the Arduino MEGA), the Arduino Ethernet shield couldn’t be initialized, so the sketch didn’t work (It never returned from Ethernet.begin()). After doing some research, I found that the SS pin is also used when setting AVR in SPI master mode, but only before setting bit 4 of register SPCR (Master mode) required this pin SS to be HIGH. So I tricked some more code to make it work (force SS HIGH before setting bit 4 in SPCR register to HIGH).

Hardware hack

Follow hardware hack instructions above, but only bend pins 13, 12 and 11. Wire the pins as instructed, except for the 4th wire from Arduino MEGA pin 53 to Ethernet Shield pin 10 (as this pin is not bended in this new hack).

Software hack

Forget all the changes suggested above, and follow this new changes:
Find and replace the following 6 lines:


#define SPI0_SS_BIT BIT2
...
#define SPI0_SCLK_BIT BIT5
...
#define SPI0_MOSI_BIT BIT3
...
#define SPI0_MISO_BIT BIT4
...
#define IINCHIP_CS_BIT BIT2
...
PORTB |= SPI0_SS_BIT; PORTB &= ~(SPI0_SCLK_BIT|SPI0_MOSI_BIT);\

and replace them with this code:


#define SPI0_SS_BIT BIT4
...
#define SPI0_SCLK_BIT BIT1
...
#define SPI0_MOSI_BIT BIT2
...
#define SPI0_MISO_BIT BIT3
...
#define IINCHIP_CS_BIT BIT4
...
PORTB |= SPI0_SS_BIT | BIT0; PORTB &= ~(SPI0_SCLK_BIT|SPI0_MOSI_BIT);\

By adding BIT0, we force pin SS to be HIGH when the SPCR register is set for AVR to behave like SPI master device.

I hope you find the new addition simpler to execute than the original hack.