0

I am trying to send the data calculated on Python to an Arduino but I think below method sends the whole double at one clock cycle. How can I split this into a byte array and send one byte at a time?

ser.write(bytes(round(i * double(self.amplitude), 5)))
ser = serial.Serial(
     port=self.outputFile,
     baudrate=115200,
     parity=serial.PARITY_ODD,
     stopbits=serial.STOPBITS_ONE,
     bytesize=serial.EIGHTBITS
)
for i in created_wave:
     ser.write(bytes(round(i * double(self.amplitude), 5)))
                

1 Answer 1

0

I don't know why but I couldn't access the elements of bytearr using bytearr[j] notation but I accessed them with bytearr[j:j+1] notation. It works this way.

            ser = serial.Serial(
                port=self.outputFile,
                baudrate=115200,
                parity=serial.PARITY_ODD,
                stopbits=serial.STOPBITS_ONE,
                bytesize=serial.EIGHTBITS
            )
            for i in created_wave:
                bytearr = struct.pack('f', round(i * float(self.amplitude), 5)) #4 byte
                for j in range(len(bytearr)):
                    ser.write(bytearr[j:j + 1])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.