4734 views|27 replies

3386

Posts

0

Resources
The OP
 

MicroPython Hands-on (24) - Expanding the Control Panel with the Control Panel [Copy link]

 
 

Parrot is a small and portable expansion board derived from the parrot board. It supports motor drive, voice playback, voice synthesis and other functions. It can expand 12 IO interfaces and 2 I2C interfaces.

Technical Parameters

The board has the following features:

Two-way DC motor drive, single-way current 150mA

Support audio amplifier and speaker output (control board P8, P9 pins)

Supports text-to-speech (Text To Speech) speech synthesis

Expanded 12-way IO interface, 2-way I2C interface

Small size, portable, easy to carry

Supports lithium battery power supply and external USB power supply

Built-in 330mAH lithium battery, supports lithium battery cycle charging

Working voltage: 3.3V

Maximum output current: 1A@3.3V

Charging current: Maximum 170mA



This content is originally created by eagler8 , a user of EEWORLD forum. If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source

 
 

3386

Posts

0

Resources
2
 

 
 
 

3386

Posts

0

Resources
3
 

 
 
 

3386

Posts

0

Resources
4
 

The express delivery just arrived. In order to do a series of experiments, I bought two sets of expansion boards (with 350ma batteries)

 
 
 

3386

Posts

0

Resources
5
 

 
 
 

3386

Posts

0

Resources
6
 

This is how it is assembled

 
 
 

3386

Posts

0

Resources
7
 

 
 
 

3386

Posts

0

Resources
8
 

 
 
 

3386

Posts

0

Resources
9
 

Power indicator status:
v1 version
Power output indication function: 3.3V output, indicator light on; no output, off.
v2 version
Power output indication function: 3.3V output, indicator light on; no output, off.
Battery power indication function: Feedback power through the number of flashes, 4 levels of power display.


Charging indicator status:
v1 version
Note: The charging and discharging status can only be indicated when the power switch is turned on.
Charging indication function: The indicator light is on when charging; the indicator light is off when fully charged;
Discharging indication function: The battery power is fed back by the number of times the indicator light flashes. The faster the frequency, the lower the power. When the power is full, it is always on.
v2 version
Charging indication function: The indicator light flashes when charging; the indicator light is off when fully charged;
VCC: The VCC power supply is different from other 3.3V voltage power supplies. It provides higher voltage and larger current drive above 3.3V. It is used to cope with larger drive requirements. Power path management, when not connected to USB charging, VCC is directly provided by the battery voltage; when connected to USB charging, VCC is powered by USB.

Installation Instructions
The control board and control expansion board both have 3 holes. Connect the two boards through 3 copper pillars, screw them in, and put them into the soft shell, as shown in the picture.

 
 
 

3386

Posts

0

Resources
10
 

Function description of Lonkongbao

Motor drive

The control board supports 2-way PWM motor drive (marked M1 and M2 on the back of the control board). You can connect DC motors (such as TT motors, N20) and LED lights (starry light strips).

I/O

The left and right sides of the expansion board have 12 I/O interfaces and 2 I2C interfaces. These interfaces can be used to connect to classic sensor input modules and output modules. For example: buttons, human infrared, ultrasonic, LED, motor, buzzer, digital tube... The expansion board expansion pins are P0, P1, P2, P3, P5, P6, P7, P11, P13, P14, P15, P16, P19 (SCL), P20 (SDA)

important

Since P5 and P11 are the IO pins of the control board's buttons A and B, in order to avoid conflicts, the expansion board's P5 and P11 pins can only be used for digital level input, and the expansion board will flip the input level. Pay special attention when using it!

Speaker - Audio playback

The control expansion board has a built-in speaker and supports audio playback.

Text-to-speech (TTS)

Convert text into words and let the machine speak. This will give the control panel a "mouth". For example, you can input what you want to say in the program and let it speak to you.

Python Libraries

parrot module: for motor drive functions

audio module: used for audio playback

 
 
 

3386

Posts

0

Resources
11
 

1. Play online songs through the audio module

#MicroPython Hands-on (24) - Expanding the control board with the HandLongBao
# Playing online songs through the audio module (the HandLongBao has a built-in speaker)

#MicroPython动手做(24)——掌控板之拓展掌控宝
#通过音频模块播放网络歌曲(掌控宝内置喇叭)

from mpython import *
import network
import audio
import time

my_wifi = wifi()

my_wifi.connectWiFi("zh", "zy1567")


audio.player_init()
audio.set_volume(70)
audio.play("http://wiki.labplus.cn/images/4/4e/Music_test.mp3")
while True:
    oled.fill(0)
    oled.DispChar("播放网络歌曲", 30, 16, 1)
    oled.DispChar("春天在哪里", 35, 32, 1)
    oled.show()
    rgb[1] = (int(0), int(51), int(0))
    rgb.write()
    time.sleep_ms(1)


Playing Internet Audio
To play mp3 audio files on the Internet, you need to know the URL address of the audio. Currently, most music websites are protected by copyright and do not directly provide the URL of the music. You can crawl the URL address of the audio through some plug-ins.

Notes
The control panel needs to ensure that the network connection is smooth. The URL must be a complete network address, otherwise it cannot be resolved. The audio decoding function uses the audio.play(url) function of the audio module. The url parameter can be the path of the local file system of the sound source or the network URL address.

 
 
 

3386

Posts

0

Resources
12
 

mPython X Graphical Programming

 
 
 

3386

Posts

0

Resources
13
 

 
 
 

3386

Posts

0

Resources
14
 

2. Expand the component layout of LonHand

 
 
 

3386

Posts

0

Resources
15
 

3. Expand the function of LonHand motor drive

The expansion board supports 2-way PWM motor drive and can use DC motors such as TT motor, N20, etc.

(1) First import the parrot module:

import parrot

(2) M1, M2, forward speed is set to 80:

import parrot # Import the parrot module

parrot.set_speed(parrot.MOTOR_1,80) # Set M1 to forward, speed is 80
parrot.set_speed(parrot.MOTOR_2,80) # Set M2 to forward, speed is 80

(3) Reversal:

parrot.set_speed(parrot.MOTOR_1,-80) # Set M1 to reverse, speed is 80
parrot.set_speed(parrot.MOTOR_2,-80) # Set M2 to reverse, speed is 80

(4) Stop:

parrot.set_speed(parrot.MOTOR_1,0) # stop
parrot.set_speed(parrot.MOTOR_2,0) # stop

The function set_speed(motor_no, speed) is used to control the motor speed. The motor_no parameter is the motor number, and the optional number constants are MOTOR_1 and MOTOR_2. The speed parameter is the speed, ranging from -100 to 100. A positive value indicates positive rotation, and a negative value indicates negative rotation. When you need to know the current set speed value at some point, you can use get_speed(motor_no) to return the current motor speed.

 
 
 

3386

Posts

0

Resources
16
 

4. Control expansion board - button control TT motor

As an action output, it can provide power to the application by continuous rotation when receiving a high level, and can be reversed and the speed is adjustable. Here, a single-axis TT DC reduction motor is used for the experiment.

Technical parameters
Working voltage: VCC 3.3-5V
XH2.54 spacing terminal line
Single axis TT DC reduction motor
Module 30x70mm

 
 
 

3386

Posts

0

Resources
17
 

#MicroPython Hands-on (24) - Expanding the control board and the control treasure
#Button control TT motor

#MicroPython动手做(24)——掌控板之拓展掌控宝
#按键控制TT电机

from mpython import *

import time

import parrot

def on_button_a_down(_):
    global aaa
    time.sleep_ms(10)
    if button_a.value() == 1: return
    parrot.set_speed(parrot.MOTOR_1, 80)
    time.sleep(1)
    parrot.set_speed(parrot.MOTOR_1, 0)
    parrot.set_speed(parrot.MOTOR_2, 0)
    time.sleep(1)

button_a.irq(trigger=Pin.IRQ_FALLING, handler=on_button_a_down)

 
 
 

3386

Posts

0

Resources
18
 

mPython Graphics Programming

 
 
 

3386

Posts

0

Resources
19
 

 
 
 

3386

Posts

0

Resources
20
 

5. Use buttons to control the car to move forward, backward and rotate

#MicroPython Hands-on (24) - Expanded Hands-on Treasure of the Control Panel
# Buttons to control the car to move forward, backward and rotate

#MicroPython动手做(24)——掌控板之拓展掌控宝
#按键控制小车前进、后退与旋转

import parrot

from mpython import *

def forward():
    parrot.set_speed(parrot.MOTOR_1, 80)
    parrot.set_speed(parrot.MOTOR_2, 80)
    oled.fill(0)
    oled.blit(image_picture.load('face/Information/Forward.pbm', 0), 32, 0)
    oled.show()

def retreat():
    parrot.set_speed(parrot.MOTOR_1, -80)
    parrot.set_speed(parrot.MOTOR_2, -80)
    oled.fill(0)
    oled.blit(image_picture.load('face/Information/Backward.pbm', 0), 32, 0)
    oled.show()

def right():
    parrot.set_speed(parrot.MOTOR_1, 80)
    parrot.set_speed(parrot.MOTOR_2, -80)
    oled.fill(0)
    oled.blit(image_picture.load('face/Information/Right.pbm', 0), 32, 0)
    oled.show()

import time

def on_button_a_down(_):
    global aaa
    time.sleep_ms(10)
    if button_a.value() == 1: return
    rgb.fill((int(0), int(102), int(0)))
    rgb.write()
    time.sleep_ms(1)
    forward()
    time.sleep(2)
    Left()
    time.sleep(1)
    retreat()
    time.sleep(2)
    right()
    time.sleep(1)
    oled.fill(0)
    parrot.set_speed(parrot.MOTOR_1, 0)
    parrot.set_speed(parrot.MOTOR_2, 0)
    rgb.fill( (0, 0, 0) )
    rgb.write()
    time.sleep_ms(1)
    oled.show()

def Left():
    parrot.set_speed(parrot.MOTOR_1, -80)
    parrot.set_speed(parrot.MOTOR_2, 80)
    oled.fill(0)
    oled.blit(image_picture.load('face/Information/Left.pbm', 0), 32, 0)
    oled.show()

image_picture = Image()

button_a.irq(trigger=Pin.IRQ_FALLING, handler=on_button_a_down)

 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

Room 1530, Zhongguancun MOOC Times Building, Block B, 18 Zhongguancun Street, Haidian District, Beijing 100190, China Tel:(010)82350740 Postcode:100190

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