Vous êtes sur la page 1sur 20

Arduino workshop 1

Arduino workshop
4 workshops (for 3 labs)
1 resit workshop

Serial communication

Serial communication
Serial
Synchronous
SPI, I2C

Asynchronous

Parallel

4
https://learn.sparkfun.com/tutorials/serial-communication

Configuration

Data bits
Synchronization bits
Parity bits
Baud rate (bits/s)

5
https://learn.sparkfun.com/tutorials/serial-communication

Configuration
Data bits
Endianness / LSB / MSB

Synchronization bits
Start /stop bit

6
https://learn.sparkfun.com/tutorials/serial-communication

Configuration
Parity bits
very simple, low-level error
checking.
odd or even parity setting
all 5-9 bits of the data byte are
added
up
8 bits including parity
7 bits of data
(count of 1 bits)

even

odd

0000000

00000000

00000001

1010001

10100011

10100010

1101001

11010010

11010011

1111111

11111111

11111110
7
https://learn.sparkfun.com/tutorials/serial-communication

Configuration
Baud rate (bits/s)
9600 bps. Other standard baudrates
are 1200, 2400, 4800, 19200, 38400,
57600, and 115200.

Configuration: 9600 8N1 = 9600


baud, 8 data bits, no parity, and 1
stop bit
Eg. 9600 5E2 , 115200 7O1
8
https://learn.sparkfun.com/tutorials/serial-communication

Serial
Sending : OK (ASCII)
O = 01001111
K = 01001011

9
https://learn.sparkfun.com/tutorials/serial-communication

ASCII Table
ASCII table, defines a character for
each byte
ASCII = 127, extended = 256
Unicode is a superset of ASCII, and
the numbers 0126 are the same in
ASCII as they are in Unicode.
1.112.064 characters.
UTF-8 .. UTF-32
UTF-8, char can take between 1 and 4
10
bytes

Connecting
Full-duplex: send and receive
simultaneously.
Half-duplex: take turns sending and
receiving.
Simplex: single connection to send

11
https://learn.sparkfun.com/tutorials/serial-communication

Implementation
TTL serial (transistor-transistor logic)
Easier but more loss at long distance
0V (logic 0 ) and Vcc (3.3v / 5V) (logic 1)

RS232
-3V to -25V = 1
3V to 25V = 0
Mostly used = -13 to +13V

Shift signals
12

RS232

Tx: Transmit (or TD, Transmit Data)


Rx: Receive (or RD, Receive Data)
DTR: Data Terminal Ready
DSR: Data Set Ready
RTS: Request to Send
CTS: Clear To Send
DCD: Data Carrier Detect
RI: Ring Indicator
13
https://learn.sparkfun.com/tutorials/serial-communication

Null modem
Connecting two devices together on
RS232

14
http://en.wikipedia.org/wiki/Null_modem

UART
A universal asynchronous receiver/transmitter
(UART) is a block of circuitry responsible for
implementing serial communication
Create the data packet(data,sync,parity)
TX: Send packet at
baudrate speed
RX :Sample line at baudrate
pick out the sync bits
and spit out the data.

15
https://learn.sparkfun.com/tutorials/serial-communication

No UART?
Bit banging, control the lines in
software
Used in SoftwareSerial
Processor-intensive, not as precise
as a UART

16

Baudrate mismatch

17
https://cdn.sparkfun.com/assets/c/e/2/d/a/50d247c5ce395fdc6b000000.png

Arduino
Serial:
Serial.begin(57600);
Serial.println(Hi!");
SoftSerial:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
mySerial.begin(9600);
mySerial.println("Hello, world?");
18

Sending text between


Arduinos
ASCII table, defines a character for each
byte, 127 characters
Text is converted to int ( ASCII value )
and send in binary

// get the int ascii value of


int numberInt;
char numberChar = 3;
numberInt = numberChar -'0';

Assignments
1.1. Putty <> Serial port <> Rx Tx Loop on Arduino board, measure
with the oscilloscope
1.2. Putty <> Serial port <> Arduino <> Software serial port <> Rx
Tx Loop
(Use Altsoftserial)
1.3. Putty <> Serial port <> Arduino <> Software serial port <> Null
modem <> Software serial port <> Arduino <> Serial port <> Putty
1.4. BONUS: Putty <> Serial port <> Arduino <> Software serial
port <> Null modem <> Software serial port <> Arduino <> Sensor
// request sensor data from port e.g. A5, not just streaming
sensor data
1.5. BONUS: Demonstrate correct communication using the
following Serial configurations between Arduino and Putty: (HINT: look
into Serial.begin() parameters)

Vous aimerez peut-être aussi