Great minds worked in coordination to create this essential asset for the human race. Development and generation of electricity changed the lives drastically, starting from domestic use to industrial activities.
Despite its great importance in daily life, few people probably stop to think about what life would be like without electricity. Like air and water, people tend to take electricity for granted.
Non renewable resources and renewable resources are used to generate electricity but non renewable resources cannot be replaced and release carbon dioxide and other greenhouse gases when they are burned to produce electricity.
Countries all around the world are powering towards a low-carbon future by embracing solar, wind and geothermal energy. This is a good sign but we can improve this by providing a simple system to homes and offices.
Aim/ ObjectiveSolar energy is used worldwide and is renewable. Nearly 74% of the energy demand is supplied by coal and natural gas. Renewable energy sources play a vital role in securing sustainable energy with lower emissions.
Photovoltaic (PV) and solar-thermal power are the two main types of solar electricity generation technologies. PV conversion produces electricity directly from sunlight in a photovoltaic cell.
In this project, I will be using the SensiML software to predict and analyze the voltage output of a given photo-voltaic (PV) module at particular solar irradiation levels.
The QuickFeather board will be powered by a rechargeable battery - Li-ion.
Hardware setupQuickLogic QuickFeather Development KitThe QuickFeather Development Kit is a small form factor system ideal for enabling the next generation of low-power Machine Learning (ML) capable IoT devices. Unlike other development kits which are based on proprietary hardware and software tools, QuickFeather is based on open source hardware, compatible with the Adafruit Feather form factor, and is built around 100% open source software (including the Symbiflow FPGA Tools).
The QuickFeather is powered by QuickLogic’s EOS™ S3, the first FPGA-enabled Arm Cortex®-M4F MCU to be fully supported with Zephyr RTOS
6V 3.5W Solar PanelI will be using a 6V 3.5W Solar panel for this project. To prevent damage to the IO port of the QuickFeather Development Kit, a voltage divider will be used.
Light Dependent ResistorAn LDR will be used to measure the light levels and it is assumed that the light levels are directly proportional to the solar irradiance levels.
Voltage DividerFor this project, we will be needing the qf_ssi_app from the qorc-sdk github repository. The instructions for using this repository is given in the Readme file.
You need to follow the instructions provided in the Readme file from the qf_ssi_app to learn how to add a new sensor. You will not need to add a sensor but you have to read the analog input of the IO ports and then use the analog readings to measure the voltage at particular irradiance levels.
Eclipse IDEI will be using the Eclipse IDE to build and debug this project.
The following software tools and plug-ins are needed in order to setup the Eclipse IDE environment.
- ARM GCC toolchain available for download from -https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads
- GNU Make program Version 3.81 available for download from -https://sourceforge.net/projects/gnuwin32/files/make/3.81
Install to the folder C:\GnuWin32\
Note:
Please make sure the PATH contains "C:\GnuWin32\bin" as the first "make utility".
Other versions of Make may "not work" with the Makefiles provided.
- Eclipse IDE available for download from - https://projects.eclipse.org/projects/iot.embed-cdt/downloads
- ARM Cross Compiler plug-in and J-Link debugger plug-in for Eclipse available from - http://gnu-mcu-eclipse.netlify.com/v4-neon-updates
The recommended Eclipse for QORC SDK is Eclipse IDE for Embedded C/ C++ Developers.
Open Eclipse IDE, on the main menu select Window -> Preferences
On the "Preferences" dialog box, navigate to MCU -> "Global Build Tools Path"
Enter Build tools folder location as "C:\GnuWin32\bin" as setup above in the installation procedures.
Build setup:
In the Eclipse IDE, select the project to build
In the Eclipse IDE's main menu:
- Select Project -> Properties
- Select C/C++ Build from the left pane of the "Properties for <YourProject>" dialog box.
On the "Builder Settings" tab
- unselect "Use default build command"
- Enter the following in the Build command box:
make -C ${workspace_loc:/${ProjName}}/../
Click on sub -option "Settings" under "C/C++ Build"
Select "Toolchains" Tab and pull-down Name option and select
"GNU Tools for ARM Embedded Processors (arm-none-eabi-gcc)"
- Select the Environment from the C/C++ Build
- Double-click on the PATH environment variable
- Add the folder C:\GnuWin32\bin to the PATH environment variable
- Add the folder where the ARM GCC toolchain is installed to the PATH environment variable (for example, C:\Program Files (x86)\GNU Tools ARM Embedded\7 2017-q4-major\bin)
- Select Project -> "Build Project"
- Add the 3 output files from GCC_project/output/bin folder to the virtual folder GCC_project/output/bin (else the you would not be able select the project in the next step)
All QORC SDK applications have Makefile support, and the application_dir/GCC_Project/
contains the necessary Makefiles.
To convert this to an Eclipse Project, the following steps can be followed:
- Create a directory
eclipse_make_project
in the application'sGCC_Project dir
. - Create a file
eclipse_custom_build_command.sh
in the application'sGCC_Project dir
.
Copy the below content into the file :
#!/usr/bin/env bash
cd $1
echo $INSTALL_DIR
export PATH="$INSTALL_DIR/quicklogic-arch-defs/bin:$INSTALL_DIR/quicklogic-arch-defs/bin/python:$PATH"
source "$INSTALL_DIR/conda/etc/profile.d/conda.sh"
conda activate
make $2
Save the file, and mark it executable with chmod +x eclipse_custom_build_command.sh
- Open Eclipse and Select Preferred Workspace.
- Select
File -> New -> Project
From theNew Project
dialog box,SelectMakefile project with existing code
underC++
and click Next. - Specify the Project Name ("Use Your Preferred Name") in the
Project Name
text box.Specify the path toeclipse_make_project
that was created in Step [1] in theExisting Code Location
text boxKeep bothC
andC++
checked inLanguages
SelectARM Cross GCC
in theToolchain for Indexer Settings
optionsClick Finish - Add files and folder to the Eclipse Virtual Filesystem
Select the following directories in the File Explorer
from the QORC SDK repo directory:
- BSP
- HAL
- FreeRTOS
- Libraries
- Tasks
Drag the selected directories and drop them onto the newly created project in Eclipse IDE.
Once dropped, a File and Folder Operation
dialog pops up.
Choose Link to files and recreate folder structure with virtual folders
option.
Ensure that the option Check the Create link locations relative to PROJECT_LOC
is checked.
Click OK.
Any other QORC SDK directories can be added to the eclipse project in the same way.
- Create Virtual Folder named "App".
Ensure that the newly create project is selected in Eclipse IDE
Select File -> New -> Folder
Specify folder name as App
Click the Advanced
tab and ensure to select the option Folder is not located in the file system (Virtual Folder)
Click Finish
Select the following directories in the File Explorer
from the application directory:
- GCC_Project
- src
- inc
Drag the selected directories and drop them onto the newly App
Virtual Folder in Eclipse IDE.
Now, the project structure is ready.
Set the sensor sampling rate and the number of channels in the macros file defined in the header file sensor_ssss.h.
Update the string value definition of json_string_sensor_config in sensor_ssss.cpp.
Repeat the same process to obtain readings from the photoresistor.
In order to read your data, edit the configuration within the dcl_import.ssf file in the qf_ssi_ai_app directory.
Setup Build Configuration For Project- Ensure that the newly create project is selected in Eclipse IDE
- Select
Project -> Properties
- Select C/C++ Build from the left pane
Select the Builder Settings
tab
Deselect Use default build command
Enter the following in the Build command
text box:
${workspace_loc:/${ProjName}}/../eclipse_custom_build_command.sh ${workspace_loc:/${ProjName}}/../
- Select sub option Settings
under C/C++ Build
Select Toolchains
tab and pull-down Name
option and select GNU Tools for ARM Embedded Processors (arm-none-eabi-gcc)
- Select sub option Environment
under C/C++ Build
Click option Add
, input Name
as INSTALL_DIR
and Value
as "Path to the FPGA Toolchain Installation Directory"
(same as in regular setup)
Click option Add
, input Name
as PATH
and Value
as "Path to the ARM GCC Toolchain Directory":"$INSTALL_DIR/install/bin:$INSTALL_DIR/install/bin/python:$PATH
Click Apply and Close
the Project Properties
- Right-Click on the project in
Project Explorer
, selectClean Project
You should be able to see the project cleaned successfully.
The CDT Build Console
output should look to be the same as what you would see while executing make clean
from the command line.
- Right-Click on the project in
Project Explorer
, selectBuild Project
You should be able to see the project build successfully.TheCDT Build Console
output should look to be the same as what you would see while executingmake
from the command line. - Select the bin directory in the File Explorer from the application's GCC_Project/output/ directory.Drag the selected directory and drop it onto the App/GCC_Project/output/ Virtual Folder in Eclipse IDE
Ensure you have a Python installation on your system. It is recommended to have Python 3.6 or newer installed.
You will need the TinyFPGA Programmer from QuickLogic to flash your device. Instructions for setting up your computer to flash a QuickFeather board are in the Utilities section of the qorc-sdk README.
When you download the TinyFPGA Programmer you need to use git to clone the repo from the github. Downloading a zip version of the repo can cause unexpected results
2. QuickFeather ButtonsThe QuickFeather has two buttons, USR (User), and RST (Reset). They are used in flashing. In the figure below, RST is highlighted in orange, the USR button is highlighted in purple.
- Connect your QuickFeather board to your computer using a USB to Micro-USB cable.
- Press the ‘Reset’ button on the QuickFeather board. The LED will flash blue for five seconds. Press the ‘User’ button while the LED is still flashing blue.After pressing the ‘User’ button the LED will begin to flash green. This means the device is now in upload mode. If the LED is not flashing green then repeat this step
- While the LED is blinking green, program the data collection binary into QuickFeather by running the following command:
python /Your-directory-path-to-TinyFPGA-Programmer/tinyfpga-programmer-gui.py --port COMX --m4app /Your-directory-path-to-binary/your-binary-file.bin --mode m4
# Replace COMX with your own device COM port number.
# Replace /Your-directory-path-to-TinyFPGA-Programmer/ and /Your-directory-path-to-binary/ with your computer's file path locations.
# Replace your-binary-file.bin with the name of the file you are flashing.
- After programming has completed, press the ‘Reset’ button The LED should flash blue for 5 seconds and load the selected application. Once the application is done loading the LED will turn off. Reset the board to start running the qf_ssi_app application.
By default, the Simple Streaming version of the QuickFeather firmware uses the hardware UART. This means that a USB to TTL serial adapter must be used (or another Feather/Wing to communicate)
In order to see data collection and recognition output with the qf_ssi_ai_app firmware, the adapter must be wired accordingly. This adapter plugs in RXD to Pin 2 (white wire, orange box) and TXD to Pin 3 on J3 (green wire, purple box).
You can then open the port in Tera Term, PuTTy, or other serial port program at 460800 to test the connection.
Data Capture LabThe Data Capture Lab is an application that helps you capture, organize, and label raw data from the sensor and transform it into the events you want to detect.
Creating a Project- Log in to your account in the main window of the Data Capture Lab and click New project…
- Give your project a project a name and click OK
You should try to collect some examples of the PV output and the corresponding irradiance levels.
After opening your project, click Switch Modes and open Capture Mode.
Device Plugins are a list of properties that describe how the DCL will collect data from your device. For example, the device plugin may contain a list of sample rates that your device supports. This allows the DCL to collect data from any device that has been built to accept the supported parameters below.
The Data Capture Lab allows you to import Device Plugins via.SSF files through the menu item Edit → Import Device Plugin… Next, you will be able to select your plugin protocol. In this project, you will be using the dcl_import.ssf
found within the qf_ssi_ai_app
directory.
Configure your sensor and set the appropriate sampling rate.
Configure your deviceWe have configured our device in the earlier steps of this project and it is important that you collect your sensor data with the same configuration that you plan to use for your event detection sensor. Collecting data with different settings can cause unexpected results depending on various aspects like sensor orientation and sensor calibration settings.
Within the hardware setup found in the right side of the DCL software, set the Capture Method as Live Stream Capture and the connection method as Serial Port.
Select the 'Find Devices' option and click on scan for devices after you have plugged in your QuickFeather Development kit. Select the appropriate COM port and connect your device.
Recording Raw Sensor DataAfter connecting your device and selecting the event click 'Being Recording' and the DCL will start recording the live sensor stream. Once you stop recording the DCL will automatically save the file to your local hard drive and upload it to the cloud.
At this point, you will want to capture several examples as this allows for variation in the examples which will make a more robust sensor application. You should try to record the irradiance level at various voltage output levels. The labels should be various voltage levels so that we will be able to know the amount of voltage generated by the solar panel at each irradiance level.
Labeling Your DataAfter collecting examples of our application, it's time for us to label them.
- Switch to Label Explorer mode
- To open the raw sensor data files you have captured, use the Project Explorer. This can be found in the upper left-hand corner of the DCL.
- Double-click on a file name to open the file.
After labeling your data, it's time for you to break them into segments which will then be used for training your Machine Learning Model.
After going to File menu and selecting Close File option, you are now ready to generate a model from the captured data using the Analytics Studio.
The Data saved within the DCL is automatically uploaded and stored in the cloud.
SensiML Analytics StudioSensiML Analytics Studio builds a machine learning model for predicting the solar panel's voltage output at each irradiance level.
Training a ModelGo to Analytics Studio and sign in to your account. Select the project which you now created in the Data Capture Lab.
To train a model, we must first tell the Analytics Studio which data we want to use in the form of a Query. This can be done by clicking on the Prepare Data tab and entering a name, session, label, relevant metadata, the sensor(s), and how to plot it. After saving the dataset should appear on the right, and we can see how many segments are in each label.
Pipelines can be constructed by going to the Build Model tab and entering a name, the query that was just created, window size (make it the same size as the capture rate for the sensor), optimization metric (f1-score is the most balanced), and the classifier size, which limits how large the model can be, great for loading onto ROM-constrained chips. Clicking Optimize will go through and build the model, and depending on how large the dataset is, it might take a while to complete.
After checking the accuracy of your model, download the project's knowledge pack.
Generating Knowledge PackThe final step in this project is to deploy the Machine Learning model to your QuickLogic QuickFeather Development Kit. This can be done by obtaining the Knowledge Pack. For this project, we will be downloading the model in the form of binary. In the Download Model tab, select the pipeline you just optimised with the following settings:
- HW Platform : QuickFeather
- Platform version : 1.8.0
- Processor : QuickLogic EOS-S3 (Cortex M4)
- Float Options : Hard FP
- Compiler : GNU ARM Embedded (none-eabi) 9.3.1
- Format : Library
- Data Source : Sensor 1
- Application : SensiML AI Simple Stream
- Output : Serial
Download the zip file and extract the knowledge pack library. Replace the knowledge pack from the qf_ssi_ai_app with the downloaded knowledge pack. Build the new project with Eclipse IDE and you will find the regenerated binary in the output folder within the GCC_Project directory.
Follow the flash programming procedure to flash the regenerated binary file to the QuickLogic QuickFeather Development kit. Reset the board to start the application.
Open a serial monitor with a baud rate of 460800 and you will be able to see the classification output of the model.
You can check the Machine Learning Model recognition accuracy by using the SensiML Test App.
I am currently facing issues with downloading the Knowledge pack so I could not make a working video at the moment. I've asked for help in the discussion forum. But I will try my best and upload the video when the knowledge pack is available.
Future updates- Due to the current lockdown in Sri Lanka, I was unable to purchase an Adafruit Huzzah32 - ESP32 Feather board.
In future, I would like to:
- Use this board with the QuickFeather development kit and turn this POC into an IoT POC.
- Test the Machine Learning model in various situations and feed variable data to the Machine Learning model to increase its accuracy.
- Experiment my Machine Learning model with a higher sampling frequency.
- Improve my project with a display to solar panel voltage output.
- Add a system to store and utilize the solar power instead of mains electricity.
- Find a way to automatically charge the Li-ion battery powering the QuickFeather development board.
Comments