Arduino-Based TME Educational Board Manual
Arduino-Based TME Educational Board Manual
www.TMEeducation.com
2
TME-EDU-ARD-2
Contents
Introduction ....................................................................................................................................... 4
What is Arduino? ......................................................................................................................... 4
Basic kit description .................................................................................................................... 4
List of available peripherals .............................................................................................................. 5
Safety information............................................................................................................................. 5
Power supply .................................................................................................................................... 7
Necessary software .......................................................................................................................... 7
Programming the educational board ................................................................................................ 8
Comments ................................................................................................................................... 8
Uploading the programme to the board ...................................................................................... 9
Peripherals support in practice ......................................................................................................... 9
Simple, single-colour LED (LED1 - D13) .................................................................................... 9
Using definitions ........................................................................................................................ 10
Delays ....................................................................................................................................... 11
Buzzer with generator (D2) ....................................................................................................... 12
Simple, three-colour (RGB) LED (LED2 - D9, D10, D11) ......................................................... 12
Control of the RGB diode with PWM signal .............................................................................. 14
5-button keyboard (D4, D5, D6, D7, D8)................................................................................... 16
Communication with a computer via UART .............................................................................. 17
Sending information to Arduino ................................................................................................. 18
Text LCD display 2x16 characters ............................................................................................ 19
Support for analog sensors ....................................................................................................... 21
Analog sensors - potentiometer (A1) ........................................................................................ 21
Analog sensors - light sensor (A3) ............................................................................................ 23
Analog sensors - temperature sensor (A2) ............................................................................... 24
Analog sensors - microphone (A0) ........................................................................................... 25
Expander and 7-segment display ............................................................................................. 26
Expander and 7-segment display (digits).................................................................................. 28
For loop ..................................................................................................................................... 29
While loop ................................................................................................................................. 29
OLED graphic display ............................................................................................................... 30
IR receiver (D3) ........................................................................................................................ 31
Support of digitally controlled RGB LEDs (D12) ....................................................................... 32
Bluetooth module............................................................................................................................ 34
Arduino shields connectors ............................................................................................................ 35
Configuration jumpers .................................................................................................................... 35
List of Arduino functions ................................................................................................................. 36
List of libraries with licenses ........................................................................................................... 40
3
Arduino based TME Educational Board
Introduction
The TME-EDU-ARD-2 educational board for learning of Arduino programming has been prepared
for the needs of the TME Education programme. More information on the subject can be found at:
https://www.tmeeducation.com
https://fb.com/tmeeducation
This documentation describes the use of peripherals included in the TME-EDU-ARD-2 educational
board, which works with the popular Arduino UNO controller. The board has over 20
peripherals using all available outputs of the controller. The elements are connected, however, it is
still possible to change these connections using the jumpers (more on this later).
What is Arduino?
Arduino platform is one of the most popular solutions dedicated to beginners to electronics in the
world. It integrates popular AVR microcontrollers and dedicated, beginners-friendly programming
language (based on C / C++) into a coherent and easy-to-use tool with an infinite number of
applications.
4
TME-EDU-ARD-2
On the right-hand side there is an IR receiver, a potentiometer, light sensor, buzzer, temperature
sensor, microphone and a 7-segment display with a pin expander. In the upper, middle part of the
board, you can find a connector for external power, a set of jumpers to reconfigure the connections
and place for a Bluetooth module and any additional shield with other accessories.
Safety information
When operating the device, avoid direct contact with the PCB (touching electronic components and
paths), because in extreme situations it may damage the board. The exception are 7 buttons and a
potentiometer, which can be used in programmes loaded onto the board.
5
Arduino based TME Educational Board
Before turning on the board, it is also worth making sure that the plate was not accidentally placed
on metal objects (e.g. on a screwdriver), which could close the signals flowing under the plate.
6
TME-EDU-ARD-2
Power supply
The educational board can be powered in one of the three ways:
USB connector (1) placed on the Arduino board (power supply from the computer's USB
port or from the 5V adapter allowing to connect a cable with a USB type B connector).
External power connector (2) on the Arduino board (from 7V to 12V).
External power connector (3) placed on the expansion board (from 7V to 12V).
In the vast majority of cases, it’s best to power the educational board
with a USB cable that is used for Arduino programming.
Necessary software
For programming the board you need the Arduino IDE environment, which can be downloaded for
free from the project website, i.e.: https://arduino.cc. From the page navigation menu, select the
"SOFTWARE" tab. On the newly opened page, go to the "Download the Arduino IDE" section and
select the appropriate version for the given system from the list on the right.
7
Arduino based TME Educational Board
Then you will be asked for voluntary financial support for the project. At this stage, you can donate
or download the software for free by selecting the "JUST DOWNLOAD" button. At this point, the
installer will start downloading.
The loop function acts as an infinite loop. Instructions contained inside it will be performed all the
time. This loop starts after the instructions inside the setup function are completed.
A blank sketch, which should be the starting point for each programme:
// the setup function runs once when you press reset or power the board
void setup() {
Comments
It’s possible to add comments inside the programme, i.e. information that are skipped when sending
a sketch to Arduino, and they are only meant to make it easier for programmers to understand the
code. Comments can be placed in one line (then they should be preceded by "//" characters) or in
many lines (then the comment text should be placed between "/*" and "*/" characters).
void setup() {
// comment in one line
/*
multi-line
comment
*/
Comments can be placed in any part of the programme. Often they are also used to temporarily
"turn off" a part of the programme, e.g. for testing time.
8
TME-EDU-ARD-2
The programme that turns the diode on should start with setting the
pin as an output. To do this, use the pinMode function (pin_number,
OUTPUT), in which we replace pin_number with the pin number to
be used in the output mode.
From that moment on, it will be possible to switch on or off the diode
with the digitalWrite(pin_number, status) function anywhere in the
9
Arduino based TME Educational Board
programme. Where, similarly in place of pin_number we insert pin number to which the diode was
connected, and in the place described as status, we give one of the two possible options: LOW,
that is logical low state (or “0”) or HIGH, that is logical high state (or “1”).
Setting the low state is equivalent to giving the mass potential to the output,
and setting the high state is equivalent to giving a positive power bus
to the output, i.e. 5 V in this case.
The programme that turns the diode on will look like this:
// the setup function runs once when you press reset or power the board
void setup() {
// pin configuration
pinMode(13, OUTPUT);
Both instructions are included in the setup function, because after switching on Arduino, we turn the
diode on only once and we do not have to do anything with it.
Using definitions
In the above programme, the pin number to which the diode is connected had to be entered in two
places (in the configuration of the output and in the instruction turning on the diode). To simplify
later changes, information about the pin number can be written in the form of definitions e.g.:
#define LED1 13
From now on, the compiler will automatically substitute the number "13" at every place in the
programme where "LED1" is placed. This is particularly convenient when making changes to the
pins to which the peripherals are connected in more complex programmes.
The programme turning on the diode with the use of definitions may look like this:
#define LED1 13
// the setup function runs once when you press reset or power the board
void setup() {
// pin configuration
pinMode(LED1, OUTPUT);
10
TME-EDU-ARD-2
// turn the LED on
digitalWrite(LED1, HIGH);
}
Delays
When creating many programmes, it is useful to be able to enter a delay. A popular example is a
programme flashing a diode. In practice, this means it’s necessary to turn on the diode, wait for a
certain time, turn off the diode, wait for a certain time and start the cycle from the beginning. For
this purpose, in Arduino programming, the delay(time) function is used, where for time we enter the
duration of the delay in milliseconds (1 second = 1000 milliseconds).
During the delay, the entire programme is stopped (and stands still)!
// the setup function runs once when you press reset or power the board
void setup() {
// pin configuration
pinMode(LED1, OUTPUT);
}
This time, the diode control instructions have been moved to the loop function, because they are to
be executed all the time (in the loop). Of course, the instruction configuring the pin (to which the
diode is connected) as an output remained inside the setup function (because the configuration is
done only once).
11
Arduino based TME Educational Board
12
TME-EDU-ARD-2
Controlling of individual LEDs is performed in an analogous way to the previously described LED1.
We start from the pin configuration as input, and then control each colour separately:
#define LED2R 9
#define LED2G 10
#define LED2B 11
// the setup function runs once when you press reset or power the board
void setup() {
// pin configuration
pinMode(LED2R, OUTPUT);
pinMode(LED2G, OUTPUT);
pinMode(LED2B, OUTPUT);
}
Of course, it is also possible to light two / three colours at the same time. Thanks to this, it is possible
to mix colours and obtain different, intermediate colours. An example of such a programme:
#define LED2R 9
#define LED2G 10
#define LED2B 11
// the setup function runs once when you press reset or power the board
void setup() {
// pin configuration
pinMode(LED2R, OUTPUT);
pinMode(LED2G, OUTPUT);
pinMode(LED2B, OUTPUT);
}
13
Arduino based TME Educational Board
In order to generate the PWM signal, use the analogWrite(pin_number, duty_cycle), where in place
of the pin_number, we enter the terminal number to which the diode is connected, and in place of
the duty_cycle we enter a number in the range from 0 to 255.
Setting 0 will be equivalent to lighting the diode with the brightness of 0%,
and 255 will mean lighting with the brightness equal to 100%.
void setup() {
// pin configuration
pinMode(LED2R, OUTPUT);
}
void loop() {
// set LED brightness
14
TME-EDU-ARD-2
analogWrite(LED2R, 0);
delay(500); // wait for 500ms
Using testing terminals described as D9, D10, D11 and GND, it is possible to connect the board to
the oscilloscope, which will show changes in the signal duty cycle that the diode is being controlled
with.
If you don’t have an oscilloscope, a voltmeter can be connected to this point (between any
measuring point and GND). With the increase of the PWM signal duty cycle, the voltmeter should
indicate higher and higher voltage (from 0 to 5V).
15
Arduino based TME Educational Board
The buttons are connected via reversing buffers, so when the button is not pressed, the low state
(logic "0") is visible at the Arduino input. After pressing the button, the input state will be high (logic
"1").
Depending on the version of the board, the resistors marked as "NA" might
not be soldered in, which doesn't influence operation of the circuit.
To use the buttons, the pin should be configured as an input using the pinMode(pin_number,
INPUT) function, in which as pin_number we enter the pin number to be used in the input mode. In
the further part of the programme, we read the input status using the digitalRead(pin_number)
function.
The programme, which will turn on the LED1 diode after pressing the button connected to the D4
pin (to the left):
#define LED1 13
#define SW_LEFT 4
// the setup function runs once when you press reset or power the board
void setup() {
// pin configuration
pinMode(LED1, OUTPUT);
pinMode(SW_LEFT, INPUT);
}
Serial.begin(115200);
The value given in brackets, i.e. "115200" means the selected transfer rate, which in this case was
set to one of the most popular, standard values.
Then, using the following command, it is possible to send various values to the computer. In this
case, it is the word "TEST":
Serial.println("TEST");
In order to check the operation of this mechanism in practice, you can expand the previous
programme that used the button and add to it sending information about the button pressed to the
computer.
Additional delay added at the end of the programme means that the loop is
executed only every 200 ms, so the information will not be sent to the
computer too often.
#define LED1 13
#define SW_LEFT 4
void setup() {
// pin configuration
pinMode(LED1, OUTPUT);
pinMode(SW_LEFT, INPUT);
Serial.begin(115200);
}
void loop() {
if (digitalRead(SW_LEFT) == HIGH) { // if the pushbutton is pressed
digitalWrite(LED1, HIGH);
17
Arduino based TME Educational Board
Serial.println("LEFT");
} else { // if not
digitalWrite(LED1, LOW);
}
delay(200);
}
After uploading this programme, run the Serial Port Monitor, which can be found in the Arduino IDE
menu in the Tools option. From now on, after pressing the button on the board (D4), the text "LEFT"
should appear in a new window:
18
TME-EDU-ARD-2
Program operation in practice:
Then, it is necessary to provide information about connection method of the LCD display to the
expander. First information given to the called function (0x20) is the address of the expander
controlling this display.
// information about the LCD connection
hd44780_I2Cexp lcd(0x20, I2Cexp_MCP23008,7,6,5,4,3,2,1,HIGH);
19
Arduino based TME Educational Board
The next step is a display configuration, in which we set the allowed number of columns (16) and
rows (2). This information is closely related to the display used and should always be set in the
same way:
void setup() {
// lcd configuration
lcd.begin(16, 2);
}
In order to display information on the display, use the lcd.setCursor(x, y) command, which will
position the cursor in the appropriate location. Lines and positions in lines are counted from zero
(not from 1), so for example:
o lcd.setCursor(0, 0) - start with the first character in the first line,
o lcd.setCursor(0, 1) - start with the first character in the second line,
o lcd.setCursor(5, 0) - start with the sixth character in the first line,
o lcd.setCursor(5, 1) - start with the sixth character in the second line.
After setting the cursor, you can use the lcd.print("TEXT") function, which will display the indicated
text on the LCD. In order to delete display content, you can write a string of spaces on it or use the
special function lcd.clear().
void setup() {
// lcd configuration
lcd.begin(16, 2);
}
void loop() {
// set the cursor to position
lcd.setCursor(0, 0);
// print text on lcd
lcd.print("TME");
// set the cursor to position
lcd.setCursor(0, 1);
// print text on lcd
lcd.print("TESTER - 2");
delay(1000);
lcd.clear();
20
TME-EDU-ARD-2
// print text on lcd
lcd.print("TESTER - 1");
// set the cursor to position
lcd.setCursor(0, 1);
// print text on lcd
lcd.print("TME");
delay(1000);
lcd.clear();
}
If the text is not visible on the display in spite of the programme being loaded, it may be necessary
to adjust the contrast, which can be done using a small, silver potentiometer located above the
top right-hand corner of the display. All you have to do is to turn the potentiometer gently with the
loaded programme and running system, e.g. using a flat-head screwdriver.
To use the analog input you do not have to declare it in any way. It is enough to read the voltage
value, which is represented by a number between 0 and 1023. Where 0 means ~0V and 1023
means ~5V. The information is read using the analogRead(pin_number) function.
Range 0-1023 results from the fact that Arduino has an analog-digital
converter (ADC) with a resolution of 10 bits.
21
Arduino based TME Educational Board
void loop() {
// read sensor data
int pot = analogRead(A1);
// send information to PC
Serial.println(pot);
After uploading the programme and launching the Serial Port Monitor, a sequence of numbers
should be visible, the values of which change during manual adjustment of the potentiometer.
A more convenient form of displaying values read from an analog sensor can be an LCD. In this
case, the content of the top line is printed only once, at the beginning of the programme, and only
the content displayed in the second line is replaced in the loop:
#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>
void setup() {
// lcd configuration
lcd.begin(16, 2);
22
TME-EDU-ARD-2
void loop() {
// read sensor data
int pot = analogRead(A1);
After uploading this programme, any change of the potentiometer position should be immediately
visible on the display in form of a changing number between 0 and 1023.
void setup() {
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("LIGHT:");
}
void loop() {
int light = analogRead(A3); // read sensor data
23
Arduino based TME Educational Board
// clear second line of LCD
lcd.setCursor(0, 1);
lcd.print(" ");
}
The sensor indications may be unstable with some sources of artificial light
(e.g. in case of fluorescent lamps).
For easier interpretation of the results, you can use the map function, which allows you to scale the
values. The following code will give you a value between 0 and 100, instead of a value between
0 and 1023, because you can interpret it for example as a percentage level of lighting:
lcd.print(map(light, 0, 1023, 0, 100));
void setup() {
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("TEMP [C]:");
}
void loop() {
24
TME-EDU-ARD-2
// read sensor data
int temp = analogRead(A2);
lcd.setCursor(0, 1);
delay(200);
lcd.setCursor(0, 1);
lcd.print(" ");
}
The following code is the simplest form of using this sensor. Arduino regularly checks the voltage
level at the input to which the microphone system is connected. This information is shown on the
display. If the measured value exceeds 250, the condition will be met and the LED1 will be switched
on for a second. The value triggering the diode switching on was selected experimentally in such
a way that the system responded to the clap.
#define LED1 13
#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>
void setup() {
pinMode(LED1, OUTPUT);
lcd.begin(16, 2);
lcd.setCursor(0, 0);
25
Arduino based TME Educational Board
lcd.print("MIC:");
}
void loop() {
// read sensor data
int mic = analogRead(A0);
lcd.setCursor(0, 1);
lcd.print(mic);
if (mic > 250) { // if a clap was detected
// turn the LED on
digitalWrite(LED1, HIGH);
delay(1000);
} else { // if not
// turn the LED off
digitalWrite(LED1, LOW);
}
delay(150);
lcd.setCursor(0, 1);
lcd.print(" ");
}
26
TME-EDU-ARD-2
There is a jumper described as "ON / OFF" below the display. Using this jumper it is possible to
disconnect the common anode from the mass of the system, which will completely turn the display
off. This jumper is useful in situations where we want to use the expander pins in a different way.
You can then remove the jumper, turn off the display and use the expander pins led out to the
double connector next to the display.
You should start using the expander from adding a library and declaring a new object (here named
as seg7), which will allow you to control individual pins:
#include "Adafruit_MCP23008.h"
Adafruit_MCP23008 seg7;
We initialize the expander and set all its pins in as inputs. The names of functions and how they are
used are similar to those used to control the pins built into Arduino:
seg7.begin(0x4);
seg7.pinMode(0, OUTPUT);
seg7.pinMode(1, OUTPUT);
seg7.pinMode(2, OUTPUT);
seg7.pinMode(3, OUTPUT);
seg7.pinMode(4, OUTPUT);
seg7.pinMode(5, OUTPUT);
seg7.pinMode(6, OUTPUT);
seg7.pinMode(7, OUTPUT);
Address of the expander responsible for the 7-segment display is 0x24, however the library used
here only requires providing the offset value above address 0x20 as an address. Therefore, we only
pass the address in form of 0x4 to the function. (However, this method is specific only to this library,
more information on this subject can be found in the Adafruit_MCP23008 library documentation.)
From now on, after the configuration of the display, it will be possible to control all the LEDs that
are part of it. Turning on the diode is as follows: seg7.digitalWrite(pin_number, HIGH). An example
of a programme flashing with two elements of the display:
#include "Adafruit_MCP23008.h"
Adafruit_MCP23008 seg7;
void setup() {
seg7.begin(0x4); // expander pin configuration
seg7.pinMode(0, OUTPUT);
seg7.pinMode(1, OUTPUT);
seg7.pinMode(2, OUTPUT);
seg7.pinMode(3, OUTPUT);
seg7.pinMode(4, OUTPUT);
seg7.pinMode(5, OUTPUT);
seg7.pinMode(6, OUTPUT);
seg7.pinMode(7, OUTPUT);
}
27
Arduino based TME Educational Board
void loop() {
seg7.digitalWrite(5, HIGH);
seg7.digitalWrite(2, LOW);
delay(250);
seg7.digitalWrite(5, LOW);
seg7.digitalWrite(2, HIGH);
delay(250);
}
Thanks to this, using the new seg7.writeGPIO() function it will be possible to display any digit using
a single line of code. The following demonstration programme displays all values (0-9) in a loop:
#include "Adafruit_MCP23008.h"
Adafruit_MCP23008 seg7;
uint8_t digit[10] = {
B00111111, // "0"
B00000110, // "1"
B01011011, // "2"
B01001111, // "3"
B01100110, // "4"
B01101101, // "5"
B01111101, // "6"
B00000111, // "7"
B01111111, // "8"
B01101111, // "9"
};
void setup() {
// expander pin configuration
seg7.begin(0x4);
seg7.pinMode(0, OUTPUT);
28
TME-EDU-ARD-2
seg7.pinMode(1, OUTPUT);
seg7.pinMode(2, OUTPUT);
seg7.pinMode(3, OUTPUT);
seg7.pinMode(4, OUTPUT);
seg7.pinMode(5, OUTPUT);
seg7.pinMode(6, OUTPUT);
seg7.pinMode(7, OUTPUT);
}
void loop() {
for (int i=0; i<10; i++) {
seg7.writeGPIO(digit[i]);
delay(250);
}
}
For loop
In the example above, we used the for loop. By using the loop, we can execute the same instructions
multiple times (without the need for re-typing them), and therefore we can shorten the notation. In
this example, the loop will execute 10 times (from 0 to 9). Each time, a value from the digit array
will be displayed on the screen, indicating the current cycle of the loop. This is possible because
the value of variable "i" will be incremented (increased) after each execution of the instructions in
the for loop. After the defined number of executions, the program will proceed to further instructions
(in this case, it will go back to the beginning and restart execution of instructions in the for loop).
While loop
Another equally common loop in Arduino is the while loop, which executes itself until the condition
in the bracket is met. The for loop described above can be replaced with the new while loop in the
following manner:
int i = 0;
while(i < 10){
seg7.writeGPIO(digit[i]);
delay(250);
i++;
}
At the beginning, a counter variable is created (here, it is the "i" variable). Right after while in the
bracket, a condition is added, which makes the loop execute itself until the value of the "i" variable
is less than 10. The loop contains instructions to be performed several times. At the end of the loop,
an increment operator is added (i++), i.e. the increase of the variable by 1. Thanks to that, after the
10th cycle the condition is not met, and the program will exit the loop.
Loops of this type are also used for creating infinite loops. In such cases, there’s no need for adding
a condition – you can simply use "1", which means that the condition will always be true:
while(1){
//infinite loop
}
29
Arduino based TME Educational Board
Then, inside the setup function configuration of OLED is necessary, which means its initialization
(with entering the address 0x3C), waiting for a short time for the controller initialization, clearing the
display content and setting the colour to white (the only possible one):
display.begin(SSD1306_SWITCHCAPVCC, 0x3C, false);
delay(500);
display.clearDisplay();
display.setTextColor(WHITE);
Displaying the text on the screen consists in selecting the cursor position (set in pixels), entering
the text, and then "sending" all information to the screen.
The following programme first displays two test lines (one under the other with 50 pixels shift to the
right). Then, slides the text "TEST LINE 12345" diagonally through the screen:
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 display(NULL);
void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C, false);
delay(500);
display.clearDisplay();
30
TME-EDU-ARD-2
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("TEST LINE 1");
display.setCursor(50,10);
display.println("TEST LINE 2");
display.display();
delay(2000);
}
void loop() {
for (int i = 0; i < 8; i++) {
display.clearDisplay();
display.setCursor(5*i,8*i);
display.println("TEST LINE 12345");
display.display();
delay(250);
}
}
IR receiver (D3)
The board is equipped with an integrated infrared
receiver TSOP2236, which can be used to receive
information sent by IR remotes working in the RC5
standard. This method of communication was
developed by Philips over 30 years ago for remote
control of consumer electronics and is still very popular.
The remote control working in the RC5 standard sends an infrared beam with a frequency of 36
kHz. Each time, 14 bits of data are sent, which create a data frame. If the button on the remote
control is pressed, data frames are transmitted all the time (every ~114 ms).
The use of a sensor connected to the D3 pin should be started from adding a library, creating an
object and declaring a new structure to store the received information:
#include <IRremote.h>
IRrecv irrecv(3);
decode_results results;
Sample demo programme that decodes signals from the remote and sends them to a computer via
UART is shown below:
#include <IRremote.h>
IRrecv irrecv(3);
decode_results results;
31
Arduino based TME Educational Board
void setup() {
Serial.begin(115200);
irrecv.enableIRIn(); // start IR receiver
}
void loop() {
if (irrecv.decode(&results)) { // if data detected
// send data via UART to PC in HEX format
Serial.println(results.value, HEX);
irrecv.resume(); // resume receiver
}
delay(100);
}
As a result of its work decoded codes should appear in the Serial Port Monitor, which are sent by
the IR remote. Remote codes may vary, depending on the particular model. Some of the remotes
also send other codes depending on whether the button is pressed for the first or for the next time.
32
TME-EDU-ARD-2
The following entry is a declaration of 5 LEDs connected to pin 12:
#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(5, 12, NEO_GRB + NEO_KHZ800);
pixels.setPixelColor(0, pixels.Color(10,20,30));
pixels.show();
This code means that the first diode in the series (No. 0) will be set to red with intensity 10/255,
green with intensity 20/255 and blue with intensity 30/255. After assigning colours, simply call the
show function, which will send information to the LEDs.
The following test programme runs all the colours of the LED next to the OLED display and then
alternately blinks with 4 LEDs on the bottom of the board (in blue and red):
#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(5, 12, NEO_GRB + NEO_KHZ800);
void setup() {
pixels.begin();
pixels.setPixelColor(0, pixels.Color(10,20,30));
pixels.show();
}
void loop() {
pixels.setPixelColor(1, pixels.Color(0,0,255));
pixels.setPixelColor(2, pixels.Color(255,0,0));
pixels.setPixelColor(3, pixels.Color(0,0,255));
pixels.setPixelColor(4, pixels.Color(255,0,0));
pixels.show();
delay(250);
pixels.setPixelColor(1, pixels.Color(255,0,0));
pixels.setPixelColor(2, pixels.Color(0,0,255));
pixels.setPixelColor(3, pixels.Color(255,0,0));
pixels.setPixelColor(4, pixels.Color(0,0,255));
pixels.show();
delay(250);
}
In case of a problem with turning on the diodes, make sure that after setting the colours, function
show was called, which is responsible for sending information to the controllers.
33
Arduino based TME Educational Board
Bluetooth module
The board has a space for attaching an optional Bluetooth module, e.g. HC-05. The angled 6-pin
connector for its connection is located to the right of the jumper strip. The following signals have
been led out there:
o power supply for the BT module,
o 2 pins controlling the module,
o 2 pins for data transmission (UART).
Bluetooth module can be used, for example, to communicate the set with mobile phones running
Android operating system. Communication is performed via the UART interface - the same one
which is used for communication with a PC. Therefore, it is possible to use only one of these two
ways of communication at the same time.
To verify the operation of the module, the following test code can be used. It works by sending the
text "TME BT" (every 250 ms). At the same time, the system receives all data sent to it from the
phone. If the "TEST" string is received, the system will respond by sending "TME BT TEST OK"
and will stop sending new information for 1 second.
void setup() {
Serial.begin(115200);
}
34
TME-EDU-ARD-2
// if there is "TEST" string received
if (data == "TEST") {
// send back "TME BT TEST OK"
Serial.println("TME BT TEST OK");
delay(1000);
}
}
Serial.println("TME BT");
delay(250);
}
After uploading the programme, slide switch should be set to the BT ON position. Set with the BT
module should be detected by the phone as a new Bluetooth device that can be paired using the
default pin code: "1234". After pairing, application in the mobile phone should display messages
sent by the board.
Configuration jumpers
All peripherals on the board are connected to Arduino by default. However, it is possible to change
the configuration very easily. By removing jumpers, you can disconnect the peripherals from the
controller. If it is necessary, you can change the assignment of peripherals to specific pins using
an additional connection cable (not included).
Changing the configuration of connections using jumpers can be particularly convenient when it is
necessary to connect certain peripheral of the board to another pin, e.g.: connecting the LED1 diode
to the pin on which hardware PWM signal generation is possible.
35
Arduino based TME Educational Board
The following example shows how you can disconnect the buzzer and LED1 and change the
configuration in such a way that the buzzer is controlled by pin D13 (instead of D2).
abs(x) – function that returns the absolute value, for the correct operation of the function you should
avoid using other functions inside of the arguments.
x – number of which the absolute value is to be calculated.
Returned value: absolute value from the number x.
constrain(x, a, b) – function that checks if the number is in the given range.
x – tested number (of any type)
a – lower range value
b – upper range value
Returned value:
x – if the number is greater than a and smaller than b.
a - if the number x is smaller than a
b – if the number x is greater than b
map(value, fromLow, fromHigh, toLow, toHigh) – function that scales a number from one range
to the other. It is useful, for example, for rescaling the value measured by the ADC
converter (0 ... 1023) to a percentage value (0 ... 100%).
value – value to be scaled
fromLow – lower range of the current range
fromHigh – upper range of the current range
toLow – lower range of the future range
toHigh – upper range of the future range
Returned value: scaled number.
37
Arduino based TME Educational Board
max(x, y) – function that compares two numbers.
x – first number
y – second number
Returned value: larger of the numbers
min(x, y) – function that compares two numbers.
x – first number
y – second number
Returned value: smaller of the numbers
pow(base, exponent) – function calculating power.
base – number to be raised to power
exponent – value of the power
Returned value: base number raised to exponent power.
sqrt(x) – square root function.
x – number
Returned value: square root of the number x.
sq(x) – square function.
x – number
Returned value: x raised to the power of 2.
cos(rad) – function calculating cosine of an angle.
rad – angle in Radians
Returned value: cosine of the given angle.
sin(rad) – function calculating sine of an angle.
rad – angle in Radians
Returned value: sine of the given angle.
tan(rad) – function calculating tangent of an angle.
rad – angle in Radians
Returned value: tangent of the given angle.
millis() – function that returns the number of milliseconds since Arduino was started. The value is
reset after about 50 days.
Returned value: time since start in milliseconds (variable of unsigned long type)
pulseIn(pin, value, timeout) – function calculating duration of the pulse on a given input. For
example, measurement starts when state changes from low to high and stops when the
low state reappears. The function works properly for pulses from 10 microseconds to 3
minutes.
pin – output on which the pulse is to be measured
value – pulse type to be measured (LOW or HIGH)
timeout – optional number of microseconds after which the system will stop measuring
if the state on the pin does not change before
Returned value: duration – duration of the pulse in microseconds or 0 if no measurement
isAlpha(char) – function checking if the given character is a letter.
char – character to be checked
Returned value: true if the character is a letter
38
TME-EDU-ARD-2
isAlphaNumeric(char) – function checking if the given character is a letter or a digit.
char – character to be checked
Returned value: true if the character is a letter or a digit
isDigit(char) – function checking if the given character is a digit.
char – character to be checked
Returned value: true if the character is a digit
random(min, max) – function that returns a pseudo-random value. The use of the function should
be preceded by a single call of the randomSeed() function.
min – start of the range
max – end of the range
Returned value: pseudo-random value from min to (max-1)
randomSeed(seed) – function that initializes the pseudorandom number generator. Without the
correct use of this function, values returned by the random function will be the same
each time Arduino is started.
seed – numerical value that initializes a pseudo-random number generator.
Returned value: none
Example: randomSeed(analogRead (0)) ADC value read from the A0 pin which can be
used by sensors connected to the system or may be unused is given as an
argument to the function. Random reading of ADC makes that after each start
of Arduino, the pseudo-random number generator can return different values
in subsequent draws.
byte(x) – function converting the variable x.
x – variable to be converted
Returned value: variable of type byte.
char(x) – function converting the variable x.
x – variable to be converted
Returned value: char variable.
int(x) – function converting the variable x.
x – variable to be converted
Returned value: variable of type int.
long(x) – function converting the variable x.
x – variable to be converted
Returned value: variable of type long.
for (initialization; condition; update) { } – the for loop is used for multiple execution of instructions
provided in the body of the function; initialization is used only once, and it is usually used to create
a counter variable in the loop (e.g. "int i = 0"); next, a condition is added to define how long the loop
shall be executed (e.g. "i < 10"); the final element is the information on what happens with the
counter variable after each cycle of the loop (e.g. "i++").
while(condition) { } – instructions in the while loop will be executed indefinitely as long as the
condition in parentheses is true; the condition may be a numeric value or e.g. the status of a
connected button or sensor.
39
Arduino based TME Educational Board
Operators:
• % modulo division
• * multiplication
• + addition
• - subtraction
• / division
• = assignment
• != not equals
• < lower
• <= lower or equal
• > greater
• >= greater or equal
• == equal
• ! negation
• && logical AND
• || logical OR
Arduino RC5 remote control decoder library – library for decoding infrared remote control
commands encoded with the Philips RC5 protocol
Project website: www.github.com/guyc/RC5
Author: Guy Carpenter
Licence: BSD
40