How to include driver into micropython compilation

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
vinz-uts
Posts: 22
Joined: Fri Sep 10, 2021 9:22 am

Re: How to include driver into micropython compilation

Post by vinz-uts » Mon Nov 15, 2021 1:32 pm

Hi, this is the files that you have to upload on the board. In the .zip archive there is also an example script that use ETH connection to require the current data from a NTP server. Best Regards.
Attachments
wiznet5k.zip
Pure-python driver for WIZNET5K working on ESP32
(18.77 KiB) Downloaded 9795 times

neveregret
Posts: 28
Joined: Sun Aug 08, 2021 5:48 pm

Re: How to include driver into micropython compilation

Post by neveregret » Mon Nov 15, 2021 1:49 pm

vinz-uts wrote:
Mon Nov 15, 2021 1:32 pm
Hi, this is the files that you have to upload on the board. In the .zip archive there is also an example script that use ETH connection to require the current data from a NTP server. Best Regards.
Can I use it with raspberry pi pico? Will it work?

vinz-uts
Posts: 22
Joined: Fri Sep 10, 2021 9:22 am

Re: How to include driver into micropython compilation

Post by vinz-uts » Mon Nov 15, 2021 3:31 pm

I think it will works with every board with the WIZNET5500 module connected via a machine.SPI. You can try if it works...

neveregret
Posts: 28
Joined: Sun Aug 08, 2021 5:48 pm

Re: How to include driver into micropython compilation

Post by neveregret » Tue Nov 16, 2021 9:10 am

Hi, I tried with raspberry pi pico.It gives some error.When I run wiznet5k.py, it gives this:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 32, in <module>
  File "wiznet5k_dhcp.py", line 19, in <module>
  File "wiznet5k_socket.py", line 19, in <module>
  File "wiznet5k.py", line 33, in <module>
  File "wiznet5k_dns.py", line 20, in <module>
ImportError: can't import name htons
When I run wiznet5k_dhcp.py , wiznet5k_dns.py gives same error on different lines.
wiznet5k_socket.py doesn't gives error.

When I use your example code , I changed cs pin for my pico (I used wiznett w5500 with circuitpython same pin). It gives this:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 9, in <module>
  File "wiznet5k.py", line 159, in __init__
  File "wiznet5k.py", line 339, in _w5100_init
  File "wiznet5k.py", line 354, in detect_w5500
AssertionError: Expected 0x08.
When I added line 9 to bottom it gives this error:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 10, in <module>
  File "wiznet5k_socket.py", line 64, in getaddrinfo
  File "wiznet5k_socket.py", line 72, in gethostbyname
AttributeError: 'NoneType' object has no attribute 'get_host_by_name'

vinz-uts
Posts: 22
Joined: Fri Sep 10, 2021 9:22 am

Re: How to include driver into micropython compilation

Post by vinz-uts » Tue Nov 16, 2021 9:24 pm

For the `AssertionError: Expected 0x08.`, it seems is that the problem is in writing register on the chip. Are you sure your connected pin configuration is right. I had the same error when I had choose too high frequency for SPI. `htonl` and `htons` are function defined in `wiznet5k_socket`, so, if the import works, you have to be able to manually call these function.

neveregret
Posts: 28
Joined: Sun Aug 08, 2021 5:48 pm

Re: How to include driver into micropython compilation

Post by neveregret » Wed Nov 17, 2021 5:50 am

vinz-uts wrote:
Tue Nov 16, 2021 9:24 pm
For the `AssertionError: Expected 0x08.`, it seems is that the problem is in writing register on the chip. Are you sure your connected pin configuration is right. I had the same error when I had choose too high frequency for SPI. `htonl` and `htons` are function defined in `wiznet5k_socket`, so, if the import works, you have to be able to manually call these function.
I didn't set frequency, I tried with your example code (esp32_eth_wiznet5500_ntp).
I am using circuitpython like this,

Code: Select all

spi_bus = busio.SPI(board.GP10, MOSI=board.GP11, MISO=board.GP12)
cs = digitalio.DigitalInOut(board.GP13)
I tried to write like this with micropython:

Code: Select all

spi = SPI(1)
cs = Pin(13,Pin.OUT)
nic = WIZNET5K(spi,cs)
Only socket is not giving error.
wiznet5k_socket.py

Code: Select all

import gc
import time
import wiznet5k as wiznet5k
from micropython import const
When I import other modules on wiznet5k.socket.py (dhcp and dns) it gives 'ImportError: can't import name htons' error too. I guess I can't import them.I don't know why.
wiznet5k.socket.py :

Code: Select all

import gc
import time
import wiznet5k as wiznet5k
import wiznet5k_dhcp as dhcp
import wiznet5k_dns as dns
from micropython import const
_the_interface = None  # pylint: disable=invalid-name

irinakim
Posts: 1
Joined: Wed Oct 20, 2021 7:27 am

Re: How to include driver into micropython compilation

Post by irinakim » Thu Nov 18, 2021 7:35 am

Code: Select all

import network
from usocket import socket
from machine import Pin,SPI
import rp2

def main(): 
    spi=SPI(0,2_000_000, mosi=Pin(19),miso=Pin(16),sck=Pin(18))
    nic = network.WIZNET5K(spi,Pin(17),Pin(20))
    nic.ifconfig(('192.168.100.20','255.255.255.0','192.168.100.1','8.8.8.8'))
    
    while True:
        if nic.isconnected() == True:
            #print(nic.regs())
            s=socket()
            s.connect(('192.168.100.10',5000))
            while True:
                data = s.recv(1500)
                print(data.decode('utf-8'))
                if data != 'NULL' :
                    s.send(data)
            
main()
Image
github : https://github.com/irinakim12/micropyt ... e/wiznet5k
Loopback example : https://www.hackster.io/irinakim1225/ho ... hon-a6c351

steeley
Posts: 10
Joined: Mon Mar 21, 2022 6:09 pm

Re: How to include driver into micropython compilation

Post by steeley » Sat Apr 16, 2022 4:55 pm

vinz-uts wrote:
Mon Nov 15, 2021 1:32 pm
Hi, this is the files that you have to upload on the board. In the .zip archive there is also an example script that use ETH connection to require the current data from a NTP server. Best Regards.
I've upload the directory to my esp32 - but it won't run because of this error:
ImportError: no module named 'wiznet5k.WIZNET5K'

I'm in the right directory.

How do I get it to work?

TIA

sepehr jami
Posts: 2
Joined: Wed Apr 06, 2022 4:58 am

Re: How to include driver into micropython compilation

Post by sepehr jami » Sun Apr 17, 2022 7:20 am

vinz-uts wrote:
Fri Nov 12, 2021 9:25 pm
Hi, I've done some test with a ESP32-WROVER-IE and an external SPI Wiznet5500 ethernet chip. After a lot of research on this forum and github, I've decided to try to modify a pure-python adafruit driver (developed for circuitpython) for this chip. Now it seems works, but maybe it need more test. I can share this driver if someone will try to use it, or, if someone help me to understand the right steps, I will upload it in the right folder of micropython repo.
hello sir. can you share it ?

vinz-uts
Posts: 22
Joined: Fri Sep 10, 2021 9:22 am

Re: How to include driver into micropython compilation

Post by vinz-uts » Wed May 11, 2022 11:10 am

Hi, this is the folder which contains the drivers files and the script test. You have to copy only the content of the folder (files, not the folder) in your micro and run the `esp32_eth_wiznet5500_ntp.py` file to try it. I've just tested it now and seems all works, I've also changed the NTP server with the google one. Let's me know if it works.
Best regards,
Vinz.
Attachments
wiznet5k.zip
(18.57 KiB) Downloaded 9789 times

Post Reply