All posts by Michael

About Michael

Freelance PHP Symfony2 & Magento developer, passionate about programming and electronics.

Arduino Ethernet modules and Microchip ENC28J60

Ethernet Microchip ENC28J60 module

If you’d like to connect your Arduino to a local wired network, you have several options :

This last option is offering a big advantage among others : you can use a bare microcontroller (ie. ATMega328) if you don’t need a “big” Arduino Uno for your circuit, which is my case.

As the WIZnet W5100 chip, which is also part of Ethernet shields, the Microchip ENC28J60 chip uses SPI to communicate with micocontrollers.

It can be wired to an Arduino Uno or ATMega328 as following :

Microchip ENC28J60 Arduino Uno ATMega328
INT D2 Pin 4
SO D12 Pin 18
SI D11 Pin 17
SCK D13 Pin 19
CS D8 Pin 14
VCC +3.3V +3.3V
(via voltage regulator)

Unfortunately, this Ethernet module does not work at all with Arduino’s standard Ethernet library provided with the IDE. Fortunatrly, an Arduino (> 1.0 compatible) open-source library exists: EtherCard.

To install it, simply download the library’s ZIP and unzip it into your “libraries” folder of your Arduino IDE installation. Rename it to “EtherCard”.

(Re)start your Arduino IDE, you should now see EtherCard appear in File / Examples.

You can test if your module is properly working by loading the “backSoon” example on your µC / Uno.

When reaching the IP address (configured in your code) in your favorite web browser, you should see a “Back Soon” web page.

Raspberry PI + Xbee: UART / Serial howto

Happy owner of a Raspberry PI for almost a year now, I couldn’t resist to take advantage of if advanced features, and especially it’s GPIO, to communicate with my other electronics parts including my Xbee-enabled wireless sensors.

Although RPI’s onboard UART usage seemed quite simple at first, it finally took me some time to figure out exactly how to read my first bytes received trough UART via Xbee on my RPI, that’s why I’m writing this short snippet.

On the original Debian available for the Raspberry PI, the UART allow you to have a serial console so you can connect to it, without needing network nor SSH.

It takes a few steps to change this default behavior so we can connect our Xbee (Series 1) to our RPI.

First of all, you will need to edit the /boot/cmdline.txt file :

sudo cp /boot/cmdline.txt /boot/cmdline.txt.bak # Backup file
sudo vi /boot/cmdline.txt

Remove all references to ttyAMA0 (console and kgdboc) so your file looks something like that :

dwc_otg.lpm_enable=0 rpitestmode=1 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait

Now edit /etc/inittab :

sudo cp /etc/inittab /etc/inittab.bak # Backup file
sudo vi /etc/inittab

Comment out the following line :

2:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

Now reboot your Raspberry PI.

Let’s now connect our Xbee to the RPI’s GPIO. Here is a quick schema explaining how :

Raspberry PI Xbee

Raspberry PI and Xbee Series 1

Note that on this schema, I only connected a wire from Xbee’s DOUT to RPI’s RXD as will only use it to receive data. However, you might also connect your Xbee’s DIN to RPI’s TX according to this RPI GPIO pinout.

Your Raspberry PI should now receive it’s first bytes via the Xbee ; you can test this using Minicom (sudo aptitude install minicom, if not already installed) :

sudo minicom -b 9600 -o -D /dev/ttyAMA0

(You could also use minicom without sudoing by adding your current user [I guess pi] to dialout group)

Special thanks to Clayton Smith’s blog post which greatly helped me figure out what was wrong with my RPI’s UART.