How to Set up serial communication between Raspberry pi and Heythi 40 using GPIO
How to Setup serial communication between Raspberry pi and Heythi 40 using GPIO
Hardware connections:
-
Heythi 40 signals +5v and 0 ,Raspberry pi signals are +3.3v and 0.Raspberry pi GPIO pin are very sensitive.If 5v may drop on that it will get damaged.Inorder to avoid that we may use voltage divider logic
-
Take a breadboard and do connections as mentioned below
-
Take a 1 kilo ohm resistor connect the one end with Heythi 40 Transmitter(PD1) and other end with Raspberry pi receiver(Rx) in series.
-
Connect another 1 kilo ohm resistor with Raspberry pi receiver(Rx) and other end of resistor should be grounded
-
Connect the both ground pins with ground rail of breadboard
-
Connect the Raspberry pi transmitter(Tx) with Heythi 40 Receiver(PD0)
-
Connect the Usbtiny to the usb port and other end is connected with Heythi 40
-
Connect the Heythi Max 232 female port with Heythi 40 and other end of Max232 is connected with Max232 wire to wire connector
-
The other end of Max 232 wire to wire connector is connected with your system serial port
Raspberry pi
-
Open the Lxterminal and type sudo idle
-
Open File->New Window and type the following Program
#!/usr/bin/env python
import serial
import string
rot13 = string.maketrans(
"ABCDEFGHIJKLMabcdefghijklmNOPQRSTUVWXYZnopqrstuvwxyz",
"NOPQRSTUVWXYZnopqrstuvwxyzABCDEFGHIJKLMabcdefghijklm")
test=serial.Serial("/dev/ttyAMA0",4800)
test.open()
try:
while True:
line = test.readline(eol='\r')
test.write(string.translate(line, rot13))
except KeyboardInterrupt:
pass # do cleanup here
test.close()
-
Then click on save to save the module
-
Then click on Run to Run module
-
Open the minicom to view the data which is sent/received in serial communication by the following command
-
sudo minicom -b 4800 -o -D /dev/ttyAMA0 type the command in the Lxterminal
Heythi 40
-
Open Arduino IDE as administrator
-
Type the following program
void setup() {
Serial.begin(9600);
}
void loop() {
int incomingByte;
if(Serial.available() > 0)
// read the incoming byte:
incomingByte = Serial.read();
// echo
Serial.write(incomingByte);
}
}
3.Click to save icon to save the file
4.Select Heythi 40/Atmega32 under Tools ->Board menu
5.Select UsbtinyISP programmer under Tools -> Programmer
6.Select Tools->Serial port ->/dev/ttys0
7.Click to verify icon to compile the file
8.Click to File ->Upload using Programmer
9.Select the baud rate 4800 in serial moniton
10.Open the serial monitor in the arduino IDE to view the data which is sent/received in serial communication
Note:
1.Kindly disconnect the Arduino Tx and Arduino Rx with Raspberry pi Tx and Raspberry pi Rx unless you will get an error while uploading your program.It may damage your Raspberry pi
2.Kindly Follow the instructions given in How to Set up serial communication between Raspberry pi and Arduino using GPIO document to
-
Disable getty
-
Remove the console statement carefully
-
Minicom installation
-
Kindly follow the instruction given in Interfacing Between Arduino uno and Raspberry pi document to install Pyserial in Raspberry pi
Output:
Type your data (anything) in the minicom that will shown in arduino serial monitor
(i.e) YourRaspberry pi transmits the data and your Heythi 40 receives the data via serial communication