I am trying to write four values relating to energy (current, power, energy, and peak demand) via a SoftwareSerial connection from my Arduino UNO to my Raspberry Pi 4. However, two things are occurring:
All of the values should be different, but they are printing to the RPi terminal as if they're identical.
It seems as if the values I'm writing are merging together(?), creating a nonsense value. For example, if the values that I'm sending are 0.24, 28, 0.05, and 71, they appear in the RPI terminal looking like this:
Current: 54543878
Power: 54543878
Energy: 54543878
Peak Power: 54543878
This is a snip of my Arduino code that writes to the Bluetooth serial connection (uses HC-06):
bluetoothSerial.write(RMSCurrent);
bluetoothSerial.write(RMSPower);
bluetoothSerial.write(kilos);
bluetoothSerial.write(peakPower);
This is a snip of the Python script that receives it:
while 1:
try:
received_data = bluetoothSocket.recv(1024)
RMSCurrent = int.from_bytes(received_data,byteorder='big')
RMSPower = int.from_bytes(received_data,byteorder='big')
kilos = int.from_bytes(received_data,byteorder='big')
peakPower = int.from_bytes(received_data,byteorder='big')
print("Current (A): %d" % RMSCurrent)
print("Power (W): %d" % RMSPower)
print("Energy (kWh): %d" % kilos)
print("Peak Demand: %d" % peakPower)
except KeyboardInterrupt:
print("keyboard interrupt detected")
break
bluetoothSocket.close()
Does anyone have any ideas of what is going on? Two of my values are floats and two are integers. I've tried to fix this for the past 12 hours, but to no avail.
printing to the RPi terminal as if they're identical
... why are you surprised? ... it appears that you are setting all four to the same value .... print the value ofreceived_data
instead0.24
is not an int. You python code expects ints only (and reads the first bytes of received_data four times).