📖
CorgiDude
  • Introduction
  • Specification
  • Installation
    • การใช้งาน Maixpy IDE เบื้องต้น
    • วิธีการลง Maixpy ใน Sipeed Maix Bit
    • การใช้งาน Kflash GUI และการอัพโหลดไฟล์ .bin kmodel
  • Lessons
  • Article & API
    • การใช้งาน GPIO
    • การอ่านและเขียนไฟล์ SD Card
    • การเชื่อมต่อ WiFi
    • การใช้งาน HTTP Request
    • การใช้งาน MQTT
    • การใช้งาน Google Spreadsheet ผ่านทาง IFTTTT
    • การใช้งาน LINE Notify
    • การใช้งาน ThingSpeak
    • การใช้งาน Google Vision
  • Modules
    • Button Switch
    • Drive Motor
    • GPIO Input
    • Servo Motor
  • Demo Projects
    • Face Recognition
      • ตอนที่ 1
      • ตอนที่ 2
      • ตอนที่ 3
      • ตอนที่ 4
    • Image Classification
      • CorgiDude บอร์ด Image Classification โดยใช้ MobileNetV1
      • CorgiDude บอร์ด Image Classification โดยใช้ Transfer Learning MobileNetV1
    • Object Detection
      • CorgiDude บอร์ดกับการทำ Object Detection โดยใช้ Yolo
      • CorgiDude บอร์ด ตรวจจับใบหน้าด้วย Yolo Face Detection
      • CorgiDude บอร์ดกับการทำ Cat Face Detection โดยใช้ Yolo2
      • การทำ Dataset แบบ Object Detection ชนิด VOC ที่สามารถเอาไปใช้ตอนเทรนใน Yolo2 ได้เลย
      • CorgiDude บอร์ดกับการทำ License Plate Detection ของรถมอเตอร์ไซค์ โดยใช้ Yolo2
      • CorgiDude บอร์ด ตรวจจับใบหน้า และ Mask ด้วย Yolo2 Face Mask Detection
  • Downloads
    • Firmware
    • Models
Powered by GitBook
On this page

Was this helpful?

  1. Article & API

การเชื่อมต่อ WiFi

Previousการอ่านและเขียนไฟล์ SD CardNextการใช้งาน HTTP Request

Last updated 4 years ago

Was this helpful?

หลังจากที่ได้ลองเขียนโค๊ดลง CorgiDude กันไปแล้ว วันนี้เรามาเพิ่มความสามารถ เชื่อมต่อ WiFi กันดูดีกว่าครับ!

เนื่องจาก CorgiDude ใช้ Sipeed K210 Module ที่มี chip ESP8285 อยู่ในนั้นด้วย เราจึงสามารถประมวลผล AI และเชื่อมต่อ Internet ผ่าน WiFi กันได้ แบบครบเครื่องบน CorgiDude ตัวเดียวเลยครับ

ภาพ Sipeed Module

เริ่มเชื่อมต่อ WiFi! เริ่มต้นด้วยการ Select Board ให้เป็น Sipeed Maix Dock

มาเริ่มโค๊ดกันเลย!

from Maix import GPIO
from machine import UART
from fpioa_manager import fm, board_info

import lcd, image
import usocket, network, time


fm.register(8, fm.fpioa.GPIOHS0)
wifi_en=GPIO(GPIO.GPIOHS0,GPIO.OUT)

fm.register(board_info.WIFI_RX,fm.fpioa.UART2_TX)
fm.register(board_info.WIFI_TX,fm.fpioa.UART2_RX)

counter = 1
line_height = 20

WIFI_SSID = "CMMC_3BB_2.4GHz"
WIFI_PASS = "xxxxxxxxxx"


lcd.init(type=1, freq=15000000)
lcd.freq(16000000)


def draw_line(text, color=lcd.RED):
    global counter
    lcd.draw_string(0, line_height*counter, text, color, lcd.BLACK)
    counter += 1

def wifi_enable(en):
    global wifi_en
    wifi_en.value(en)
    #draw_line("wifi_en({})".format(en))


def wifi_reset():
    global uart
    print("wifi reset")
    wifi_enable(0)
    time.sleep_ms(200)
    wifi_enable(1)
    time.sleep_ms(200)
    uart = UART(UART.UART2,115200,timeout=1000, read_buf_len=1024)
    tmp = uart.read()
    time.sleep_ms(200);
    print(uart.read())
    uart.write("AT\r\n")
    tmp = uart.read()
    if tmp and not tmp.endswith("OK\r\n"):
        draw_line("reset failed")
        print("reset fail")
        return None
    try:
        nic = network.ESP8285(uart)
        #draw_line("NIC OK!", lcd.GREEN)
    except Exception:
        return None
    return nic

draw_line("CorgiDude!", lcd.YELLOW)
time.sleep(2)
draw_line("Preparing NIC...")
nic = wifi_reset()


if not nic:
    draw_line("WiFi init fail!")
    raise Exception("WiFi init fail")
else:
    draw_line("Connectin to WiFi...")
    nic.connect(WIFI_SSID, WIFI_PASS)
    ip,subnet,gateway,dns,b,mac,ssid = nic.ifconfig()
    print("WiFi Connected. ip={}, gateway={}".format(ip,gateway))
    draw_line("WiFi Connected.", lcd.GREEN)
    draw_line("")
    draw_line("ip={}, gateway={}".format(ip,gateway), lcd.YELLOW)
    draw_line("mac={}, ssid={}".format(mac,ssid), lcd.YELLOW)