Merge branch 'master' of github.com:Tinyu-Zhao/M5Stack into master

This commit is contained in:
Tinyu
2021-08-05 17:48:02 +08:00
22 changed files with 405 additions and 825 deletions
-150
View File
@@ -1,150 +0,0 @@
#include "GrblControl.h"
#include <Wire.h>
GRBL::GRBL(int addr){
this->addr = addr;
}
void GRBL::Init()
{
Wire.begin();
}
void GRBL::Init(uint32_t x_step,uint32_t y_step,uint32_t z_step,uint32_t acc)
{
Wire.begin();
if(x_step){
char code[256];
sprintf(code,"$0=%d",x_step);
Gcode(code);
}
if(y_step){
char code[256];
sprintf(code,"$1=%d",y_step);
Gcode(code);
}
if(z_step){
char code[256];
sprintf(code,"$2=%d",z_step);
Gcode(code);
}
if(acc){
char code[256];
sprintf(code,"$8=%d",acc);
Gcode(code);
}
}
void GRBL::Gcode(char *c)
{
Wire.beginTransmission(addr);
while ((*c) != 0) {
Wire.write(*c);
c++;
}
Wire.write(0x0d);
Wire.write(0x0a);
Wire.endTransmission();
}
void GRBL::SendByte(byte b) {
Wire.beginTransmission(addr);
Wire.write(b);
Wire.endTransmission();
}
void GRBL::SendBytes(uint8_t *data, size_t size) {
Wire.beginTransmission(addr);
Wire.write(data,size);
Wire.endTransmission();
}
void GRBL::ReadClean(){
while(1){
uint8_t i = 0;
char data[10];
Wire.requestFrom(addr, 10);
while (Wire.available() > 0) {
data[i++] = Wire.read();
}
if(data[9] == 0xff) break;
}
}
void GRBL::UnLock() {
this->SendByte(0x18);
delay(5);
char bytes[] = "$X\r\n";
this->SendBytes((uint8_t *)bytes, 4);
}
void GRBL::SetMotor(int x, int y, int z, int speed) {
char code[256];
memset(code,0,sizeof(char)*256);
sprintf(code,"G1 X%dY%dZ%d F%d",x,y,z,speed);
return this->Gcode(code);
}
void GRBL::SetMode(String mode){
if(mode == "distance"){
char bytes[] = "G91\n";
this->SendBytes((uint8_t *)bytes, 4);
this->mode = mode;
}else if(mode == "absolute"){
char bytes[] = "G90\n";
this->SendBytes((uint8_t *)bytes, 4);
this->mode = mode;
}
}
void GRBL::WaitIdle(){
this->ReadClean();
while(1){
this->SendByte('@');
char state;
Wire.requestFrom(addr, 1);
if (Wire.available() > 0) {
state = Wire.read();
}
if(state == 'I'){
break;
}
delay(5);
}
}
//read grbl return message
String GRBL::ReadLine() {
String Data = "";
while(1){
uint8_t i = 0;
char data[10];
Wire.requestFrom(addr, 10);
while (Wire.available() > 0) {
data[i] = Wire.read();
i++;
}
Data += data;
if (data[9] == 0xff) {
break;
}
}
return Data;
}
String GRBL::ReadStatus() {
this->ReadClean();
this->SendByte('@');
return this->ReadLine();
}
// read grbl state
bool GRBL::ReadIdle() {
return this->ReadStatus()[0] == 'I';
}
bool GRBL::InLock() {
return this->ReadStatus()[0] == 'A';
}
-26
View File
@@ -1,26 +0,0 @@
#include <M5Stack.h>
class GRBL
{
private:
void SendByte(byte b);
void SendBytes(uint8_t *data, size_t size);
public:
GRBL(int addr=0x70);
void Init();
void Init(uint32_t x_step, uint32_t y_step,uint32_t z_step,uint32_t acc);
int addr;
String mode;
void Gcode(char *c);
void UnLock();
void ReadClean();
void WaitIdle();
void SetMotor(int x=0, int y=0, int z=0, int speed=300);
void SetMode(String mode);
String ReadLine();
String ReadStatus();
bool ReadIdle();
bool InLock();
};
@@ -0,0 +1,66 @@
/*
Description: GRBL 13.2 Module TEST Example.Stack two Module at the same time.
*/
#include <M5Stack.h>
#include "MODULE_GRBL13.2.h"
/*
* The I2C address of GRBL 13.2 Module is 0x70 by default.
* You could use the DIP Switch for modify I2C address to 0x71
*/
#define STEPMOTOR_I2C_ADDR_1 0x70
#define STEPMOTOR_I2C_ADDR_2 0x71
GRBL _GRBL_A = GRBL(STEPMOTOR_I2C_ADDR_1);
GRBL _GRBL_B = GRBL(STEPMOTOR_I2C_ADDR_2);
void setup() {
// put your setup code here, to run once:
M5.begin();
M5.Power.begin();
_GRBL_A.Init();
_GRBL_B.Init();
Serial.begin(115200);
m5.Lcd.setTextColor(WHITE, BLACK);
m5.Lcd.setTextSize(3);
m5.lcd.setBrightness(100);
M5.Lcd.setCursor(80, 40);
M5.Lcd.println("GRBL 13.2");
M5.Lcd.setCursor(50, 80);
M5.Lcd.println("Press Btn A/B");
M5.Lcd.setCursor(50, 120);
M5.Lcd.println("Control Motor");
_GRBL_A.setMode("absolute");
_GRBL_B.setMode("absolute");
}
void loop() {
/*
If Button A was pressed,
stepmotor will rotate back and forth at a time
*/
if (M5.BtnA.wasPressed()) // A button
{
Serial.print(_GRBL_A.readStatus());
_GRBL_A.setMotor(5,5,5,200);
_GRBL_B.setMotor(5,5,5,200);
_GRBL_A.setMotor(0,0,0,200);
_GRBL_B.setMotor(0,0,0,200);
}
if (M5.BtnB.wasPressed())
{
//USE Gcode
_GRBL_A.sendGcode("G1 X5Y5Z5 F200");
_GRBL_B.sendGcode("G1 X5Y5Z5 F200");
_GRBL_A.sendGcode("G1 X0Y0Z0 F200");
_GRBL_B.sendGcode("G1 X0Y0Z0 F200");
}
if (M5.BtnC.wasReleased()) {
_GRBL_A.unLock();
_GRBL_B.unLock();
}
M5.update();
}
@@ -2,7 +2,7 @@
Description: GRBL 13.2 Module TEST Example.
*/
#include <M5Stack.h>
#include "GrblControl.h"
#include "MODULE_GRBL13.2.h"
/*
* The I2C address of GRBL 13.2 Module is 0x70 by default.
@@ -29,7 +29,7 @@ void setup() {
M5.Lcd.println("Press Btn A/B");
M5.Lcd.setCursor(50, 120);
M5.Lcd.println("Control Motor");
_GRBL.SetMode("absolute");
_GRBL.setMode("absolute");
}
void loop() {
@@ -39,20 +39,20 @@ void loop() {
*/
if (M5.BtnA.wasPressed()) // A button
{
Serial.print(_GRBL.ReadStatus());
_GRBL.SetMotor(5,5,5,200);
_GRBL.SetMotor(0,0,0,200);
Serial.print(_GRBL.readStatus());
_GRBL.setMotor(5,5,5,200);
_GRBL.setMotor(0,0,0,200);
}
if (M5.BtnB.wasPressed())
{
//USE Gcode
_GRBL.Gcode("G1 X5Y5Z5 F200");
_GRBL.Gcode("G1 X0Y0Z0 F200");
_GRBL.sendGcode("G1 X5Y5Z5 F200");
_GRBL.sendGcode("G1 X0Y0Z0 F200");
}
if (M5.BtnC.wasReleased()) {
_GRBL.UnLock();
_GRBL.unLock();
}
M5.update();
}
+62 -61
View File
@@ -1,8 +1,10 @@
/*
Description: Control 4 relays and demonstrate the asynchronous control relay LED
lib: https://github.com/m5stack/UNIT_4RELAY
*/
#include <M5Stack.h>
#include "UNIT_4RELAY.h"
/*-----------------------------------------------------------------------------*/
// |RELAY control reg | 0x10
@@ -19,39 +21,7 @@
//
/*-------------------------------------------------------------------------------*/
void WriteRelayReg( int regAddr, int data )
{
Wire.beginTransmission(0x26);
Wire.write(regAddr);
Wire.write(data);
Wire.endTransmission();
Serial.printf("[ W ] %02X : %02X. \r\n", regAddr, data);
}
int readRelayReg(int regAddr)
{
Wire.beginTransmission(0x26);
Wire.write(regAddr);
Wire.endTransmission();
Wire.requestFrom(0x26, 1);
int data = Wire.read() & 0x00ff;
Serial.printf("[ R ] %02X : %02X. \r\n", regAddr, data);
return data;
}
void WriteRelayNumber( int number, int state )
{
int StateFromDevice = readRelayReg(0x11);
if( state == 0 )
{
StateFromDevice &= ~( 0x01 << number );
}
else
{
StateFromDevice |= ( 0x01 << number );
}
WriteRelayReg(0x11,StateFromDevice);
}
UNIT_4RELAY unit_4relay;
void setup() {
// put your setup code here, to run once:
@@ -69,53 +39,84 @@ void setup() {
M5.Lcd.print("Relay State: ");
M5.Lcd.setCursor(20, 80, 4);
M5.Lcd.print("Sync Mode: ");
readRelayReg(0x10);
readRelayReg(0x11);
WriteRelayReg(0x10,1);
WriteRelayReg(0x11,0);
//WriteRelayNumber(0,0);
/*
* MODE:
* Async == 0;
* Sync == 1;
*/
unit_4relay.Init(0);
}
int count_i = 0;
bool flag_led, flag_relay = false;
uint8_t count_i = 0;
bool state = 0;
bool flag_mode = 0, flag_all= false;
void loop() {
if(M5.BtnA.wasPressed()){
M5.Lcd.fillRect(160, 50, 100, 20, TFT_BLACK);
M5.Lcd.setCursor(160, 50, 4);
M5.Lcd.printf("%d ON", count_i);
WriteRelayReg(0x11,(0x01 << count_i));
if((count_i<4)&&(flag_mode == 1))
{
M5.Lcd.printf("%d ON", count_i);
unit_4relay.relayWrite(count_i,1);
}
else if((count_i>=4)&&(flag_mode == 1))
{
M5.Lcd.printf("%d OFF", (count_i-4));
unit_4relay.relayWrite((count_i-4),0);
}
else if((count_i<4)&&(flag_mode == 0))
{
M5.Lcd.printf("%d ON", count_i);
unit_4relay.LEDWrite(count_i,1);
}
else if((count_i>=4)&&(flag_mode == 0))
{
M5.Lcd.printf("%d OFF", (count_i-4));
unit_4relay.LEDWrite((count_i-4),0);
}
count_i++;
if( count_i >= 4 ) count_i = 0;
if( count_i >= 8 ) count_i = 0;
}
if(M5.BtnB.wasPressed()){
flag_mode = !flag_mode;
M5.Lcd.fillRect(160, 80, 100, 20, TFT_BLACK);
if(!flag_led){
if(!flag_mode){
M5.Lcd.setCursor(160, 80, 4);
M5.Lcd.print("Async");
WriteRelayReg(0x10, 0);
}else {
M5.Lcd.setCursor(160, 80, 4);
M5.Lcd.print("Sync");
WriteRelayReg(0x10, 1);
}
flag_led = !flag_led;
unit_4relay.switchMode(flag_mode);
}
if(M5.BtnC.wasPressed()){
M5.Lcd.fillRect(160, 50, 100, 20, TFT_BLACK);
for(int i=0; i<4; i++){
if(!flag_relay) {
M5.Lcd.setCursor(160, 50, 4);
M5.Lcd.print("ON");
WriteRelayNumber(i, 1);
}else {
M5.Lcd.setCursor(160, 50, 4);
M5.Lcd.print("OFF");
WriteRelayNumber(i, 0);
M5.Lcd.fillRect(160, 50, 100, 20, TFT_BLACK);
M5.Lcd.setCursor(160, 50, 4);
if(flag_mode == 1){
if(flag_all){
M5.Lcd.printf("ALL.ON ");
unit_4relay.relayALL(1);
}
}
flag_relay = !flag_relay;
else{
M5.Lcd.printf("ALL.OFF");
unit_4relay.relayALL(0);
}
}
else{
if(flag_all){
M5.Lcd.printf("ALL.ON ");
unit_4relay.LED_ALL(1);
}
else{
M5.Lcd.printf("ALL.OFF");
unit_4relay.LED_ALL(0);
}
}
flag_all = !flag_all;
}
M5.update();
}
}
@@ -0,0 +1,43 @@
/*
Description: Use ENV III Unit to read temperature, humidity, atmospheric pressure, and display the data on the screen.
Please install library before compiling:
UNIT_ENV: https://github.com/m5stack/UNIT_ENV
*/
#include <M5Stack.h>
#include <Wire.h>
#include "Adafruit_Sensor.h"
#include <Adafruit_BMP280.h>
#include "UNIT_ENV.h"
SHT3X sht30;
QMP6988 qmp6988;
float tmp = 0.0;
float hum = 0.0;
float pressure = 0.0;
void setup() {
M5.begin();
M5.Power.begin();
Wire.begin();
M5.Lcd.setBrightness(10);
M5.Lcd.setTextSize(3);
qmp6988.init();
M5.Lcd.clear(BLACK);
}
void loop() {
pressure = qmp6988.calcPressure();
if(sht30.get()==0){
tmp = sht30.cTemp;
hum = sht30.humidity;
}
Serial.printf("Temperatura: %2.2f*C Humedad: %0.2f%% Pressure: %0.2fPa\r\n", tmp, hum, pressure);
M5.Lcd.setCursor(0, 0);
M5.Lcd.setTextColor(WHITE, BLACK);
M5.Lcd.printf("Temp: %2.1f \r\nHumi: %2.0f%% \r\nPressure:%2.0fPa\r\n", tmp, hum, pressure);
delay(100);
}
@@ -1,156 +0,0 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software< /span>
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Update by K. Townsend (Adafruit Industries) for lighter typedefs, and
* extended sensor support to include color, voltage and current */
#ifndef _ADAFRUIT_SENSOR_H
#define _ADAFRUIT_SENSOR_H
#ifndef ARDUINO
#include <stdint.h>
#elif ARDUINO >= 100
#include "Arduino.h"
#include "Print.h"
#else
#include "WProgram.h"
#endif
/* Intentionally modeled after sensors.h in the Android API:
* https://github.com/android/platform_hardware_libhardware/blob/master/include/hardware/sensors.h */
/* Constants */
#define SENSORS_GRAVITY_EARTH (9.80665F) /**< Earth's gravity in m/s^2 */
#define SENSORS_GRAVITY_MOON (1.6F) /**< The moon's gravity in m/s^2 */
#define SENSORS_GRAVITY_SUN (275.0F) /**< The sun's gravity in m/s^2 */
#define SENSORS_GRAVITY_STANDARD (SENSORS_GRAVITY_EARTH)
#define SENSORS_MAGFIELD_EARTH_MAX (60.0F) /**< Maximum magnetic field on Earth's surface */
#define SENSORS_MAGFIELD_EARTH_MIN (30.0F) /**< Minimum magnetic field on Earth's surface */
#define SENSORS_PRESSURE_SEALEVELHPA (1013.25F) /**< Average sea level pressure is 1013.25 hPa */
#define SENSORS_DPS_TO_RADS (0.017453293F) /**< Degrees/s to rad/s multiplier */
#define SENSORS_GAUSS_TO_MICROTESLA (100) /**< Gauss to micro-Tesla multiplier */
/** Sensor types */
typedef enum
{
SENSOR_TYPE_ACCELEROMETER = (1), /**< Gravity + linear acceleration */
SENSOR_TYPE_MAGNETIC_FIELD = (2),
SENSOR_TYPE_ORIENTATION = (3),
SENSOR_TYPE_GYROSCOPE = (4),
SENSOR_TYPE_LIGHT = (5),
SENSOR_TYPE_PRESSURE = (6),
SENSOR_TYPE_PROXIMITY = (8),
SENSOR_TYPE_GRAVITY = (9),
SENSOR_TYPE_LINEAR_ACCELERATION = (10), /**< Acceleration not including gravity */
SENSOR_TYPE_ROTATION_VECTOR = (11),
SENSOR_TYPE_RELATIVE_HUMIDITY = (12),
SENSOR_TYPE_AMBIENT_TEMPERATURE = (13),
SENSOR_TYPE_VOLTAGE = (15),
SENSOR_TYPE_CURRENT = (16),
SENSOR_TYPE_COLOR = (17)
} sensors_type_t;
/** struct sensors_vec_s is used to return a vector in a common format. */
typedef struct {
union {
float v[3];
struct {
float x;
float y;
float z;
};
/* Orientation sensors */
struct {
float roll; /**< Rotation around the longitudinal axis (the plane body, 'X axis'). Roll is positive and increasing when moving downward. -90°<=roll<=90° */
float pitch; /**< Rotation around the lateral axis (the wing span, 'Y axis'). Pitch is positive and increasing when moving upwards. -180°<=pitch<=180°) */
float heading; /**< Angle between the longitudinal axis (the plane body) and magnetic north, measured clockwise when viewing from the top of the device. 0-359° */
};
};
int8_t status;
uint8_t reserved[3];
} sensors_vec_t;
/** struct sensors_color_s is used to return color data in a common format. */
typedef struct {
union {
float c[3];
/* RGB color space */
struct {
float r; /**< Red component */
float g; /**< Green component */
float b; /**< Blue component */
};
};
uint32_t rgba; /**< 24-bit RGBA value */
} sensors_color_t;
/* Sensor event (36 bytes) */
/** struct sensor_event_s is used to provide a single sensor event in a common format. */
typedef struct
{
int32_t version; /**< must be sizeof(struct sensors_event_t) */
int32_t sensor_id; /**< unique sensor identifier */
int32_t type; /**< sensor type */
int32_t reserved0; /**< reserved */
int32_t timestamp; /**< time is in milliseconds */
union
{
float data[4];
sensors_vec_t acceleration; /**< acceleration values are in meter per second per second (m/s^2) */
sensors_vec_t magnetic; /**< magnetic vector values are in micro-Tesla (uT) */
sensors_vec_t orientation; /**< orientation values are in degrees */
sensors_vec_t gyro; /**< gyroscope values are in rad/s */
float temperature; /**< temperature is in degrees centigrade (Celsius) */
float distance; /**< distance in centimeters */
float light; /**< light in SI lux units */
float pressure; /**< pressure in hectopascal (hPa) */
float relative_humidity; /**< relative humidity in percent */
float current; /**< current in milliamps (mA) */
float voltage; /**< voltage in volts (V) */
sensors_color_t color; /**< color in RGB component values */
};
} sensors_event_t;
/* Sensor details (40 bytes) */
/** struct sensor_s is used to describe basic information about a specific sensor. */
typedef struct
{
char name[12]; /**< sensor name */
int32_t version; /**< version of the hardware + driver */
int32_t sensor_id; /**< unique sensor identifier */
int32_t type; /**< this sensor's type (ex. SENSOR_TYPE_LIGHT) */
float max_value; /**< maximum value of this sensor's value in SI units */
float min_value; /**< minimum value of this sensor's value in SI units */
float resolution; /**< smallest difference between two values reported by this sensor */
int32_t min_delay; /**< min delay in microseconds between events. zero = not a constant rate */
} sensor_t;
class Adafruit_Sensor {
public:
// Constructor(s)
Adafruit_Sensor() {}
virtual ~Adafruit_Sensor() {}
// These must be defined by the subclass
virtual void enableAutoRange(bool enabled) { (void)enabled; /* suppress unused warning */ };
virtual bool getEvent(sensors_event_t*) = 0;
virtual void getSensor(sensor_t*) = 0;
private:
bool _autoRange;
};
#endif
@@ -7,7 +7,7 @@
#include <Wire.h>
#include "Adafruit_Sensor.h"
#include <Adafruit_BMP280.h>
#include "SHT3X.h"
#include "UNIT_ENV.h"
SHT3X sht30;
Adafruit_BMP280 bme;
@@ -1,49 +0,0 @@
#include "SHT3X.h"
/* Motor()
*/
SHT3X::SHT3X(uint8_t address)
{
Wire.begin();
_address=address;
}
byte SHT3X::get()
{
unsigned int data[6];
// Start I2C Transmission
Wire.beginTransmission(_address);
// Send measurement command
Wire.write(0x2C);
Wire.write(0x06);
// Stop I2C transmission
if (Wire.endTransmission()!=0)
return 1;
delay(500);
// Request 6 bytes of data
Wire.requestFrom(_address, 6);
// Read 6 bytes of data
// cTemp msb, cTemp lsb, cTemp crc, humidity msb, humidity lsb, humidity crc
for (int i=0;i<6;i++) {
data[i]=Wire.read();
};
delay(50);
if (Wire.available()!=0)
return 2;
// Convert the data
cTemp = ((((data[0] * 256.0) + data[1]) * 175) / 65535.0) - 45;
fTemp = (cTemp * 1.8) + 32;
humidity = ((((data[3] * 256.0) + data[4]) * 100) / 65535.0);
return 0;
}
-27
View File
@@ -1,27 +0,0 @@
#ifndef __SHT3X_H
#define __HT3X_H
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include "Wire.h"
class SHT3X{
public:
SHT3X(uint8_t address=0x44);
byte get(void);
float cTemp=0;
float fTemp=0;
float humidity=0;
private:
uint8_t _address;
};
#endif
@@ -1,156 +0,0 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software< /span>
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Update by K. Townsend (Adafruit Industries) for lighter typedefs, and
* extended sensor support to include color, voltage and current */
#ifndef _ADAFRUIT_SENSOR_H
#define _ADAFRUIT_SENSOR_H
#ifndef ARDUINO
#include <stdint.h>
#elif ARDUINO >= 100
#include "Arduino.h"
#include "Print.h"
#else
#include "WProgram.h"
#endif
/* Intentionally modeled after sensors.h in the Android API:
* https://github.com/android/platform_hardware_libhardware/blob/master/include/hardware/sensors.h */
/* Constants */
#define SENSORS_GRAVITY_EARTH (9.80665F) /**< Earth's gravity in m/s^2 */
#define SENSORS_GRAVITY_MOON (1.6F) /**< The moon's gravity in m/s^2 */
#define SENSORS_GRAVITY_SUN (275.0F) /**< The sun's gravity in m/s^2 */
#define SENSORS_GRAVITY_STANDARD (SENSORS_GRAVITY_EARTH)
#define SENSORS_MAGFIELD_EARTH_MAX (60.0F) /**< Maximum magnetic field on Earth's surface */
#define SENSORS_MAGFIELD_EARTH_MIN (30.0F) /**< Minimum magnetic field on Earth's surface */
#define SENSORS_PRESSURE_SEALEVELHPA (1013.25F) /**< Average sea level pressure is 1013.25 hPa */
#define SENSORS_DPS_TO_RADS (0.017453293F) /**< Degrees/s to rad/s multiplier */
#define SENSORS_GAUSS_TO_MICROTESLA (100) /**< Gauss to micro-Tesla multiplier */
/** Sensor types */
typedef enum
{
SENSOR_TYPE_ACCELEROMETER = (1), /**< Gravity + linear acceleration */
SENSOR_TYPE_MAGNETIC_FIELD = (2),
SENSOR_TYPE_ORIENTATION = (3),
SENSOR_TYPE_GYROSCOPE = (4),
SENSOR_TYPE_LIGHT = (5),
SENSOR_TYPE_PRESSURE = (6),
SENSOR_TYPE_PROXIMITY = (8),
SENSOR_TYPE_GRAVITY = (9),
SENSOR_TYPE_LINEAR_ACCELERATION = (10), /**< Acceleration not including gravity */
SENSOR_TYPE_ROTATION_VECTOR = (11),
SENSOR_TYPE_RELATIVE_HUMIDITY = (12),
SENSOR_TYPE_AMBIENT_TEMPERATURE = (13),
SENSOR_TYPE_VOLTAGE = (15),
SENSOR_TYPE_CURRENT = (16),
SENSOR_TYPE_COLOR = (17)
} sensors_type_t;
/** struct sensors_vec_s is used to return a vector in a common format. */
typedef struct {
union {
float v[3];
struct {
float x;
float y;
float z;
};
/* Orientation sensors */
struct {
float roll; /**< Rotation around the longitudinal axis (the plane body, 'X axis'). Roll is positive and increasing when moving downward. -90°<=roll<=90° */
float pitch; /**< Rotation around the lateral axis (the wing span, 'Y axis'). Pitch is positive and increasing when moving upwards. -180°<=pitch<=180°) */
float heading; /**< Angle between the longitudinal axis (the plane body) and magnetic north, measured clockwise when viewing from the top of the device. 0-359° */
};
};
int8_t status;
uint8_t reserved[3];
} sensors_vec_t;
/** struct sensors_color_s is used to return color data in a common format. */
typedef struct {
union {
float c[3];
/* RGB color space */
struct {
float r; /**< Red component */
float g; /**< Green component */
float b; /**< Blue component */
};
};
uint32_t rgba; /**< 24-bit RGBA value */
} sensors_color_t;
/* Sensor event (36 bytes) */
/** struct sensor_event_s is used to provide a single sensor event in a common format. */
typedef struct
{
int32_t version; /**< must be sizeof(struct sensors_event_t) */
int32_t sensor_id; /**< unique sensor identifier */
int32_t type; /**< sensor type */
int32_t reserved0; /**< reserved */
int32_t timestamp; /**< time is in milliseconds */
union
{
float data[4];
sensors_vec_t acceleration; /**< acceleration values are in meter per second per second (m/s^2) */
sensors_vec_t magnetic; /**< magnetic vector values are in micro-Tesla (uT) */
sensors_vec_t orientation; /**< orientation values are in degrees */
sensors_vec_t gyro; /**< gyroscope values are in rad/s */
float temperature; /**< temperature is in degrees centigrade (Celsius) */
float distance; /**< distance in centimeters */
float light; /**< light in SI lux units */
float pressure; /**< pressure in hectopascal (hPa) */
float relative_humidity; /**< relative humidity in percent */
float current; /**< current in milliamps (mA) */
float voltage; /**< voltage in volts (V) */
sensors_color_t color; /**< color in RGB component values */
};
} sensors_event_t;
/* Sensor details (40 bytes) */
/** struct sensor_s is used to describe basic information about a specific sensor. */
typedef struct
{
char name[12]; /**< sensor name */
int32_t version; /**< version of the hardware + driver */
int32_t sensor_id; /**< unique sensor identifier */
int32_t type; /**< this sensor's type (ex. SENSOR_TYPE_LIGHT) */
float max_value; /**< maximum value of this sensor's value in SI units */
float min_value; /**< minimum value of this sensor's value in SI units */
float resolution; /**< smallest difference between two values reported by this sensor */
int32_t min_delay; /**< min delay in microseconds between events. zero = not a constant rate */
} sensor_t;
class Adafruit_Sensor {
public:
// Constructor(s)
Adafruit_Sensor() {}
virtual ~Adafruit_Sensor() {}
// These must be defined by the subclass
virtual void enableAutoRange(bool enabled) { (void)enabled; /* suppress unused warning */ };
virtual bool getEvent(sensors_event_t*) = 0;
virtual void getSensor(sensor_t*) = 0;
private:
bool _autoRange;
};
#endif
-60
View File
@@ -1,60 +0,0 @@
/*
DHT12.cpp - Library for DHT12 sensor.
v0.0.1 Beta
Created by Bobadas, July 30,2016.
Released into the public domain.
*/
#include "DHT12.h"
DHT12::DHT12(uint8_t scale,uint8_t id)
{
if (id==0 || id>126) _id=0x5c;
else _id=id;
if (scale==0 || scale>3) _scale=CELSIUS;
else _scale=scale;
}
uint8_t DHT12::read()
{
Wire.beginTransmission(_id);
Wire.write(0);
if (Wire.endTransmission()!=0) return 1;
Wire.requestFrom(_id, (uint8_t)5);
for (int i=0;i<5;i++) {
datos[i]=Wire.read();
};
delay(50);
if (Wire.available()!=0) return 2;
if (datos[4]!=(datos[0]+datos[1]+datos[2]+datos[3])) return 3;
return 0;
}
float DHT12::readTemperature(uint8_t scale)
{
float resultado=0;
uint8_t error=read();
if (error!=0) return (float)error/100;
if (scale==0) scale=_scale;
switch(scale) {
case CELSIUS:
resultado=(datos[2]+(float)datos[3]/10);
break;
case FAHRENHEIT:
resultado=((datos[2]+(float)datos[3]/10)*1.8+32);
break;
case KELVIN:
resultado=(datos[2]+(float)datos[3]/10)+273.15;
break;
};
return resultado;
}
float DHT12::readHumidity()
{
float resultado;
uint8_t error=read();
if (error!=0) return (float)error/100;
resultado=(datos[0]+(float)datos[1]/10);
return resultado;
}
-29
View File
@@ -1,29 +0,0 @@
/*
DHT12.h - Library for DHT12 sensor.
v0.0.1 Beta
Created by Bobadas, July 30,2016.
Released into the public domain.
*/
#ifndef DHT12_h
#define DHT12_h
#include "Arduino.h"
#include "Wire.h"
#define CELSIUS 1
#define KELVIN 2
#define FAHRENHEIT 3
class DHT12
{
public:
DHT12(uint8_t scale=0,uint8_t id=0);
float readTemperature(uint8_t scale=0);
float readHumidity();
private:
uint8_t read();
uint8_t datos[5];
uint8_t _id;
uint8_t _scale;
};
#endif
@@ -5,10 +5,10 @@
*/
#include <M5Stack.h>
#include "DHT12.h"
#include <Wire.h> //The DHT12 uses I2C comunication.
#include "Adafruit_Sensor.h"
#include <Adafruit_BMP280.h>
#include "UNIT_ENV.h"
DHT12 dht12; //Preset scale CELSIUS and ID 0x5c.
Adafruit_BMP280 bme;
@@ -0,0 +1,41 @@
#include <M5UnitLCD.h>
M5UnitLCD display;
M5Canvas canvas(&display);
static constexpr char text[] = "Hello world ! こんにちは世界! this is long long string sample. 寿限無、寿限無、五劫の擦り切れ、海砂利水魚の、水行末・雲来末・風来末、喰う寝る処に住む処、藪ら柑子の藪柑子、パイポ・パイポ・パイポのシューリンガン、シューリンガンのグーリンダイ、グーリンダイのポンポコピーのポンポコナの、長久命の長助";
static constexpr size_t textlen = sizeof(text) / sizeof(text[0]);
int textpos = 0;
int scrollstep = 2;
void setup(void)
{
display.init();
display.setRotation(2);
canvas.setColorDepth(1); // mono color
canvas.setFont(&fonts::lgfxJapanMinchoP_32);
canvas.setTextWrap(false);
canvas.setTextSize(2);
canvas.createSprite(display.width() + 64, 72);
}
void loop(void)
{
int32_t cursor_x = canvas.getCursorX() - scrollstep;
if (cursor_x <= 0)
{
textpos = 0;
cursor_x = display.width();
}
canvas.setCursor(cursor_x, 0);
canvas.scroll(-scrollstep, 0);
while (textpos < textlen && cursor_x <= display.width())
{
canvas.print(text[textpos++]);
cursor_x = canvas.getCursorX();
}
display.waitDisplay();
canvas.pushSprite(&display, 0, (display.height() - canvas.height()) >> 1);
}
+41
View File
@@ -0,0 +1,41 @@
#include <M5UnitOLED.h>
M5UnitOLED display;
M5Canvas canvas(&display);
static constexpr char text[] = "Hello world ! こんにちは世界! this is long long string sample. 寿限無、寿限無、五劫の擦り切れ、海砂利水魚の、水行末・雲来末・風来末、喰う寝る処に住む処、藪ら柑子の藪柑子、パイポ・パイポ・パイポのシューリンガン、シューリンガンのグーリンダイ、グーリンダイのポンポコピーのポンポコナの、長久命の長助";
static constexpr size_t textlen = sizeof(text) / sizeof(text[0]);
int textpos = 0;
int scrollstep = 2;
void setup(void)
{
display.init();
display.setRotation(2);
canvas.setColorDepth(1); // mono color
canvas.setFont(&fonts::lgfxJapanMinchoP_32);
canvas.setTextWrap(false);
canvas.setTextSize(2);
canvas.createSprite(display.width() + 64, 72);
}
void loop(void)
{
int32_t cursor_x = canvas.getCursorX() - scrollstep;
if (cursor_x <= 0)
{
textpos = 0;
cursor_x = display.width();
}
canvas.setCursor(cursor_x, 0);
canvas.scroll(-scrollstep, 0);
while (textpos < textlen && cursor_x <= display.width())
{
canvas.print(text[textpos++]);
cursor_x = canvas.getCursorX();
}
display.waitDisplay();
canvas.pushSprite(&display, 0, (display.height() - canvas.height()) >> 1);
}
@@ -33,7 +33,7 @@ String UHF_RFID::Query_hardware_version()
String UHF_RFID::Query_software_version()
{
Sendcommand(1);
Delay(20);
Delay(50);
Readcallback();
if (DelayScanwarning())
@@ -43,7 +43,7 @@ String UHF_RFID::Query_software_version()
else
{
Return_to_convert(0);
Serial.print(DATA_Str_M5led);
return DATA_Str_M5led.substring(6, 12);
}
}
@@ -1308,7 +1308,7 @@ String UHF_RFID::Sets_to_transmit_a_continuous_carrier(UWORD Parameter)
混频器增益 Mixer_G: 0x03(混频器 Mixer 增益为 9dB)
中频放大器增益 IF_G: 0x06(中频放大器 IF AMP 增益为 36dB)
信号解调阈值 Thrd: 0x01B0(信号解调阈值越小能解调的标签返回 RSSI 越低,但越不稳定,
低于一 定值完全不能解调;相反阈值越大能解调的标签返回信号 RSSI 越大,距离越近,越稳定。
低于一定值完全不能解调;相反阈值越大能解调的标签返回信号 RSSI 越大,距离越近,越稳定。
0x01B0 是推荐的 最小值)
混频器 Mixer 增益表 中频放大器 IF AMP 增益表
@@ -159,4 +159,4 @@ size_t TFTTerminal::write(const uint8_t *buffer, size_t size)
}
_dis_buff_ptr->pushSprite(_win_x_pos, _win_y_pos);
return 1;
}
}
@@ -1,6 +1,10 @@
#include <M5Stack.h>
#include "RFID_command.h"
#include "TFTTerminal.h"
TFT_eSprite TerminalBuff = TFT_eSprite(&M5.Lcd);
TFTTerminal terminal(&TerminalBuff);
UHF_RFID RFID;
@@ -18,124 +22,160 @@ void setup()
{
M5.begin();
RFID._debug = 1;
RFID._debug = 0;
Serial2.begin(115200, SERIAL_8N1, 16, 17);//16.17
if (RFID._debug == 1)Serial.begin(115200, SERIAL_8N1, 21, 22);
M5.Lcd.fillRect(0, 0, 340, 280, BLACK);
TerminalBuff.createSprite(280,200);
terminal.setGeometry(20,30,300,200);
terminal.setFontsize(1);
// UHF_RFID set UHF_RFID设置
RFID.Set_transmission_Power(2600);
RFID.Set_the_Select_mode();
RFID.Delay(100);
RFID.Readcallback();
RFID.clean_data();
// Prompted to connect to UHF_RFID 提示连接UHF_RFID
terminal.println("Please connect UHF_RFID to Port C");
// Determined whether to connect to UHF_RFID 判断是否连接UHF_RFID
String soft_version;
soft_version = RFID.Query_software_version();
while(soft_version.indexOf("V2.3.5") == -1)
{
RFID.clean_data();
M5.Lcd.fillCircle(310, 10, 6, RED);
RFID.Delay(150);
M5.Lcd.fillCircle(310, 10, 6, BLACK);
RFID.Delay(150);
soft_version = RFID.Query_software_version();
}
// The prompt will be RFID card close 提示将RFID卡靠近
terminal.println("Please approach the RFID card you need to use");
}
void loop()
{
M5.Lcd.fillCircle(310, 10, 6, GREEN);
RFID.Delay(150);
M5.Lcd.fillCircle(310, 10, 6, BLACK);
RFID.Delay(150);
// breathing light 呼吸灯
M5.Lcd.fillCircle(310, 10, 6, GREEN);
RFID.Delay(150);
M5.Lcd.fillCircle(310, 10, 6, BLACK);
RFID.Delay(150);
// A read/write operation specifies a particular card 读写操作需指定某一张卡
// comd = RFID.Set_the_select_parameter_directive("30751FEB705C5904E3D50D70");
// M5.Lcd.drawString(comd, 0, 0, 2);
// RFID.Delay(1000);
// terminal.println(comd);
// RFID.clean_data();
// M5.Lcd.fillRect(0, 0, 340, 280, BLACK);
//
card = RFID.A_single_poll_of_instructions();
if (card._ERROR.length() != 0)
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Query the card information once 查询一次卡的信息例子
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
card = RFID.A_single_poll_of_instructions();
if (card._ERROR.length() != 0)
{
Serial.print(card._ERROR);
}
else
{
if(card._EPC.length() == 24)
{
Serial.print(card._ERROR);
}
else
{
M5.Lcd.drawString(card._RSSI, 0, 0, 2);
M5.Lcd.drawString(card._PC, 0, 15, 2);
M5.Lcd.drawString(card._EPC, 0, 30, 2);
M5.Lcd.drawString(card._CRC, 0, 45, 2);
}
RFID.Delay(1000);
RFID.clean_data();
M5.Lcd.fillRect(0, 0, 340, 280, BLACK);
//
terminal.println("RSSI :" + card._RSSI);
terminal.println("PC :" + card._PC);
terminal.println("EPC :" + card._EPC);
terminal.println("CRC :" + card._CRC);
terminal.println(" ");
}
}
RFID.clean_data(); //Empty the data after using it 使用完数据后要将数据清空
/*Other feature usage examples 其他功能使用例子*/
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Read multiple RFID cards at once 一次读取多张RFID卡
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
// cards = RFID.Multiple_polling_instructions(6);
// for (size_t i = 0; i < cards.len; i++)
// {
// M5.Lcd.drawString(cards.card[i]._RSSI, 200, 5 + i * 15, 2);
// M5.Lcd.drawString(cards.card[i]._PC, 230, 5 + i * 15, 2);
// M5.Lcd.drawString(cards.card[i]._EPC, 0, 5 + i * 15, 2);
// M5.Lcd.drawString(cards.card[i]._CRC, 280, 5 + i * 15, 2);
// if(cards.card[i]._EPC.length() == 24)
// {
// terminal.println("RSSI :" + cards.card[i]._RSSI);
// terminal.println("PC :" + cards.card[i]._PC);
// terminal.println("EPC :" + cards.card[i]._EPC);
// terminal.println("CRC :" + cards.card[i]._CRC);
// }
// }
// RFID.Delay(1000);
// terminal.println(" ");
// RFID.clean_data();
// M5.Lcd.fillRect(0, 0, 340, 280, BLACK);
//
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Used to get the SELECT parameter 用于获取Select参数
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
// Select = RFID.Get_the_select_parameter();
// M5.Lcd.drawString(Select.Mask, 0, 0, 2);
// M5.Lcd.drawString(Select.SelParam, 0, 15, 2);
// M5.Lcd.drawString(Select.Ptr, 0, 30, 2);
// M5.Lcd.drawString(Select.MaskLen, 0, 45, 2);
// M5.Lcd.drawString(Select.Truncate, 0, 60, 2);
// RFID.Delay(1000);
// RFID.clean_data();
// M5.Lcd.fillRect(0, 0, 340, 280, BLACK);
//
// Cardinformation = RFID.NXP_Change_EAS(0x00000000);
// M5.Lcd.drawString(Cardinformation._UL, 0, 0, 2);
// M5.Lcd.drawString(Cardinformation._PC, 0, 15, 2);
// M5.Lcd.drawString(Cardinformation._EPC, 0, 30, 2);
// M5.Lcd.drawString(Cardinformation._Parameter, 0, 45, 2);
// M5.Lcd.drawString(Cardinformation._ErrorCode, 0, 60, 2);
// M5.Lcd.drawString(Cardinformation._Error, 0, 75, 2);
// M5.Lcd.drawString(Cardinformation._Data, 0, 90, 2);
// M5.Lcd.drawString(Cardinformation._Successful, 0, 105, 2);
// RFID.Delay(1000);
// RFID.clean_data();
// M5.Lcd.fillRect(0, 0, 340, 280, BLACK);
//
// Query = RFID.Get_the_Query_parameter();
// M5.Lcd.drawString(Query.QueryParameter, 0, 0, 2);
// M5.Lcd.drawString(Query.DR, 0, 15, 2);
// M5.Lcd.drawString(Query.M, 0, 30, 2);
// M5.Lcd.drawString(Query.TRext, 0, 45, 2);
// M5.Lcd.drawString(Query.Sel, 0, 60, 2);
// M5.Lcd.drawString(Query.Session, 0, 75, 2);
// M5.Lcd.drawString(Query.Target, 0, 90, 2);
// M5.Lcd.drawString(Query.Q, 0, 105, 2);
// RFID.Delay(1000);
// RFID.clean_data();
// M5.Lcd.fillRect(0, 0, 340, 280, BLACK);
//
//
// Read = RFID.Read_receive_demodulator_parameters();
// M5.Lcd.drawString(Read.Region, 0, 0, 2);
// M5.Lcd.drawString(Read.Channel_Index, 0, 15, 2);
// M5.Lcd.drawString(Read.Pow, 0, 30, 2);
// M5.Lcd.drawString(Read.Mixer_G, 0, 45, 2);
// M5.Lcd.drawString(Read.IF_G, 0, 60, 2);
// M5.Lcd.drawString(Read.Thrd, 0, 75, 2);
// RFID.Delay(1000);
// RFID.clean_data();
// M5.Lcd.fillRect(0, 0, 340, 280, BLACK);
//
// Test = RFID.Test_the_RSSI_input_signal();
// M5.Lcd.drawString(Test.CH_L, 0, 0, 2);
// M5.Lcd.drawString(Test.CH_H, 0, 15, 2);
// for (size_t i = 0; i < 20; i++)
// if(Select.Mask.length() != 0)
// {
// if (i < 10)
// {
// M5.Lcd.drawString(Test.Data[i], i * 20, 30, 2);
// }
// else
// {
// M5.Lcd.drawString(Test.Data[i], (i - 10) * 20, 45, 2);
// }
// terminal.println("Mask :" + Select.Mask);
// terminal.println("SelParam :" + Select.SelParam);
// terminal.println("Ptr :" + Select.Ptr);
// terminal.println("MaskLen :" + Select.MaskLen);
// terminal.println("Truncate :" + Select.Truncate);
// terminal.println(" ");
// }
// RFID.clean_data();
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Used to change the PSF bit of the NXP G2X label 用于改变 NXP G2X 标签的 PSF 位
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
// Cardinformation = RFID.NXP_Change_EAS(0x00000000);
// if(Cardinformation._UL.length() != 0)
// {
// terminal.println("UL :" + Cardinformation._UL);
// terminal.println("PC :" + Cardinformation._PC);
// terminal.println("EPC :" + Cardinformation._EPC);
// terminal.println("Parameter :" + Cardinformation._Parameter);
// terminal.println("ErrorCode :" + Cardinformation._ErrorCode);
// terminal.println("Error :" + Cardinformation._Error);
// terminal.println("Data :" + Cardinformation._Data);
// terminal.println("Successful :" + Cardinformation._Successful);
// terminal.println(" ");
// }
// RFID.clean_data();
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Used to get the Query parameters 用于获取Query参数
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
// Query = RFID.Get_the_Query_parameter();
// if(Query.QueryParameter.length() != 0)
// {
// terminal.println("QueryParameter :" + Query.QueryParameter);
// terminal.println("DR :" + Query.DR);
// terminal.println("M :" + Query.M);
// terminal.println("TRext :" + Query.TRext);
// terminal.println("Sel :" + Query.Sel);
// terminal.println("Session :" + Query.Session);
// terminal.println("Targetta :" + Query.Target);
// terminal.println("Q :" + Query.Q);
// terminal.println(" ");
// }
// RFID.Delay(1000);
// RFID.clean_data();
// M5.Lcd.fillRect(0, 0, 340, 280, BLACK);
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Used to get the Query parameters 用于读取接收解调器参数
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
// Read = RFID.Read_receive_demodulator_parameters();
// if(Read.Mixer_G.length()!= 0)
// {
// terminal.println("Mixer_G :" + Read.Mixer_G);
// terminal.println("IF_G :" + Read.IF_G);
// terminal.println("Thrd :" + Read.Thrd);
// terminal.println(" ");
// }
// RFID.clean_data();
}

Some files were not shown because too many files have changed in this diff Show More