Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Arduino Read Update Datetime from Python
#1
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?

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')
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:
İmage


when i use command line in code,it become like that:
İmage


What differentes to use? I researched nearly all website but no information like that.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  from datetime import * drnshaw 2 76 Aug-16-2019, 08:30 PM
Last Post: drnshaw
  How to update libc6 with Putty SSH? drogontargaryen 1 79 Jul-20-2019, 03:35 PM
Last Post: ndc85430
  XML update using python sathiyarajmca 1 177 Jun-18-2019, 06:11 PM
Last Post: Larz60+
  update values in list based on dictionary bunti 3 712 Jun-10-2019, 07:26 AM
Last Post: perfringo
  is it possible to use python to read and write from a jsx file? nadavrock 3 262 Jun-08-2019, 02:59 AM
Last Post: heiner55
  Problems displaying data sent from Arduino to Pi VostokRising 2 167 May-18-2019, 08:28 PM
Last Post: VostokRising
  ValueError: dictionary update sequence element #0 has length 1; 2 Jmekubo 4 460 Apr-28-2019, 07:25 PM
Last Post: Jmekubo
  Python csv compare two file, update value if two value is matched kinojom 1 212 Apr-17-2019, 10:36 AM
Last Post: DeaD_EyE
  Help me with python read file and save file wereak 9 671 Apr-02-2019, 04:17 PM
Last Post: wereak
  Read Byte Array from Zigbee coordinator using python jenkins43 3 295 Mar-26-2019, 03:03 PM
Last Post: micseydel

Forum Jump:


Users browsing this thread: 1 Guest(s)