Wiznet makers

matthew

Published January 03, 2024 ©

76 UCC

8 WCC

28 VAR

0 Contests

0 Followers

0 Following

Original Link

W5500 Ethernet module on Raspberry Pi Zero

For the base station (gateway) for LoRa thermometers,

COMPONENTS Hardware components

WIZnet - W5500

x 1


PROJECT DESCRIPTION

Raspberry Pi Zero

 

For the base station (gateway) for LoRa thermometers, I decided to use a Raspberry Pi Zero.
Due to unstable WiFi in one of the installation locations, the Raspberry Pi Zero W cannot be used, but a connection via LAN is required.

The Raspberry Pi can use some "USB LAN" or "HAT" (which still wants the USB). But this solution breaks the aesthetic appearance of the box – it blocks one USB connector.

Therefore, I decided to use an ethernet module that connects via SPI directly to the GPIO header of the raspberry. The choice fell on the "Mini Ethernet module W5500" - because it is in stock and at a good price on the Czech DIY Aliexpress. In addition, there is already a tutorial for Instructables - How to Use Ethernet on Raspberry Pi Zero W

, so this article is basically just a quick summary so I don't have to look for it next time. In addition, I have added a fixed HW MAC address


setting, connection The connection

of the W5500 to the Raspberry Pi is according to the diagram below. Realization of a "cut brace", er, IDE connecting flat cable. GND and 3.3V can be used with any of the pins from the GPIO header.

Connecting RPi and W5500 W5500 pinout

Raspberry Pi
configuration
It can be clicked in raspi-config, but by editing /boot/config.txt it's faster. Just add two options – enable SPI and load the appropriate module at boot

For
other parameters (int_pin, speed, Chip Select) see README
Reboot and check if there is another network adapter present – ifconfig ...


sudo nano /boot/config.txt

dtparam=spi=on
dtoverlay=w5500




Fixed MAC address The MAC address

of the module is generated on every reboot, which makes a mess in DHCP, DNS and so on - because raspberry has a different IP every time.
This can be worked around by adding rules/service for systemd and a script that hard-codes the interface with a MAC.


The script itself generates a MAC address from the serial number of the Raspberry Pi. Alternatively, you can hack it hard.

Do not forget about rights and automatic start/enable of the service


A similar procedure can be applied to modules with LAN8720, just load another module. (I haven't tried)


sudo nano /lib/systemd/system/setmac.service

[Unit]
Description=DSet the MAC address for the W5500 net adapter at eth0
Wants=network-pre.target
Before=network-pre.target
BindsTo=sys-subsystem-net-devices-eth0.device
After=sys-subsystem-net-devices-eth0.device

[Service]
Type=oneshot
ExecStart=/path/to/setmac.sh

[Install]
WantedBy=multi-user.target


sudo nano /path/to/setmac.sh

sudo /sbin/ip link set dev eth0 address `/bin/sed -n "s/Serial.*: 00000000..(..)(..)(..)/b8:27:eb:1:2:3/p" /proc/cpuinfo`


sudo systemctl enable setmac.service

sudo chmod +x /path/to/setmac.sh
Documents
Comments Write