Skip to content

Commit

Permalink
v0.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
0x1abin committed Nov 9, 2017
1 parent 6a7841d commit d18abc1
Show file tree
Hide file tree
Showing 13 changed files with 430 additions and 17 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@
```
- Restart Arduino IDE

#### Installing with Boards Manager(beta)
~~#### Installing with Boards Manager(beta)~~

Starting with 1.6.4, Arduino allows installation of third-party platform packages using Boards Manager. We have packages available for Windows, Mac OS, and Linux (32 and 64 bit).
~~Starting with 1.6.4, Arduino allows installation of third-party platform packages using Boards Manager. We have packages available for Windows, Mac OS, and Linux (32 and 64 bit).~~

- Install Arduino 1.8.2 from the [Arduino website](http://www.arduino.cc/en/main/software).
- Start Arduino and open Preferences window.
- Enter ```http://www.m5stack.com/download/package_m5stack_index.json``` into *Additional Board Manager URLs* field. You can add multiple URLs, separating them with commas.
- Open Boards Manager from Tools > Board menu and install *ESP32* platform (and don't forget to select your ESP32 board from Tools > Board menu after installation).
~~- Install Arduino 1.8.2 from the [Arduino website](http://www.arduino.cc/en/main/software).~~
~~- Start Arduino and open Preferences window.~~
~~- Enter ```http://www.m5stack.com/download/package_m5stack_index.json``` into *Additional Board Manager URLs* field. You can add multiple URLs, separating them with commas.~~
~~- Open Boards Manager from Tools > Board menu and install *ESP32* platform (and don't forget to select your ESP32 board from Tools > Board menu after installation).~~
## How to use:
Expand Down Expand Up @@ -82,7 +82,10 @@ BUTTON A | GPIO39
BUTTON B | GPIO38
BUTTON C | GPIO37
SPEAKER | GPIO25
MPU9250 SDA | GPIO21
MPU9250 SCL | GPIO22
GOVER SDA | GPIO21
GOVER SCL | GPIO22

### M-BUS
![image](extras/M-BUS.jpg)
1 change: 1 addition & 0 deletions examples/Advanced/Display/JpegDraw/JpegDraw.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ void setup(void) {
//Draw the jpeg file form TF card
M5.Lcd.setBrightness(200);
M5.Lcd.drawJpgFile(SD, "/p2.jpg");
// M5.Lcd.drawJpgFile(fs::FS &fs, const char *path, uint16_t x, uint16_t y, uint16_t maxWidth, uint16_t maxHeight, uint16_t offX, uint16_t offY, jpeg_div_t scale);
}

void loop() {
Expand Down
55 changes: 55 additions & 0 deletions examples/Modules/DHT12/DHT12.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <M5Stack.h>
#include "utility/DHT12.h"
#include <Wire.h> //The DHT12 uses I2C comunication.
DHT12 dht12; //Preset scale CELSIUS and ID 0x5c.

/*
For configuration library:
DHT12 dht12("Scale temperature","ID device for I2C");
On "Scale temperature" you can select the preset scale:
CELSIUS, FAHRENHEIT or KELVIN.
And on "ID device", you can put ID sensor, on DHT12
normally is 0x5c.
Examples:
DHT12 dht12;
The preset scale is CELSIUS and ID is 0x5c.
DHT12 dht12(KELVIN);
the preset scale is KELVIN and ID is 0x5c.
DHT12 dht12(FAHRENHEIT,0x53);
The preset scale is FAHRENHEIT and ID is 0x53.
*/

void setup() {
M5.begin();
Wire.begin();
Serial.println("Prueba de libreria DHT12:");
M5.Lcd.println("Prueba de libreria DHT12:");
}

void loop() {
//Read temperature with preset scale.
Serial.print("Temperatura: ");
M5.Lcd.print("Temperatura: ");
Serial.print(dht12.readTemperature());
M5.Lcd.print(dht12.readTemperature());

//Read humidity.
Serial.print("*C Humedad: ");
M5.Lcd.print("*C Humedad: ");
Serial.print(dht12.readHumidity());
M5.Lcd.println(dht12.readHumidity());

//Read temperature as forced fahrenheit.
Serial.println("%RH");
Serial.println("%RH");
Serial.print("Temperatura: ");
Serial.print(dht12.readTemperature(FAHRENHEIT));

//Read termperature as forced kelvin.
Serial.println("*F");
Serial.print("Temperatura: ");
Serial.print(dht12.readTemperature(KELVIN));
Serial.println("*K");

delay(5000);
}
161 changes: 161 additions & 0 deletions examples/Modules/GPS/FullExample/FullExample.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
#include <M5Stack.h>
#include <TinyGPS++.h>

/*
This sample code demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object.
It requires the use of SoftwareSerial, and assumes that you have a
4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
*/
static const uint32_t GPSBaud = 9600;

// The TinyGPS++ object
TinyGPSPlus gps;

// The serial connection to the GPS device
HardwareSerial ss(2);

void setup()
{
M5.begin();
ss.begin(GPSBaud);

// M5.Lcd.println(F("FullExample.ino"));
// M5.Lcd.println(F("An extensive example of many interesting TinyGPS++ features"));
// M5.Lcd.print(F("Testing TinyGPS++ library v. ")); M5.Lcd.println(TinyGPSPlus::libraryVersion());
// M5.Lcd.println(F("by Mikal Hart"));
// M5.Lcd.println();
M5.Lcd.println(F("Sats HDOP Latitude Longitude Fix Date Time Date Alt Course Speed Card Distance Course Card Chars Sentences Checksum"));
M5.Lcd.println(F(" (deg) (deg) Age Age (m) --- from GPS ---- ---- to London ---- RX RX Fail"));
M5.Lcd.println(F("---------------------------------------------------------------------------------------------------------------------------------------"));
}

void loop()
{
M5.Lcd.setCursor(0, 70);
M5.Lcd.setTextColor(WHITE, BLACK);
static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;

printInt(gps.satellites.value(), gps.satellites.isValid(), 5);
printInt(gps.hdop.value(), gps.hdop.isValid(), 5);
printFloat(gps.location.lat(), gps.location.isValid(), 11, 6);
printFloat(gps.location.lng(), gps.location.isValid(), 12, 6);
printInt(gps.location.age(), gps.location.isValid(), 5);
printDateTime(gps.date, gps.time);
printFloat(gps.altitude.meters(), gps.altitude.isValid(), 7, 2);
printFloat(gps.course.deg(), gps.course.isValid(), 7, 2);
printFloat(gps.speed.kmph(), gps.speed.isValid(), 6, 2);
printStr(gps.course.isValid() ? TinyGPSPlus::cardinal(gps.course.deg()) : "*** ", 6);

unsigned long distanceKmToLondon =
(unsigned long)TinyGPSPlus::distanceBetween(
gps.location.lat(),
gps.location.lng(),
LONDON_LAT,
LONDON_LON) / 1000;
printInt(distanceKmToLondon, gps.location.isValid(), 9);

double courseToLondon =
TinyGPSPlus::courseTo(
gps.location.lat(),
gps.location.lng(),
LONDON_LAT,
LONDON_LON);

printFloat(courseToLondon, gps.location.isValid(), 7, 2);

const char *cardinalToLondon = TinyGPSPlus::cardinal(courseToLondon);

printStr(gps.location.isValid() ? cardinalToLondon : "*** ", 6);

printInt(gps.charsProcessed(), true, 6);
printInt(gps.sentencesWithFix(), true, 10);
printInt(gps.failedChecksum(), true, 9);
M5.Lcd.println();

smartDelay(1000);

if (millis() > 5000 && gps.charsProcessed() < 10)
M5.Lcd.println(F("No GPS data received: check wiring"));
}

// This custom version of delay() ensures that the gps object
// is being "fed".
static void smartDelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (ss.available())
gps.encode(ss.read());
} while (millis() - start < ms);
}

static void printFloat(float val, bool valid, int len, int prec)
{
if (!valid)
{
while (len-- > 1)
M5.Lcd.print('*');
M5.Lcd.print(' ');
}
else
{
M5.Lcd.print(val, prec);
int vi = abs((int)val);
int flen = prec + (val < 0.0 ? 2 : 1); // . and -
flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
for (int i=flen; i<len; ++i)
M5.Lcd.print(' ');
}
smartDelay(0);
}

static void printInt(unsigned long val, bool valid, int len)
{
char sz[32] = "*****************";
if (valid)
sprintf(sz, "%ld", val);
sz[len] = 0;
for (int i=strlen(sz); i<len; ++i)
sz[i] = ' ';
if (len > 0)
sz[len-1] = ' ';
M5.Lcd.print(sz);
smartDelay(0);
}

static void printDateTime(TinyGPSDate &d, TinyGPSTime &t)
{
if (!d.isValid())
{
M5.Lcd.print(F("********** "));
}
else
{
char sz[32];
sprintf(sz, "%02d/%02d/%02d ", d.month(), d.day(), d.year());
M5.Lcd.print(sz);
}

if (!t.isValid())
{
M5.Lcd.print(F("******** "));
}
else
{
char sz[32];
sprintf(sz, "%02d:%02d:%02d ", t.hour(), t.minute(), t.second());
M5.Lcd.print(sz);
}

printInt(d.age(), d.isValid(), 5);
smartDelay(0);
}

static void printStr(const char *str, int len)
{
int slen = strlen(str);
for (int i=0; i<len; ++i)
M5.Lcd.print(i<slen ? str[i] : ' ');
smartDelay(0);
}
26 changes: 26 additions & 0 deletions examples/Modules/GPS/GPSRaw/GPSRaw.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <M5Stack.h>

HardwareSerial GPSRaw(2);

void setup() {

M5.begin();
GPSRaw.begin(9600);

Serial.println("hello");
termInit();
}

void loop() {
// put your main code here, to run repeatedly:
if(Serial.available()) {
int ch = Serial.read();
GPSRaw.write(ch);
}

if(GPSRaw.available()) {
int ch = GPSRaw.read();
Serial.write(ch);
termPutchar(ch);
}
}
Loading

0 comments on commit d18abc1

Please sign in to comment.