Skip to content

Commit

Permalink
Initial untested version.
Browse files Browse the repository at this point in the history
  • Loading branch information
slav-at-attachix committed Jul 1, 2022
1 parent 2758617 commit 96a39b7
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Sming/Libraries/AMG8833/Melopero_AMG8833
Submodule Melopero_AMG8833 added at b144e5
33 changes: 33 additions & 0 deletions Sming/Libraries/AMG8833/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
AMG8833
=======

.. highlight:: c++

Introduction
------------

A library to communicate with the cheap `thermal sensor AMG8833 <https://mediap.industry.panasonic.eu/assets/imported/industrial.panasonic.com/cdbs/www-data/pdf/ADI8000/ADI8000C66.pdf>`_.

Using
-----

1. Add ``COMPONENT_DEPENDS += AMG8833`` to your application componenent.mk file.
2. Add these lines to your application::

#include <Melopero_AMG8833.h>
namespace
{
Melopero_AMG8833 sensor;
// ...
} // namespace
void init()
{
Wire.begin();
sensor.initI2C();
// ...
}
4 changes: 4 additions & 0 deletions Sming/Libraries/AMG8833/component.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
COMPONENT_SUBMODULES := Melopero_AMG8833

COMPONENT_SRCDIRS := $(COMPONENT_SUBMODULES)/src
COMPONENT_INCDIRS := $(COMPONENT_SRCDIRS)
9 changes: 9 additions & 0 deletions Sming/Libraries/AMG8833/samples/TemperatureMatrix/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
12 changes: 12 additions & 0 deletions Sming/Libraries/AMG8833/samples/TemperatureMatrix/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Temperature Matrix
==================

A simple demonstrating 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
Empty file.
103 changes: 103 additions & 0 deletions Sming/Libraries/AMG8833/samples/TemperatureMatrix/app/application.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#include <SmingCore.h>
#include <Melopero_AMG8833.h>

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();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
COMPONENT_DEPENDS := AMG8833

0 comments on commit 96a39b7

Please sign in to comment.