Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CS5460 Arduino library #2106

Merged
merged 6 commits into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,8 @@
path = Sming/Libraries/modbusino/modbusino
url = https://github.com/kmihaylov/modbusino.git
ignore = dirty
[submodule "Libraries.CS5460"]
path = Sming/Libraries/CS5460/CS5460
url = https://github.com/xxzl0130/CS5460.git
ignore = dirty

1 change: 1 addition & 0 deletions Sming/Libraries/CS5460/CS5460
Submodule CS5460 added at 9a3e56
13 changes: 13 additions & 0 deletions Sming/Libraries/CS5460/CS5460.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/CS5460.h b/CS5460.h
index 0fbbb5b..fe7ff1d 100644
--- a/CS5460.h
+++ b/CS5460.h
@@ -1,7 +1,7 @@
#ifndef __CS5460_H__
#define __CS5460_H__

-#include <arduino.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try to replace <arduino.h> with <Arduino.h> and see if the library compiles and works?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating it!

+#include <Arduino.h>
#include <stdint.h>
#include <SPI.h>

7 changes: 7 additions & 0 deletions Sming/Libraries/CS5460/component.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
COMPONENT_SUBMODULES := CS5460
COMPONENT_SRCDIRS := CS5460
COMPONENT_INCDIRS := CS5460

COMPONENT_VARS += MISO
MISO ?= 12
COMPONENT_CXXFLAGS += -DMISO=$(MISO)
9 changes: 9 additions & 0 deletions Sming/Libraries/CS5460/samples/generic/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#####################################################################
#### Please don't change this file. Use component.mk instead ####
#####################################################################

ifndef SMING_HOME
$(error SMING_HOME is not set: please configure it as an environment variable)
endif

include $(SMING_HOME)/project.mk
14 changes: 14 additions & 0 deletions Sming/Libraries/CS5460/samples/generic/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CS5460 generic sample
=====================

.. highlight:: bash

The sample prints the measured RMS voltage each second (with CS5460 voltage and current filters enabled).

The default MISO pin (12) can be changed through the envvar:`MISO` variable. For example::

make MISO=13

These variables can be listed with::

make list-config
Empty file.
29 changes: 29 additions & 0 deletions Sming/Libraries/CS5460/samples/generic/app/application.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <SmingCore.h>
#include <Debug.h>
#include <CS5460.h>

CS5460 powerMeter(PIN_NDEFINED, PIN_NDEFINED, PIN_NDEFINED, PIN_NDEFINED);

Timer printVoltageTimer;

void printVoltage()
{
debugf("Measured RMS voltage is: %f", powerMeter.getRMSVoltage());
}

void init()
{
Serial.begin(SERIAL_BAUD_RATE, SERIAL_8N1,
SERIAL_FULL); // 115200 by default, GPIO1,GPIO3, see Serial.swap(), HardwareSerial
Serial.systemDebugOutput(true);
Debug.setDebug(Serial);

powerMeter.init();
powerMeter.setCurrentGain(190.84); //0.25 / shunt (0.00131)
powerMeter.setVoltageGain(500); //0.25V (Veff max) * dividerGain
powerMeter.writeRegister(CONFIG_REGISTER, ENABLE_CURRENT_HPF);
powerMeter.writeRegister(CONFIG_REGISTER, ENABLE_VOLTAGE_HPF);
powerMeter.startMultiConvert();

printVoltageTimer.initializeMs(1000, printVoltage).start();
}
2 changes: 2 additions & 0 deletions Sming/Libraries/CS5460/samples/generic/component.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ARDUINO_LIBRARIES := CS5460
DISABLE_SPIFFS = 1