element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Summer of Green Tech Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Summer of Green Tech Design Challenge
  • More
  • Cancel
Summer of Green Tech Design Challenge
Blog Smart Home Energy Management System - Blog Post #4 - Interfacing with the Expansion Board Base for XIAO
  • Blog
  • Forum
  • Documents
  • Leaderboard
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Summer of Green Tech Design Challenge to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: MarioPJ98
  • Date Created: 30 Sep 2023 12:54 PM Date Created
  • Views 707 views
  • Likes 9 likes
  • Comments 1 comment
  • expansion board
  • competition
  • design challenge
  • summer of green tech design challenge
  • seeedstudio
  • monitor
  • green
  • challengers
  • json
  • green tech
  • Xiao
  • http
  • api
  • interface
  • SD card
  • arduino
  • Nicla Vision Board
  • seeeduino
Related
Recommended

Smart Home Energy Management System - Blog Post #4 - Interfacing with the Expansion Board Base for XIAO

MarioPJ98
MarioPJ98
30 Sep 2023
Smart Home Energy Management System - Blog Post #4 - Interfacing with the Expansion Board Base for XIAO

Since I got the Expansion Board Base for XIAO board, I wanted to use the monitor to interface with the SHEM. The monitor should display basic things like the date, the weather and how much energy I am consuming each day. I like the idea of accessing the weather since I always forget when it is too late to check the weather so I don't know if it is going to rain or the temperatures (in Germany, the weather can be really unpredictable). It would be awesome to just go to the bathroom and automatically the monitor turns on and I can check the weather while I am brushing my teeth.

The monitor is really small so there is a limit of how much information it can contain at one time. Likely, there is button integrated on the expansion board so I can just press the button to switch screen. An SD card slot is included as well, and I can use to store data like how much energy consumption was used each day and I can use this data to plot it on the monitor.

I followed these instructions to set up the monitor:

Expansion Board Base for XIAO | Seeed Studio Wiki

The code was really easy to learn since it reminded me of the LCD Arduino monitor (luckily there weren't any wire to set up for this monitor if you know what I mean). The button was easy to set up as well. Right now, I have only two pages (a welcome page and one to access the SD card) so the code to switch between pages is really basic but if I want to include more pages I need to rewrite it. By ready the library to write text on the monitor, I notice there are examples also for weather like this one:

U8g2_Arduino/examples/full_buffer/Weather/Weather.ino at master · olikraus/U8g2_Arduino (github.com)

I will try to expand my code to include some images on the display to show the weather (so if it is sunny show a picture of a sun and so on). I need to find something also to plot a scatterplot or histogram to show the power consumption of the SHME. I would say just to plot the hours each day of the week (so Monday the SHME was on for 2 hours, Tuesday for 2.5 hours, Wednesday for 1 hours, and so on).

Right now, I have tried to write code on the SD card. I have used the example from the first link. Although the tutorial mentions for XIAO SAMD21 board I didn't have to download any external libraries, still the FS.h library wasn't included. There wasn't any link to where download the library so I just commented the library and everything worked fine for the example. I was able to write a file and read it.

Problems came when I included the example into my code. First of all, the most annoying problem I was getting was that Arduino IDE couldn't find the port although it showed it was connected. image

The only guaranteed way to fix this issue was to restart my computer. I am getting this error too often. Second problem, when I managed to upload the code, reading the file was corrupted. What I was reading wasn't the same. For now I am thinking of 3 possible issues:

  1. Some libraries are incompatible between each other
  2. The FS.h library was important and I need to find a way to import it
  3. This line might be the issue

u8x8.setFont(u8x8_font_chroma48medium8_r);   // choose a suitable font

On the tutorial there were two examples to read and write on the SD card. I will try the other one and import the library (for the second example they provided the link to import the library.

So these are the things to do to improve the interface:

  • Find a solution for writing and reading on the SD card
  • Find a script on the examples to plot data
  • Test the weather icons and include them on the welcome page

I was working for a long time to get access to a weather API using the Nicla Vision Board. I found this tutorial that explains how to use the openweather API, read JSON file and do a HTTP GET request. The first two parts were a piece of cake but the third one not. The tutorial uses an ESP32 and different boards. The library HTTPClient.h is not included with the Nicla Vision Board and I didn't find any library compatible with the board to do an HTTP GET request. I can use a board at home that has an ESP32 but this would increase the complexity of the entire system (and it is already complex as it is). Maybe if somebody knows how to do a HTTP GET request can help me. I am new on this field.

ESP32 HTTP GET with Arduino IDE (OpenWeatherMap.org and ThingSpeak) | Random Nerd Tutorials

I am attaching below my code for the interface so far.

#include <Arduino.h>
#include <U8x8lib.h>
#include <Wire.h>

#include <PCF8563.h>
PCF8563 pcf;

#include <SPI.h>
#include <SD.h>
//#include "FS.h"

U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* clock=*/ PIN_WIRE_SCL, /* data=*/ PIN_WIRE_SDA, /* reset=*/ U8X8_PIN_NONE);   // OLEDs without Reset of the Display

const int buttonPin = 1;     // the number of the pushbutton pin
int buttonState = 0;         // variable for reading the pushbutton status
int page = 1;

File myFile;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while(!Serial);              // Execute after turning on the serial monitor
  delay(500);

  Serial.print("Initializing SD card...");

  pinMode(D2, OUTPUT);          // Modify the pins here to fit the CS pins of the SD card you are using.
  if (!SD.begin(D2)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("/test5.txt", FILE_WRITE);          // The path to read and write files needs to start with "/"

  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("1");
    myFile.println("2");
    myFile.println("3");
    myFile.println("4");
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT_PULLUP);

  u8x8.begin();
  u8x8.setFlipMode(1);   // set number from 1 to 3, the screen word will rotary 180
  Wire.begin();
  pcf.init();//initialize the clock
  pcf.stopClock();//stop the clock
  pcf.setYear(23);//set year
  pcf.setMonth(10);//set month
  pcf.setDay(01);//set dat
  pcf.setHour(10);//set hour
  pcf.setMinut(33);//set minut
  pcf.setSecond(0);//set second
  pcf.startClock();//start the clock
}

void loop() {
  buttonState = digitalRead(buttonPin);
  Time nowTime = pcf.getTime();//get current time
  u8x8.setFont(u8x8_font_chroma48medium8_r);   // choose a suitable font

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == LOW) {
    page = page * -1;
    u8x8.setCursor(0, 0);
    u8x8.print("              ");
    u8x8.setCursor(0, 1);
    u8x8.print("               ");
    u8x8.setCursor(0, 2);
    u8x8.print("               ");
    u8x8.setCursor(0, 3);
    u8x8.print("               ");
    u8x8.setCursor(0, 4);
    u8x8.print("               ");
    u8x8.setCursor(0, 5);
    u8x8.print("               ");
    u8x8.setCursor(0, 6);
    u8x8.print("               ");
  }

  if (page > 0) {
    u8x8.setCursor(0, 0);
    u8x8.print("Hello World!");
    u8x8.setCursor(0, 1);
    u8x8.print(nowTime.day);
    u8x8.print("/");
    u8x8.print(nowTime.month);
    u8x8.print("/");
    u8x8.print("20");
    u8x8.print(nowTime.year);
    u8x8.setCursor(0, 2);
    u8x8.print(nowTime.hour);
    u8x8.print(":");
    u8x8.print(nowTime.minute);
    u8x8.print(":");
    u8x8.println(nowTime.second);
  } else if (page< 0) {
    // re-open the file for reading:
  myFile = SD.open("/test5.txt");                       // The path to read and write files needs to start with "/"
  if (myFile) {
    Serial.println("test5.txt:");

    // read from the file until there's nothing else in it:
    int count = 0;
    while (myFile.available()) {
      Serial.write(myFile.read());
      u8x8.setCursor(0, count);
      u8x8.print(myFile.read());
      count++;
      Serial.println(count);
      delay(500);
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
  
    }
  delay(250);
}
You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

  • Sign in to reply
  • DAB
    DAB over 2 years ago

    That display is way too small for my eyes.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube