Im new to IoT platform.I need to read Reads blood pressure and heart rate and outputs at 9600 baud rate(Device name:Sunrom blood pressure sensor) using serial port RS232 in Python.Please help me to give any helpful reference link and useful material.
1 Answers
A quick guide in three steps:
1) Disable kernel messages on UART on your Rpi: run sudo raspi-config
, select option 5 (Interfacing Options) on the menu, then option P6 (Serial) and choose No. More details on this here.
2) Wire your sensor to the RPi's UART: according to this link the UART on your sensor works on 3.3V levels so it should be safe to wire it directly to the Pi's UART. Proceed to make the following connections:
|Sensor | RPi connector |
|=============================|
| +5V | 2 or 4 (+5V) |
| GND | 6 or 9 (GND) |
| TX-OUT| 10 (UART0 RXD) |
3) Fire up your Pi and sensor and run the following script (with Python 3.x), adapted from here, only removing the parts intended to write to the port (you don't need to write anything, your sensor is continuously sending data) and decoding the raw data received to display it correctly:
import serial, time
#initialization and open the port
#possible timeout values:
# 1. None: wait forever, block call
# 2. 0: non-blocking mode, return immediately
# 3. x, x is bigger than 0, float allowed, timeout block call
ser = serial.Serial()
ser.port = "/dev/ttyS0"
ser.baudrate = 9600
ser.bytesize = serial.EIGHTBITS #number of bits per bytes
ser.parity = serial.PARITY_NONE #set parity check: no parity
ser.stopbits = serial.STOPBITS_ONE #number of stop bits
#ser.timeout = None #block read
ser.timeout = 1 #non-block read
ser.xonxoff = False #disable software flow control
ser.rtscts = False #disable hardware (RTS/CTS) flow control
ser.dsrdtr = False #disable hardware (DSR/DTR) flow control
try:
ser.open()
except Exception as e:
print("error open serial port: " + str(e))
exit()
if ser.isOpen():
try:
ser.flushInput() #flush input buffer, discarding all its contents
ser.flushOutput()#flush output buffer, aborting current output
#and discard all that is in buffer
numOfLines = 0
while True:
response = ser.readline().decode()
print("Blood Pressure [mmHg] (Systolic, Diastolic, Pulse): " + response)
numOfLines = numOfLines + 1
time.sleep(1)
if (numOfLines >= 5):
break
ser.close()
except Exception as e1:
print("error communicating...: " + str(e1))
else:
print("cannot open serial port ")
Disclaimer: Nothing of the above has been tested (together with the sensor, I did test the code on its own) but it should work right away, or at least give you some guidance to start you up.

- 3,371
- 2
- 8
- 16