You are on page 1of 16

Gr 1 – T 1 07/01/2018

Abdelkader Sallemine Mark


Andriamanalina Max Cohen Brown
Jean Marie Vianney Haburukundo
Angela Okuley Comments
Master M2 : PAUWES ENERGY
Instrumentation

EXP 1

Title : ???

Objectives:

Introduction :

Explain the programs, comments

Conclusions :

CR EC741 TP n°1 1
Experiment 1
Introduction to Arduino and serial communication

Image of Fig 1
Objective
The objective of this experiment is to learn how to use Arduino nano,
Arduino IDE and serial monitor over USB. Digital input/output.

Ex 1.1
Things needed
 Bread board
 Arduino Nano (Micro controller)
 Mini USB cable
 Wires
 You must have installed (Arduino IDE)
Steps
 Connect circuit on bread board as shown in Fig. 1 above
 Using the mini USB cable, connect the Arduino to your PC USB port
 Launch Arduino IDE
 Type your code. (Find our code in code section)
 Go to tools to confirm selected port and board; Select port and choose the Port
you are using (COM 101).
 Go to tools and select board, make sure Arduino NANO is the selected.
 Compile and run your code.

CR EC741 TP n°1 2

Pay attention to memory consumption (variables in RAM and program in Flash memory).
Sketch uses 1,066 bytes (3%) of program storage space. Maximum is 30,720 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2,039 bytes for local variables.
Maximum is 2,048 bytes.
Introduce an error and see how the compiler reacts.:
We have deleted one curly bracket at the beginning of the loop function and as we can see the
compiler reacted to the change by displaying an error message:
exit status 1
expected initializer before 'digitalWrite'

Change the delay of the blinking. The value is in milliseconds (ms).


0.5 s, 0.25

For a delay of 0.5 seconds, we replace 1000 ms by 500 ms which is 0.5 seconds.

Same procedure is done for 0.25 seconds by adding 250 instead of 500.

CR EC741 TP n°1 3
Ex 1.2 :

Fig.2
 A push button is added on the circuit connected as shown in Fig. 2
Observe the change of the input on the Serial Monitor.

CR EC741 TP n°1 4
It was realized that the values on the display monitor keeps changing randomly when the
button is not pressed.
This is because, when the button is pressed a small current is maintained, this charges are
released when the button is released.
This can be solved by adding a resistance of about 10kΩ.
Modify the program to transmit messages to host PC only when the push button is down.
The use of an IF statement will check the value of the variable affected to the input from the button
and decide what actions to take If it is true, and if not.
In our case we will display a text message of “Button Pressed” when the value of the variable is 1 and
“Button is not pressed” when otherwise.

Experiment 2
OLED display, analog conversion, amplification and data acquisition.

CR EC741 TP n°1 5
Objective
The main objective of this experiment is to learn :
 the use of the ADC for data conversion from a continuous voltage (0‐5V)
 to send data to host PC through serial COM port
 to display numerical data on the OLED screen by sending them through I2C bus.
 to modify the analog signal with an Op‐Amp before applying it on the ADC input.

Things needed
 Bread board
 Arduino Nano (Micro controller)
 Mini USB cable
 Wires
 OLED display
 Potentiometer
 Resistor
 OP-AMP
Experiment 2.1

Fig 2.1

CR EC741 TP n°1 6
Steps
 Using the same circuit Exp. 1 as in Fig 1, add a potentiometer as shown in figure 2.1.
 Connect the potentiometer to be powered by +5V / GND. Its middle point is the
voltage divider and must be connected to the analog input A0 of the Arduino nano.
 Implement the example “AnalogReadSerial”.
 Go to tools to confirm selected port and board; Select port and choose the Port
you are using.
 Go to tools and select board, make sure Arduino NANO is the selected.
 Compile and run your code.
From the experiment, it was realized that :
Why the output changes from 0 to 1023?
The output changes from 0 to 1023. This because for 10 bits of ADC; 210-1 = 1024 – 1023.
The resolution therefore results in the change from 0- 1023. Also, the last digit of the output
oscillates, this can be attributed to the voltage filtrations coming from the resistance. A
capacitor or digital filter can be added.
Why the output oscillates (last digit changes)? ??

What do I have to do to display the actual voltage instead of these numbers?


We will modify the program for it to display appropriately the voltage instead of those
numbers.
Declare a float type variable which will contain the value of the calculated voltage by
multiplying the analog value read from pin A0 by 5.0 in order to avoid variable type error and
conflict integer/float.
Then we will print a text message to the user “VA0= “ and then print the real value of the
variable followed by a text message “V” to indicate it’s a voltage.

CR EC741 TP n°1 7
Ex 2.2 OLED display

CR EC741 TP n°1 8
There are many ways to communicate with this driver and thus the display. We use the I2C
serial communication interface and a particular library that you installed within the Arduino
IDE.

 A 0.98” OLED display with its embedded driver SS1306 is added to the circuit in the
above experiment.
U8g2 is a monochrome graphics library for embedded devices. It has 2 options: graphic
display (u8g2) or 8x8 pixels characters (u8x8). This libray must have be added to the arduino
setup so it is recalled when coding. If not it willl not function.
 The code is the compiled and run.
Below is the code of OLED graphic display,

The problem that was noticed is : Low memory available within our Arduino NANO, which
may result instability issues.
In addition we will have a limited number of characters to display on our screen because
we’re using Graphic mode which requires way more memory which we don’t dispose.

CR EC741 TP n°1 9
JMV PLEASE INCLUDE THE PICTURE THAT HAS A
DISPLAY IN OLED SCREEN OF THE VALUE OF
SENSOR

Ex 2.3 OLED 8x8 display


Please put this code and the output.
After including the library U8g2lib.h we’ll now initialize screen and then select our font.
We will select the position of our text message by providing coordinates of our text message
on the x, y of our screen using drawstring function.

CR EC741 TP n°1 10
What is the differences when using this 8x8 pixels version instead of the graphical one?
What about other microcontrollers?
The difference is in the 8x8 pixel display you’ll be using the 8 pixels to display your messages
which will have a reduced display quality, which means reduced memory required.
The graphical display will have a more sophisticated view which can be used in other
purposes like games etc..
We haven’t noticed any issue with memory load. Which makes the 8x8 display perfect for
this kind of microcontrollers not having enough memories.
The 8g2 would be perfect on microcontrollers with more memory in board.

Ex 2.4 Op-Amp
Use 1/2 of the MCP6002 [4] to implement a non‐inverting amplifier with gain of 1 with
R1=R2=10k. The input of the Op‐Amp is the potentiometer and its output is the analog A0.
What is the particularity of this Op‐Amp in comparison with the one we studied in course (TL082)?
What do you notice when you turn the potentiometer?

Exp 3 Temperature and humidity acquisition

CR EC741 TP n°1 11
Objective
The objectives of this experiment is to learn how to:
 Interface a DHT11 sensor to acquire the local temperature and humidity
 Display data on the OLED screen
 Send data to host PC through serial COM port
 Interface with MATLAB to read the data and record them

Steps
 Add the DHT sensor to the previous OLED experiment as shown in Fig 3. It has 4
pins:
1. VCC (3 to 5V power)
2. Data out
3. Not connected
4. GND
 Add a 10k resistor between VCC and Data Out. It is called a push‐up resistor.
 Connect Data Out to digital pin D5 of the Arduino nano.

Blow on the DHT sensor and/or hold it between your fingers or get it close the fan of the PC.
Why the humidity changes much faster than temperature?
Change the delay of the loop function.

Exp 3.1 Sending data between two devices and data processing

Objective
The objective of this part of the experiment is :
 Work by paired groups and send data from/to Arduino devices.
Data processing by FFT analysis.

Steps
 Connect Arduino Device 1 to Arduino Device 2 through the connection diagrams
below
TX D6 TX D6
RX D7 RX D7
GND GND
Arduino 1 Arduino 2

Figure 4.1. Serial cross connection between two UART

Device 1:
Get local temperature and humidity
Send data to Device 2

CR EC741 TP n°1 12
Get data from Device 2
Display local (Device 1) and distant (Device 2) on OLED and on serial monitor

Device 2:
Get local temperature and humidity
Send data to Device 1
Get data from Device 1
Display local (Device 2) and distant (Device 1) on OLED and on serial monitor
/*
Exp4.1 Serial DHT11 + OLED display 8x8
L. BAGHLI 01/2018
*/
#include <U8g2lib.h>
#include "DHT.h"
#include <SoftwareSerial.h>
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(U8X8_PIN_NONE);
// https://github.com/olikraus/u8g2/wiki/u8x8reference#c‐example
float humid, temp, hic;
int pwm=0, light = 0;
#define DHTPIN 5
#define DHTTYPE DHT11 // DHT 11 or DHT 22 (AM2302), AM2321 or DHT 21
(AM2301)
DHT dht(DHTPIN, DHTTYPE);
SoftwareSerial mySerial(7, 6); // RX, TX
void setup() {
Serial.begin(9600);
mySerial.begin(9600);
u8x8.begin();
dht.begin();
Serial.println("DHT11 + OLED display");

u8x8.setFont(u8x8_font_chroma48medium8_r);
u8x8.clearDisplay();
u8x8.drawString(0, 0, "PAUWES");
u8x8.drawString(0, 1, "Instrumentation");
u8x8.drawString(0, 2, "DHT11");
u8x8.drawString(0, 3, "T=");
u8x8.drawString(0, 4, "H=");
u8x8.drawString(0, 5, "Remote :");
}
void loop() {
String data;
humid = dht.readHumidity();
temp = dht.readTemperature(); // Read temperature as Celsius (the default)
if (isnan(humid) || isnan(temp)) {

CR EC741 TP n°1 13
Serial.println("Failed to read from DHT sensor!");
}
Serial.print("Local read : ");
Serial.print("Humidity: ");
Serial.print(humid);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(temp);
Serial.println(" °C");

mySerial.print(humid);
mySerial.print("% ");
mySerial.print(temp);
mySerial.println("*C");

//read from other device


if (mySerial.available()) {
data = mySerial.read();
}
Serial.print("Remote read : ");
Serial.print(data);
data="";
while (mySerial.available() > 0) {
char inByte = mySerial.read();
data +=inByte;
// Serial.write(inByte);
}
Serial.print(data);
u8x8.setCursor(2, 3);
u8x8.print(temp);
u8x8.print("*C");
u8x8.setCursor(2, 4);
u8x8.print(humid);
u8x8.print("%");

u8x8.setCursor(0, 6);
u8x8.print(data);
delay(1000);
}

CR EC741 TP n°1 14
What electronic problems could arise from connecting 2 devices through a UART connection
?
The problem lay on the internal crystal or clock generator, the internal quartz is not accurate
enough, which results in errors in baudrate which is not compatible.1

How can we modify the transmission part of the experiment? Explain with a schematic 
the I2C protocol involves using two lines to send and receive data: a serial clock pin (SCL)
that the Arduino Master board pulses at a regular interval, and a serial data pin (SDA) over
which data is sent between the two devices. As the clock line changes from low to high
(known as the rising edge of the clock pulse), a single bit of information - that will form in

1
https://community.cypress.com/thread/13080

CR EC741 TP n°1 15
sequence the address of a specific device and a command or data - is transferred from the
board to the I2Cdevice over the SDA line.2

2
https://www.arduino.cc/en/Tutorial/MasterWriter

CR EC741 TP n°1 16

You might also like