Wiznet makers

louis_m

Published March 17, 2023 ©

85 UCC

11 WCC

37 VAR

0 Contests

0 Followers

0 Following

Original Link

Create a webcam with a "W5100S PoE module" without additional power supply

Create a webcam with a "W5100S PoE module" without additional power supply

COMPONENTS Hardware components

Raspberry Pi - Raspberry Pi Pico

x 1


PROJECT DESCRIPTION

Overview

A PoE (Power over Ethernet) web module is a device that uses a technology that enables both power supply and data transmission through an Ethernet cable. This technology is commonly used in network devices or IP cameras.

A PoE web module is an internet connectivity device that can be easily controlled remotely using only one Ethernet cable. By using this module, there is no need for additional power cables, which can reduce maintenance or installation costs for existing systems.

A PoE web module typically supports web applications such as web servers, databases, CGI scripts, etc. Users can view web pages through a browser on the network and control the module through the web page.

PoE web modules can be used in various industrial and household applications and provide high reliability and stability. Additionally, this module usually supports multiple protocols, making it highly compatible with existing systems.

 

Development

More information can be found at the link below.

 
  • Raspberry Pi Pico

https://www.raspberrypi.com/products/raspberry-pi-pico/

 
  • Arducam OV2640

https://www.arducam.com/product/arducam-2mp-spi-camera-b0067-arduino/

 
  • Connect to pins
 

Prepare

 

 

Installing CircuitPython

Install CircuitPython on Raspberry Pi Pico by referring to the link above.

https://learn.adafruit.com/getting-started-with-raspberry-pi-pico-circuitpython/circuitpython

  • Download the below uf2 file link on your computer

CircuitPython 7.0.0 - https://downloads.circuitpython.org/bin/raspberry_pi_pico/en_US/adafruit-circuitpython-raspberry_pi_pico-en_US-7.0.0.uf2

 

Setup Library

Copy into the lib folder inside the Raspberry Pi Pico. Download Bundle from the link below and place it in the lib folder inside the "CIRCUITPY" file.

https://circuitpython.org/libraries

 

 

Test

connect the your board to the internet router using ethernet cable. A few minutes after.

 

 

Press "Ctrl+D" on the terminal window. you can see the messages as follows.

Conversely, pressing "Ctrl+C" causes the running source to stop.

  • Open a web browser and enter the IP address of the module.
 

 

This is the executable image. Have a nice day.

 

A PoE (Power over Ethernet) web module is a device that can be used in network devices or IP cameras and can transmit both power and data simultaneously through an Ethernet cable.

This module is commonly used in industrial and household applications, such as building management systems, security systems, and CCTV. Additionally, it is used in various industrial fields, such as manufacturing processes, energy management, vehicle control, and robot control.

Since a PoE web module does not require a power cable, it can be conveniently added to existing network devices such as wireless APs and VoIP phones. Furthermore, this module supports web applications such as web servers, databases, CGI scripts, etc., allowing users to control the module through a web page.

 

import time as utime
import busio
import board
import usb_cdc
from Arducam import *
from board import *

import board
import busio
import digitalio
import time
import gc
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
from adafruit_wiznet5k.adafruit_wiznet5k import *
from adafruit_wiznet5k.adafruit_wiznet5k_socket import socket
from adafruit_wiznet5k.adafruit_wiznet5k_socket import *
        
once_number=1024
#once_number=128
mode = 0
prev_mode = mode
start_capture = 0
stop_flag=0
data_in=0
value_command=0
flag_command=0
buffer=bytearray(once_number)

mycam = ArducamClass(OV2640)
mycam.Camera_Detection()
mycam.Spi_Test()
mycam.Camera_Init()
utime.sleep(1)
mycam.clear_fifo_flag()


def read_fifo_burst():
    count=0
    lenght=mycam.read_fifo_length()
    mycam.SPI_CS_LOW()
    mycam.set_fifo_burst()
    while True:
        mycam.spi.readinto(buffer,start=0,end=once_number)
        usb_cdc.data.write(buffer)
        utime.sleep(0.00015)
        count+=once_number
        if count+once_number>lenght:
            count=lenght-count
            mycam.spi.readinto(buffer,start=0,end=count)
            usb_cdc.data.write(buffer)
            mycam.SPI_CS_HIGH()
            mycam.clear_fifo_flag()
            break
    return lenght

def read_fifo_burst_socket(cli_sock, length):
    count=0
    #lenght=mycam.read_fifo_length()
    mycam.SPI_CS_LOW()
    mycam.set_fifo_burst()
    while True:
        mycam.spi.readinto(buffer,start=0,end=once_number)
        #usb_cdc.data.write(buffer)
        cli_sock.send(buffer)
        #utime.sleep(0.001)
        count+=once_number
        if count+once_number>length:
            count=length-count
            mycam.spi.readinto(buffer,start=0,end=count)
            #usb_cdc.data.write(buffer)
            cli_sock.send(buffer[0:count])
            mycam.SPI_CS_HIGH()
            mycam.clear_fifo_flag()
            break

    gc.collect()    
    return length   

def read_fifo_burst_socket1(cli_sock, length):
    count=0
    #lenght=mycam.read_fifo_length()
    mycam.SPI_CS_LOW()
    mycam.set_fifo_burst()
    send_buffer = b''  #bytearray()
    while True:
        mycam.spi.readinto(buffer,start=0,end=once_number)
        send_buffer += buffer
        #usb_cdc.data.write(buffer)
        count+=once_number
        if count+once_number>length:
            count = length-count
            mycam.spi.readinto(buffer,start=0,end=count)
            send_buffer += buffer[0:count]
            #usb_cdc.data.write(buffer)
            mycam.SPI_CS_HIGH()
            mycam.clear_fifo_flag()
            break

    index = 0
    while True:
        buff = send_buffer[index:index+2048]
        print(buff)
        cli_sock.send(buffer)
        index += 2048
        gc.collect()    
        utime.sleep(0.001)
        if index + 2048 >= length:
            buff = send_buffer[index:length]
            cli_sock.send(buff)
            gc.collect()    
            break            
    
    return length   

def w5x00_init():
    ##SPI0
    SPI0_SCK = board.GP18
    SPI0_TX = board.GP19
    SPI0_RX = board.GP16
    SPI0_CSn = board.GP17

    ##reset
    W5x00_RSTn = board.GP20

    print("Wiznet5k (DHCP)")

    # Setup your network configuration below
    # random MAC, later should change this value on your vendor ID
    MY_MAC = (0x00, 0x01, 0x02, 0x03, 0x04, 0x05)
    IP_ADDRESS = (192, 168, 11, 5)
    SUBNET_MASK = (255, 255, 255, 0)
    GATEWAY_ADDRESS = (192, 168, 11, 1)
    DNS_SERVER = (8, 8, 8, 8)

    ethernetRst = digitalio.DigitalInOut(W5x00_RSTn)
    ethernetRst.direction = digitalio.Direction.OUTPUT

    led = digitalio.DigitalInOut(board.GP25)
    led.direction = digitalio.Direction.OUTPUT

    # For Adafruit Ethernet FeatherWing
    cs = digitalio.DigitalInOut(SPI0_CSn)
    spi_bus = busio.SPI(SPI0_SCK, MOSI=SPI0_TX, MISO=SPI0_RX)

    # Reset W5500 first
    ethernetRst.value = False
    time.sleep(1)
    ethernetRst.value = True


    # Initialize ethernet interface without DHCP
    eth = WIZNET5K(spi_bus, cs, is_dhcp=True, mac=MY_MAC)

    # Set network configuration
    #eth.ifconfig = (IP_ADDRESS, SUBNET_MASK, GATEWAY_ADDRESS, DNS_SERVER)

    print("Chip Version:", eth.chip)
    print("MAC Address:", [hex(i) for i in eth.mac_address])
    print("My IP address is:", eth.pretty_ip(eth.ip_address))
    print("Done!")

    return eth, led


def httpServer_init():
    eth, led = w5x00_init()
    set_interface(eth)
    sock = socket()
    return sock


def httpServer_listen(sock):
    sock.bind((None, 80))
    sock.listen()
    
def httpServer_accept(sock):    
    cli_sock, addr = sock.accept()
    while not cli_sock.connect:
        time.sleep(0.01)
    print('Connect')
    #print(conn)
    return cli_sock

def httpServer_read(cli_sock):
    request = cli_sock.recv()
    print(request)
    if len(request) > 0:
        #print(request)
        request = request.decode("utf-8")
        #print('Content = %s' % request)
        reqlines = request.split('\r\n')
        #print(reqlines)
        method = reqlines[0].split(' ')
        print(method)
        print(method[1][1:])

        return True, method[1][1:]
    else:
        time.sleep(0.001)
        return False, b''

def httpServer_response_single(cli_sock):
    print('httpServer_response_single()')
    length = mycam.read_fifo_length()
    print(length)
    cli_sock.send(b'HTTP/1.1 200 OK\n')
    cli_sock.send(b'Connection: close\n')
    cli_sock.send(b"Content-Type: image/jpeg\n")
    cli_sock.send(b"Content-Length: %d\n\n" % length)
    read_fifo_burst_socket(cli_sock, length)
    #eth.socket_write(s, b"\n\n")
    print('response done')


BOUNDARY = b"e8b8c539-047d-4777-a985-fbba6edff11e"

def httpServer_response_stream_init(cli_sock):
    print('httpServer_response_stream_init()')
    cli_sock.send(b'HTTP/1.1 200 OK\n')
    cli_sock.send(b'Content-Type: multipart/x-mixed-replace;boundary=' + BOUNDARY + b'\n\n')

def httpServer_response_stream_burst(cli_sock):
    print('httpServer_response_stream_burst()')
    length = mycam.read_fifo_length()
    print(length)
    cli_sock.send(b"Content-Type: image/jpeg\n")
    cli_sock.send(b"Content-Length: %d\n\n" % length)
    read_fifo_burst_socket(cli_sock, length)
    cli_sock.send(b"\n--" + BOUNDARY + b"\n");


def httpServer_close(cli_sock):
    cli_sock.disconnect()
    time.sleep(0.05)


#########################################################################

mycam.OV2640_set_JPEG_size(OV2640_320x240)
mycam.set_format(JPEG)
mycam.OV2640_set_Light_Mode(Auto)
mycam.OV2640_set_Color_Saturation(Saturation0)
mycam.OV2640_set_Brightness(Brightness0)
mycam.OV2640_set_Contrast(Contrast0)
mycam.OV2640_set_Special_effects(Normal)
mycam.Camera_Init()
mycam.set_bit(ARDUCHIP_TIM,VSYNC_LEVEL_MASK)

mycam.OV2640_set_JPEG_size(OV2640_176x144)
mycam.set_format(JPEG)
#mycam.Camera_Init()
mycam.set_bit(ARDUCHIP_TIM,VSYNC_LEVEL_MASK)

sock = httpServer_init()
httpServer_listen(sock)

while True:
    cli_sock = httpServer_accept(sock)

    while True:
        has_cmd, cmd = httpServer_read(cli_sock)

        if has_cmd:
            value_command = cmd
            flag_command=1
        if flag_command==1:
            flag_command=0
            #value=int.from_bytes(value_command,"big")
            try:
                value = int(value_command)
                #print(value)
            except:
                value = -1
                httpServer_close(cli_sock)
                break
                
            if value==0:
                mycam.OV2640_set_JPEG_size(OV2640_160x120)
            elif value==1:
                mycam.OV2640_set_JPEG_size(OV2640_176x144)
            elif value==2:
                mycam.OV2640_set_JPEG_size(OV2640_320x240)
            elif value==3:
                mycam.OV2640_set_JPEG_size(OV2640_352x288)
            elif value==4:
                mycam.OV2640_set_JPEG_size(OV2640_640x480)
            elif value==5:
                mycam.OV2640_set_JPEG_size(OV2640_800x600)
            elif value==6:
                mycam.OV2640_set_JPEG_size(OV2640_1024x768)
            elif value==7:
                mycam.OV2640_set_JPEG_size(OV2640_1280x1024)
            elif value==8:
                mycam.OV2640_set_JPEG_size(OV2640_1600x1200)
            elif value==0x10:
                print('single capture')
                mode=1
                start_capture=1
            elif value==0x11:
                mycam.set_format(JPEG)
                mycam.Camera_Init()
                mycam.set_bit(ARDUCHIP_TIM,VSYNC_LEVEL_MASK)
            elif value==0x20:
                print('stream capture')
                mode=2
                start_capture=2
                stop_flag=0
                httpServer_response_stream_init(cli_sock)
            elif value==0x21:
                stop_flag=1
            elif value==0x30:
                mode=3
                start_capture=3
            elif value==0x40:
                mycam.OV2640_set_Light_Mode(Auto)
            elif value==0x41:
                mycam.OV2640_set_Light_Mode(Sunny)
            elif value==0x42:
                mycam.OV2640_set_Light_Mode(Cloudy)
            elif value==0x43:
                mycam.OV2640_set_Light_Mode(Office)
            elif value==0x44:
                mycam.OV2640_set_Light_Mode(Home)
            elif value==0x50:
                mycam.OV2640_set_Color_Saturation(Saturation2)
            elif value==0x51:
                mycam.OV2640_set_Color_Saturation(Saturation1)
            elif value==0x52:
                mycam.OV2640_set_Color_Saturation(Saturation0)
            elif value==0x53:
                mycam.OV2640_set_Color_Saturation(Saturation_1)
            elif value==0x54:
                mycam.OV2640_set_Color_Saturation(Saturation_2)
            elif value==0x60:
                mycam.OV2640_set_Brightness(Brightness2)
            elif value==0x61:
                mycam.OV2640_set_Brightness(Brightness1)
            elif value==0x62:
                mycam.OV2640_set_Brightness(Brightness0)
            elif value==0x63:
                mycam.OV2640_set_Brightness(Brightness_1)
            elif value==0x64:
                mycam.OV2640_set_Brightness(Brightness_2)
            elif value==0x70:
                mycam.OV2640_set_Contrast(Contrast2)
            elif value==0x71:
                mycam.OV2640_set_Contrast(Contrast1)
            elif value==0x72:
                mycam.OV2640_set_Contrast(Contrast0)
            elif value==0x73:
                mycam.OV2640_set_Contrast(Contrast_1)
            elif value==0x74:
                mycam.OV2640_set_Contrast(Contrast_2)
            elif value==0x80:
                mycam.OV2640_set_Special_effects(Antique);
            elif value==0x81:
                mycam.OV2640_set_Special_effects(Bluish);
            elif value==0x82:
                mycam.OV2640_set_Special_effects(Greenish);
            elif value==0x83:
                mycam.OV2640_set_Special_effects(Reddish);
            elif value==0x84:
                mycam.OV2640_set_Special_effects(BW);
            elif value==0x85:
                mycam.OV2640_set_Special_effects(Negative); 
            elif value==0x86:
                mycam.OV2640_set_Special_effects(BWnegative);
            elif value==0x87:
                mycam.OV2640_set_Special_effects(Normal);
                
        if mode==1:
            if start_capture==1:
                mycam.flush_fifo();
                mycam.clear_fifo_flag();
                mycam.start_capture();
                start_capture=0
            if mycam.get_bit(ARDUCHIP_TRIG,CAP_DONE_MASK)!=0:
                #read_fifo_burst_socket(eth, s)
                httpServer_response_single(cli_sock)
                mode=0
        elif mode==2:
            if stop_flag==0:
                if start_capture==2:
                    start_capture=0
                    mycam.flush_fifo();
                    mycam.clear_fifo_flag();
                    mycam.start_capture();
                if mycam.get_bit(ARDUCHIP_TRIG,CAP_DONE_MASK)!=0:
                    httpServer_response_stream_burst(cli_sock)
                    #read_fifo_burst_socket(eth, s)
                    start_capture=2
            else:
                mode=0
                start_capture=0
        
        if mode == 0:
            if prev_mode != mode:
                print('Stop')
                httpServer_close(cli_sock)
                break

        prev_mode = mode
Documents
Comments Write