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
  show and storage real temperature data Arduino in Python3 linkxxx 0 108 Aug-21-2019, 04:07 PM
Last Post: linkxxx
  from datetime import * drnshaw 2 92 Aug-16-2019, 08:30 PM
Last Post: drnshaw
  How to update libc6 with Putty SSH? drogontargaryen 1 91 Jul-20-2019, 03:35 PM
Last Post: ndc85430
  XML update using python sathiyarajmca 1 184 Jun-18-2019, 06:11 PM
Last Post: Larz60+
  update values in list based on dictionary bunti 3 720 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 270 Jun-08-2019, 02:59 AM
Last Post: heiner55
  Problems displaying data sent from Arduino to Pi VostokRising 2 181 May-18-2019, 08:28 PM
Last Post: VostokRising
  ValueError: dictionary update sequence element #0 has length 1; 2 Jmekubo 4 498 Apr-28-2019, 07:25 PM
Last Post: Jmekubo
  Python csv compare two file, update value if two value is matched kinojom 1 214 Apr-17-2019, 10:36 AM
Last Post: DeaD_EyE
  Help me with python read file and save file wereak 9 693 Apr-02-2019, 04:17 PM
Last Post: wereak

Forum Jump:


Users browsing this thread: 1 Guest(s)