File tree 6 files changed +75
-0
lines changed
6 files changed +75
-0
lines changed Original file line number Diff line number Diff line change
1
+ # import the serial and time library
2
+ import serial
3
+ import time
4
+
5
+ # initialize a serial object using our serial library
6
+ # Note: It is very important to mention the correct COM port name.
7
+ # It can found by using the Device manager on your computer.
8
+ arduinoData = serial .Serial ('com3' , 9600 )
9
+
10
+ # hold the program for two seconds
11
+ time .sleep (2 )
12
+
13
+ # read anything coming from Arduino
14
+ data = arduinoData .readline ()
15
+ print (data .decode ('utf-8' ))
16
+ # read another line coming from Arduino
17
+ print (arduinoData .readline ().decode ('utf-8' ))
18
+
19
+
20
+ while 1 :
21
+ # get input from user
22
+ data = input ('-->' )
23
+
24
+ if (data == '1' ):
25
+ # write the value of the parameter to Arduino
26
+ arduinoData .write (data .encode ('utf-8' ))
27
+ print (arduinoData .readline ().decode ('utf-8' ))
28
+
29
+ if (data == '0' ):
30
+ arduinoData .write (data .encode ('utf-8' ))
31
+ print (arduinoData .readline ().decode ('utf-8' ))
Original file line number Diff line number Diff line change
1
+ char serialData;
2
+
3
+ void setup ()
4
+ {
5
+ Serial.begin (9600 );
6
+ pinMode (LED_BUILTIN, OUTPUT);
7
+
8
+ Serial.println (" Hi!, I am Arduino" );
9
+ // Serial.print("Hi!, I am Arduino\n");
10
+ // Serial.write("Hi!, I am Arduino\n");
11
+
12
+ Serial.println (" Enter 1 to turn ON LED and 0 to turn OFF LED" );
13
+ }
14
+
15
+ void loop ()
16
+ {
17
+ /*
18
+ while (Serial.available())
19
+ {
20
+ serialData = Serial.read();
21
+ Serial.print(serialData);
22
+ }
23
+ */
24
+
25
+ if (Serial.available () > 0 )
26
+ {
27
+ serialData = Serial.read ();
28
+ if (serialData == ' 1' )
29
+ {
30
+ digitalWrite (LED_BUILTIN, HIGH);
31
+ Serial.println (" LED turned ON" );
32
+ }
33
+ else if (serialData == ' 0' )
34
+ {
35
+ digitalWrite (LED_BUILTIN, LOW);
36
+ Serial.println (" LED turned OFF" );
37
+ }
38
+ }
39
+ }
Original file line number Diff line number Diff line change
1
+ # ** Python & Arduino**
2
+
3
+ ![ Arduino] ( images/1arduino.png ) ![ Laptop] ( images/2-lenovo-ideapad-300.png )
4
+
5
+ ![ Library] ( images/pyserial.PNG )
You can’t perform that action at this time.
0 commit comments