Introduction: Read and Write From Serial Port With Raspberry Pi Using Wemos
Communicating with a Raspberry Pi using a Wemos D1 mini R2.
Step 1: Step 1: Flash Wemos D1 R2 Mini
Upload following code to the Wemos D1 R2 mini:
/*
* ESP8266 Deep sleep mode*/
void setup() {
ESP.deepSleep(0);
}
void loop() {
}
Step 2: Step 2: Disabling Console Service on the Raspberry Pi
Disable serial-getty service.
sudo systemctl disable serial-getty@ttyS0.service
Open “/boot/cmdline.txt”.
sudo nano /boot/cmdline.txt
Remove “console=serial0,115200”, then save the file.
Reboot.
sudo reboot
Step 3: Step 3: Connect Raspberry Pi With Wemos D1 R2 Mini
RX <--> RX
TX <--> TX
GND <--> GND
Step 4: Step 4: Upload Python Script
Run following code on your Raspberry Pi:
import time
import serialser = serial.Serial(
port='/dev/ttyUSB0', baudrate = 9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=1 ) counter=0
while 1: x=ser.readline() print x
ssssss
Step 5: Step 5: Input Serial Data in Putty
Write serial data in Putty and see the echo on the Raspberry Pi.