STM32: Cheap and Powerful

About: Do you like technology? Follow my channel on Youtube and my Blog. In them I put videos every week of microcontrollers, arduinos, networks, among other subjects. New tutorials on Tuesdays and Fridays.

Intro: STM32: Cheap and Powerful

Four times more powerful than the Arduino Mega, today I continue the discussion concerning the STM32 Maple Mini. I’m a big fan of this, as it is an Arm chip and (even better) supports Arduino IDE. Thus, I program this microcontroller as if it were an Arduino. However, the STM32 is much more powerful.

STM32 Maple Mini can be find in this link:http://s.click.aliexpress.com/e/uV7QZBI

We made an assembly with a sensor, this time the BMP180. Added to this is a 1.8 "TFT Display, 160 pixels by 128, which I consider a lot for a device of this size.

In today's video, we’ll read the temperature and pressure values using the BMP180, display the read data on the display, and log this read data into a file on the SD card.

Step 1: Pinning

Check out the Maple Mini pinout which, in addition to being incredible because it has many doors, is relatively cheap, because its SMT core costs only a few cents.

Step 2: Assembly

In our assembly, we have an STM32 Maple Mini connected via i2c port to a BMP180, which is a temperature and pressure sensor. The circuit is powered by the USB port. We determined the temperature data printing in red and the pressure in blue.

Step 3: Install Adafruit Unified Sensor Library

Look for Adafruit Unified Sensor and install Adafruit Unified Sensor.

Step 4: Install ST7735 Library Modified to STM32

Go to https://github.com/KenjutsuGH/Adafruit-ST7735-Library

and download the zip.

Unzip the file and place it in the Documents / Arduino / libraries folder

Step 5: Library BMP085 / BMP180

Look for BMP085 and install Adafruit BMP085 Library.

Step 6: GFX Library

Look for BMP085 and install Adafruit BMP085 Library.

Step 7: DisplaySTM32.ino

First, we import libs from the display, text source, sensor, communication, and SD card. We have defined the settings we use in the display assembly and the SD pin.

//Importamos as libs do display, fonte do texto,
//sensor, comunicação e cartão SD

#include <Adafruit_GFX_AS.h>

#include <Adafruit_ST7735.h>

#include <Fonts/FreeSans9pt7b.h>

#include <Adafruit_Sensor.h>

#include <Adafruit_BMP085.h>

#include <SPI.h>

#include <Wire.h>

#include <SD.h>

//Configuração que usamos na montagem //do display #define DISPLAY_CS PA2 #define DISPLAY_RST PA4 #define DISPLAY_DC PA3 //Pino CS que o SD está ligado #define SD_CS PA8 #define ROW_SIZE 18 #define DISPLAY_WIDTH 160 #define LEFT_MARGIN 9 //Objeto responsável pelo display Adafruit_ST7735 display = Adafruit_ST7735(DISPLAY_CS, DISPLAY_DC, DISPLAY_RST); //Objeto responsável pelo sensor Adafruit_BMP085 bmp;

Step 8: Setup

We initialize the sensor, the SD, and the display, and then define the formatting of this screen.

void setup() {
Serial.begin(115200); //Inicializa o sensor if (!bmp.begin()) { Serial.println("Não achou o sensor BMP, verifique a montagem"); } //Inicializa o SD if (!SD.begin(SD_CS)) { Serial.println("Erro ao inicializar lib SD!"); } //Inicializa o display display.initR(INITR_BLACKTAB); //Rotaciona o conteúdo mostrado display.setRotation(1); //Configura a fonte do texto display.setFont(&FreeSans9pt7b); //Pinta a tela de branco display.fillScreen(ST7735_WHITE); //Configura e mostra o texto da temperatura display.setCursor(LEFT_MARGIN, 1*ROW_SIZE); display.setTextColor(ST7735_RED); display.print("Temperature:"); //Configura e mostra o texto da pressão display.setCursor(LEFT_MARGIN, 4*ROW_SIZE); display.setTextColor(ST7735_BLUE); display.print("Pressure:"); }

Step 9: ​Loop

We start the Loop with the reading of the temperature, going to pressure, and point to the Strings that will be displayed on the display and recorded in the log.

void loop() {
//Faz a leitura da temperatura float temperature = bmp.readTemperature(); //Faz a leitura da pressão int pressure = bmp.readPressure(); //Strings que serão exibidas no display e gravadas no log String strTemp = String(temperature) + "C"; String strPress = String(pressure) + "Pa";

Next, we define new formatting of the display.

//Limpa o texto da temperatura anterior
display.fillRect(0, 1*ROW_SIZE + 2, DISPLAY_WIDTH, ROW_SIZE, ST7735_WHITE); //Posiciona o cursor no local correto display.setCursor(LEFT_MARGIN, 2*ROW_SIZE); //Configura a cor do texto como vermelho display.setTextColor(ST7735_RED); //Mostra a String da temperatura display.println(strTemp); //Limpa o texto da pressão anterior display.fillRect(0, 4*ROW_SIZE + 2, DISPLAY_WIDTH, ROW_SIZE, ST7735_WHITE); //Posiciona o cursor no local correto display.setCursor(LEFT_MARGIN, 5*ROW_SIZE); //Configura a cor do texto como azul display.setTextColor(ST7735_BLUE); //Mostra a String da pressão display.println(strPress);

Finally, we open the log file for writing and determine the behavior as needed.

//Abre o arquivo de log para escrita
File dataFile = SD.open("log.txt", FILE_WRITE); //Se conseguiu abrir o arquivo if (dataFile) { //Escreve a String da temperatura dataFile.println(strTemp); //Escreve a String de pressão dataFile.println(strPress); //Fecha o arquivo dataFile.close(); } //Espera 5 segundos delay(5000); }

Step 10: Files

Download the files:

PDF

INO

Share

    Recommendations

    • Plastics Contest

      Plastics Contest
    • Optics Contest

      Optics Contest
    • Electronics Tips & Tricks Challenge

      Electronics Tips & Tricks Challenge

    Discussions