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
  Unable to read update access DB saaketh 1 125 Sep-24-2019, 11:37 AM
Last Post: Malt
  update certbot's python version metulburr 0 143 Sep-19-2019, 11:51 AM
Last Post: metulburr
  TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'str' findbikash 2 288 Sep-18-2019, 08:32 AM
Last Post: buran
  Read 2 temperatures in Real Time from Arduino linkxxx 0 195 Aug-29-2019, 11:27 AM
Last Post: linkxxx
  XML update using python sathiyarajmca 1 290 Jun-18-2019, 06:11 PM
Last Post: Larz60+
  Arduino / Python Environment Setup - PIP stevealbright 0 329 Feb-24-2019, 10:48 PM
Last Post: stevealbright
  Program arduino using python sumandas89 2 1,082 Nov-30-2018, 06:29 AM
Last Post: havenronn
  How do i read particular text from text file and update those values in MS SQL table ganeshsai2912 33 3,262 Nov-20-2018, 12:55 AM
Last Post: ganeshsai2912
  Interface Arduino and MSSQL using Python MichaelDean 0 607 Nov-18-2018, 05:00 PM
Last Post: MichaelDean
  Convert arduino code to python JDutch 3 2,955 Nov-07-2018, 09:16 PM
Last Post: Larz60+

Forum Jump:


Users browsing this thread: 1 Guest(s)