Skip to content

Commit 8902b73

Browse files
Added serial communication test for jetson
1 parent 9d824f2 commit 8902b73

File tree

6 files changed

+133
-0
lines changed

6 files changed

+133
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cells": [],
3+
"metadata": {},
4+
"nbformat": 4,
5+
"nbformat_minor": 4
6+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#! /usr/bin/env python3
2+
3+
import serial
4+
import time
5+
6+
ON = bytes("on","utf8")
7+
OFF = bytes("off","utf8")
8+
9+
def main():
10+
led_state = True
11+
with serial.Serial('/dev/ttyUSB1',115200,timeout=3.) as port:
12+
time.sleep(1.6)
13+
while(True):
14+
next_led_state = ON if led_state else OFF
15+
print("asking led to switch on" if led_state else "asking led to switch off")
16+
port.write(next_led_state)
17+
port.flush()
18+
response = port.readline()
19+
print(response)
20+
led_state = not led_state
21+
time.sleep(.1)
22+
23+
if __name__=="__main__":
24+
main()
25+

jetson-nano-plastic-detector/serial-communication/.ipynb_checkpoints/__init__-checkpoint.py

Whitespace-only changes.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 2,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import serial"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": 5,
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"port = serial.Serial('/dev/ttyUSB0',9600)"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": 44,
24+
"metadata": {},
25+
"outputs": [
26+
{
27+
"name": "stdout",
28+
"output_type": "stream",
29+
"text": [
30+
"b'-1891\\t5897\\r\\n'\n"
31+
]
32+
}
33+
],
34+
"source": [
35+
"print(port.readline())"
36+
]
37+
},
38+
{
39+
"cell_type": "code",
40+
"execution_count": 66,
41+
"metadata": {},
42+
"outputs": [
43+
{
44+
"name": "stdout",
45+
"output_type": "stream",
46+
"text": [
47+
"4\n"
48+
]
49+
}
50+
],
51+
"source": [
52+
"print(port.write(bytes(\"123\\n\",\"utf8\")))"
53+
]
54+
}
55+
],
56+
"metadata": {
57+
"kernelspec": {
58+
"display_name": "Python 3",
59+
"language": "python",
60+
"name": "python3"
61+
},
62+
"language_info": {
63+
"codemirror_mode": {
64+
"name": "ipython",
65+
"version": 3
66+
},
67+
"file_extension": ".py",
68+
"mimetype": "text/x-python",
69+
"name": "python",
70+
"nbconvert_exporter": "python",
71+
"pygments_lexer": "ipython3",
72+
"version": "3.6.9"
73+
}
74+
},
75+
"nbformat": 4,
76+
"nbformat_minor": 4
77+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#! /usr/bin/env python3
2+
3+
import serial
4+
import time
5+
6+
ON = bytes("on","utf8")
7+
OFF = bytes("off","utf8")
8+
9+
def main():
10+
led_state = True
11+
with serial.Serial('/dev/ttyUSB1',115200,timeout=3.) as port:
12+
time.sleep(1.6)
13+
while(True):
14+
next_led_state = ON if led_state else OFF
15+
print("asking led to switch on" if led_state else "asking led to switch off")
16+
port.write(next_led_state)
17+
port.flush()
18+
response = port.readline()
19+
print(response)
20+
led_state = not led_state
21+
time.sleep(.1)
22+
23+
if __name__=="__main__":
24+
main()
25+

jetson-nano-plastic-detector/serial-communication/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)