Skip to content

Commit

Permalink
Initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
squix78 committed Mar 10, 2024
0 parents commit 744db22
Show file tree
Hide file tree
Showing 18 changed files with 650 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# documentation at https://docs.platformio.org/en/latest/integration/ci/github-actions.html

name: PlatformIO CI

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/.cache/pip
~/.platformio/.cache
key: ${{ runner.os }}-pio
- uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install PlatformIO Core
run: pip install --upgrade platformio

- name: Build PlatformIO Project
run: pio run
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
.DS_Store
10 changes: 10 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"files.associations": {
"functional": "cpp",
"tuple": "cpp",
"*._h": "cpp"
}
}
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
ThingPulse ePulse Feather C6
=================


Sample projects for [ThingPulse ePulse Feather C6](https://thingpulse.com/products/epulse-feather-c6/)
![ePulse C6](assets/img/epulse-c6.jpeg)

# Sample Projects

To build and run these sample projects follow these steps:
1. Install VS Code and install [Platformio](https://platformio.org/install/ide?install=vscode)
2. Checkout this repository and open it in VS Code
3. Select the sample project by clicking on env section in the footer:
![Environment Selector](assets/img/project.png)
4. Build and flash the sample by clicking on the right arrow in VS Code footer:
![Build & Flash](assets/img/build-flash.png)
5. Turn on serial monitor by clicking on the plug symbol:
![Monitor](assets/img/monitor.png)

## Fuel Gauge Simple

This example shows how to use the MAX17048 fuel gauge chip.

1. Preparation: connect a LiPo battery to the ePulse Feather C6. Make sure polarity of the battery
is correct-
2. Select `env:fuel-gauge-simple` to run this example. The `ESP32-C6` connects to the `MAX17048` chip
and reads battery voltage, state of charge (SoC) and change rate

### Links
* [MAX 17048 DataSheet](https://www.analog.com/media/en/technical-documentation/data-sheets/max17048-max17049.pdf)

## Fuel Gauge WiFi

This example shows how to use the MAX17048 fuel gauge chip. In addition to the previous example this code sends
the battery voltage and the SoC to the given HTTP server. We used a node-red instance with http node to receive
the values

1. Preparation: connect a LiPo battery to the ePulse Feather C6. Make sure polarity of the battery
is correct-
2. Select `env:fuel-gauge-wifi` to run this example. The `ESP32-C6` connects to the `MAX17048` chip
and reads battery voltage, state of charge (SoC) and change rate
3. Adjust WiFi ssid and password in `main-fuel-gauge-wifi.cpp`
4. Adjust host and port in the same file
5. Setup http server to receive GET requests

Here is an example flow of node red. It receives requests under /epulsec6, converts them and sends the message to influx:
![Monitor](assets/img/node-red.png?)

Content of the `convert message` node
```js
let payload = {};

payload.vBat = Number(msg.req.query.voltage);
payload.soc = Number(msg.req.query.soc);

let values = payload;
let tags = {};
tags.name = "epulse feather c6";
msg.payload = [values, tags];
return msg;
```

Binary file added assets/img/build-flash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/epulse-c6.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/monitor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/node-red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/project.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions include/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

This directory is intended for project header files.

A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.

```src/main.c

#include "header.h"

int main (void)
{
...
}
```

Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.

In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.

Read more about using header files in official GCC documentation:

* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes

https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
46 changes: 46 additions & 0 deletions lib/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.

The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").

For example, see a structure of the following two libraries `Foo` and `Bar`:

|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c

and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>

int main (void)
{
...
}

```

PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.

More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html
42 changes: 42 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[platformio]
;default_envs = deepsleep
default_envs = fuel-gauge-simple
;default_envs = battery-monitor
;default_envs = awake-consumption
;default_envs = charge-pin



[env]
platform = https://github.com/Jason2866/platform-espressif32.git#Arduino/IDF5

framework = arduino
board = esp32-c6-devkitc-1

monitor_speed = 115200
upload_speed = 921600
monitor_filters = esp32_exception_decoder, time
board_build.partitions = no_ota.csv
build_src_filter = +<*.h> +<main-${PIOENV}.cpp>
build_flags = -DCORE_DEBUG_LEVEL=5
-DARDUINO_USB_CDC_ON_BOOT=1
-DARDUINO_USB_MODE=1

[env:fuel-gauge-simple]
lib_deps = sparkfun/SparkFun MAX1704x Fuel Gauge Arduino Library@^1.0.4

[env:fuel-gauge-wifi]
lib_deps = sparkfun/SparkFun MAX1704x Fuel Gauge Arduino Library@^1.0.4




73 changes: 73 additions & 0 deletions src/main-fuel-gauge-simple.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// SPDX-FileCopyrightText: 2024 ThingPulse Ltd., https://thingpulse.com
// SPDX-License-Identifier: MIT

#include <Arduino.h>
#include <Wire.h> // Needed for I2C
#include <SparkFun_MAX1704x_Fuel_Gauge_Arduino_Library.h>
#include "settings.h"

SFE_MAX1704X lipo(MAX1704X_MAX17048); // Create a MAX17048


double voltage = 0; // Variable to keep track of LiPo voltage
double soc = 0; // Variable to keep track of LiPo state-of-charge (SOC)
bool alert; // Variable to keep track of whether alert has been triggered

void setup()
{
Serial.begin(115200); // Start serial, to output debug data
while (!Serial)
; //Wait for user to open terminal
Serial.println(F("MAX17043 Example"));

Wire.begin(PIN_I2C_SDA, PIN_I2C_SCL);

lipo.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial

// Set up the MAX17043 LiPo fuel gauge:
if (lipo.begin() == false) // Connect to the MAX17043 using the default wire port
{
Serial.println(F("MAX17043 not detected. Please check wiring. Freezing."));
while (1)
;
}

// Quick start restarts the MAX17043 in hopes of getting a more accurate
// guess for the SOC.
lipo.quickStart();

// We can set an interrupt to alert when the battery SoC gets too low.
// We can alert at anywhere between 1% - 32%:
lipo.setThreshold(20); // Set alert threshold to 20%.
}

void loop()
{
// lipo.getVoltage() returns a voltage value (e.g. 3.93)
voltage = lipo.getVoltage();
// lipo.getSOC() returns the estimated state of charge (e.g. 79%)
soc = lipo.getSOC();
// lipo.getAlert() returns a 0 or 1 (0=alert not triggered)
alert = lipo.getAlert();



// Print the variables:
Serial.print("Voltage: ");
Serial.print(voltage); // Print the battery voltage
Serial.println(" V");

Serial.print("Percentage: ");
Serial.print(soc); // Print the battery state of charge
Serial.println(" %");

Serial.print("Change Rate: ");
Serial.print(lipo.getChangeRate()); // Print the battery state of charge
Serial.println(" %/h");

Serial.print("Alert: ");
Serial.println(alert);
Serial.println();

delay(1000);
}
Loading

0 comments on commit 744db22

Please sign in to comment.