From a32995279500615735025ee6913e6cee7b41cfcd Mon Sep 17 00:00:00 2001 From: Slavey Karadzhov Date: Mon, 2 May 2022 16:35:08 +0200 Subject: [PATCH] Initial untested version. --- .gitmodules | 4 + Sming/Libraries/AMG8833/Melopero_AMG8833 | 1 + Sming/Libraries/AMG8833/README.rst | 33 ++++++ Sming/Libraries/AMG8833/component.mk | 4 + .../samples/TemperatureMatrix/Makefile | 9 ++ .../samples/TemperatureMatrix/README.rst | 12 ++ .../AMG8833/samples/TemperatureMatrix/app/.cs | 0 .../TemperatureMatrix/app/application.cpp | 103 ++++++++++++++++++ .../samples/TemperatureMatrix/component.mk | 1 + 9 files changed, 167 insertions(+) create mode 160000 Sming/Libraries/AMG8833/Melopero_AMG8833 create mode 100644 Sming/Libraries/AMG8833/README.rst create mode 100644 Sming/Libraries/AMG8833/component.mk create mode 100644 Sming/Libraries/AMG8833/samples/TemperatureMatrix/Makefile create mode 100644 Sming/Libraries/AMG8833/samples/TemperatureMatrix/README.rst create mode 100644 Sming/Libraries/AMG8833/samples/TemperatureMatrix/app/.cs create mode 100644 Sming/Libraries/AMG8833/samples/TemperatureMatrix/app/application.cpp create mode 100644 Sming/Libraries/AMG8833/samples/TemperatureMatrix/component.mk diff --git a/.gitmodules b/.gitmodules index 7607e1ac02..375f453473 100644 --- a/.gitmodules +++ b/.gitmodules @@ -285,6 +285,10 @@ path = Sming/Libraries/ModbusMaster/ModbusMaster url = https://github.com/nomis/ModbusMaster.git ignore = dirty +[submodule "Libraries.Melopero_AMG8833"] + path = Sming/Libraries/AMG8833/Melopero_AMG8833 + url = https://github.com/melopero/Melopero_AMG8833_Arduino_Library.git + ignore = dirty [submodule "Libraries.MCP_CAN_lib"] path = Sming/Libraries/MCP_CAN_lib url = https://github.com/coryjfowler/MCP_CAN_lib.git diff --git a/Sming/Libraries/AMG8833/Melopero_AMG8833 b/Sming/Libraries/AMG8833/Melopero_AMG8833 new file mode 160000 index 0000000000..b144e5a1dd --- /dev/null +++ b/Sming/Libraries/AMG8833/Melopero_AMG8833 @@ -0,0 +1 @@ +Subproject commit b144e5a1dd2a50a3e56d7394602eb8454ac613d0 diff --git a/Sming/Libraries/AMG8833/README.rst b/Sming/Libraries/AMG8833/README.rst new file mode 100644 index 0000000000..7bd67dc2b5 --- /dev/null +++ b/Sming/Libraries/AMG8833/README.rst @@ -0,0 +1,33 @@ +AMG8833 +======= + +.. highlight:: c++ + +Introduction +------------ + +A library to communicate with the cheap `thermal sensor AMG8833 `_. + +Using +----- + +1. Add ``COMPONENT_DEPENDS += AMG8833`` to your application componenent.mk file. +2. Add these lines to your application:: + + #include + + namespace + { + Melopero_AMG8833 sensor; + + // ... + + } // namespace + + void init() + { + Wire.begin(); + sensor.initI2C(); + + // ... + } diff --git a/Sming/Libraries/AMG8833/component.mk b/Sming/Libraries/AMG8833/component.mk new file mode 100644 index 0000000000..c9509b88a0 --- /dev/null +++ b/Sming/Libraries/AMG8833/component.mk @@ -0,0 +1,4 @@ +COMPONENT_SUBMODULES := Melopero_AMG8833 + +COMPONENT_SRCDIRS := $(COMPONENT_SUBMODULES)/src +COMPONENT_INCDIRS := $(COMPONENT_SRCDIRS) diff --git a/Sming/Libraries/AMG8833/samples/TemperatureMatrix/Makefile b/Sming/Libraries/AMG8833/samples/TemperatureMatrix/Makefile new file mode 100644 index 0000000000..ff51b6c3a7 --- /dev/null +++ b/Sming/Libraries/AMG8833/samples/TemperatureMatrix/Makefile @@ -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 diff --git a/Sming/Libraries/AMG8833/samples/TemperatureMatrix/README.rst b/Sming/Libraries/AMG8833/samples/TemperatureMatrix/README.rst new file mode 100644 index 0000000000..dcedaf8797 --- /dev/null +++ b/Sming/Libraries/AMG8833/samples/TemperatureMatrix/README.rst @@ -0,0 +1,12 @@ +Temperature Matrix +================== + +A simple demonstrating to how to handle interrupts with the Melopero AMG8833 sensor. +The sensor communicates through I2C. Connection scheme:: + + Microcontroller ----------- Melopero AMG8833 + 3.3V ----------- VIN + GND ----------- GND + SCL ----------- SCL + SDA ----------- SDA + a valid INT Pin----------- INT \ No newline at end of file diff --git a/Sming/Libraries/AMG8833/samples/TemperatureMatrix/app/.cs b/Sming/Libraries/AMG8833/samples/TemperatureMatrix/app/.cs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Sming/Libraries/AMG8833/samples/TemperatureMatrix/app/application.cpp b/Sming/Libraries/AMG8833/samples/TemperatureMatrix/app/application.cpp new file mode 100644 index 0000000000..34be230d78 --- /dev/null +++ b/Sming/Libraries/AMG8833/samples/TemperatureMatrix/app/application.cpp @@ -0,0 +1,103 @@ +#include +#include + +Melopero_AMG8833 sensor; + +namespace +{ +const byte interruptPin = 2; + +Timer procTimer; +bool state = true; + +bool interruptOccurred = false; + +//The high and low temperature thresholds. If a temperature that exceeds +//these values is detected an interrupt will be triggered. The temperatures +//are expressed in Celsius degrees. +float highThreshold = 26.5; +float lowThreshold = 10; + +void onInterrupt() +{ + interruptOccurred = true; +} + +void loop() +{ + //Update the sensors thermistor temperature and print it. + Serial.print("Updating thermistor temperature ... "); + int statusCode = sensor.updateThermistorTemperature(); + Serial.println(sensor.getErrorDescription(statusCode)); + + Serial.print("Thermistor temp: "); + Serial.print(sensor.thermistorTemperature); + Serial.println("°C"); + + //Check if an interrupt occurred. + //The interrupt occurred flag gets set by the interrupt service routine + //each time an interrupt is triggered. + if(interruptOccurred) { + interruptOccurred = false; + Serial.println("Interrupt triggered!"); + + //Update the interrupt matrix to know which pixels triggered the interrupt. + Serial.print("Updating interrupt matrix ... "); + statusCode = sensor.updateInterruptMatrix(); + Serial.println(sensor.getErrorDescription(statusCode)); + + //Print out the interrupt matrix. + Serial.println("Interrupt Matrix: "); + for(int x = 0; x < 8; x++) { + for(int y = 0; y < 8; y++) { + Serial.print(sensor.interruptMatrix[y][x]); + Serial.print(" "); + } + Serial.println(); + } + } +} + +} // namespace + +void init() +{ + Wire.begin(); + sensor.initI2C(); + // To use Wire1 (I2C-1): + // Wire1.begin(); + // sensor.initI2C(AMG8833_I2C_ADDRESS_B, Wire1); + + //Reset the device flags and settings and read the returned status code. + Serial.print("Resetting sensor ... "); + int statusCode = sensor.resetFlagsAndSettings(); + + //Check if there were any problems. + Serial.println(sensor.getErrorDescription(statusCode)); + + //Setting the FPS_MODE this can be: FPS_MODE::FPS_10 or FPS_MODE::FPS_1 + Serial.print("Setting FPS ... "); + statusCode = sensor.setFPSMode(FPS_MODE::FPS_10); + Serial.println(sensor.getErrorDescription(statusCode)); + + //Setting the threshold values + Serial.print("Setting threshold values ... "); + statusCode = sensor.setInterruptThreshold(lowThreshold, highThreshold); + Serial.println(sensor.getErrorDescription(statusCode)); + Serial.print("low threshold : "); + Serial.print(lowThreshold); + Serial.print(" high threshold : "); + Serial.println(highThreshold); + + //Enable the interrupt. + Serial.print("Enabling interrupt ... "); + statusCode = sensor.enableInterrupt(); + Serial.println(sensor.getErrorDescription(statusCode)); + + //Configuring the interrupt pin to listen for the interrupt. + pinMode(interruptPin, INPUT_PULLUP); + //Attaching our function onInterrupt to the interrupt. + attachInterrupt(interruptPin, onInterrupt, CHANGE); + + procTimer.initializeMs(100, loop).start(); +} diff --git a/Sming/Libraries/AMG8833/samples/TemperatureMatrix/component.mk b/Sming/Libraries/AMG8833/samples/TemperatureMatrix/component.mk new file mode 100644 index 0000000000..4ec626969b --- /dev/null +++ b/Sming/Libraries/AMG8833/samples/TemperatureMatrix/component.mk @@ -0,0 +1 @@ +COMPONENT_DEPENDS := AMG8833