How to: Zigduino and Ethernet 2

Posted on July 3, 2018

Arduino is so fantastic!

… hell no. Here is the truth when you try to use Zigduino and the Ethernet Shield 2.

First, we download Arduino libraries and zigduino files (platform-specific parameters, such as pin numbers, that sort of stuff).


git clone $zigduinopath
wget && tar xf arduino-1.8.5-linux64.tar.xz && mv arduino-1.8.5 $arduinopath

# we do not need this file anymore, we will replace it
mv $arduinopath/hardware/arduino/avr/boards.txt $arduinopath/hardware/arduino/avr/boards.txt.000

# symbolic links, to handle a new platform
ln -s $zigduinopath/hardware/arduino/cores/zigduino        $arduinopath/hardware/arduino/avr/cores/
ln -s $zigduinopath/hardware/arduino/boards.txt            $arduinopath/hardware/arduino/avr/
ln -s $zigduinopath/hardware/arduino/variants/zigduino_r2/ $arduinopath/hardware/arduino/avr/variants/

Now we need the Ethernet shield 2 libraries, because guess what, they are not shipped with the arduino libraries for some reason, even if the module was released years ago (circa 2015).

git clone $arduinopath/librairies/

Fantastic. Now we try to compile our programs, and makefiles are the way to do it. There is a dedicated project for that: Arduino mk.

git clone $arduinomk

To finish, we need to tell our program makefile to extend itself with the arduino mk one, and give some parameters such as the platform to use, where the libraries are (and the ones we want to use), where the user libraries are, etc. The simplest way:

ARDMK_DIR		= ~/arduinomk
ARDUINO_DIR		= ~/arduino
AVR_TOOLS_DIR		= $(ARDUINO_DIR)/hardware/tools/avr

USER_LIB_PATH		= $(realpath ../../libraries) # all my libs here

TARGET			= .

#### For Zigduino r2 platform and 802.15.4
BOARD_TAG		= zigduino_r2
ARDUINO_CORE_PATH	= $(ARDUINO_DIR)/hardware/arduino/avr/cores/zigduino
MONITOR_PORT		?= /dev/ttyUSB0
ARDUINO_LIBS		= SPI Ethernet2 # and yours ;)

include $(ARDMK_DIR)/

CPPFLAGS		+= -Wall -std=c++11

	echo $(CPPFLAGS)

test : all upload monitor

retest: reset monitor

Et voilà ! Now you can compile… and see by yourself two ugly errors.

Let’s fix this. First, we need to create a totally useless function yield.

File $arduinopath/hardware/arduino/cores/zigduino/Arduino.h

void yield (void);

File $arduinopath/hardware/arduino/cores/zigduino/Arduino.cpp

void yield (void) {}

No comment.

Also, we have to uncomment a line in the file $arduinopath/hardware/arduino/variants/zigduino_r2/pins_arduino.h, there a little diff:

-/*const static uint8_t SS   = 10*/
+const static uint8_t SS   = 10;

As we can see, this is a line that was already there, but developers guessed that this should be commented for some reason… Don’t forget to replace Ethernet.h by Ethernet2.h and EthernetUdp.h by EthernetUdp2.h… THEN we can compile our programs! Hooray!

Tags: zigduino, arduino