Python Forum
Arduino Read Update Datetime from Python
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:
[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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python error on mentioned Arduino port name dghosal 5 849 Aug-22-2023, 04:54 PM
Last Post: deanhystad
  How to read csv file update matplotlib column chart regularly SamLiu 2 1,058 Jan-21-2023, 11:33 PM
Last Post: SamLiu
  Trying to Get Arduino sensor data over to excel using Python. eh5713 1 1,703 Dec-01-2022, 01:52 PM
Last Post: deanhystad
  Is it possible to update a CSS file from Python bigAL_python 4 2,277 Apr-20-2022, 01:38 PM
Last Post: bigAL_python
  |SOLVED] Glob JPGs, read EXIF, update file timestamp? Winfried 5 2,471 Oct-21-2021, 03:29 AM
Last Post: buran
Question Python + Google Sheet | Best way to update specific cells in a single Update()? Vokofe 1 2,675 Dec-16-2020, 05:26 AM
Last Post: Vokofe
  Update Python Files Harshil 3 2,266 Aug-28-2020, 10:52 AM
Last Post: Harshil
  Can't transmit serial fast Python to Arduino pyserial mRKlean 0 2,358 Mar-29-2020, 08:12 PM
Last Post: mRKlean
  About Arduino and Python usb webcam tuts Simurg 1 2,154 Mar-20-2020, 07:25 PM
Last Post: Larz60+
  Help Graphing Arduino Data Real Time in Python nschulz 0 2,532 Mar-12-2020, 06:15 PM
Last Post: nschulz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020