I dont know how to send and integer by serial port from raspberry to arduino
I am trying to connect my raspberry pi with an arduino mega via usb. I did the connection and I can send an integer but only if i put the number by keyboard here is the code:
import serial import time arduino=serial.Serial('/dev/ttyUSB0',baudrate=9600, timeout = 3.0) arduino.close() arduino.open() var = raw_input("Introducir un Comando: ") arduino.write(var)
but if I want to send a varible integer like
var=1 it appears an error saying that the port is close, only making this change. I tried using var =1, var ='1' var ="1" but nothing.
Can anyone help me? thanks and sorry for my bad english.
My friends helped me. The way to send is:
after open the port wait with the time library 1 second.
import time time.sleep(1)
and then the way to send it is:
and we send a number 3. Thanks to everyone.