Article count:858 Read by:1113778

Account Entry

ELVIS III learning notes: Python series | Try PyCharm embedded development

Latest update time:2020-07-24
    Reads:

Note: This article is reproduced from the WeChat public account of "Zeng Yihui Chuang"



Note: The implementation process of this article is based on the fact that the Python environment has been established on ELVIS III. For the specific experimental steps to establish the environment, please refer to the article: "How to use Python to program ELVIS III" (You can also follow this public account and reply "python" to obtain the corresponding offline data package)


The long-awaited release of five peripherals is waiting for you to see

Embedded development is as deep as the sea, brother ΠChaum is here to help


Hello, teachers and students!


I am Shuke. In the previous article, we built an environment for embedded application development on ELVIS III using Python . With this tool chain, I have a feeling that embedded development on ELVIS III will become particularly convenient and efficient. Recently, I have carried out relevant development and proved the correctness of this speculation. I dare not say that the whole debugging process is smooth and completed in one go, but it is true that the debugging speed is amazing, the debugging effect is touching, and the debugging results are gratifying. Shuke is also very excited after the successful debugging!



First of all, let me lead the teachers and students to get to know the five peripherals that have been adjusted.


【Peripheral 1】-16-button Keypad



The keypad contains sixteen single-pole single-throw (SPST) buttons arranged in a 4x4 grid, so we need 8 wires to control them. The principle is as follows:



The core of keypad debugging is to control the DIO port. First, write a high level to the column line to drive the column, then scan each row corresponding to the column, read the high and low level status of each row through the DIO port, so as to determine the position of the key, and finally output the specific value of the key through decoding.


【Peripheral 2】-LCD Display



The LCD character display uses the Atmega48 chip, which supports three serial communication standards: UART (Asynchronous Receiver/Transmitter), SPI (Serial Peripheral Interface), and I2C bus. In the debugging of the LCD display, I chose the UART communication standard. The core of the task was converted to using Python to configure the UART, and then driving the UART through ELVIS III to achieve data (ASCII) writing and displaying on the LCD screen. The principle is shown in the figure below:



【Peripheral 3】- 8x8 Dot Matrix LED Display



Each dot of the 8x8LED matrix contains a green LED and a red LED. The cathodes of each diode pair are connected to the same horizontal line, the anodes of all green LEDs in the same column are connected to the same vertical line, and the red LEDs are connected in a similar way, so the two LEDs at each dot can be controlled individually. Lighting up two LEDs at the same time can mix the colors into yellow. The principle is shown in the figure below:



The core of this external device debugging is: write a high level to the row corresponding to the position that needs to be lit through DIO to drive the row, and then write a high level to the corresponding column line through DIO to light up the LED at that position. It should be noted that there are a total of 16 column lines, eight of which correspond to red column lines and eight correspond to green column lines. (Note: If both the red and green column lines are written as high at the same time, it will be displayed in yellow)


【Peripheral 4】- IC 25LC040A Serial EEPROM




EEPROM (Electrically Erasable Programmable Read-Only Memory) provides non-volatile data storage that can save data even when the power is off. The Microchip 25LC040A serial EEPROM we use provides 4KB of storage space, organized as an array of 512 8-bit bytes, which can be accessed through the SPI serial bus. The module logic is shown in the figure below:


The debugging core of this peripheral is: use python to configure the SPI serial interface, send read and write instructions to the EEPROM through the SPI interface, drive the EEPROM read and write status, and then write data to the address specified by the EEPROM or read data from the address specified by the EEPROM.


(For detailed working principle and SPI principle of Microchip 25LC040A serial EEPROM, please refer to: https://www.microchip.com/wwwproducts/en/25LC040A )


【Peripheral 5】- Temperature Sensor



The temperature sensor debugged in this experiment is based on the Microchip TCN75A temperature sensor, which has I2C bus serial communication function. Two 8-bit registers provide the measured temperature (in degrees Celsius) every 30ms (9-bit resolution) and 240ms (12-bit resolution). The module logic is shown in the figure below:



The debugging core of this peripheral is: use python to configure the I2C bus, select the write or read address through the keycap (for the temperature sensor, I only need to read the data), and use the I2C read instruction to read the value of the specific address.


(For detailed working principle and I2C principle of Microchip TCN75A temperature sensor, please refer to: https://reference.digilentinc.com/reference/pmod/pmodtmp3/reference-manual?redirect=1 )

At this point, we have a clearer understanding of the working principles of these five peripherals. The next step is to study how to use Python to control the digital I/O, analog I/O, bus, and interrupts of ELVIS III. In fact, NI has provided a relatively complete set of Python-based APIs, and developers can directly use this set of APIs for data acquisition and processing, which is like the sea to fish and the sky to birds for this experiment. After mastering the basic principles of peripherals and the control methods of ELVIS III, everything is ready, and only the east wind is needed. There are not many problems to "take off".


(For the complete API resources, please refer to: https://github.com/ni/NI-ELVIS-III-Python-Examples)


ELVIS III - Python API at a Glance


The next step is to enter the final debugging phase. For different peripherals, you need to select the corresponding API for communication between the peripheral and ELVIS III, and then process the communication data to drive the device to realize its functions. With the powerful assistance of PyCharm, it is no longer a dream to efficiently debug five peripherals!


The debugging Keypad currently prints out the value of the pressed key in the background. Based on this, we can design many other demos, such as using the keypad as a calculator or using it as a controller to control other peripherals through different inputs, etc.


Debugging the LCD display screen has now achieved printing a sentence that all programmers feel close to - "Hello World" on the display screen, and the main function of the LCD display screen is to display ASCII code strings, so I will not go into details;


Debugging the LED matrix is ​​a fun process, because the LED matrix has 128 light-emitting diodes that can light up in three different colors. With such a colorful combination, we can achieve some interesting or romantic effects. It is no exaggeration to say that this may be a little magic weapon to break the world's inherent perception of programmers as boring!


Debugging EEPROM mainly implements writing data to the specified address of EEPROM and reading data from the specified address of EEPROM.


Finally, the temperature sensor directly returns and prints out the ambient temperature obtained by the temperature sensor.


The following figure will focus on the debugging effect. At the same time, I have uploaded the experimental source code to https://github.com/NIEYUTONG/ELVIS-III-Python. Teachers and students are welcome to refer to it and make corrections.



Technical Implementation | Zeng Yihui Chuang- Shuke

Content Planning | Zeng Yihui Chuang- Shuke

Article written by Zeng Yihui Chuang- Shuke




About Zeng Yi Huichuang


IECUBE is committed to cultivating innovative engineering and technological talents. It is a comprehensive engineering education service provider focusing on the integration of industry and education. It serves the needs of engineering education by combining teaching methods with advanced technologies, providing course content that is in line with industrial development, and an ecological system that empowers talent training.



As an important solution partner of NI in the academic industry , Zeng Yihuichuang has developed a series of complete solutions covering basic engineering teaching, student innovation practice, engineering training and the integration of science and education based on the NI technology platform.



For more exciting recommendations, please follow Zeng Yihui

Long press the QR code to identify and follow Zeng Yihui


Latest articles about

 
EEWorld WeChat Subscription

 
EEWorld WeChat Service Number

 
AutoDevelopers

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

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

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号