Workshop 1(3)

20
Arduino workshop 1

description

workshop ceva smecher

Transcript of Workshop 1(3)

Page 1: Workshop 1(3)

Arduino workshop 1

Page 2: Workshop 1(3)

Arduino workshop

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

Page 3: Workshop 1(3)

Serial communication

Page 4: Workshop 1(3)

Serial communication

• Serial– Synchronous

• SPI, I2C– Asynchronous

• Parallel

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

Page 5: Workshop 1(3)

Configuration

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

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

Page 6: Workshop 1(3)

Configuration

– Data bits • Endianness / LSB / MSB

– Synchronization bits• Start /stop bit

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

Page 7: Workshop 1(3)

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

7

7 bits of data (count of 1 bits)8 bits including parity

even odd

0000000 0 00000000 00000001

1010001 3 10100011 10100010

1101001 4 11010010 11010011

1111111 7 11111111 11111110

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

Page 8: Workshop 1(3)

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

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

Page 9: Workshop 1(3)

Serial

• Sending : “OK” (ASCII)– O = 01001111– K = 01001011

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

Page 10: Workshop 1(3)

ASCII Table

• ASCII table, defines a character for each byte• ASCII = 127, extended = 256• Unicode is a superset of ASCII, and the

numbers 0–126 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 bytes– UTF-32 takes 4 bytes for a char

10

Page 11: Workshop 1(3)

Connecting

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

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

Page 12: Workshop 1(3)

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 signals12

Page 13: Workshop 1(3)

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

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

Page 14: Workshop 1(3)

Null modem

• Connecting two devices together on RS232

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

Page 15: Workshop 1(3)

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 bitsand spit out the data.

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

Page 16: Workshop 1(3)

No UART?

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

16

Page 17: Workshop 1(3)

Baudrate mismatch

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

Page 18: Workshop 1(3)

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

Page 19: Workshop 1(3)

Sending text between Arduino’s

• 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';

Page 20: Workshop 1(3)

Assignments1.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)

19200 , 6 data bits , no parity check and 1 stop bit9600 , 8 data bits, even parity check and 2 stop bits