Nov-09-2024, 06:01 PM
Hello there,
I have been undergoing a personal project for a while, involving sending 6 separate strings to an Arduino over serial communication. I currently have two things I do not know how to do with this code, and honestly I am impressed I have gotten this much code done and working.
First problem is it will only send one of the pieces of code over serial, currently I only have two functions to make it simple, the cpu and ram functions as seen below, I am trying to turn them into messages and send but it is only sending one. I need some help figuring out how to send both pieces and why it will only send one over to the arduino. I have tested and both values will output in terminal, but it will only send the first variable through the communication.
Second problem is just some advice, I do not want to use psutil in the final code, I do not trust it's cpu values and so I plan to rely on librehardwaremonitor's library instead. I found a page that seems to document the calling of each function (assuming they are correct as there is no documentation i could find on their github.). I want to call on it's functions but I do not know how to access them, I have seen some sample code of someone doing something similar on this project
The main part of the code works, and the arduino is done, I am completely new to this language and just any help at getting these two functions working would be greatly appreciated. The code is below this text for you to see.
I have been undergoing a personal project for a while, involving sending 6 separate strings to an Arduino over serial communication. I currently have two things I do not know how to do with this code, and honestly I am impressed I have gotten this much code done and working.
First problem is it will only send one of the pieces of code over serial, currently I only have two functions to make it simple, the cpu and ram functions as seen below, I am trying to turn them into messages and send but it is only sending one. I need some help figuring out how to send both pieces and why it will only send one over to the arduino. I have tested and both values will output in terminal, but it will only send the first variable through the communication.
Second problem is just some advice, I do not want to use psutil in the final code, I do not trust it's cpu values and so I plan to rely on librehardwaremonitor's library instead. I found a page that seems to document the calling of each function (assuming they are correct as there is no documentation i could find on their github.). I want to call on it's functions but I do not know how to access them, I have seen some sample code of someone doing something similar on this project
The main part of the code works, and the arduino is done, I am completely new to this language and just any help at getting these two functions working would be greatly appreciated. The code is below this text for you to see.
import psutil import serial import time import clr # Set up the serial connection ser = serial.Serial('COM3', 9600) # COM3 port at 9600 baud rate time.sleep(2) # Wait for the connection to initialize message = "cpupt = 100" # Send the string message ser.write(message.encode()) while True: time.sleep(2) cpuL = int(psutil.cpu_percent()*255/100) message = "cpupt = " + str(cpuL) ser.write(message.encode()) # Convert the string to bytes and send it print("cpupt = " + str(cpuL)) memT = int(psutil.virtual_memory().percent*255/100) message = "rampt = " + str(memT) ser.write(message.encode()) # Convert the string to bytes and send it print("rampt = 77" + str(memT)) # Close the serial connection ser.close()I thank you for reading and appreciate any feedback.