SlideShare une entreprise Scribd logo
1  sur  26
PHYSICAL PROTOTYPING
© 2011 K3 Creative Commons v3.0 SA-NC
Lab 3: Serious Serial
…and small sounds
With the Arduino prototyping board
SERIAL COMMUNICATION
Serial.xxxx
Serial is a class designed to use serial communication
Serial.begin(baud);
Placed in setup() to initiate serial communication at a certain baudrate (speed)
Typical transmission speed for many existing devices is 9600 bps (bits per second)
Serial.print();
Writes (sends) anything to the serial port
Serial.println();
Writes (sends) with CR (carriage return) and LF (line feed)
Serial.available();
Used to check if data has arrived over the serial port
Serial.read();
Reads the first byte that arrived to the port and erases it from the communication buffer
2
3
After line feed:
After carriage return:
cursor
cursor
cursor
SERIAL COMMUNICATION
is used to have your Arduino and your
personal computer ‘talk’ to each other
(send data)
SERIAL
4
ASCII vs. RAW BYTES
ASCII stands for American Standard Code for
Information Interchange
Alphanumeric characters are represented by
numbers ranging from 0 to 127 and are translated
into a 7-bit binary code. ASCII allows for easy
transfer of text-only files between different kinds of
computers
ASCII can be extended to cover symbol tables for
other languages
5
ASCII vs. RAW BYTES
One could say that ASCII is kind of a markup
language for symbols
The symbol 'A' (which represents the capital letter
A) is represented by numeric code 65, the symbol
for number '1' by numeric code 49, etc.
The communication between devices is encoded
using this standard
This allows including special symbols like:
LineFeed (LF), Carriage Return, Tab(ulator) (T)...
6
Source: http://www.it-echo.com/2009/01/11/ascii-table-decimal-hex-oct-html-char.html
ASCII vs. RAW BYTES
Arduino uses 8N1 serial communication, this means
that information is encoded in packages of 8-bits
(1 byte)
With 8-bits we can encode 255 different symbols
If we were just sending numbers, smaller than 255,
we wouldn't need to encode the data. We could just
send bytes
Most of the times, this is not the case, therefore we
need to use ASCII as a code
8
ASCII vs. RAW BYTES
Serial.print() or Serial.println() will, by
default, encode all the data as ASCII
Therefore, the command: Serial.print(1) will
send the code 49 over the serial line
Serial.println(1) will send, in this order, 49-
10-13
Terminal programs like Bray-Terminal for Windows,
or Gnome Serial for Linux can show the pure data
sent
9
ASCII vs. RAW BYTES
• Arduino's IDE Serial Monitor is ready to present
only ASCII data
• This means that the black window at the IDE's
bottom will display only the ASCII representation
of numbers
• Therefore, Serial.print(67, BYTE) will
show character 'C'
• Serial.print(1) will show character '1'
• BYTE is commonly used to send information to
programs like Processing and Puredata
10
ABOUT THE SPEED
Arduino is a small but powerful computer designed
to do just three tasks at the same time:
– send/receive serial data
– operate analog outputs
– compute your program
Arduino’s processor works at 16MHz, and makes
about 1.000.000 operations/second.
If you send data at that pace, there is no computer
in the world that can follow
11
ABOUT THE SPEED
It is necessary to wait a short amount of time
between messages when sending data from your
Arduino to your computer otherwise you might run
the risk of hanging up your computer.
You should use delay(50)if you want the Serial
Monitor to display what comes through the port. If
the delay is any shorter, it’s hard to read the values.
Personal computers are capable of doing many
things at the same time. Arduino is good at doing
only one particular task very quickly, over and over
again.
12
LIVECODING
• Serial.begin();
• Serial.print();
• Serial.println();
• Speed issues
• Monitor
• Remember the delay(50);
13
SENDING SERIAL BACK
• We can also send data from the computer
to Arduino
• The best is to make use of a simple
character or symbol-based communication
protocol
• It is of course possible to send full strings
between the computer and Arduino, but
that will require too much effort in parsing
the information
14
LIVECODING
See:
Examples / Communication / PhysicalPixel
Serial.available();
Serial.read();
Using serial input switch on and off the
onboard LED at port 13
15
SOFTWARE TO USE
Connecting to Flash and other programs like
PureData, Processing, MAX/MSP, VVVV, Isadora,
etc is a story for another time, it involves serial
communication in both directions.
There are plenty of examples of installations that
make use of serial communication
Also, two Arduinos can communicate with each
other through serial communication, using the TX
and RX pins.
16
EXERCISE ►MAKING 2 ARDUINOS TALK
• In pairs, connect
your Arduinos
• Connect RX to TX
• Connect TX to RX
• GND to GND
• Create a protocol to
do the Physical
pixel between two
Arduinos
17
SMALL SOUNDS
PIEZO ELEMENT/BUZZER
a.k.a. CONTACT MICROPHONE
The piezo element is both a sensor and an actuator
As sensor:
Check the example ANALOG/KNOCK
As actuator:
Electronic music greeting cards
18
SMALL SOUNDS
Piezo speaker can be replaced by a stereo plug
which you connect to another sound output
*BEWARE* the sound output is VERY high when
connected to a stereo or headphones
=
19
HOW TO PLAY SOUNDS
Piezos consist of materials which attract / repel each
other (vibrate) when flows through them.
Quick vibrations on the piezo element produce sounds
We only need to connect the piezo directly to an output
and write the pin HIGH and LOW
We will use the method delayMicroseconds(time)to
create soundwaves
20
EXAMPLE ►PLAY “A”
int outputPin = 9; // plug the piezo to pin 9
void setup() {
pinMode(outputPin, OUTPUT); // declare the piezo pin as
an output
}
void loop() {
digitalWrite(outputPin, HIGH);
delayMicroseconds(1136); // the time here will
// determine the
tone
digitalWrite(outputPin, LOW);
delayMicroseconds(1136); // the time here will
// determine the tone
}
21
EXERCISE ►FM OSCILLATOR
Connect a potentiometer to an analog
input, the Piezo element to a ‘digital’ input
and make a sound generator which lets you
change the tone by turning the potentiometer
22
potentiometer
EXERCISE ►OSCILLATOR
int outputPin = 9; // plug the piezo to pin 9
int inputPin = 2; // the potentiometer at analog 2
void setup() {
pinMode(outputPin, OUTPUT); // declare the piezo pin as an
output
}
void loop() {
int val = analogRead(inputPin); // read the potentiometer into a
variable
digitalWrite(outputPin, HIGH);
delayMicroseconds(val); // the time here will determine the
tone
digitalWrite(outputPin, LOW);
delayMicroseconds(val); // the time here will determine the
tone
}23
MODIFY
Modify the code to create more funky sounds!
See Webzone for some examples
24
HOMEWORK: SERIAL KEYBOARD
Make a program in Arduino that plays sounds when
receiving characters over the serial port
e.g. the character 'E' should play the tone 'E4'
The interaction with the program will happen
entirely through serial communication
HINT: the table on next slide shows the
delayMicroseconds value for the notes
Go wild on your serial synthesizer!
25
HOMEWORK: SERIAL KEYBOARD
tone frequency period delay
C4 261,63 3,822 1,911
D4 293,66 3,405 1,703
E4 329,63 3,034 1,517
F4 349,23 2,863 1,432
G4 392,00 2,551 1,276
A4 440,00 2,273 1,136
B4 493,88 2,025 1,012
C5 523,25 1,911 0,956
26

Contenu connexe

Tendances

The IoT Academy IoT training Arduino Part 5 Arduino peripherals
The IoT Academy IoT training Arduino Part 5 Arduino peripheralsThe IoT Academy IoT training Arduino Part 5 Arduino peripherals
The IoT Academy IoT training Arduino Part 5 Arduino peripherals
The IOT Academy
 
Introduction to the Arduino
Introduction to the ArduinoIntroduction to the Arduino
Introduction to the Arduino
Wingston
 

Tendances (20)

برمجة الأردوينو - اليوم الأول
برمجة الأردوينو - اليوم الأولبرمجة الأردوينو - اليوم الأول
برمجة الأردوينو - اليوم الأول
 
Interface stepper motor through Arduino using LABVIEW.
Interface stepper motor through Arduino using LABVIEW.Interface stepper motor through Arduino using LABVIEW.
Interface stepper motor through Arduino using LABVIEW.
 
Arduino Programming
Arduino ProgrammingArduino Programming
Arduino Programming
 
Programming with arduino
Programming with arduinoProgramming with arduino
Programming with arduino
 
Distance measurement using Ultrasonic sensor on Arduino Uno
Distance measurement using Ultrasonic sensor on Arduino UnoDistance measurement using Ultrasonic sensor on Arduino Uno
Distance measurement using Ultrasonic sensor on Arduino Uno
 
Qt arduino serial_port
Qt arduino serial_portQt arduino serial_port
Qt arduino serial_port
 
Arduino
ArduinoArduino
Arduino
 
Astrobot session 3
Astrobot session 3Astrobot session 3
Astrobot session 3
 
Intro to Arduino
Intro to ArduinoIntro to Arduino
Intro to Arduino
 
Programming arduino makeymakey
Programming arduino makeymakeyProgramming arduino makeymakey
Programming arduino makeymakey
 
The IoT Academy IoT training Arduino Part 5 Arduino peripherals
The IoT Academy IoT training Arduino Part 5 Arduino peripheralsThe IoT Academy IoT training Arduino Part 5 Arduino peripherals
The IoT Academy IoT training Arduino Part 5 Arduino peripherals
 
Lab2ppt
Lab2pptLab2ppt
Lab2ppt
 
Introduction to the Arduino
Introduction to the ArduinoIntroduction to the Arduino
Introduction to the Arduino
 
How to measure frequency and duty cycle using arduino
How to measure frequency and duty cycle using  arduinoHow to measure frequency and duty cycle using  arduino
How to measure frequency and duty cycle using arduino
 
Introduction to arduino!
Introduction to arduino!Introduction to arduino!
Introduction to arduino!
 
Arduino Workshop
Arduino WorkshopArduino Workshop
Arduino Workshop
 
Arduino slides
Arduino slidesArduino slides
Arduino slides
 
Multi Sensory Communication 2/2
Multi Sensory Communication 2/2Multi Sensory Communication 2/2
Multi Sensory Communication 2/2
 
Basic Sensors
Basic Sensors Basic Sensors
Basic Sensors
 
Arduino cic3
Arduino cic3Arduino cic3
Arduino cic3
 

En vedette

13η συνάντηση
13η συνάντηση13η συνάντηση
13η συνάντηση
prasino
 
David Cuartielles and Tony Olsson - Going Physical (K3 research seminar)
David Cuartielles and Tony Olsson - Going Physical (K3 research seminar)David Cuartielles and Tony Olsson - Going Physical (K3 research seminar)
David Cuartielles and Tony Olsson - Going Physical (K3 research seminar)
K3Research
 
Karen Riley Resume3 Project Coordinator
Karen Riley Resume3 Project CoordinatorKaren Riley Resume3 Project Coordinator
Karen Riley Resume3 Project Coordinator
Karen Riley
 
LINK - Discovery Communications
LINK - Discovery CommunicationsLINK - Discovery Communications
LINK - Discovery Communications
Gabriela Galke
 
Gongali Model Presentation
Gongali Model PresentationGongali Model Presentation
Gongali Model Presentation
Gabriela Galke
 

En vedette (16)

13η συνάντηση
13η συνάντηση13η συνάντηση
13η συνάντηση
 
Physical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalPhysical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digital
 
David Cuartielles and Tony Olsson - Going Physical (K3 research seminar)
David Cuartielles and Tony Olsson - Going Physical (K3 research seminar)David Cuartielles and Tony Olsson - Going Physical (K3 research seminar)
David Cuartielles and Tony Olsson - Going Physical (K3 research seminar)
 
Creating an Integrated International Public Relations Campaign
Creating an Integrated International Public Relations CampaignCreating an Integrated International Public Relations Campaign
Creating an Integrated International Public Relations Campaign
 
Матрица. КРС - система для автоматизации работы ферм и колхозов работающих с ...
Матрица. КРС - система для автоматизации работы ферм и колхозов работающих с ...Матрица. КРС - система для автоматизации работы ферм и колхозов работающих с ...
Матрица. КРС - система для автоматизации работы ферм и колхозов работающих с ...
 
1С. Свиноводство - АВТОМАТИЗАЦИЯ ЗООТЕХНИЧЕСКОГО И ПЛЕМЕННОГО СВИНОВОДСТВА
1С. Свиноводство - АВТОМАТИЗАЦИЯ ЗООТЕХНИЧЕСКОГО И ПЛЕМЕННОГО СВИНОВОДСТВА1С. Свиноводство - АВТОМАТИЗАЦИЯ ЗООТЕХНИЧЕСКОГО И ПЛЕМЕННОГО СВИНОВОДСТВА
1С. Свиноводство - АВТОМАТИЗАЦИЯ ЗООТЕХНИЧЕСКОГО И ПЛЕМЕННОГО СВИНОВОДСТВА
 
Aliñamos aceitunas
Aliñamos  aceitunasAliñamos  aceitunas
Aliñamos aceitunas
 
Karen Riley Resume3 Project Coordinator
Karen Riley Resume3 Project CoordinatorKaren Riley Resume3 Project Coordinator
Karen Riley Resume3 Project Coordinator
 
13 Tips: How to Succeed in Business (without really trying)
13 Tips: How to Succeed in Business (without really trying)13 Tips: How to Succeed in Business (without really trying)
13 Tips: How to Succeed in Business (without really trying)
 
LINK - Discovery Communications
LINK - Discovery CommunicationsLINK - Discovery Communications
LINK - Discovery Communications
 
Herrera
HerreraHerrera
Herrera
 
Datanomi koulutus alkaa syksyllä 2016
Datanomi koulutus alkaa syksyllä 2016Datanomi koulutus alkaa syksyllä 2016
Datanomi koulutus alkaa syksyllä 2016
 
Gongali Model Presentation
Gongali Model PresentationGongali Model Presentation
Gongali Model Presentation
 
Computacion 1 sesion 02 windows 7
Computacion 1 sesion 02  windows 7Computacion 1 sesion 02  windows 7
Computacion 1 sesion 02 windows 7
 
Week Day Vegetarian
Week Day Vegetarian Week Day Vegetarian
Week Day Vegetarian
 
Data mining
Data miningData mining
Data mining
 

Similaire à Physical prototyping lab3-serious_serial

arduinocourse-180308074529 (1).pdf
arduinocourse-180308074529 (1).pdfarduinocourse-180308074529 (1).pdf
arduinocourse-180308074529 (1).pdf
ssusere5db05
 
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf
4 IOT 18ISDE712  MODULE 4 IoT Physical Devices and End Point-Aurdino  Uno.pdf4 IOT 18ISDE712  MODULE 4 IoT Physical Devices and End Point-Aurdino  Uno.pdf
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf
Jayanthi Kannan MK
 

Similaire à Physical prototyping lab3-serious_serial (20)

Arduino Programming Familiarization
Arduino Programming FamiliarizationArduino Programming Familiarization
Arduino Programming Familiarization
 
Electronz_Chapter_14.pptx
Electronz_Chapter_14.pptxElectronz_Chapter_14.pptx
Electronz_Chapter_14.pptx
 
Arduino Lab 2 0
Arduino Lab 2 0Arduino Lab 2 0
Arduino Lab 2 0
 
Cassiopeia Ltd - standard Arduino workshop
Cassiopeia Ltd - standard Arduino workshopCassiopeia Ltd - standard Arduino workshop
Cassiopeia Ltd - standard Arduino workshop
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Introduction to Arduino Microcontroller
Introduction to Arduino MicrocontrollerIntroduction to Arduino Microcontroller
Introduction to Arduino Microcontroller
 
arduinoedit.pptx
arduinoedit.pptxarduinoedit.pptx
arduinoedit.pptx
 
Arduino Programming Basic
Arduino Programming BasicArduino Programming Basic
Arduino Programming Basic
 
Processing - MORE Erasmus+ PAU, 2016 February
Processing - MORE Erasmus+ PAU, 2016 FebruaryProcessing - MORE Erasmus+ PAU, 2016 February
Processing - MORE Erasmus+ PAU, 2016 February
 
IOT beginnners
IOT beginnnersIOT beginnners
IOT beginnners
 
IOT beginnners
IOT beginnnersIOT beginnners
IOT beginnners
 
Arduino course
Arduino courseArduino course
Arduino course
 
Arduino Day 1 Presentation
Arduino Day 1 PresentationArduino Day 1 Presentation
Arduino Day 1 Presentation
 
arduinocourse-180308074529 (1).pdf
arduinocourse-180308074529 (1).pdfarduinocourse-180308074529 (1).pdf
arduinocourse-180308074529 (1).pdf
 
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf
4 IOT 18ISDE712  MODULE 4 IoT Physical Devices and End Point-Aurdino  Uno.pdf4 IOT 18ISDE712  MODULE 4 IoT Physical Devices and End Point-Aurdino  Uno.pdf
4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf
 
IOTC08 The Arduino Platform
IOTC08 The Arduino PlatformIOTC08 The Arduino Platform
IOTC08 The Arduino Platform
 
Fun with arduino
Fun with arduinoFun with arduino
Fun with arduino
 
How to use an Arduino
How to use an ArduinoHow to use an Arduino
How to use an Arduino
 
Arduino Slides With Neopixels
Arduino Slides With NeopixelsArduino Slides With Neopixels
Arduino Slides With Neopixels
 
Day1
Day1Day1
Day1
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Dernier (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 

Physical prototyping lab3-serious_serial

  • 1. PHYSICAL PROTOTYPING © 2011 K3 Creative Commons v3.0 SA-NC Lab 3: Serious Serial …and small sounds With the Arduino prototyping board
  • 2. SERIAL COMMUNICATION Serial.xxxx Serial is a class designed to use serial communication Serial.begin(baud); Placed in setup() to initiate serial communication at a certain baudrate (speed) Typical transmission speed for many existing devices is 9600 bps (bits per second) Serial.print(); Writes (sends) anything to the serial port Serial.println(); Writes (sends) with CR (carriage return) and LF (line feed) Serial.available(); Used to check if data has arrived over the serial port Serial.read(); Reads the first byte that arrived to the port and erases it from the communication buffer 2
  • 3. 3 After line feed: After carriage return: cursor cursor cursor
  • 4. SERIAL COMMUNICATION is used to have your Arduino and your personal computer ‘talk’ to each other (send data) SERIAL 4
  • 5. ASCII vs. RAW BYTES ASCII stands for American Standard Code for Information Interchange Alphanumeric characters are represented by numbers ranging from 0 to 127 and are translated into a 7-bit binary code. ASCII allows for easy transfer of text-only files between different kinds of computers ASCII can be extended to cover symbol tables for other languages 5
  • 6. ASCII vs. RAW BYTES One could say that ASCII is kind of a markup language for symbols The symbol 'A' (which represents the capital letter A) is represented by numeric code 65, the symbol for number '1' by numeric code 49, etc. The communication between devices is encoded using this standard This allows including special symbols like: LineFeed (LF), Carriage Return, Tab(ulator) (T)... 6
  • 8. ASCII vs. RAW BYTES Arduino uses 8N1 serial communication, this means that information is encoded in packages of 8-bits (1 byte) With 8-bits we can encode 255 different symbols If we were just sending numbers, smaller than 255, we wouldn't need to encode the data. We could just send bytes Most of the times, this is not the case, therefore we need to use ASCII as a code 8
  • 9. ASCII vs. RAW BYTES Serial.print() or Serial.println() will, by default, encode all the data as ASCII Therefore, the command: Serial.print(1) will send the code 49 over the serial line Serial.println(1) will send, in this order, 49- 10-13 Terminal programs like Bray-Terminal for Windows, or Gnome Serial for Linux can show the pure data sent 9
  • 10. ASCII vs. RAW BYTES • Arduino's IDE Serial Monitor is ready to present only ASCII data • This means that the black window at the IDE's bottom will display only the ASCII representation of numbers • Therefore, Serial.print(67, BYTE) will show character 'C' • Serial.print(1) will show character '1' • BYTE is commonly used to send information to programs like Processing and Puredata 10
  • 11. ABOUT THE SPEED Arduino is a small but powerful computer designed to do just three tasks at the same time: – send/receive serial data – operate analog outputs – compute your program Arduino’s processor works at 16MHz, and makes about 1.000.000 operations/second. If you send data at that pace, there is no computer in the world that can follow 11
  • 12. ABOUT THE SPEED It is necessary to wait a short amount of time between messages when sending data from your Arduino to your computer otherwise you might run the risk of hanging up your computer. You should use delay(50)if you want the Serial Monitor to display what comes through the port. If the delay is any shorter, it’s hard to read the values. Personal computers are capable of doing many things at the same time. Arduino is good at doing only one particular task very quickly, over and over again. 12
  • 13. LIVECODING • Serial.begin(); • Serial.print(); • Serial.println(); • Speed issues • Monitor • Remember the delay(50); 13
  • 14. SENDING SERIAL BACK • We can also send data from the computer to Arduino • The best is to make use of a simple character or symbol-based communication protocol • It is of course possible to send full strings between the computer and Arduino, but that will require too much effort in parsing the information 14
  • 15. LIVECODING See: Examples / Communication / PhysicalPixel Serial.available(); Serial.read(); Using serial input switch on and off the onboard LED at port 13 15
  • 16. SOFTWARE TO USE Connecting to Flash and other programs like PureData, Processing, MAX/MSP, VVVV, Isadora, etc is a story for another time, it involves serial communication in both directions. There are plenty of examples of installations that make use of serial communication Also, two Arduinos can communicate with each other through serial communication, using the TX and RX pins. 16
  • 17. EXERCISE ►MAKING 2 ARDUINOS TALK • In pairs, connect your Arduinos • Connect RX to TX • Connect TX to RX • GND to GND • Create a protocol to do the Physical pixel between two Arduinos 17
  • 18. SMALL SOUNDS PIEZO ELEMENT/BUZZER a.k.a. CONTACT MICROPHONE The piezo element is both a sensor and an actuator As sensor: Check the example ANALOG/KNOCK As actuator: Electronic music greeting cards 18
  • 19. SMALL SOUNDS Piezo speaker can be replaced by a stereo plug which you connect to another sound output *BEWARE* the sound output is VERY high when connected to a stereo or headphones = 19
  • 20. HOW TO PLAY SOUNDS Piezos consist of materials which attract / repel each other (vibrate) when flows through them. Quick vibrations on the piezo element produce sounds We only need to connect the piezo directly to an output and write the pin HIGH and LOW We will use the method delayMicroseconds(time)to create soundwaves 20
  • 21. EXAMPLE ►PLAY “A” int outputPin = 9; // plug the piezo to pin 9 void setup() { pinMode(outputPin, OUTPUT); // declare the piezo pin as an output } void loop() { digitalWrite(outputPin, HIGH); delayMicroseconds(1136); // the time here will // determine the tone digitalWrite(outputPin, LOW); delayMicroseconds(1136); // the time here will // determine the tone } 21
  • 22. EXERCISE ►FM OSCILLATOR Connect a potentiometer to an analog input, the Piezo element to a ‘digital’ input and make a sound generator which lets you change the tone by turning the potentiometer 22 potentiometer
  • 23. EXERCISE ►OSCILLATOR int outputPin = 9; // plug the piezo to pin 9 int inputPin = 2; // the potentiometer at analog 2 void setup() { pinMode(outputPin, OUTPUT); // declare the piezo pin as an output } void loop() { int val = analogRead(inputPin); // read the potentiometer into a variable digitalWrite(outputPin, HIGH); delayMicroseconds(val); // the time here will determine the tone digitalWrite(outputPin, LOW); delayMicroseconds(val); // the time here will determine the tone }23
  • 24. MODIFY Modify the code to create more funky sounds! See Webzone for some examples 24
  • 25. HOMEWORK: SERIAL KEYBOARD Make a program in Arduino that plays sounds when receiving characters over the serial port e.g. the character 'E' should play the tone 'E4' The interaction with the program will happen entirely through serial communication HINT: the table on next slide shows the delayMicroseconds value for the notes Go wild on your serial synthesizer! 25
  • 26. HOMEWORK: SERIAL KEYBOARD tone frequency period delay C4 261,63 3,822 1,911 D4 293,66 3,405 1,703 E4 329,63 3,034 1,517 F4 349,23 2,863 1,432 G4 392,00 2,551 1,276 A4 440,00 2,273 1,136 B4 493,88 2,025 1,012 C5 523,25 1,911 0,956 26

Notes de l'éditeur

  1. Encourage people to interrupt you so you can help them immediately. Explain they do you a favor. It’s good to time the duration of the presentation.
  2. Serial communication is in a library because you might not always use it. So when you don’t use it you don;t have to include it Serial.begin calls the library and starts it. You have to specify a communication speed in baud. Arduino uses asynchronous serial communication, you have to use the same speed on both the devices that communicate to eachother. Print() prints a message We use Println to print a message and jump to the next line afterwards. Computers don’t need the line feed and carriage return to be able to read the message. Serial.available is used to check when there is activity on the serial port. You use it to only read serial data when it’s available so the constant reading on the serial port doesn’t slow down the rest of the code.
  3. Explain that the concepts of carriage return and line feed come from the original typewriters which needed to move the assembly holding the sheet of paper back to the beginning of the sentence and line feed to jump down to the next line.
  4. Serial communication is in a library because you might not always use it. So when you don’t use it you don;t have to include it Serial.begin calls the library and starts it. You have to specify a communication speed in baud. Arduino uses asynchronous serial communication, you have to use the same speed on both the devices that communicate to eachother. Print() prints a message We use Println to Computers don’t need the line feed and carriage return to be able to read the message. Serial.available is used to check when there is activity on the serial port. You use it to only read serial data when it’s available so the constant reading on the serial port doesn’t slow down the rest of the code.
  5. Different computers use different ways of communication. Which becomes a problem if everyone does their own thing. This is why they invented a standard for communication. Relate it to a keyboard. Historically, a byte was the number of bits (0’s or 1’s) used to encode a single character of text in a computer. When you type 65 on your screen and send it to Arduino, you’re not actually sending ‘65’ your sending the ASCII code for ‘A’ What you see is not what you get. CR = 10 LF = 13 Talk about example of the IPCam with the LCD screen and ascii problems.
  6. 8N1 serial communication, Arduino sends all the information in packages of 8 bits. 8 bits = 1 byte. Communicating between two arduino’s: send just one character, like move the motor up: send a ‘u’, move the motor down, send a ‘d’ You can’t send a whole string ‘turn the motor up’ ASCII is needs to we can encode more than 255 characters. The numbers on your keyboard represent actually a sequence of numbers, just like the letter keys.
  7. Show examples of how it works
  8. Write a program from scratch which: Prints stuff on the same line, Print stuff on a new line each time Has a different baud rate for sending and receiving, which results in garbled data Which has different delays to show how it affects reading speed
  9. Don’t do the processing part, just send the character for turning it on or off through the serial monitor.
  10. Find examples
  11. Pair them up in two groups: One group keeps the physical example which controls the LED on port 13, The other group writes code to control the LED on the other Arduino
  12. Sound are just vibrations in air Piezo speakers have the ability to vibrate really fast, to generate sound you move it at high speed. Piezo speaker contains two metal sheets which vibrate close to each other to create the sound. You can use it as a knock sensor aswell. Look up ‘knock’ example on arduino website and add it as slide. Add it after the play “a” slide
  13. You can also replace Only do it if you have a microphone control slider on your headphones otherwise you blow your ears out. You can make a volume control with a potentiometer and piezo. Connect the piezo to power and left pin of pot, connect middle pin of pot to a pin.
  14. Analogy: pushing against an object, when you push slow and hard it’s difficult to move and object, but when you make it vibrate softly very fast it becomes easier to move. In theory it can make a table, a solid piece of wood, into a speaker aswell. In theory any material can make sound.
  15. This value is fixed. The delay time determines which tone you are generating.
  16. An oscillator is anything that can change it’s own resistance. Or anything that can change it’s own values. Write this code together: int outputPin = 9; // plug the piezo to pin 9 int inputPin = 2; // the potentiometer at analog 2 void setup() { pinMode(outputPin, OUTPUT); // declare the piezo pin as an output } void loop() { int val = analogRead(inputPin); // read the potentiometer into a variable digitalWrite(outputPin, HIGH); delayMicroseconds(val); // the time here will determine the tone digitalWrite(outputPin, LOW); delayMicroseconds(val); // the time here will determine the tone }
  17. Modify the code to change it so that all the values are multiplied by two to make it play a different sound
  18. Skip frequency and period Frequency is the number of oscillations and seconds. Period: Tony doesn’t know  Maybe someone in class knows who has had musical training and plays an instrument.