Академический Документы
Профессиональный Документы
Культура Документы
starters workshop 2
We advice to finish part 1 of this workshop before following this one.
There are a set of assignments in this workshop that can be taken individually. First try assignment 1
and after that you can take them in any order you like.
There is unique material for each assignment so when multiple people are following the workshop
divide them equally and keep the materials together for the next person.
All the programs that are needed for the assignments are available on a USB stick. It will be copies of
this on the desktop of the computers so it will not be necessary to enter this code by hand. It is vital
though to read the code carefully to understand what is happening.
Assignment 1:
The object of this assignment is to known how to use the serial monitor.
There is a serial monitor inside the Arduino IDE, you can use it to write input data from the arduino to
the screen. It can be used to quickly check the state of a push button, temperature sensor or other
device.
Connect the arduino to a USB port on the pc and run this code:
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println(Hello World!);
delay (100);
}
Now click on the serial monitor and the text Hello Work! will be displayed continuously on the
screen.
Serial.begin(); set the baud-rate of the serial port.
Serial.println(); print the text contents of a variable and continue to the next line.
delay(); make the processor wait for the specified number of milliseconds before continuing with the
program.
In the next example we will read the data from an analogue input port:
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println(analogRead(0));
delay (100);
}
When we display data from more than one input port it is better to show which port we are reading.
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.print("analogue port 0 ");
Serial.println(analogRead(0));
Serial.print("analogue port 1 ");
Serial.println(analogRead(1));
delay(100);
}
We now use two new functions:
Serial.print(); print the text version of a variable and stay on the same line.
analogRead(); reads the value of an analogue port. The arduino continues 6 of these ports numbered
from 0 to 5. The value read is 0 to the maximum of 1023 for normally 5 volt.
Assignment 2:
The goal is to learn to show text on a 2x16 LCD display.
Assignment 3:
The goal is to know how to read a temperature sensor.
This a relative simple variant of a temperature sensor that returns a voltage relative to the power
voltage. Normally a value between 0 and 5 volt.
This is easy to use in combination with the analogue input of the arduino boards.
This project is also fully documented on the internet:
http://www.danielandrade.net/2008/07/05/temperature-sensor-arduino/
Connect the temperature sensor to the arduino as written on the site:
The easiest way to read and show the temperature is via de serial monitor:
Assignment 4:
The goal is to work with the data logger shield from Adafruit.
We will now show the data on the serial monitor that the clock sends:
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;
void setup () {
Serial.begin(9600);
Wire.begin();
RTC.begin();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
RTC.adjust(DateTime(__DATE__,__TIME__));
}
}
void loop () {
DateTime now = RTC.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
delay(1000);
}
Upload this code to the arduino with the data logger shield attached to it and start the serial monitor.
We will store the data we read with the temperature sensor on the SD card. We will log the time
together with the data so we can read what the temperature was on a given moment.
The code to do this is a bit too large to type into the arduino environment. It is on the USB stick or on
the desktop (opdracht 4_2). It is directly copied from the Adafruit website.
In the serial monitor you can read what data is written and to which file on the SD it is written.
Remove the USB connector from the laptop.
Take the SD card out of the shield and put it directly into the laptop or into an available SD card reader.
There will be a file on the SD card with the file-name that where shown in the serial monitor. Open it
with the laptop.
On the Adafruit website it is shown how to read this data with for example Excel.
This is outside the scope of this workshop but when you are interested open:
http://www.ladyada.net/make/logshield/lighttemp.html