Serial Communication and Networking Jun Hu Today Serial

  • Slides: 28
Download presentation
Serial Communication and Networking Jun Hu

Serial Communication and Networking Jun Hu

Today • Serial Communication • Between Arduino and Processing • Networking • Client/Server between

Today • Serial Communication • Between Arduino and Processing • Networking • Client/Server between two Processing programs Department of Industrial Design 26 -9 -2020 PAGE 1

Serial Communication • Using Serial Library of Processing • https: //www. processing. org/reference/libraries/serial/index. html

Serial Communication • Using Serial Library of Processing • https: //www. processing. org/reference/libraries/serial/index. html • And Arduino Serial Class • https: //www. arduino. cc/en/Reference/Serial Department of Industrial Design 26 -9 -2020 PAGE 2

Simple. Read Department of Industrial Design 26 -9 -2020 PAGE 3

Simple. Read Department of Industrial Design 26 -9 -2020 PAGE 3

Simple. Read Department of Industrial Design 26 -9 -2020 PAGE 4

Simple. Read Department of Industrial Design 26 -9 -2020 PAGE 4

Simple. Read Department of Industrial Design 26 -9 -2020 PAGE 5

Simple. Read Department of Industrial Design 26 -9 -2020 PAGE 5

Simple. Read Department of Industrial Design 26 -9 -2020 PAGE 6

Simple. Read Department of Industrial Design 26 -9 -2020 PAGE 6

Simple. Write Department of Industrial Design 26 -9 -2020 PAGE 7

Simple. Write Department of Industrial Design 26 -9 -2020 PAGE 7

Simple. Write Department of Industrial Design 26 -9 -2020 PAGE 8

Simple. Write Department of Industrial Design 26 -9 -2020 PAGE 8

Simple. Write Department of Industrial Design 26 -9 -2020 PAGE 9

Simple. Write Department of Industrial Design 26 -9 -2020 PAGE 9

Firmata • http: //playground. arduino. cc/Interfacing/processing Department of Industrial Design 26 -9 -2020 PAGE

Firmata • http: //playground. arduino. cc/Interfacing/processing Department of Industrial Design 26 -9 -2020 PAGE 10

Firmata • http: //playground. arduino. cc/Interfacing/processing Department of Industrial Design 26 -9 -2020 PAGE

Firmata • http: //playground. arduino. cc/Interfacing/processing Department of Industrial Design 26 -9 -2020 PAGE 11

Firmata • http: //playground. arduino. cc/Interfacing/processing Department of Industrial Design 26 -9 -2020 PAGE

Firmata • http: //playground. arduino. cc/Interfacing/processing Department of Industrial Design 26 -9 -2020 PAGE 12

Firmata • http: //playground. arduino. cc/Interfacing/processing Department of Industrial Design 26 -9 -2020 PAGE

Firmata • http: //playground. arduino. cc/Interfacing/processing Department of Industrial Design 26 -9 -2020 PAGE 13

Firmata • http: //playground. arduino. cc/Interfacing/processing Department of Industrial Design 26 -9 -2020 PAGE

Firmata • http: //playground. arduino. cc/Interfacing/processing Department of Industrial Design 26 -9 -2020 PAGE 14

Client/Server Networking • Help>Reference: Libraries : Network : Server • Help>Reference: Libraries : Network

Client/Server Networking • Help>Reference: Libraries : Network : Server • Help>Reference: Libraries : Network : Client Department of Industrial Design 26 -9 -2020 PAGE 15

Client/Server Networking • Before we continue … Department of Industrial Design 26 -9 -2020

Client/Server Networking • Before we continue … Department of Industrial Design 26 -9 -2020 PAGE 16

Client/Server Networking • Find your IP • On windows: • WIN+R, cmd, ipconfig •

Client/Server Networking • Find your IP • On windows: • WIN+R, cmd, ipconfig • On Mac: • Applications menu>Utilities>Terminal, ifconfig Department of Industrial Design 26 -9 -2020 PAGE 17

Client/Server Networking Server. Background Client. Background Department of Industrial Design 26 -9 -2020 PAGE

Client/Server Networking Server. Background Client. Background Department of Industrial Design 26 -9 -2020 PAGE 18

Client/Server Networking • Now try to change the server code: • Reacts to mouse

Client/Server Networking • Now try to change the server code: • Reacts to mouse clicks • Position of the mouse changes the background color • Send the background color to clients Department of Industrial Design 26 -9 -2020 PAGE 19

Client/Server Networking Server. Click Department of Industrial Design Client. React 26 -9 -2020 PAGE

Client/Server Networking Server. Click Department of Industrial Design Client. React 26 -9 -2020 PAGE 20

Client/Server Networking • Now try out with your neighbor Ms/r Nice: • Nice runs

Client/Server Networking • Now try out with your neighbor Ms/r Nice: • Nice runs the server. • You replace “ 127. 0. 0. 1” in your client with the IP address of Ms/r Nice’s computer • You run the client. • Try the opposite. • Later you can always try the same. Department of Industrial Design 26 -9 -2020 PAGE 21

Client/Server Networking • Now try to change the client code: • Reacts to mouse

Client/Server Networking • Now try to change the client code: • Reacts to mouse clicks • Position of the mouse changes the background color • Send the background color to the server Department of Industrial Design 26 -9 -2020 PAGE 22

Client/Server Networking Server. React Department of Industrial Design Client. Click 26 -9 -2020 PAGE

Client/Server Networking Server. React Department of Industrial Design Client. Click 26 -9 -2020 PAGE 23

Client/Server Networking • Now let’s synchronize the background of all clients and the server.

Client/Server Networking • Now let’s synchronize the background of all clients and the server. Department of Industrial Design 26 -9 -2020 PAGE 24

Client/Server Networking Server. Click. NReact Client. Click. NReact 26 -9 -2020 PAGE 25

Client/Server Networking Server. Click. NReact Client. Click. NReact 26 -9 -2020 PAGE 25

Today • Serial Communication • Between Arduino and Processing • Networking • Client/Server between

Today • Serial Communication • Between Arduino and Processing • Networking • Client/Server between two Processing programs Department of Industrial Design 26 -9 -2020 PAGE 26

Homework • Try out the examples that come with Firmata for both input (button

Homework • Try out the examples that come with Firmata for both input (button or LDR) and output (LED on/off). • For serial communication, try to combine Simple. Read and Simple. Write, such that • • When an Arduino button is pressed, Processing changes the background; When the mouse is detected in a rectangle in Processing, light up an LED on Arduino. Clicking outside the rectangle switches off the LED. • Try to extend the above with client/server networking, such that • • When an Arduino button is pressed, the signal will be sent to a local Processing program, then to a remote Processing program to change its background; When the mouse is detected in a rectangle in a local Processing program, the signal will be sent to a remote Processing program, where an Arduino is connected, to light up the LED on the Arduino. Clicking outside the rectangle switches off the LED. Department of Industrial Design 26 -9 -2020 PAGE 27