Pycharm Arduino
Sample interconnection between arduino and pycharm ...
import serial import time import matplotlib.pyplot as grp arduino = serial.Serial('COM#', 9600, timeout=1) time.sleep(2) data = [] for i in range(50): line = arduino.readline() # read a byte
if line: string = line.decode() # convert byte to unicode num = int(string) # convert unicode to interger print(num) data.append(num) # add interger to database arduino.close() # build the plot grp.plot(data) grp.xlabel('Time') grp.ylabel('Sensor Reading') grp.title('Sensor Reading vs.Time') grp.show()
import serial #pyserial
import time
# Define the serial port and baud rate.
ser = serial.Serial('COM#', 9600)
def led_on_off():
user_input = input("\n Type on / off / quit : ")
if user_input == "on":
print("LED is on...")
time.sleep(0.1)
ser.write(b'1')
led_on_off()
elif user_input == "off":
print("LED is off...")
time.sleep(0.1)
ser.write(b'2')
led_on_off()
elif user_input == "quit" or user_input == "q":
print("Program terminated")
time.sleep(0.1)
ser.write(b'L')
ser.close()
else:
print("Invalid input. Type on / off / quit.")
led_on_off()
import serial
import time
arduino=serial.Serial('COM5', 9600)
time.sleep(2) #sleep 2 secs
print("Type 1 to turn ON LED and 2 to turn OFF LED") #print some output
while 1: #loop forever
x=input()
if x == '1': #datafromUser equals 1?
arduino.write(b'1') #send '1' over serial port
print("LED turned ON") #print some output
elif x == '2': #datafromUser equals 0?
arduino.write(b'2') #send '0' over serial port
print("LED turned OFF") #print some output
Disclaimer: We shall not be liable for any loss or damage of whatever nature - direct, indirect, consequential, or otherwise - which may arise as a result of your use of any information on this website. However, if you are interested in using any of the projects for personal or educational purposes, please inform the author by email for guidance and technical support.
Public Domain Notice: Copyright (c) 1988. All rights reserved. This article is part of a book entitled Autognorics. Copies are welcome to be shared or distributed publicly as long proper citations are observed. Please cite as follows: Inscription by Design, Joey Lawsin, 1988, USA.
==================================================================
Patent Pending. 2000 © ®
A L.A.W.S.I.N. Educational Production
Comments
Post a Comment