Surf5 deposit box
Use POE powered safe box. Support electronic lock.
Software Apps and online services
Story
Modern wireless networks are very convenient. Is it still necessary for traditional wired networks to exist? After thinking for a long time, I came up with this scenario where a wired network must be used.
Safe deposit box:
For security reasons, the safe deposit box is a sealed space surrounded by metal, which blocks wireless network signals.
Hardware
Surf5
Grove Shield for Pi Pico
Grove - Servo
Shoe Box
TL-POE150S | PoE Injector | TP-Link
Software
Arm Keil MDK-Community Edition
hercules
Build
From Wiznet github download the example code. Here I modify example WZTOE_WebServer and use Arm Keil MDK-Community Edition to compile download and debug.
Follow surf5 getting-start to use Keil MDK. If you wanna use SWD to download and debug.
1.connect SWDIO/SWCLK on surf5 J3
2. add FLM file.
Analog servo control
Analog servos are controlled using PWM. It didn't work if I changed the PWM period directly, so I reinitialized and changed the period.
// https://github.com/arduino-libraries/Servo/blob/master/src/Servo.h
#define MIN_PULSE_WIDTH 544 // the shortest pulse sent to a servo
#define MAX_PULSE_WIDTH 2400 // the longest pulse sent to a servo
#define DEFAULT_PULSE_WIDTH 1500 // default pulse width when servo is attached
#define REFRESH_INTERVAL 20000 // minimum time to refresh servos in microseconds
static void Lock_ON(void)
{
PWM_InitTypeDef PWM_InitStructure;
PWM_Cmd(PWM5, DISABLE);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource5, PAD_AF2);
PWM_StructInit(&PWM_InitStructure);
PWM_InitStructure.PWM_Output = PWM_Output_OutEnable_InDisable;
// 1/8,000,000Hz = 0.000000125s
// 0.000000125 * 8 = 0.000001s
PWM_InitStructure.PWM_Prescale_Counter = 8 - 1;
PWM_InitStructure.PWM_Duty = DEFAULT_PULSE_WIDTH - 1;
PWM_InitStructure.PWM_Period = REFRESH_INTERVAL - 1;
PWM_Init(PWM5, &PWM_InitStructure);
PWM_Cmd(PWM5, ENABLE);
Lock_state=1;
}
static void Lock_OPEN(void)
{
PWM_InitTypeDef PWM_InitStructure;
PWM_Cmd(PWM5, DISABLE);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource5, PAD_AF2);
PWM_StructInit(&PWM_InitStructure);
PWM_InitStructure.PWM_Output = PWM_Output_OutEnable_InDisable;
// 1/8,000,000Hz = 0.000000125s
// 0.000000125 * 8 = 0.000001s
PWM_InitStructure.PWM_Prescale_Counter = 8 - 1;
PWM_InitStructure.PWM_Duty = MIN_PULSE_WIDTH - 1;
PWM_InitStructure.PWM_Period = REFRESH_INTERVAL - 1;
PWM_Init(PWM5, &PWM_InitStructure);
PWM_Cmd(PWM5, ENABLE);
Lock_state=0;
}
static IP
Because I use a laptop to share the Internet, I must use a static IP.
static void Network_Config(void)
{
uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x01, 0x02, 0x03};
uint8_t ip_addr[4] = {192, 168, 137, 200}; // the IP address is dependent on your network
uint8_t dns_addr[4] = {192, 168, 137, 1}; // the dns server ip
uint8_t gw_addr[4] = {192, 168, 137, 1}; // the Gateway ip
uint8_t sn_addr[4] = {255, 255, 255, 0}; // the subnet:
memcpy(gWIZNETINFO.mac, mac_addr, 6);
memcpy(gWIZNETINFO.ip, ip_addr, 4);
memcpy(gWIZNETINFO.sn, sn_addr, 4);
memcpy(gWIZNETINFO.gw, gw_addr, 4);
memcpy(gWIZNETINFO.dns, dns_addr, 4);
gWIZNETINFO.dhcp = NETINFO_STATIC;
ctlnetwork(CN_SET_NETINFO, (void *)&gWIZNETINFO);
printf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\r\n", gWIZNETINFO.mac[0], gWIZNETINFO.mac[1], gWIZNETINFO.mac[2], gWIZNETINFO.mac[3], gWIZNETINFO.mac[4], gWIZNETINFO.mac[5]);
printf("IP: %d.%d.%d.%d\r\n", gWIZNETINFO.ip[0], gWIZNETINFO.ip[1], gWIZNETINFO.ip[2], gWIZNETINFO.ip[3]);
printf("GW: %d.%d.%d.%d\r\n", gWIZNETINFO.gw[0], gWIZNETINFO.gw[1], gWIZNETINFO.gw[2], gWIZNETINFO.gw[3]);
printf("SN: %d.%d.%d.%d\r\n", gWIZNETINFO.sn[0], gWIZNETINFO.sn[1], gWIZNETINFO.sn[2], gWIZNETINFO.sn[3]);
printf("DNS: %d.%d.%d.%d\r\n", gWIZNETINFO.dns[0], gWIZNETINFO.dns[1], gWIZNETINFO.dns[2], gWIZNETINFO.dns[3]);
}
Connect
Demo
Conclusion
Since it is inconvenient to process iron boxes, I used paper boxes instead in this project. In actual applications, the same function can still be achieved in iron boxes.
The original plan also included LCM display and camera functionality, but due to the 7500's lack of I2C hardware, the LCM had to use GPIO emulation instead. It will take some time to complete this function.
-
Surf5 deposit box
use keil open .\Projects\Surf5_deposit_box\MDK\Project.uvprojx
-
Grove_shield_for_PI_PICO
Grove_shield_for_PI_PICOv1.0SCH