1021 views|0 replies

23

Posts

2

Resources
The OP
 

【Digi-Key Electronics Follow me Issue 2】+ Task Collection Post [Copy link]

 
[Digi-Key Electronics Follow me Issue 2] + Task Summary Post
Content 1: Video

Content 2: Task/Project Summary Report
Project Introduction:
This project completed a robot human-computer interaction interface, which is wirelessly connected to the robot through the TCP protocol, and displays the robot's set speed, actual speed, and mileage data in real time. It also displays a perpetual calendar clock, local weather information, etc.
This time, most of the required tasks (except creating wifi) are implemented through a code.py:
Description of each task and function display:
Task 1: Control the screen to display Chinese
Requirements: Complete screen control and be able to display Chinese
First, you can see that the content on the screen is displayed in a rounded rectangle. This is because a picture background is added to the screen. All subsequent displayed content is displayed on top of this picture. For the specific adding process, please refer to the teaching video.
Next, Chinese is displayed:
CircuitPython itself does not support Chinese display, but it can achieve Chinese display by loading Chinese character libraries.
Corresponding library: from adafruit_bitmap_font import bitmap_font
Use fonts:
[wenquanyi_13px.pcf]
Program implementation:
Here is the image added to the display group
# display init
display = board.DISPLAY
board.DISPLAY.brightness = 0.35
board.DISPLAY.rotation = 0

# display group
group = displayio.Group()
image, palette = adafruit_imageload.load("/pic/tqbg.png")
grid = displayio.TileGrid(image, pixel_shader=palette)
group.append(grid)


Here all the displayed contents of the interface are initialized and displayed

#group init
text_area = label.Label(font, text=str(datetime.tm_year)+"年"+str(datetime.tm_mon)+"月"+str(datetime.tm_mday)+"日", color=0xee7959,x=10,y=10)
group.append(text_area)
text_area1 = label.Label(font, text=str(datetime.tm_hour)+":"+str(datetime.tm_min), color=0x45465e,x=180,y=10)
group.append(text_area1)
text_area2 = label.Label(font, text="城市:"+city, color=0x3271ae,x=10,y=25)
group.append(text_area2)
text_area3 = label.Label(font, text="天气:"+weather, color=0x779649,x=180,y=25)
group.append(text_area3)
text_area4 = label.Label(font, text="温度:"+temperature, color=0x3271ae,x=120,y=10)
group.append(text_area4)
# odom
text_area5 = label.Label(font, text="设置速度:", color=color,x=10,y=50)
group.append(text_area5)
text_area6 = label.Label(font, text="实际速度:", color=color,x=10,y=70)
group.append(text_area6)
text_area7 = label.Label(font, text="里程数据:", color=color,x=10,y=90)
group.append(text_area7)
display.show(group)


Task 2: Network Function Usage

Requirements: Complete the use of network functions, be able to create hotspots and connect to WiFi
Super simple!!!!
First, connect to wifi:
Circuitpython connects to wifi conveniently and easily. The code prints the wifi name and ip of the successful connection, as shown in the figure:

# connect wifi
wifi.radio.connect(os.getenv("CIRCUITPY_WIFI_SSID"), os.getenv("CIRCUITPY_WIFI_PASSWORD"))
print(f"Connected to {os.getenv('CIRCUITPY_WIFI_SSID')}")
print(f"My IP address: {wifi.radio.ipv4_address}")


Creating a wifi is also simple: I created a wifi named start_robot with a password of 12345678

wifi.radio.start_ap(ssid='start_robot', password='12345678')

Task 3: Controlling the WS2812B

Requirements: Use buttons to control the display and color switching of the onboard Neopixel LED
This task is also relatively simple to complete. The board has a three-color LED light, and you can directly call the neopixel library to achieve different color combinations of lights.
Key input detection can use the onboard boot key and directly call the digitalio library.

video:


First initialize the buttons and lights:
# button
button = digitalio.DigitalInOut(board.BUTTON)
button.switch_to_input(pull=digitalio.Pull.UP)
button_buf = button.value
button_change = 0

# light
pixel = neopixel.NeoPixel(board.NEOPIXEL, 1)
pixel.brightness = 0.3

Then detect whether the key input is pressed, and let the light display different color combinations after pressing it.
if ((button_buf != button.value) and (button.value==True)) :
button_change = button_change + 1
if(button_change == 1):
pixel.fill((255, 0, 0))
elif (button_change == 2):
pixel.fill((0, 255, 0))
elif (button_change == 3):
button_change = 0
pixel.fill((0, 0, 255))
button_buf = button.value

Task 4: Subtask 1: Calendar & Clock

Requirements: Complete a perpetual calendar clock that can be updated via the Internet and display local weather information
Perpetual calendar clock: Wi-Fi has been connected before. Here you need to access the NTP service to obtain real-time time information. It can be done with a few lines of code. Remember to offset 8 time zones:
ntp = adafruit_ntp.NTP(pool, tz_offset=8)

#获取时间
def sync_rtc():
try:
rtc.RTC().datetime = ntp.datetime
except:
print("获取时间异常")
datetime = rtc.RTC().datetime

To obtain weather information, I used the API of Xinzhi Weather

Call the API and parse the data, and finally add it to the screen for display.
#解析天气数据
def sync_weather():
print(f"Fetching text from {os.getenv("TEXT_URL")}")
response = requests.get(os.getenv("TEXT_URL"))
print("-" * 40)
print(response.text)
print("-" * 40)
obj = json.loads(response.text)
print(obj, type(obj))
temperature = obj['results'][0]['now']['temperature']
print(temperature, type(temperature))
weather = obj['results'][0]['now']['text']
print(weather, type(weather))
city = obj['results'][0]['location']['path']
print(city, type(city))
return temperature,weather,city

# 显示时间、天气数据
def disp_time_weather():
#日期
text_area.text = str(datetime.tm_year)+"年"+str(datetime.tm_mon)+"月"+str(datetime.tm_mday)+"日"
#时间
text_area1.text =str(datetime.tm_hour)+":"+str(datetime.tm_min)

other:

In addition to the ESP32-S3 FRONT TFT FEATHER, the products purchased this time also include the DISCOVERY STM32F10X EVAL BRD.

The DISCOVERY series comes with a downloader, which makes downloading programs very convenient, and it can be done with just a USB cable.
I use this DISCOVERY STM32F10X EVAL BRD as the motor driver layer of the robot to control the forward and reverse movement of the motor, use pid to control the motor speed, and feedback the real-time speed.
The main controller of the robot is a Linux development board, which communicates with STM32 through the serial port, and ESP32 and Linux communicate through TCP via WiFi. Finally, ESP32-S3 can view real-time speed, mileage and other data.
The hardware and software include:

System architecture design:

Program flow chart:

The detailed design of the robot can be viewed at:
Experience:
I am very grateful to Digi-Key and EEWORLD for providing this opportunity. We also hope to provide more interesting boards and topics in the next activities so that everyone can have fun tinkering with computers together.
Content 3: Compilable and downloadable code
[code.py]
code.py (5.38 KB, downloads: 3)
stm32 code: https://gitee.com/FFD8/STM32F100RBT_robot.git
f100test.zip (19.97 MB, downloads: 1)
This post is from DigiKey Technology Zone
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list