Skip to content

Commit

Permalink
CS5460 Arduino library (#2106)
Browse files Browse the repository at this point in the history
* Add CS5460 submodule
* Add CS5460 component.mk file with default MISO value
* Add CS5460 sample
* Simplified Arduino include change.
  • Loading branch information
kmihaylov authored Sep 14, 2020
1 parent 77a054e commit a889336
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 0 deletions.
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>
+#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

0 comments on commit a889336

Please sign in to comment.