class ENC28J60 – control enc28j60 Ethernet modules¶
This class provides control over enc28j60 Ethernet chips.
Usually the SPI bus and the required pin numbers are already defined in the board-specific part of the firmware, therefore there is no need to specify them explicitly.
Example usage:
import network
nic = network.ENC28J60(mac=b'\x42\x42\x42\xa0\xa2\xa3')
nic.ifconfig('dhcp')
print(nic.ifconfig())
# now use socket as usual
...
Constructors¶
- class network.ENC28J60(spi=- 1, cs=None, irq=None, rst=None, mac=None)¶
Create an ENC28J60 driver object, initialize the enc28j60 module using the given SPI bus and pins, and return the ENC28J60 object.
Arguments are:
spi is an SPI object (or the SPI id number) which is the SPI bus that the ENC28J60 is connected to (the MOSI, MISO and SCLK pins).
-1
means use the board-specific default value.cs is a Pin object which is connected to the enc28j60 nSS pin.
None
means use the board-specific default value.irq is a Pin object which is connected to the enc28j60 nIRQ pin.
None
means use the board-specific default value.rst is a Pin object which is connected to the enc28j60 nRESET pin.
None
means use the board-specific default value.mac is a bytes object (must be 6 bytes exactly). If not None, the enc28j60 will be configured with this MAC address. Otherwise, the MAC address will be deduced from the MCU unique id.
All of these objects will be initialized by the driver, so there is no need to initialize them yourself. In the end, the
ifup()
method is called.
Methods¶
- ENC28J60.isconnected()¶
Returns
True
if the physical Ethernet link is connected and up. ReturnsFalse
otherwise.
- ENC28J60.ifconfig([(ip, subnet, gateway, dns)])¶
Get/set IP address, subnet mask, gateway and DNS.
When called with no arguments, this method returns a 4-tuple with the above information.
To set the above values, pass a 4-tuple with the required information. For example:
nic.ifconfig(('192.168.0.4', '255.255.255.0', '192.168.0.1', '8.8.8.8'))
If “dhcp” is passed as the only parameter then the DHCP client is enabled and the IP params are negotiated with the AP.
- ENC28J60.ifup()¶
Activate the network interface card and make it ready to receive/transmit data.
- ENC28J60.ifdown()¶
Deactivate the network interface card. It will not be able to receive/transmit data.
- ENC28J60.mac()¶
Returns the current MAC address as bytes.
- ENC28J60.config(param[, start=<ip>, end=<ip>])¶
Param (str) can be one of:
mac - the same as
mac()
method.ap - configure the NIC as a DHCP server. The current IP address (ref.
ifconfig()
) will become the DHCP server address, the client address range can be specified via the start and end arguments.