-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modules: Plus, Servo Unit: ADC, DAC, Color, TOF Stick: test
- Loading branch information
Showing
13 changed files
with
858 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <Arduino.h> | ||
#include <M5Stack.h> | ||
|
||
#define IrPin 13 | ||
#define PLUS_ADDR 0x62 | ||
|
||
int32_t number = 0; | ||
uint8_t press = 0; | ||
|
||
|
||
void setup() { | ||
M5.begin(true, false, false); | ||
M5.Lcd.setTextFont(6); | ||
M5.Lcd.clear(BLACK); | ||
M5.Lcd.setTextColor(ORANGE, BLACK); | ||
Wire.begin(); | ||
ledcSetup(1, 38000, 10); | ||
ledcAttachPin(IrPin, 1); | ||
} | ||
|
||
void plus_encode() { | ||
Wire.requestFrom(PLUS_ADDR, 2); | ||
while(Wire.available()) { | ||
int8_t encode = Wire.read(); | ||
uint8_t press_n = Wire.read(); | ||
number += encode; | ||
if(press_n == 0xff) { | ||
press = 0; | ||
} | ||
else { | ||
press = 1; | ||
} | ||
} | ||
} | ||
|
||
void loop() { | ||
char data[20]; | ||
|
||
plus_encode(); | ||
ledcWrite(1, ledcRead(1) ? 0 : 512); | ||
sprintf(data, "%d %d ", number, press); | ||
M5.Lcd.setCursor(100, 100); | ||
M5.Lcd.print(data); | ||
vTaskDelay(200); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <Arduino.h> | ||
#include <M5Stack.h> | ||
#include <Wire.h> | ||
|
||
#define SERVO_ADDR 0x53 | ||
void setup() { | ||
M5.begin(true, false, true); | ||
M5.Lcd.setTextFont(4); | ||
M5.Lcd.setCursor(70, 100); | ||
M5.Lcd.print("Servo Example"); | ||
|
||
Wire.begin(21, 22, 100000); | ||
// put your setup code here, to run once: | ||
} | ||
|
||
// addr 0x01 mean control the number 1 servo by us | ||
void Servo_write_us(uint8_t number, uint16_t us) { | ||
Wire.beginTransmission(SERVO_ADDR); | ||
Wire.write(0x00 | number); | ||
Wire.write(us & 0x00ff); | ||
Wire.write(us >> 8 & 0x00ff); | ||
Wire.endTransmission(); | ||
} | ||
|
||
// addr 0x11 mean control the number 1 servo by angle | ||
void Servo_write_angle(uint8_t number, uint8_t angle) { | ||
Wire.beginTransmission(SERVO_ADDR); | ||
Wire.write(0x10 | number); | ||
Wire.write(angle); | ||
Wire.endTransmission(); | ||
} | ||
|
||
void loop() { | ||
for(uint8_t i = 0; i < 12; i++){ | ||
Servo_write_us(i, 700); | ||
// Servo_write_angle(i, 0); | ||
} | ||
delay(1000); | ||
for(uint8_t i = 0; i < 12; i++){ | ||
Servo_write_us(i, 2300); | ||
// Servo_write_angle(i, 180); | ||
} | ||
delay(1000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
Stick test | ||
hardware: M5Stack Stick | ||
please install the U8g2 library first ... | ||
*/ | ||
|
||
#include <Arduino.h> | ||
#include <U8x8lib.h> | ||
#include <SPI.h> | ||
#include <Wire.h> | ||
|
||
#define LedPin 19 | ||
#define IrPin 17 | ||
#define BuzzerPin 26 | ||
#define BtnPin 35 | ||
|
||
U8X8_SH1107_64X128_4W_HW_SPI u8x8(14, /* dc=*/ 27, /* reset=*/ 33); | ||
bool mpu9250_exis = false; | ||
void mpu9250_test() { | ||
uint8_t data = 0; | ||
Wire.beginTransmission(0x68); | ||
Wire.write(0x75); | ||
Wire.endTransmission(true); | ||
Wire.requestFrom(0x68, 1); | ||
data = Wire.read(); | ||
|
||
Serial.print("mpu9250 addr: "); | ||
Serial.println(data, HEX); | ||
if(data == 0x71) { | ||
mpu9250_exis = true; | ||
} | ||
} | ||
|
||
void setup() { | ||
// put your setup code here, to run once: | ||
Wire.begin(21, 22, 100000); | ||
u8x8.begin(); | ||
Serial.begin(115200); | ||
|
||
pinMode(LedPin, OUTPUT); | ||
pinMode(IrPin, OUTPUT); | ||
pinMode(BuzzerPin, OUTPUT); | ||
pinMode(BtnPin, INPUT_PULLUP); | ||
ledcSetup(1, 38000, 10); | ||
ledcAttachPin(IrPin, 1); | ||
digitalWrite(BuzzerPin, LOW); | ||
u8x8.fillDisplay(); | ||
u8x8.setFont(u8x8_font_chroma48medium8_r); | ||
delay(1500); | ||
u8x8.clearDisplay(); | ||
mpu9250_test(); | ||
} | ||
|
||
void loop() | ||
{ | ||
digitalWrite(LedPin, 1 - digitalRead(LedPin)); | ||
ledcWrite(1, ledcRead(1) ? 0 : 512); | ||
delay(200); | ||
if(digitalRead(BtnPin) == 0){ | ||
u8x8.drawString(2,0,"Hello"); | ||
u8x8.drawString(2,1,"World!"); | ||
if(mpu9250_exis) { | ||
u8x8.drawString(2, 3, "Exis"); | ||
} else{ | ||
u8x8.drawString(3, 3, "No"); | ||
} | ||
for(int i=0;i<100;i++){ | ||
digitalWrite(BuzzerPin,HIGH); | ||
delay(1); | ||
digitalWrite(BuzzerPin,LOW); | ||
delay(1); | ||
} | ||
} else { | ||
u8x8.clearDisplay(); | ||
} | ||
// delay(200); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
hardware: M5Stack unit ADC | ||
connect: PORTA(21, 22) or PORTC(17, 16) | ||
*/ | ||
#include <M5Stack.h> | ||
#include <Wire.h> | ||
#include "ADS1100.h" | ||
|
||
ADS1100 ads; | ||
|
||
void setup(void) | ||
{ | ||
M5.begin(true, false, false); | ||
Serial.begin(115200); | ||
|
||
M5.Lcd.fillScreen(BLACK); | ||
M5.Lcd.setTextColor(ORANGE); | ||
|
||
// The address can be changed making the option of connecting multiple devices | ||
ads.getAddr_ADS1100(ADS1100_DEFAULT_ADDRESS); // 0x48, 1001 000 (ADDR = GND) | ||
|
||
// The ADC gain (PGA), Device operating mode, Data rate | ||
// can be changed via the following functions | ||
|
||
ads.setGain(GAIN_ONE); // 1x gain(default) | ||
// ads.setGain(GAIN_TWO); // 2x gain | ||
// ads.setGain(GAIN_FOUR); // 4x gain | ||
// ads.setGain(GAIN_EIGHT); // 8x gain | ||
|
||
ads.setMode(MODE_CONTIN); // Continuous conversion mode (default) | ||
// ads.setMode(MODE_SINGLE); // Single-conversion mode | ||
|
||
ads.setRate(RATE_8); // 8SPS (default) | ||
// ads.setRate(RATE_16); // 16SPS | ||
// ads.setRate(RATE_32); // 32SPS | ||
// ads.setRate(RATE_128); // 128SPS | ||
|
||
ads.setOSMode(OSMODE_SINGLE); // Set to start a single-conversion | ||
|
||
ads.begin(); | ||
} | ||
|
||
void loop(void) | ||
{ | ||
byte error; | ||
int8_t address; | ||
|
||
address = ads.ads_i2cAddress; | ||
// The i2c_scanner uses the return value of | ||
// the Write.endTransmisstion to see if | ||
// a device did acknowledge to the address. | ||
Wire.beginTransmission(address); | ||
error = Wire.endTransmission(); | ||
if (error == 0) | ||
{ | ||
int16_t result; | ||
|
||
Serial.println("Getting Differential Reading from ADS1100"); | ||
Serial.println(" "); | ||
result = ads.Measure_Differential(); | ||
Serial.print("Digital Value of Analog Input between Channel 0 and 1: "); | ||
Serial.println(result); | ||
M5.Lcd.fillScreen(BLACK); | ||
char data[20] = { 0 }; | ||
sprintf(data, "%d", result); | ||
M5.Lcd.drawCentreString(data, 160, 100, 4); | ||
Serial.println(" "); | ||
Serial.println(" *************************** "); | ||
Serial.println(" "); | ||
} | ||
else | ||
{ | ||
Serial.println("ADS1100 Disconnected!"); | ||
Serial.println(" "); | ||
Serial.println(" ************ "); | ||
Serial.println(" "); | ||
} | ||
|
||
delay(1000); | ||
} |
Oops, something went wrong.