Python Forum
sending strings to arduino over serial/accessing DLLs
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sending strings to arduino over serial/accessing DLLs
#1
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.

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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  pyserial/serial "has no attribute 'Serial' " gowb0w 11 21,490 Sep-27-2024, 12:18 PM
Last Post: NigelHalse
  Failed attempts to load Microsoft Appstore Python DLLs piyushd 0 1,014 Oct-31-2023, 10:43 AM
Last Post: piyushd
  Trying to understand strings and lists of strings Konstantin23 2 1,719 Aug-06-2023, 11:42 AM
Last Post: deanhystad
Star Pyserial not reading serial.readline fast enough while using AccelStepper on Arduino MartyTinker 4 8,364 Mar-13-2023, 04:02 PM
Last Post: deanhystad
  Splitting strings in list of strings jesse68 3 2,546 Mar-02-2022, 05:15 PM
Last Post: DeaD_EyE
  serial connection to Arduino Jack9 4 3,740 Oct-22-2021, 10:18 AM
Last Post: Jack9
  Serial loopback with Arduino doesn't work ThomasS 3 3,808 Sep-19-2020, 12:47 PM
Last Post: deanhystad
  Can't transmit serial fast Python to Arduino pyserial mRKlean 0 2,894 Mar-29-2020, 08:12 PM
Last Post: mRKlean
  Finding multiple strings between the two same strings Slither 1 3,234 Jun-05-2019, 09:02 PM
Last Post: Yoriz
  assign the variable to every value received serial from Arduino barry76 4 4,283 Feb-01-2019, 10:19 AM
Last Post: barry76

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020