当前位置:网站首页>Use of Arduino series pressure sensors and detected data displayed by OLED (detailed tutorial)
Use of Arduino series pressure sensors and detected data displayed by OLED (detailed tutorial)
2022-06-13 01:47:00 【It's Beichen bupiacra】
Use Arduino MEGA 2560 And Hx711 Pressure sensors and OLED Display the detected data
One 、 The pressure sensor is used alone
1.Hx711 And Arduino MEGA 2560 The wiring of the cable
Arduino MEGA 2560 -------- Hx711 modular
D8 -------------------------------- SCK
D9 -------------------------------- DT
Vcc ------------------------------- Vcc
Gnd ------------------------------ Gnd
D8 and D9 You can see the library file for the wiring of HX711.h Inside HX711_SCK and HX711_DT Change the following numbers to change the wiring , The library file is linked as follows :

Hx711 modular --------------------- sensor
E+ --------------------------------- red
E- ---------------------------------- black
A- ---------------------------------- white
A+ --------------------------------- green
2.Hx711 And Arduino MEGA 2560 Physical connection of

3.Hx711 And Arduino MEGA 2560 Code for
#include <HX711.h>
float Weight = 0;
void setup()
{
Serial.begin(9600);
Init_Hx711();
Serial.print("Welcome to use!\n");
Get_Maopi();
delay(3000);
}
void loop()
{
delay(100);
int x = 0;
Weight = Get_Weight(); // Calculate the weight of the weight placed on the sensor
// Serial.print(float(Weight/1000),3); // The serial port displays the weight
// Serial.print(" kg\n"); // Display units
// Serial.print("\n"); // Display units
delay(200); // Time delay 1s
x = abs(Weight);
Serial.print(x);
Serial.print(" g\n"); // Display units
}
Two 、OLED Used alone
1.OLED And Arduino MEGA 2560 attachment
OLED ------------------ Arduino MEGA 2560
Gnd -------------------- Gnd
Vcc --------------------- 3.3V
SCL -------------------- SCL
SDA -------------------- SDA
2.OLED And Arduino MEGA 2560 A physical picture

3.OLED And Arduino MEGA 2560 Code , Show numbers , english , chinese
// Display Chinese and English character program
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define LOGO16_GLCD_HEIGHT 16 // Define the display height
#define LOGO16_GLCD_WIDTH 16 // Define the display width
// chinese : matter ( Store lattice variables , Use functions display.drawBitmap() Call )
static const unsigned char PROGMEM str_1[] =
{
0x00,0x00,0x0C,0x00,0x0E,0x70,0x0E,0x60,0x3E,0xE0,0x3E,0xC0,0x3F,0xFE,0x6F,0xFE,
0x0E,0xFE,0x1F,0xFE,0x7F,0xEC,0xEF,0xCC,0x0F,0xBC,0x0C,0x18,0x0C,0x00,0x00,0x00,
};
// chinese : United
static const unsigned char PROGMEM str_2[] =
{
0x00,0x00,0x00,0x00,0x00,0x1C,0x3F,0xD8,0x7E,0xF0,0x36,0x3C,0x3F,0xF8,0x36,0x60,
0x3E,0xFE,0x37,0xF0,0x3E,0x70,0xF6,0xF8,0x07,0xDE,0x0F,0x0F,0x0E,0x00,0x00,0x00,
};
// chinese : network
static const unsigned char PROGMEM str_3[] =
{
0x00,0x00,0x00,0x00,0x00,0x78,0x3F,0xFC,0x18,0x1C,0x1B,0xFC,0x1B,0x7C,0x1F,0xFC,
0x1F,0xFC,0x1F,0xBC,0x1C,0x1C,0x38,0x1C,0x38,0x3C,0x38,0x3C,0x00,0x18,0x00,0x00,
};
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
void setup()
{
Serial.begin(9600);
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64)
// init done
display.clearDisplay(); // Clear the screen
// English character display , Direct use display.println or print Just display the string
//println Line break ,print Don't wrap
display.setTextSize(1); // Set font size
display.setTextColor(WHITE); // Set the font color white
display.setCursor(0,0); // Set the starting position of the font
display.println("Hello, world!"); // Output characters and wrap
display.setTextColor(BLACK, WHITE); // Set the font black , Font background white
display.println(3.141592); // Output numbers and wrap
display.setTextSize(2); // Set font size
display.setTextColor(WHITE); // Set font white
display.print("0x"); // The output characters
display.println(0xDEADBEEF, HEX); // Output is ASCII Coded hexadecimal
//display.display(); // Show above
// Chinese character display
display.drawBitmap(26, 32, str_1, 16, 16, 1); // In coordinates X:26 Y:16 Display Chinese characters in the position of
display.drawBitmap(42, 32, str_2, 16, 16, 1); // In coordinates X:42 Y:16 Chinese character couplets are displayed at the position of
display.drawBitmap(58, 32, str_3, 16, 16, 1); // In coordinates X:26 Y:16 The location of the display Chinese character net
display.display(); // Show all cached
}
void loop()
{
}
3、 ... and 、OLED Used with pressure sensors
1. The wiring is the same as the above single use, so it is not repeated
2. Physical display

3.OLED With the gravity sensor and Arduino MEGA 2560 Code
#include "HX711.h"
float Weight = 0;
// Display Chinese and English character program
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET -1
//#define TrigPin 2
//#define EchoPin 3
Adafruit_SSD1306 display(OLED_RESET);
//Adafruit_SSD1306 display(128, 64, &Wire, OLED_RESET);// Statement OLED
// One , Two parameters 0.9 " OLED The long model parameters are 128,64, The third parameter defaults to &Wire, Fourth parameter
// Set reset foot ,-1 Just don't set
void setup()
{
// pressure
Init_Hx711();// initialization HX711 Module connected IO Set up
Serial.begin(9600);
Serial.print("Welcome to use!\n");
delay(3000);
Get_Maopi(); // Get fur
//oled
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.setTextColor(WHITE);// On pixel illumination
display.clearDisplay();// Clear the screen
display.setTextSize(2);// Set font size
}
void loop()
{
int dis;
Weight = Get_Weight();// Calculate the weight of the weight placed on the sensor
Serial.print(float(Weight),3);// The serial port displays the weight
Serial.print(" g\n");// Display units
Serial.print("\n");// Display units
delay(1000);
dis = Weight;
display.clearDisplay();// Clear the screen
display.setCursor(50,10);// For positioning
display.print(dis);
display.println("g");
display.drawRect(0, 33, 128, 12, WHITE);// Draw a matrix
display.fillRect(2, 35, map(dis, 2, 30, 2, 124), 8, WHITE);
//map( Values to map , The initial value of the old interval , The final value of the old interval , Initial value between new districts , The final value between new districts )
display.display();// Turn on the display
}
It's not easy to create , Please support , Your support is the driving force of my renewal , A little praise and attention
边栏推荐
- Use koa to mock data and set cross domain issues
- Qt实现思维导图功能(二)
- Installing pytorch geometric
- Devaxpress Chinese description --tcxpropertiesstore (property store recovery control)
- Detailed explanation of audience characteristics
- JSON and protobuf Any interchange
- Getting started with phaser 3
- 30: Kakfa simulates JSON data generation and transmission
- 什么是立体角
- Service creation and operation example of ROS
猜你喜欢

受众群体应该选择观察模式还是定位模式?

Use koa to mock data and set cross domain issues

四、入库管理功能的完善

How to solve the problems when using TV focusable to package APK in uni app

STM32 3*3矩阵按键(寄存器版本)

Project training (XVII) -- personal work summary

Traversal of binary tree - first order traversal, middle order traversal, and second order traversal

Using OpenCV in go
![[WSL2]WSL2迁移虚拟磁盘文件ext4.vhdx](/img/e9/4e08e07c2de2f99c2938e79f7f1c44.png)
[WSL2]WSL2迁移虚拟磁盘文件ext4.vhdx

General IP address, account and password of mobile IPv6 optical cat login, and mobile optical cat is in bridging mode
随机推荐
Pyflink implements custom sourcefunction
Wildcard usage of go standard library FMT
CXGRID keeps the original display position after refreshing the data
Design of distributed game server
[learn FPGA programming from scratch -21]: Advanced - Architecture - VerilogHDL coding specification
What is Google plus large text ads? How to use it?
Introduction to common ROS commands
[andoid][step pit]cts 11_ Testbootclasspathandsystemserverclasspath at the beginning of R3_ Analysis of nonduplicateclasses fail
三、上传织物图片至SQL Server并提供name进行展示织物照片
[official document summary] writing standards for academic dissertations of National University of science and technology
Introduction to Google unit testing tools GTEST and gmoke
D template instance does not match declaration
Uuid/guid introduction, generation rules and generation codes
Phaser3 load
Magics 23.0如何激活和使用视图工具页的切片预览功能
路径字段是什么? ——竞价广告
Implementation and design of JMeter interface test database assertion for CSDN salary increase technology
Devexpress implementation flow chart
What is the path field—— Competitive advertising
About tkinter Canvas does not display pictures