Feb-03-2019, 05:13 PM
I am learning Python new and i want send to date and time but i have some problem.
When i write to input method something, i can send to my message.But the message been date and time on windows ,cannot send to arduino.
How to send to year,month,day,hour,second,minute?
Arduino code:
Output:
[Image: 1pcuo0.jpg]
when i use command line in code,it become like that:
[Image: 6pqjck.jpg]
What differentes to use? I researched nearly all website but no information like that.
When i write to input method something, i can send to my message.But the message been date and time on windows ,cannot send to arduino.
How to send to year,month,day,hour,second,minute?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import serial import time import datetime ser = serial.Serial( 'COM3' , 9600 , timeout = 0 ) ser.reset_input_buffer() time.sleep( 1.5 ) d = datetime.datetime.now() print ( "d:" ,d) now_year = str (d.year) now_month = str (d.month) now_day = str (d.day) now_hour = str (d.hour) now_minute = str (d.minute) now_second = str (d.second) #var = input("Enter something: ")+'\r\n' #ser.write(var.encode()) ser.write(now_month.encode()) while 1 : try : print (ser.readline()) time.sleep( 1.5 ) except ser.SerialTimeoutException: print ( 'Data could not be read' ) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
int incomingByte = 0 ; void setup(){ / / Open serial connection. Serial.begin( 9600 ); } void loop(){ if (Serial.available() > 0 ) { / / read the incoming byte: incomingByte = Serial.read(); / / say what you got: Serial. print ( "I got: " ); / / ASCII printable characters Serial.println(incomingByte,DEC); } } |
[Image: 1pcuo0.jpg]
when i use command line in code,it become like that:
[Image: 6pqjck.jpg]
What differentes to use? I researched nearly all website but no information like that.