Feb-03-2019, 09:03 AM
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. Screen output become like that b' ' . I need to year,month,day,hour,minute and second data.
[Image: 1pcuo0.jpg]
How to change python code and send to date and time datas
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. Screen output become like that b' ' . I need to year,month,day,hour,minute and second data.
import serial import time import datetime ser = serial.Serial('COM3', 9600, timeout=0) ser.reset_input_buffer() time.sleep(1.5) now=datetime.datetime.now() #str_now=now.strftime("%Y.%m.%d.%H.%M.%S")+'\r\n' year = now.strftime("%Y")+'\r\n' #print("year:", year) #month = now.strftime("%m")+'\r\n' #print("month:", month) #day = now.strftime("%d")+'\r\n' #print("day:", day) #hour = now.strftime("%H")+'\r\n' #print("hour:", hour) #minute = now.strftime("%M")+'\r\n' #print("minute:", minute) #second = now.strftime("%S")+'\r\n' #print("second:", second) #var = input("Enter something: ")+'\r\n' ser.write(year.encode()) while 1: try: print (ser.readline()) time.sleep(1.5) except ser.SerialTimeoutException: print('Data could not be read')Arduino code:
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); } }Output:
[Image: 1pcuo0.jpg]
How to change python code and send to date and time datas