Skip to content

Commit a2c6b5c

Browse files
ChrisMicroEeeeBin
authored andcommitted
updated examples
* speaker off * BlackOut help light added * I2C tester added * M5Stack Fire microphone spectrum ananlyser added * Hall sensor example added
1 parent 9b5f58b commit a2c6b5c

5 files changed

Lines changed: 347 additions & 18 deletions

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/************************************************************************
2+
3+
M5StackFire internal Hall sensor example
4+
5+
The ESP32 MCU has build in Hall sensor.
6+
It is not very suscescible but if you bring a magnet close to the
7+
upper screen you will see the influence on the measurement.
8+
In this example we use some low pass filters to get rid of the noise.
9+
10+
Hardware M5StackFire
11+
Oktober 2018, ChrisMicro
12+
13+
************************************************************************/
14+
#include <M5Stack.h>
15+
16+
#define M5STACKFIRE_SPEAKER_PIN 25 // speaker DAC, only 8 Bit
17+
18+
#define HORIZONTAL_RESOLUTION 320
19+
#define VERTICAL_RESOLUTION 240
20+
#define POSITION_OFFSET_Y 20
21+
#define SIGNAL_LENGTH HORIZONTAL_RESOLUTION
22+
23+
uint16_t oldSignal[SIGNAL_LENGTH];
24+
uint16_t adcBuffer[SIGNAL_LENGTH];
25+
26+
float ESP32_hallRead()
27+
{
28+
float value = 0;
29+
int count = 400;
30+
// mean value filter
31+
for (int n = 0; n < count; n++) value += hallRead();
32+
return value / count * 10;
33+
}
34+
35+
float HallOffset = 0;
36+
37+
void setup()
38+
{
39+
dacWrite(M5STACKFIRE_SPEAKER_PIN, 0); // make sure that the speaker is quite
40+
M5.Lcd.begin();
41+
M5.Lcd.fillScreen( BLACK );
42+
M5.Lcd.fillRect(10, 1, 150, 160, BLACK);
43+
M5.Lcd.setCursor(0, 0);
44+
M5.Lcd.setTextColor(BLUE, BLACK);
45+
M5.Lcd.setTextSize(2);
46+
47+
M5.Lcd.println("ESP32 Hall sensor:");
48+
HallOffset = ESP32_hallRead(); // callibrate the output value to the magnetic field at start up
49+
M5.Lcd.setTextSize(2);
50+
}
51+
52+
float LowPassFilteredValue=0;
53+
void showSignal()
54+
{
55+
int n;
56+
57+
int oldx;
58+
int oldy;
59+
int oldSig;
60+
int x, y;
61+
62+
for (n = 0; n < SIGNAL_LENGTH; n++)
63+
{
64+
x = n;
65+
float value = ESP32_hallRead()- HallOffset;
66+
LowPassFilteredValue+=(value-LowPassFilteredValue)*0.05;
67+
M5.Lcd.setCursor(220, 1);
68+
M5.Lcd.print((int)LowPassFilteredValue);M5.Lcd.print(" ");
69+
70+
y = map(value , -127, 127, VERTICAL_RESOLUTION, POSITION_OFFSET_Y);
71+
72+
if (n > 0)
73+
{
74+
// delete old line element
75+
M5.Lcd.drawLine(oldx , oldSig, x, oldSignal[n], BLACK );
76+
77+
// draw new line element
78+
if (n < SIGNAL_LENGTH - 1) // don't draw last element because it would generate artifacts
79+
{
80+
M5.Lcd.drawLine(oldx, oldy, x, y, GREEN );
81+
}
82+
}
83+
oldx = x;
84+
oldy = y;
85+
oldSig = oldSignal[n];
86+
oldSignal[n] = y;
87+
}
88+
}
89+
90+
void loop(void)
91+
{
92+
showSignal();
93+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/************************************************************************
2+
3+
M5StackFire I2C Scanner
4+
5+
The M5StackFire has a connector for I2C devices.
6+
This program scans the addresses 1-127 continuosly and shows
7+
the devices found on the TFT.
8+
9+
The M5Stack fire has two internal I2C devices at address 0x68 and 0x75.
10+
11+
If they do not appear on the TFT it could mean you made a short cut on
12+
the I2C bus.
13+
14+
October 2018, ChrisMicro
15+
16+
************************************************************************/
17+
#include <M5Stack.h>
18+
19+
void setup()
20+
{
21+
M5.Lcd.begin();
22+
M5.Lcd.fillScreen( BLACK );
23+
M5.Lcd.setCursor(0, 0);
24+
M5.Lcd.setTextColor(YELLOW);
25+
M5.Lcd.setTextSize(2);
26+
27+
M5.Lcd.fillScreen( BLACK );
28+
M5.Lcd.setCursor(0, 0);
29+
M5.Lcd.println("M5StackFire I2C Tester");
30+
31+
Wire.begin();
32+
33+
delay(3000);
34+
M5.Lcd.fillScreen( BLACK );
35+
}
36+
37+
int textColor=YELLOW;
38+
39+
void loop()
40+
{
41+
int address;
42+
int error;
43+
M5.Lcd.setCursor(0, 0);
44+
M5.Lcd.println("scanning Address [HEX]");
45+
46+
for(address = 1; address < 127; address++ )
47+
{
48+
Wire.beginTransmission(address);
49+
error = Wire.endTransmission();
50+
if(error==0)
51+
{
52+
M5.Lcd.print(address,HEX);M5.Lcd.print(" ");
53+
}
54+
else M5.Lcd.print(".");
55+
56+
delay(10);
57+
}
58+
59+
if(textColor==YELLOW) textColor=GREEN;
60+
else textColor=YELLOW;
61+
M5.Lcd.setTextColor(textColor,BLACK);
62+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/************************************************************************
2+
3+
M5StackFire BlackOut Help
4+
5+
Here in this region we have a BlackOut.
6+
7+
Fortunatelly I have the M5StackFire with a little spare energie in its
8+
batttery. With this I can illumnate my room ...
9+
10+
4.October 2018, ChrisMicro, Swizerland, close to Zürich
11+
12+
************************************************************************/
13+
#include <M5Stack.h>
14+
15+
#define USENEOLED
16+
17+
#ifdef USENEOLED
18+
#include <Adafruit_NeoPixel.h>
19+
20+
#define M5STACK_FIRE_NEO_NUM_LEDS 10
21+
#define M5STACK_FIRE_NEO_DATA_PIN 15
22+
23+
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(M5STACK_FIRE_NEO_NUM_LEDS, M5STACK_FIRE_NEO_DATA_PIN, NEO_GRB + NEO_KHZ800);
24+
#endif
25+
26+
void setup()
27+
{
28+
M5.Lcd.begin();
29+
M5.Lcd.fillScreen( WHITE );
30+
31+
#ifdef USENEOLED
32+
pixels.begin();
33+
int r=255;
34+
int g=255;
35+
int b=255;
36+
for(int n=0;n<10;n++)pixels.setPixelColor(n, pixels.Color(r, g, b));
37+
pixels.show();
38+
#endif
39+
}
40+
41+
void loop(void)
42+
{
43+
}

examples/Fire/M5StackFire_MicrophoneSignalTFT/M5StackFire_MicrophoneSignalTFT.ino

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/************************************************************************
22
3-
M5StackFire Discovery simple oscilloscope example
3+
M5StackFire simple oscilloscope example
44
55
The oscilloscope has a auto trigger function to achive a stable
66
visual impression when a repeating signal like a sine wave is applied.
@@ -14,10 +14,11 @@
1414
#include <M5Stack.h>
1515

1616
#define M5STACKFIRE_MICROPHONE_PIN 34
17+
#define M5STACKFIRE_SPEAKER_PIN 25 // speaker DAC, only 8 Bit
1718

1819
#define HORIZONTAL_RESOLUTION 320
1920
#define VERTICAL_RESOLUTION 240
20-
#define POSITION_OFFSET_Y 30
21+
#define POSITION_OFFSET_Y 20
2122
#define SIGNAL_LENGTH HORIZONTAL_RESOLUTION
2223

2324
uint16_t oldSignal[SIGNAL_LENGTH];
@@ -28,6 +29,7 @@ uint16_t adcBuffer[SIGNAL_LENGTH];
2829

2930
void setup()
3031
{
32+
dacWrite(M5STACKFIRE_SPEAKER_PIN, 0); // make sure that the speaker is quite
3133
M5.Lcd.begin();
3234
M5.Lcd.fillScreen( BLACK );
3335
M5.Lcd.fillRect(10, 1, 150, 160, BLACK);
@@ -77,30 +79,29 @@ void showSignal()
7779

7880
int oldx;
7981
int oldy;
80-
int y;
82+
int oldSig;
83+
int x, y;
8184

82-
for (n = 1; n < SIGNAL_LENGTH; n++)
85+
for (n = 0; n < SIGNAL_LENGTH; n++)
8386
{
84-
y = VERTICAL_RESOLUTION - adcBuffer[n] * ( VERTICAL_RESOLUTION - POSITION_OFFSET_Y) / 4096 - POSITION_OFFSET_Y / 2 ;
87+
x = n;
88+
y = map(adcBuffer[n], 0, 4096, VERTICAL_RESOLUTION, POSITION_OFFSET_Y);
8589

86-
if (n == 1)
87-
{
88-
oldx = n;
89-
oldy = y;
90-
}
91-
92-
if (n < SIGNAL_LENGTH - 1)
90+
if (n > 0)
9391
{
9492
// delete old line element
95-
M5.Lcd.drawLine(n - 1 , oldSignal[n - 1], n, oldSignal[n], BLACK );
93+
M5.Lcd.drawLine(oldx , oldSig, x, oldSignal[n], BLACK );
9694

9795
// draw new line element
98-
M5.Lcd.drawLine(oldx, oldy, n, y, GREEN );
96+
if (n < SIGNAL_LENGTH - 1) // don't draw last element because it would generate artifacts
97+
{
98+
M5.Lcd.drawLine(oldx, oldy, x, y, GREEN );
99+
}
99100
}
100-
101-
oldSignal[n - 1] = oldy;
102-
oldx = n;
101+
oldx = x;
103102
oldy = y;
103+
oldSig = oldSignal[n];
104+
oldSignal[n] = y;
104105
}
105106
}
106107

@@ -112,7 +113,7 @@ void loop(void)
112113
waitForAutoTrigger();
113114

114115
// record signal
115-
for (n = 1; n < SIGNAL_LENGTH; n++)
116+
for (n = 0; n < SIGNAL_LENGTH; n++)
116117
{
117118
adcBuffer[n] = analogRead( ANALOG_SIGNAL_INPUT );
118119

0 commit comments

Comments
 (0)