diff --git a/README.md b/README.md index 86cead62..56363705 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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) \ No newline at end of file diff --git a/examples/Advanced/Display/JpegDraw/JpegDraw.ino b/examples/Advanced/Display/JpegDraw/JpegDraw.ino index 200e66a6..b2b06a50 100644 --- a/examples/Advanced/Display/JpegDraw/JpegDraw.ino +++ b/examples/Advanced/Display/JpegDraw/JpegDraw.ino @@ -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() { diff --git a/examples/Modules/DHT12/DHT12.ino b/examples/Modules/DHT12/DHT12.ino new file mode 100644 index 00000000..0411c791 --- /dev/null +++ b/examples/Modules/DHT12/DHT12.ino @@ -0,0 +1,55 @@ +#include +#include "utility/DHT12.h" +#include //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); +} diff --git a/examples/Modules/GPS/FullExample/FullExample.ino b/examples/Modules/GPS/FullExample/FullExample.ino new file mode 100644 index 00000000..8e796645 --- /dev/null +++ b/examples/Modules/GPS/FullExample/FullExample.ino @@ -0,0 +1,161 @@ +#include +#include + +/* + 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 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 + +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); + } +} diff --git a/examples/Modules/GPS/GPSRaw/TFT_Terminal.ino b/examples/Modules/GPS/GPSRaw/TFT_Terminal.ino new file mode 100644 index 00000000..6a43a5c7 --- /dev/null +++ b/examples/Modules/GPS/GPSRaw/TFT_Terminal.ino @@ -0,0 +1,154 @@ + +/************************************************************* + This sketch implements a simple serial receive terminal + program for monitoring serial debug messages from another + board. + + Connect GND to target board GND + Connect RX line to TX line of target board + Make sure the target and terminal have the same baud rate + and serial stettings! + + The sketch works with the ILI9341 TFT 240x320 display and + the called up libraries. + + The sketch uses the hardware scrolling feature of the + display. Modification of this sketch may lead to problems + unless the ILI9341 data sheet has been understood! + + Updated by Bodmer 21/12/16 for TFT_eSPI library: + https://github.com/Bodmer/TFT_eSPI + + BSD license applies, all text above must be included in any + redistribution + *************************************************************/ + +#include + +// The scrolling area must be a integral multiple of TEXT_HEIGHT +#define TEXT_HEIGHT 16 // Height of text to be printed and scrolled +#define TOP_FIXED_AREA 14 // Number of lines in top fixed area (lines counted from top of screen) +#define BOT_FIXED_AREA 0 // Number of lines in bottom fixed area (lines counted from bottom of screen) +#define YMAX 240 // Bottom of screen area + +// The initial y coordinate of the top of the scrolling area +uint16_t yStart = 16; +// yArea must be a integral multiple of TEXT_HEIGHT +uint16_t yArea = YMAX-TOP_FIXED_AREA-BOT_FIXED_AREA; +// The initial y coordinate of the top of the bottom text line +// uint16_t yDraw = YMAX - BOT_FIXED_AREA - TEXT_HEIGHT; +uint16_t yDraw = 0; + +// Keep track of the drawing x coordinate +uint16_t xPos = 0; + +// For the byte we read from the serial port +byte data = 0; + +// A few test variables used during debugging +boolean change_colour = 1; +boolean selected = 1; + +// We have to blank the top line each time the display is scrolled, but this takes up to 13 milliseconds +// for a full width line, meanwhile the serial buffer may be filling... and overflowing +// We can speed up scrolling of short text lines by just blanking the character we drew +int blank[19]; // We keep all the strings pixel lengths to optimise the speed of the top line blanking + +void termInit() { + // Setup the TFT display + // M5.begin(); + // M5.Lcd.setRotation(5); // Must be setRotation(0) for this sketch to work correctly + M5.Lcd.fillScreen(TFT_BLACK); + + // Setup baud rate and draw top banner + // Serial.begin(115200); + + // M5.Lcd.setTextColor(TFT_WHITE, TFT_BLUE); + // M5.Lcd.fillRect(0,0,320,TEXT_HEIGHT, TFT_BLUE); + // M5.Lcd.drawCentreString(" Serial Terminal - 115200 baud ",320/2,0,2); + + // Change colour for scrolling zone text + M5.Lcd.setTextColor(GREEN, TFT_BLACK); + + // Setup scroll area + // setupScrollArea(TOP_FIXED_AREA, BOT_FIXED_AREA); + setupScrollArea(0, 0); + + // Zero the array + // for (byte i = 0; i<18; i++) blank[i]=0; +} + + +void termPutchar(unsigned char data) { + // These lines change the text colour when the serial buffer is emptied + // These are test lines to see if we may be losing characters + // Also uncomment the change_colour line below to try them + // + // if (change_colour){ + // change_colour = 0; + // if (selected == 1) {M5.Lcd.setTextColor(TFT_CYAN, TFT_BLACK); selected = 0;} + // else {M5.Lcd.setTextColor(TFT_MAGENTA, TFT_BLACK); selected = 1;} + //} + + // while (Serial.available()) + { + // data = Serial.read(); + // If it is a CR or we are near end of line then scroll one line + if (data == '\r' || xPos>311) { + xPos = 0; + yDraw = scroll_line(); // It can take 13ms to scroll and blank 16 pixel lines + } + if (data > 31 && data < 128) { + xPos += M5.Lcd.drawChar(data,xPos,yDraw,2); + // blank[(18+(yStart-TOP_FIXED_AREA)/TEXT_HEIGHT)%19]=xPos; // Keep a record of line lengths + } + //change_colour = 1; // Line to indicate buffer is being emptied + } +} + +void printString(unsigned char *str) +{ + while(*str) termPutchar(*str++); +} + +// ############################################################################################## +// Call this function to scroll the display one text line +// ############################################################################################## +int scroll_line() { + int yTemp = yStart; // Store the old yStart, this is where we draw the next line + // Use the record of line lengths to optimise the rectangle size we need to erase the top line + // M5.Lcd.fillRect(0,yStart,blank[(yStart-TOP_FIXED_AREA)/TEXT_HEIGHT],TEXT_HEIGHT, TFT_BLACK); + M5.Lcd.fillRect(0,yStart,320,TEXT_HEIGHT, TFT_BLACK); + + // Change the top of the scroll area + yStart+=TEXT_HEIGHT; + // The value must wrap around as the screen memory is a circular buffer + // if (yStart >= YMAX - BOT_FIXED_AREA) yStart = TOP_FIXED_AREA + (yStart - YMAX + BOT_FIXED_AREA); + if (yStart >= YMAX) yStart = 0; + // Now we can scroll the display + scrollAddress(yStart); + return yTemp; +} + +// ############################################################################################## +// Setup a portion of the screen for vertical scrolling +// ############################################################################################## +// We are using a hardware feature of the display, so we can only scroll in portrait orientation +void setupScrollArea(uint16_t tfa, uint16_t bfa) { + M5.Lcd.writecommand(ILI9341_VSCRDEF); // Vertical scroll definition + M5.Lcd.writedata(tfa >> 8); // Top Fixed Area line count + M5.Lcd.writedata(tfa); + M5.Lcd.writedata((YMAX-tfa-bfa)>>8); // Vertical Scrolling Area line count + M5.Lcd.writedata(YMAX-tfa-bfa); + M5.Lcd.writedata(bfa >> 8); // Bottom Fixed Area line count + M5.Lcd.writedata(bfa); +} + +// ############################################################################################## +// Setup the vertical scrolling start address pointer +// ############################################################################################## +void scrollAddress(uint16_t vsp) { + M5.Lcd.writecommand(ILI9341_VSCRSADD); // Vertical scrolling pointer + M5.Lcd.writedata(vsp>>8); + M5.Lcd.writedata(vsp); +} diff --git a/examples/Modules/Lora/LoRaReceiver/LoRaReceiver.ino b/examples/Modules/Lora/LoRaReceiver/LoRaReceiver.ino index 617333b1..bb7fc2ac 100644 --- a/examples/Modules/Lora/LoRaReceiver/LoRaReceiver.ino +++ b/examples/Modules/Lora/LoRaReceiver/LoRaReceiver.ino @@ -14,6 +14,7 @@ void setup() { Serial.println("LoRa Receiver"); M5.Lcd.println("LoRa Receiver"); + // frequency in Hz (433E6, 866E6, 915E6) if (!LoRa.begin(433E6)) { Serial.println("Starting LoRa failed!"); M5.Lcd.println("Starting LoRa failed!"); diff --git a/examples/Modules/Lora/LoRaSender/LoRaSender.ino b/examples/Modules/Lora/LoRaSender/LoRaSender.ino index 1b58d295..714286c3 100644 --- a/examples/Modules/Lora/LoRaSender/LoRaSender.ino +++ b/examples/Modules/Lora/LoRaSender/LoRaSender.ino @@ -14,6 +14,7 @@ void setup() { Serial.println("LoRa Sender"); M5.Lcd.println("LoRa Sender"); + // frequency in Hz (433E6, 866E6, 915E6) if (!LoRa.begin(433E6)) { Serial.println("Starting LoRa failed!"); M5.Lcd.println("Starting LoRa failed!"); diff --git a/extras/M-BUS.jpg b/extras/M-BUS.jpg new file mode 100644 index 00000000..fc69968d Binary files /dev/null and b/extras/M-BUS.jpg differ diff --git a/library.json b/library.json index 63638e60..59fcf435 100644 --- a/library.json +++ b/library.json @@ -10,7 +10,7 @@ "type": "git", "url": "https://github.com/m5stack/m5stack.git" }, - "version": "0.1.2", + "version": "0.1.3", "framework": "arduino", "platforms": "espressif32" } diff --git a/library.properties b/library.properties index 8b480012..f5e69fc9 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=M5Stack -version=0.1.2 +version=0.1.3 author=M5Stack maintainer=Zibin Zheng sentence=Driver for M5Stack Core development kit diff --git a/src/utility/Display.cpp b/src/utility/Display.cpp index 7a250e5a..b6599901 100644 --- a/src/utility/Display.cpp +++ b/src/utility/Display.cpp @@ -260,7 +260,8 @@ void ILI9341::init(void) writedata(0x86); //-- writecommand(ILI9341_MADCTL); // Memory Access Control - writedata(0x48); + writedata(0x08); + // writedata(0x48); writecommand(ILI9341_PIXFMT); writedata(0x55); @@ -3081,6 +3082,13 @@ void ILI9341::sleep() { writecommand(ILI9341_SLPIN); // Software reset spi_end(); } + +void ILI9341::clearDisplay() { + fillScreen(0x0000); +} + +void ILI9341::display() { +} /*************************************************** This library is written to be compatible with Adafruit's ILI9341 library and automatically detects the display type on ESP_WROVER_KITs diff --git a/src/utility/Display.h b/src/utility/Display.h index 47507906..b7466136 100644 --- a/src/utility/Display.h +++ b/src/utility/Display.h @@ -246,7 +246,7 @@ #include #endif -#define clear(color) fillScreen(color) +// #define clear(color) fillScreen(color) //#define DC_C digitalWrite(TFT_DC, HIGH); GPIO.out_w1tc = (1 << TFT_DC)//digitalWrite(TFT_DC, LOW) //#define DC_D digitalWrite(TFT_DC, LOW); GPIO.out_w1ts = (1 << TFT_DC)//digitalWrite(TFT_DC, HIGH) @@ -581,11 +581,13 @@ class ILI9341 : public Print textWidth(const String& string, int font), textWidth(const String& string), fontHeight(int16_t font); -//--- - void sleep(); - void setBrightness(uint8_t brightness); - void progressBar(int x, int y, int w, int h, uint8_t val); - void setAddrWindow(int32_t xs, int32_t ys, int32_t xe, int32_t ye); + + void sleep(), + setBrightness(uint8_t brightness), + progressBar(int x, int y, int w, int h, uint8_t val), + setAddrWindow(int32_t xs, int32_t ys, int32_t xe, int32_t ye), + display(), + clearDisplay(); void startWrite(void); void endWrite(void); @@ -595,8 +597,9 @@ class ILI9341 : public Print void drawJpgFile(fs::FS &fs, const char *path, uint16_t x = 0, uint16_t y = 0, uint16_t maxWidth = 0, uint16_t maxHeight = 0, uint16_t offX = 0, uint16_t offY = 0, jpeg_div_t scale = JPEG_DIV_NONE); void drawBmpFile(fs::FS &fs, const char *path, uint16_t x = 0, uint16_t y = 0, uint16_t maxWidth = 0, uint16_t maxHeight = 0, uint16_t offX = 0, uint16_t offY = 0); void writeInitData(const uint8_t *data); - //---- - virtual size_t write(uint8_t); + + + virtual size_t write(uint8_t); // #define startWrite spi_begin // #define endWrite spi_end