Today, I found that the wringpi library sends data to the computer through the GPIO port. It feels quite convenient.
To know more about wringpi click here
If you want to use the serial module to send and receive data , click here
We continue to log in to the Raspberry Pi through ssh, the serial port is connected to the computer through the adapter module, and the cmdline is changed to:
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
Install the necessary libraries:
sudo apt-get install python-dev python-pip sudo apt-get install wiringpi
After installation, import wiringpi in python to see if nothing appears, it proves that the installation was successful
Enter vim wiring.py and add the following program:
import wiringpi wiringpi.wiringPiSetup() serial = wiringpi.serialOpen('/dev/ttyAMA0',115200) wiringpi.serialPuts(serial,'Hello World!') wiringpi.serialClose(serial)
The code is simple and there is almost nothing to explain
Then we open the serial debugging assistant, start
Run the program on the Raspberry Pi and enter python wiring.py
In this way, we have received Hello World again!
But I haven't figured out how to make the raspberry pi receive data, please enlighten me...