Uploaded by fettahmohamed799

TIT rap

advertisement
End of Studies Internship Report 

Developed to obtain: « DUT »
SECTOR: electrical engineering
Under the theme:
The development of an electronic card
around STM32 AND Sending sensor data
with Ethernet and http and Blue Pill

Work carried out within the company:
Agri 4.0
Realized by:
Supervised by:
Titrite OUAICHA
Hassane MOUHETI
AnnéeUniversitaire 2021-2022


Dedications:
I dedicate this work, as proof of respect, gratitude, and recognition to:
Mr. Hassan MOUHETI for his time, assistance and help.
My teachers Mr. ELIHSSINI Hossine and Mrs. NADIR Fatima-Zahra also
for their help, encouragement and support.
The people from the electrical engineering department who helped me to
improve my knowledge by giving me information and tips.
My dear family, for their love, patience, and prayers.
To all those who have contributed directly or indirectly in the realization
of this work. Thank you so much.




Thanks:
Before starting this report, I would first like to thank, the entire teaching team
of the superior school of technology
Of Agadir, and the professional stakeholders responsible for the electrical
engineering training, for having ensured the theoretical part and practice of it.
I would also like to express my deepest thanks to my internship supervisor Mr.
Hassane MOHTI for his guidance, his support and his precious efforts and
remarks which allowed the smooth running and implementation of this
internship project graduation.
I also thank the members of the jury who accepted to judge my work.
Finally, I thank my family, my colleagues for their encouragement, and all
those who have contributed directly or indirectly behind the development of
this work.




Table of contents:
General introduction :------------------------------------------------------------------------------------------------------7
Chapter1 : PRSENTATION OF THE COMPANY--------------------------------------------------------------------------8
I.
About agri 4.0--------------------------------------------------------------------------------------------------9
II.
Their services--------------------------------------------------------------------------------------------------9
III.
Agri 4.0 SENSORS--------------------------------------------------------------------------------------------10
IV.
Data sheet-----------------------------------------------------------------------------------------------------11
Chapter2 : Software and Hardware-------------------------------------------------------------------------------------12
I.
II.
III.
IV.
V.
VI.
Introduction--------------------------------------------------------------------------------------------------13
Specifications-------------------------------------------------------------------------------------------------13
Code------------------------------------------------------------------------------------------------------------13
1.1. http--- ----------------------------------------------------------------------------------------------------13
1.2. Libraries used------------------------------------------------------------------------------------------13
1.3. Methods and functions used-----------------------------------------------------------------------14
The Program--------------------------------------------------------------------------------------------------15
Blue Pill--------------------------------------------------------------------------------------------------------18
• Features---------------------------------------------------------------------------------------------18
• Uploading the program-------------------------------------------------------------------------18
• Setting up the Arduino IDE for STM32------------------------------------------------------20
Conclusion---------------------------------------------------------------------------------------------------- 21
Chapitre3: The STM32 Base electronic card------------------------------------------------------------------------ 22
I.
II.
III.
IV.
V.
Introduction--------------------------------------------------------------------------------------------------23
Specifications-------------------------------------------------------------------------------------------------23
Components--------------------------------------------------------------------------------------------------23
Development of the card----------------------------------------------------------------------------------29
1. Schematic capture-------------------------------------------------------------------------------------29
2. PCB Layout-----------------------------------------------------------------------------------------------34
Conclusion----------------------------------------------------------------------------------------------------37
General conclusion----------------------------------------------------------------------------------------------------------37


4


List of Figures:
Figure1: part of the code (1)……………………………………………………………………………………………………………………16
Figure2: part of the code (2)……………………………………………………………………………………………………………………17
Figure3: part of the code (3)……………………………………………………………………………………………………………………18
Figure4: block diagram showing the connection between all the cards……………………………………………………..19
Figure5: steps to add the URL to boards’ manager……………………………………………………………………………………20
Figure6: steps to add the STM32 to Arduino ide ………………………………………………………………………………………20
Figure7: selection of the board in tools……………………………………………………………………………………………………..21
Figure8: STM32F103C8T6 microcontroller…………………………………………………………………………………………….23
Figure9: STM32F103C8T6 on Proteus…………………………………………………………………………………………………….24
Figure10: BOOT selector………………………………………………………………………………………………………………...25
Figure11: Reset switch……………………………………………………………………………………………………………………25
Figure12: 3.3Vregulator…………….……………………………………………………………………………………………………25
Figure12: 32.768KHz Oscillator……………………………………………………………………………………………………….26
Figure13: ST-LINK/V2 ……………………………………………………………………………………………………………………..26
Figure14: external LSE ……………………………………………………………………………………………………………………..26
Figure15: external 8 MHz clock ……………………………………………………………………………………………………….27
Figure16: Power LED ……………………………………………………………………………………………………………………....27
Figure17: FTDI connector ………………………………………………………………………………………………………………..27
Figure18: Ethernet shield connector………………………………………………………………………………………………..28
Figure19: SP485ENL…………………………………………………………………………………………………………………………28
Figure20: components dedicated to protect the card……………………………………………………………………...29
Figure21: steps to find components placements……………………………………………………………………………..29
Figure22: search bar of components ……………………………………………………………………………………………….30
Figure23: steps to import new components (1)………………………………………………………………………………..30


5


Figure24: steps to import new components (2)………………………………………………………………………………..31
Figure25: steps to resize capacitors (1)……………………………………………………………………………………………31
Figure26: steps to resize capacitors (2) …………………………………………………………………………………………..32
Figure27: steps to resize capacitors (3) …………………………………………………………………………………………..32
Figure28: DEFAULT placement …………………………………………………………………………………………………..……33
Figure29: wiring using label mode ……………………………………………………………………………………………………33
Figure30: PCB Layout window ………………………………………………………………………………………………………….34
Figure31: components’ list in PCB Layout ………………………………………………………………………………………..34
Figure32: steps to add a Ground Plan (1) …………………………………………………………………………………………35
Figure33: steps to add a Ground Plan (2) …………………………………………………………………………………………35
Figure34: the printed circuit board……………………………………………………………………………………………………36
Figure35: the 3D vision of the card……………………………………………………………………………………………………36
List of tables:
Table 1: sensors made by AGRI 4.0……………………………………………………………………………………………………………10
Table 2: information about AGRI 4.0…………………………………………………………………………………………………………11
Table 3: BOOT mode…………………………………………………………………………………………………..…………………………….24


6


General introduction
Companies always seek to satisfy their clients by understanding their needs, and granting
their wishes by offering high quality services and products. Also, it is important to be
consistent in communicating with customers and suggest preventive solutions instead of
corrective ones. What’s more, the eye always catches new and creative things; novelty
makes people curious and fascinated witch increases product demand.
Let’s just take a look around us and count how many electronic gadgets are there; basically,
a total of 5 billion people around the world use electronic gadgets every day, equivalent to
63 percent of the world's total population. That’s because they make life much easier and
can do things that human beings can’t do; Such as, measuring temperature, humidity or light
using sensors, or sending data to a cloud for example or maybe controlling things from a
distance using microcontrollers. For these reasons and more, people reach out to companies
specialized in making electronic cards and sensors, and in giving great solutions to their
problems to make their work and life much easier.
The objective of our end-of-studies internship project is to make an electronic card based on
STM32F103C8T6, containing Analog pins, Inputs and outputs pins, also PWM pins and more.
Besides, sending sensors data to the cloud using the HTTP protocol.
This report is organized around three chapters:
The first chapter presents some information about the AGRI 4.0 Company.
The second chapter presents the code used to send the sensors’ data and some
information about the blue pill card and how to program it using Arduino IDE.
In the third chapter we’ll discuss how to make a printed circuit board using Proteus
and the components used in the electronic card we’ll be making.


7



CHAPITER 1 :
PRSENTATION OF THE
COMPANY



8

I.

About agri 4.0 :
AGRI 4.0 is a 100 % Moroccan company that invests in agriculture 4.0 and reduces the
gap between Moroccan agriculture and that of the world leaders in this field, using the
new technologies to better exploit the wealth in Morocco and Africa.
A great team of young, creative and motivated employees works for a clear mission:
• Make agriculture profitable regardless of the size of the project (reduce
consumption of inputs and energy and increase yield and quality and save the
farmer time and peace of mind).
• Make this sector more attractive for young people from cities and rural areas and
contribute to reducing the unemployment rate in Morocco.
• Improve product quality to meet the needs of the most demanding markets.
• Innovating to find solutions to the daily problems of farmers, they are constantly
attentive to the various changes and offer their customers an intuitive, intelligent
operating memory that is accessible at all times from the 5 corners of the globe.
• Provide better agronomic expertise to design a more intelligent, predictive and
sustainable agricultural system.
The AGRI 4.0 Company’s activity is the design and production of electronic sensors and
micro-controllers and the development of web and mobile applications dedicated to
agriculture. The Data collected by sensors is managed by mobile and web applications; they
allow the intelligent management of farms through real-time tracking, monitoring and
analysis tools that facilitate the decision-making process and can lead to predictive
management processes. They use technologies such as IOT, low-speed communications, big
data, AI and the cloud. The data collected thanks to the technologies they use allow farmers
to move from corrective agricultural management to preventive management thanks to the
agricultural memory they will have.
II.
•
•
•
•
•
•
•
•
Their services:
Agri 4.0 provides the following services:
Vegetable production.
Digitization of farms.
Soil and water analysis.
Maintenance of technical installations.
Fertilization, irrigation.
Integrated control and disease treatment.
Technical and financial feasibility study.
Mapping your farm.


9


III. Agri 4.0 SENSORS :
Here are some of the sensors they made:
Sensor
Function
This sensor has been specially designed to measure
conductivity, temperature, humidity directly in the soil
(soils, substrates, and composts).
This sensor measures the direct solar irradiance that
reaches the earth's surface and diffuses it, in a wavelength
ranging from 0.3um up to 3um.
This sensor measures the pH of a solution. It is directly
operational. And requires few resources (Power,
maintenance, etc.)
This sensor measures in real time the conductivity of a
solution.
This sensor measures the temperature and humidity of the
air in real time.
Table 1: sensors made by AGRI 4.0


10


IV. Data sheet:
The table below provides information about the company:
Type of company
LLC
Establishment date
2018
Address
RUE NISRINE CITE RYAD SALAM, N°8 Agadir, SOUSS
MASSA 80000, MA
Phone number
06 61 48 41 42
Fax
05 28 22 78 13
Email
Contact@agri40.ma
Website
www.agri40.ma
Capital
200000DHS
Activity
Precision agriculture, big data, artificial intelligence,
Monitoring, and remote monitoring
Table 2: information about AGRI 4.0


11



CHAPITER 2 :
Software and Hardware



12

I.

Introduction:
It’s convenient to access sensors’ data from your phone or computer anywhere just by
connecting to the internet using any browser available. This data is sent using protocols,
mainly HTTP, and using microcontrollers in our case we used STM32F103C8T6, in this
chapter we will get into the details of doing so.
II.
Specifications:
Sending sensors’ data using HTTP protocol with a blue pill card based on
STM32F103C8T6.
III. Code:
1.1 HTTP:
HTTP protocol stands for Hypertext Transfer Protocol, it is the foundation of the
World Wide Web, and is used to load web pages using hypertext links. HTTP is
an application layer protocol designed to transfer information between
networked devices and runs on top of other layers of the network protocol stack.
A typical flow over HTTP involves a client machine making a request to a server,
which then sends a response message.
What our program does is sending sensor’s data to the cloud using the HTTP
protocol, programmed in the ARDUINO IDE since it supports our microcontroller,
STM32, using different libraries and functions.
1.2 Libraries used :
SPI.h: This library allows you to communicate with SPI devices used to send to
send data between microcontrollers and small peripherals such as shift registers,
sensors, and SD cards, with the microcontroller as the controller device.
Ethernet.h: With this library you can use the Arduino Ethernet (shield or board) to
connect to Internet. The library provides both Client and server functionalities.
The library permits you to connect to a local network also with DHCP and to
resolve DNS.


13


Arduino_JSON.h: it is used to convert a string into JSON string which means under
a JavaScript Object Notation.
1.3
-
-
-
-
-

Methods and Functions used :
Some of the important methods and functions used in the code are:
The method EthernetClient: creates a client which can connect to a specified
internet IP address and port.
The method JSON.stringify() : converts objects into JSON strings.
The method Ethernet.begin() : initializes the Ethernet library and network
settings.
The method Ethernet.gatewayIP() : gets the gateway IP address of the
ethernet schield.
The method Ethernet.localIP() : gets DHCP assigned IP.
The method client.connect() :Connects to a specified IP address and port. The
return value indicates success or failure.
The method client. available() : Returns the number of bytes available for
reading (that is, the amount of data that has been written to the client by the
server it is connected to).
The method payload.substring() : It allows you to look for an instance of a
particular substring within a given String.
The function millis() : Returns the number of milliseconds passed since the
microconroller board began running the current program.
The function read_sensor(): it reads the output of sensors ; can be
replaced by any sensor’s code depending on its type.
The function Cframe() : used for frames conditioning, and it’s were data is
converted to JSON format.
The function conne_ct() : initializes Ethernet library and network settings
and providing information about the gateway IP address and DHCP assigned
IP.
The function send() : assigned to send the data to the server.

14


IV. The program :
The pictures below show the full program.
Figure1: part of the code (1)


15


Figure2: part of the code (2)


16


Figure3: part of the code (3)


17

V.

Blue Pill :
STM32 Blue Pill is a high-performance, breadboard friendly development board with loads of
features in a small form factor. It features a 32-bit ARM Cortex M3 processor running at
72MHz frequency with 64Kbytes of flash memory and 20 Kbytes of SRAM. It has an extensive
range of I/O and peripherals, including multi-channel Direct Memory Access, several high
resolution ADC, and three general purpose 16-bit timers plus one PWM timer. It also has
multiple communication interfaces including two I2Cs and SPIs, three UARTs, an USB and a
CAN. Further, it allows you to add additional flash by soldering an SPI Flash to the board. This
development board is pre-flashed with an Arduino bootloader, so you can download the
sketch just like other Arduino board.
The STM32 Blue Pill can be programmed using the Type-C USB connector (if bootloader is
flashed), the STLink USB dongle, or an external USB to 3.3V TTL adapter.
Features:
•
•
•
•
•
•
•
•
•
•
STM32F103C8T6, 72 MHz ARM Cortex-M3
64K Flash, 20K SRAM.
32.768KHz crystal for RTC
3 buttons: user, boot and reset
USB type-c connector
32 digital I/O Pins (12 of which are PWM)
14 Analog Inputs
3 UART Ports
2 I2C Ports
2 SPI Ports
Uploading the program:
As already mentioned we programmed in Arduino IDE, since it supports blue pill, you just
need to download the STM32 driver (download here: https://www.st.com/en/developmenttools/stsw-stm32102.html ).
To upload the program we used an external USB to 3.3V TTL adapter (FTDI); connections:
• RX ---------> PA9.
• TX ---------> PA10.
• VCC ---------> 3.3v.
• GND ---------> GND.
Also, we used an Ethernet shield to connect to the internet using the Ethernet library.


18


Connections:
• 10 ---------> PA4.
• ICSP pins ---------> PA5 , PA6,PA7.
• 3V3 ---------> 3.3v.
• GND ---------> GND.
Figure4: block diagram showing the connection between all the cards
(The drawing above is made in Sketchbook app on android)
To upload the program switch the BOOT 0 header from the '0' position to the '1' position
before connecting the FTDI board to the computer for flashing the bootloader.


19


Setting up the Arduino IDE for STM32:
In file >> preferences add the URL bellow to additional boards’ manager URL:
http://dan.drown.org/stm32duino/package_STM32duino_index.json
Figure5: steps to add the URL to boards’ manager
In tools >> board >> boards manager and search for STM32, once the list appears install the
version from stm32duino.
Figure6: steps to add the STM32 to Arduino ide
Connect the FTDI board to the computer using a TTL to USB cable and select the
correct board in the tools menu then upload the program.


20


Figure7: selection of the board in tools
VI. Conclusion :
In this chapter we saw what HTTP is and how to code a program that sends a
sensors data to the cloud; also we learned what a blue Pill is and how to
configure it and to work with it.
After setting up the card and connecting it to the FTDI and the Ethernet shield,
the data was successfully sent to the company’s website.


21



CHAPITER 3:
The STM32 based electronic card



22

I.

Introduction:
Despite the various types of microcontrollers, users can hardly find ones
that would best meet their needs, so in this case that board should be
personally made; and this is what most of the companies and engineers
do to simplify their work.
II.
Specifications:
Elaborating a micro-controller board based on the STM32F103C8T6 on Proteus,
containing:
- Analog pins.
- Input/output pins.
- Serial: TX, RX.
- PWM pins.
- SPI: MISO, MOSI, SCK, CS.
- Inbuilt LED.
- CAN bus ports.
- Etc.
III. Components :
Each electronic card must contain a lot of things to function; for the elaborated card in this
project the components used are:
•
STM32F103C9T6 microcontroller: 72 MHz maximum frequency, Single-cycle
multiplication and hardware division, with 64 Kbytes of Flash
memory and 20 Kbit of SRAM, also 2.0 to 3.6 V application
supply and 4-to-16 MHz crystal oscillator Internal, 8 MHz
factory-trimmed RC, Internal 40 kHz RC PLL for CPU clock, 7
timers and more.
(You can find all the stm32f103c8 features and this website:
Figure8: STM32F103C8T6 microcontroller
https://www.st.com/en/microcontrollers-microprocessors/stm32f103c8.html)


23


Figure9: STM32F103C8T6 on Proteus
•
BOOT Selector: BOOT0 and BOOT1 jumpers for selecting the booting
memory. The following image shows three different options of boot spaces
based on these pins.
BOOT MODE
SELECTION PINS
BOOT MODE
ALIASING
1
Main Flash
Memory
System memory
1
Embedded SRAM
Main Flash Memory is selected as
boot space
System memory is selected ad boot
space
Embedded SRAM is selected as
boot space
BOOT1
BOOT0
X
0
0
1
Table 3: BOOT modes


24


Figure10: BOOT selector
•
A Reset Switch: to reset the Microcontroller.
Figure11: Reset switch
•
3.3V regulator: converts 5V to 3.3V for powering the MCU.
Figure12: 3.3V regulator


25

•

32.768KHz Oscillator: a real time clock for clock calendar applications.
Figure12: 32.768KHz Oscillator
•
ST-LINK/V2: which is an in-circuit debugger and programmer.
Figure13: ST-LINK/V2
•
An external LSE (low-speed external) crystal oscillator with a frequency of
32.768 kHz (32 kHz), which provides a low-power and highly accurate clock
source to the RTC peripheral for clock calendar applications.
Figure14: external LSE


26

•

An external 8 MHz clock: Crystal, Main Clock for MCU.
Figure15: external 8 MHz clock
•
A power LED.
Figure16: Power LED
•
A FTDI connector which is a USB to Serial TTL level converter which allows
for a simple way to connect TTL interface devices to USB.
Figure17: FTDI connector


27

•

Ethernet shield connector: to connect the card to the Ethernet shield.
Figure18: Ethernet shield connector
•
SP485ENL: a half-duplex transceiver that meets the requirements of RS-485 and
RS-422.
Figure19: SP485ENL
•
To protect the card we used an Optoisolator that transfers
electrical signals between two isolated circuits by using light. It prevents high
voltages from
affecting
the card.
We
also
used
a
Zener
diode to protect the circuit from an overvoltage condition


28


Figure20: components dedicated to protect the card
IV. Development of the card:
1. Schematic capture :
The screenshots of the components above are taken from Proteus, since it’s where
the plan was made. At first, in the schematic capture we placed the
STM32F103C8T6 and renamed all the pins, then placed all the other components.
To find the components you want, search them here:
Figure21: steps to find components placements


29


Figure22: search bar of components
But if the component you’re looking for is nowhere to be found in the pick devices
window you can download it online, following these steps:
First
you
go
to
https://www.snapeda.com/?gclid=CjwKCAjwkMeUBhBuEiwA4hpqEHhjj
X5e9BU_ncEFduZsT_G0yIB9wqsoEMznZoHSDpRgnpgyTuR1BoCQFEQAvD_BwE and search for the
electronic component you want and download its footprint, then go back
to Proteus and on library click on Import Parts >> select file >> import
file.
Figure23: steps to import new components (1)


30


Figure24: steps to import new components (2)
If you want to resize capacitors and resistances follow these steps:
-
You double click on the capacitor you want to resize.
Figure25: steps to resize capacitors (1)


31


Then type the desired size in the PCB package:
Figure26: steps to resize capacitors (2)
The picture below shows the different sizes available.
Figure27: steps to resize capacitors (3)


32


After placing all the components you need to connect them, to do so, we used Wire
Label Mode which saves you some space in the design area. What you have to do is
just take the DEFAULT in terminals:
Figure28: DEFAULT placement
Place it and give it the same label as where you want to connect it.
Figure29: wiring using label mode.


33


2. PCB layout :
Now after creating the schematic we’ll make the printed circuit board. To do so we
need to click on the icon bellow to add the PCB layout window:
Figure30: PCB Layout window
In the PCB layout and exactly in the component section you’ll find all the components
you’ve created in the schematic capture.
Figure31: components’ list in PCB Layout
Next you’ll need to trace the board edge, to do this, click on the
square icon above and on the down left corner of your screen,
there’s a list, select the board edge then trace it.
Now place all your components inside the frame you’ve created,
starting with the microcontroller then the others, keep in mind
that the connectors should be on the edges. Then you’ll need to
trace the wires; the wires are made from copper and there are
two types of them: Top copper and bottom copper. You can’t
cross over two wires of the same type, what you should do is when you need to place
a wire over the other, double tap to switch between top and bottom copper.


34


Then to protect the card you need to add a Ground Plan, here is how:
•
Click on the icon below:
Figure32: steps to add a Ground Plan (1)
•
Trace the card, then a window will pop up:
o For NET choose: GND = POWER
o For Layer/Color choose : Bottom Copper
Figure33: steps to add a Ground Plan (2)


35


The picture below shows how the PCB turned out:
Figure34: the printed circuit board
Here is a 3D vision of the card:
Figure35: the 3D vision of the card


36

V.

Conclusion
In this chapter we saw the different components we used in our card and their role, and how
to import new components into Proteus then how to make an electronic circuit in Proteus.
Also we have shown the steps to make a printed circuit board and the Ground plan to
protect the board, and finally we’ve shown the 3D vision of the card.
General Conclusion
The work presented in this end-of-studies internship report is based on the design of an
electronic card based on STM32F103C8T6 microcontroller that contains inputs and outputs
pins and connectors necessary to connect FTDI, Ethernet shield and we discussed the
components necessary to make the card and also to protect it . Also, we saw how to code a
program that can send a sensor’s data to the cloud.
To do so, we used several software; in particular, Arduino IDE, Proteus and SketchBOOk to
draw the diagram. We can’t forget about the libraries and functions we used to make our
program that had successfully sent the data to the website the company made.
At last, our program worked as already mentioned, and the electronic card was approved by
the teacher since we didn’t have time to print it and test it. If we had more time we could
have been printed it and tested it.


37


Bibliographic references:
I used this websites form 01/05/2022 to 03/06/2022:
pio-bluepill-w5500-ethernet-mqtt-client/main.cpp at master · maxgerhardt/pio-bluepill-w5500ethernet-mqtt-client · GitHub
How to use STM32CubeIDE - YouTube
Arduino-STM32-Ethernet/main.cpp at master · nopnop2002/Arduino-STM32-Ethernet · GitHub
W5100 with STM32 using mbed - TCP/IP Chip / W5100 - WIZnet Developer Forum


38
Download