I am trying to communicate with a raspberry pi pico with my raspberry pi 4 over uart. The below code does transmit data, but I am only receiving data from the print statement.
import os
import utime
from machine import ADC
temp_sensor = ADC(4) # Default connection of temperature sensor
def temperature():
# get raw sensor data
raw_sensor_data = temp_sensor.read_u16()
# convert raw value to equivalent voltage
sensor_voltage = (raw_sensor_data / 65535)*3.3
# convert voltage to temperature (celcius)
temperature = 27. - (sensor_voltage - 0.706)/0.001721
return temperature
#print setup information :
print("OS Name : ",os.uname())
uart = machine.UART(0, baudrate = 9600)
print("UART Info : ", uart)
utime.sleep(3)
while True:
temp = temperature()
print(str(temp))
uart.write(str(temp))
utime.sleep(1)
And the code on my raspberry pi 4 is:
import serial
import time
import numpy as np
import matplotlib.pyplot as plt
#ser = serial.Serial('COM14',9600)
ser = serial.Serial('/dev/ttyACM0', 9600)
time.sleep(1)
while True:
# read two bytes of data
#data = (ser.read(8))
data = (ser.readline())
# convert bytestring to unicode transformation format -8 bit
temperature = str(data).encode("utf-8")
#print("Pico's Core Temperature : " + temperature + " Degree Celcius")
print(temperature)
The output in the terminal on my RPI 4 is:
27.2332
26.443
26.443
26.564
There is an extra new line between. If I remove print(str(temp)) from the pico code I get nothing. I can put just about anything in uart.write(str(temp)) and still receive the print statement, but without the uart.write() I will receive nothing.
source https://stackoverflow.com/questions/69397785/uart-communication-raspberry-pi-pico-to-raspberry-pi
Comments
Post a Comment