3538 views|21 replies

3386

Posts

0

Resources
The OP
 

MicroPython Hands-on (12) - Hello World on the Control Board [Copy link]

 
 

1. Connect to the control panel (display the latest firmware date)



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

Latest reply

Can the ordinary ESP32 be burned with your firmware and then directly use the IDE?   Details Published on 2020-4-17 09:10
 
 

3386

Posts

0

Resources
2
 

2. Open IDE (mPython X), confirm that the firmware has been burned, select the control board in the development board item, select the port (COM10 here), and check "Auto connect"

Check the five red dots

 
 
 

3386

Posts

0

Resources
3
 

3. Code programming (using Chinese, Korean, English, Japanese and French, serial port outputs hello world)

print("世界你好")
print("")
print("Hello World")
print("こんにちは、世界")
print("Bonjour au monde")

 
 
 

3386

Posts

0

Resources
4
 

4. Graphics programming (printing strings)

 
 
 

3386

Posts

0

Resources
5
 

 
 
 

3386

Posts

0

Resources
6
 

5. Python print() function

The print() method is used to print output, which is the most common function.

grammar

Following is the syntax of print() method:

print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)

parameter

objects -- plural, indicating that multiple objects can be output at one time. When outputting multiple objects, they need to be separated by ,.

sep -- used to separate multiple objects, the default value is a space.

end -- used to set what to end with. The default value is the newline character \n, which can be replaced by other strings.

file – The file object to write to.

flush – Whether output is buffered is usually determined by file, but if the flush keyword argument is True, the stream will be forced to flush.

Return Value

none.

Printing a string

print('Hello, world!')

Example results:

Hello, world!

Printing Numbers

print('1024')

Example results:

1024

Print List

L = [1, 2, 3, 4]print(L)

Example results:

[1, 2, 3, 4]

Printing Tuples

L = (1, 2, 3, 4)print(L)

Example results:

(1, 2, 3, 4)

Print Dictionary

D = {'one' : 1,'two': 2}print(D)

Example results:

{'two': 2, 'one': 1}

Print formatted string

print('Hello, {}!'.format('world'))

Example results:

Hello, world!

Print formatted floating point numbers

print('%10.3f' % 3.1415926)

Example results:

3.142

Three keyword arguments

sep

The string inserted between each object text, the default is a space. If you pass an empty character, there is no separator

end

A string added to the end of the printed text, the default is a newline character '\n'

file

Specifies the file to which the text will be sent. Usually a file-like

write(string)

However, if file is used, the text to be printed will be output to the specified file instead of being printed on the screen.

 
 
 

3386

Posts

0

Resources
7
 

6. REPL (read-evaluate-print loop)
One of the main advantages of using MicroPython is the interactive REPL, which stands for read-evaluate-print loop. REPL is very helpful for learning a new programming language because it responds immediately to programs written by beginners, which means that you execute the code and can see the results immediately without going through the tedious steps of compiling and uploading. After establishing a connection through the serial port, you can test whether it is working properly by pressing the Enter key a few times. If it works properly, you can see the Python REPL prompt, represented by >>>. After pressing the Enter key, you can type anything at the prompt. MicroPython will run the code you enter and print the results (if any); if the text you entered is wrong, it will print an error message. Try entering the following at the prompt:

>>> print("Hello World")
Hello World


 
 
 

3386

Posts

0

Resources
8
 
This post was last edited by eagler8 on 2020-4-16 20:54

7. You can try to download mPython to display characters on the OLED display:

>>> from mpython import *
>>> oled.DispChar('hello,world!',0,0)
>>> oled.show()
>>>

annotation

oled.DispChar(str,x,y) str is the string to be displayed, x, y are the x, y coordinates of the display starting point. Then use oled.show() to refresh the screen, and the string will be displayed on the OLED display. You can try to display any string in other locations.

 
 
 

3386

Posts

0

Resources
9
 

 
 
 

3386

Posts

0

Resources
10
 

8. Line Editing and Input History
You can use the left and right arrow keys to move the cursor to edit the currently input line; press the Home key or ctrl-A to move the cursor to the beginning of the line, and press End or ctrl-E to move to the end of the line; the Delete key or backspace key is used to delete.

The REPL remembers a certain number of previous lines of text you entered (up to 8 on the ESP32). To recall the previous line, use the up and down arrow keys.

The Tab key
allows you to see a list of all members of a module. This is useful for finding out what functions and methods a module or object has. Suppose you imported machine in the example above and then typed . and then pressed the Tab key to see a list of all members of the machine module:

>>> machine.
__class__       __name__        ADC             DAC
DEEPSLEEP       DEEPSLEEP_RESET                 EXT0_WAKE
EXT1_WAKE       HARD_RESET      I2C             PIN_WAKE
PWM             PWRON_RESET     Pin             RTC
SLEEP           SOFT_RESET      SPI             Signal
TIMER_WAKE      TOUCHPAD_WAKE   Timer           TouchPad
UART            ULP_WAKE        WDT             WDT_RESET
deepsleep       disable_irq     enable_irq      freq
idle            mem16           mem32           mem8
reset           reset_cause     sleep           time_pulse_us
unique_id       wake_reason
>>> machine.

 
 
 

3386

Posts

0

Resources
11
 

9. REPL paste mode and other control commands

Pressing ctrl-E will put you into special paste mode, where you can copy and paste a block of text into the REPL. If you press ctrl-E, you will see the paste mode prompt:

paste mode; Ctrl-C to cancel, Ctrl-D to finish
===

You can then paste (or type) your text. Note that none of the special keys or commands work in paste mode (such as Tab or Backspace), they are just accepted as is. Press ctrl-D to finish entering your text and execute it.

There are four other control commands:

Ctrl-A on a blank line will go to raw REPL mode. This is like forever paste mode, except characters are not echoed.
Ctrl-B on a blank line goes to normal REPL mode.
Ctrl-C cancels any input, or interrupts currently running code.
Ctrl-D on a blank line will do a soft restart.

 
 
 

150

Posts

0

Resources
12
 

Looks good

Comments

Thank you teacher for your encouragement  Details Published on 2020-4-17 05:19
 
 
 

3386

Posts

0

Resources
13
 

Thank you teacher for your encouragement

 
 
 

2002

Posts

24

Resources
14
 

Can the ordinary ESP32 be burned with your firmware and then directly use the IDE?

Comments

I haven't tried this, maybe the master controller can do it  Details Published on 2020-4-17 09:20
 
 
 

3386

Posts

0

Resources
15
 
shower.xu posted on 2020-4-17 09:10 Can the ordinary ESP32 be burned with your firmware and then directly used with IDE

I haven't tried this, maybe the master controller can do it

 
 
 

3386

Posts

0

Resources
16
 
This post was last edited by eagler8 on 2020-4-17 10:13

10. OLED screen displays Hello World

In 4 languages and centered.

The control panel has a 1.3-inch OLED display with a resolution of 128x64. It uses Google Noto Sans CJK 16x16 font with a font height of 16 pixels and supports simplified Chinese, traditional Chinese, Japanese and Korean. The experimental code is as follows:

from mpython import *

oled.fill(0)
oled.DispChar("世界你好", 40, 0, 1)
oled.DispChar("", 37, 16, 2)
oled.DispChar("Hello, world!", 26, 32, 3)
oled.DispChar("こんにちは世界", 22, 48, 4)
oled.show()

annotation

The DispChar(str,x,y) function can write the text with the upper left corner as the coordinate into the FrameBuffer. str is the displayed text content, supporting simplified Chinese, traditional Chinese, English, Japanese and Korean languages. xy is the starting xy coordinate of the oled display. oled.show() sends the FrameBuffer to the oled to refresh and display the screen.

Use Noto Sans CJK 16 pixels high and low width font. Different characters will have different widths.

 
 
 

3386

Posts

0

Resources
17
 

mPython X Graphical Programming (Four Modes)

Adjust the x value so that the displayed string "Hello World" is centered.

 
 
 

3386

Posts

0

Resources
18
 

 
 
 

3386

Posts

0

Resources
19
 

11. mPython simulation function displays Hello World
- you can test and run the program without a control board

 
 
 

3386

Posts

0

Resources
20
 

The display effect on the computer is as shown in the figure

 
 
 

Guess Your Favourite
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