Skip to content

Commit

Permalink
Merge pull request #58 from Rocketct/master
Browse files Browse the repository at this point in the history
support to new board revision
  • Loading branch information
facchinm authored Oct 19, 2022
2 parents 2eaa5e8 + e66ce54 commit d8e0105
Show file tree
Hide file tree
Showing 15 changed files with 676 additions and 60 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/Compile Examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ jobs:
- name: Adafruit GFX Library
- name: Adafruit ST7735 and ST7789 Library
- name: Arduino_MCHPTouch
- name: BSEC Software Library
- name: Arduino_LSM6DSOX
- name: TFT_eSPI
sketch-paths: |
# Ignoring Display/AnimatedGif compiling the rest of them
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ category=Sensors
url=https://github.com/arduino-libraries/Arduino_MKRIoTCarrier
architectures=samd
precompiled=false
depends=Arduino_APDS9960,Arduino_BQ24195,Arduino_HTS221,Arduino_LPS22HB,Arduino_LSM6DS3,Adafruit BusIO,Adafruit DotStar,Adafruit GFX Library,Adafruit ST7735 and ST7789 Library,Arduino_MCHPTouch,TFT_eSPI
depends=Arduino_APDS9960,Arduino_BQ24195,Arduino_HTS221,Arduino_LPS22HB,Arduino_LSM6DS3,Arduino_LSM6DSOX,BSEC Software Library,Adafruit BusIO,Adafruit DotStar,Adafruit GFX Library,Adafruit ST7735 and ST7789 Library,Arduino_MCHPTouch,TFT_eSPI
45 changes: 36 additions & 9 deletions src/Arduino_MKRIoTCarrier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,37 @@ bool CARRIER_CASE = false;
MKRIoTCarrier::MKRIoTCarrier() {
}

int MKRIoTCarrier::_revision = -1;

int MKRIoTCarrier::begin() {

pinMode(AREF_PIN,INPUT_PULLUP);
if (digitalRead(AREF_PIN) == LOW) {
MKRIoTCarrier::_revision = BOARD_REVISION_2;
} else {
MKRIoTCarrier::_revision = BOARD_REVISION_1;
}

if (!CARRIER_CASE) {
Buttons.updateConfig(200);
}

//Display
if (_revision == BOARD_REVISION_2){
Adafruit_ST7789 _display = Adafruit_ST7789(mkr_iot_carrier_rev2::TFT_CS, mkr_iot_carrier_rev2::TFT_DC, -1);
display = _display;
} else {
Adafruit_ST7789 _display = Adafruit_ST7789(mkr_iot_carrier_rev1::TFT_CS, mkr_iot_carrier_rev1::TFT_DC, -1);
display = _display;
}

display.init(240, 240);//.begin(true); // Initialize ST7789 screen
pinMode(3,INPUT_PULLUP); // RESET fix

//Default rotation to align it with the carrier
display.setRotation(2);
display.fillScreen(ST77XX_BLACK);

if (!CARRIER_CASE) {
Buttons.updateConfig(200);
}

Buttons.begin(); //init buttons

//init LEDs
Expand All @@ -50,9 +68,13 @@ int MKRIoTCarrier::begin() {
//PMIC init
PMIC.begin();
PMIC.enableBoostMode();

Relay1.begin();
Relay2.begin();

//Sensors
uint8_t sensorsOK = !Light.begin() << 0 | !Pressure.begin() << 1 | !IMUmodule.begin() << 2 | !Env.begin() << 3;
uint8_t sensorsOK = !Light.begin() << 0 | !Pressure.begin() << 1 | !IMUmodule.begin() << 2 | !Env.begin() << 3;


//If some of the sensors are not connected
if(sensorsOK > 0 ){
Expand All @@ -66,16 +88,21 @@ int MKRIoTCarrier::begin() {
if(sensorsOK & 0b0100){
Serial.println("IMU is not connected");
}
if(sensorsOK & 0b1000){
Serial.println("Environmental sensor is not connected!");
if (MKRIoTCarrier::_revision != BOARD_REVISION_2) {
if(sensorsOK & 0b1000){
Serial.println("Environmental sensor is not connected!");
}
}
return false;
}
Relay1.begin();
Relay2.begin();

if(!SD.begin(SD_CS)) {
Serial.println("Sd card not detected");
}

return true;
}

int MKRIoTCarrier::getBoardRevision() {
return MKRIoTCarrier::_revision;
}
71 changes: 28 additions & 43 deletions src/Arduino_MKRIoTCarrier.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,11 @@
#define ARDUINO_MKRIoTCarrier_h

#include <Arduino.h>
#include <Wire.h>
#include <MKRIoTCarrierDefines.h>

#include <Arduino_PMIC.h> //PMIC

//Sensor libraries
#include <Arduino_APDS9960.h> //Ambient light
#include <Arduino_LPS22HB.h> //Pressure sensor
#include <Arduino_LSM6DS3.h> //IMU
#include <Arduino_HTS221.h> // env sensor

#include <Arduino_MKRIoTCarrier_Relay.h> //Relays
#include <Arduino_MKRIoTCarrier_Buzzer.h>//Buzzer
#include <Arduino_MKRIoTCarrier_Qtouch.h>//Buttons
#include <SD.h> //SD card

//Display
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>
#include <IMUClass.h> //IMU
#include <PressureClass.h> //IMU
#include <EnvClass.h> //IMU

//RGB LEDs
#include <Adafruit_DotStar.h>
Expand All @@ -50,29 +35,18 @@
#define CLOCKPIN 4

//Taken from the carrier schematics
#define RELAY_1 14
#define RELAY_2 13

#define BUZZER 7

#define GROVE_AN1 A5
#define GROVE_AN2 A6

#define SD_CS 0

#define Y0 A0
#define Y1 A1
#define Y2 A2
#define Y3 A3
#define Y4 A4

#define INT 6 //Every sensor interrupt pin , PULL-UP

#define LED_CKI 4
#define LED_SDI 5

#define TFT_CS 2
#define TFT_RST -1 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC 1
#define TFT_BACKLIGHT 3

//Touch pads values for using the case or just directly on the board
Expand All @@ -88,43 +62,54 @@ enum {
RIGHT = 0
};

typedef enum {
RELAY_1 = 1,
RELAY_2
} Relay_t;

class MKRIoTCarrier{
public:
MKRIoTCarrier();
int begin();
static int getBoardRevision();

// Case
void withCase() { CARRIER_CASE = true; };
void noCase() { CARRIER_CASE = false; };

//Sensors
APDS9960& Light = APDS;
LPS22HBClass& Pressure = BARO;
LSM6DS3Class& IMUmodule = IMU;
HTS221Class& Env = HTS;
PressureClass Pressure{MKRIoTCarrier::getBoardRevision};
IMUClass IMUmodule{MKRIoTCarrier::getBoardRevision};
EnvClass Env{MKRIoTCarrier::getBoardRevision};

//Misc
//Relays
MKRIoTCarrier_Relay Relay1 = MKRIoTCarrier_Relay(RELAY_1); //Relay 1 , pin 14
MKRIoTCarrier_Relay Relay2 = MKRIoTCarrier_Relay(RELAY_2); //Relay 2 , pin 13
MKRIoTCarrier_Relay Relay1 = MKRIoTCarrier_Relay{RELAY_1,MKRIoTCarrier::getBoardRevision};
MKRIoTCarrier_Relay Relay2 = MKRIoTCarrier_Relay{RELAY_2,MKRIoTCarrier::getBoardRevision};

//Buzzer
MKRIoTCarrier_Buzzer Buzzer = MKRIoTCarrier_Buzzer(BUZZER); //Buzzer, pin 6

//Buttons
MKRIoTCarrierQtouch Buttons = MKRIoTCarrierQtouch();
MKRIoTCarrierQtouch Buttons{MKRIoTCarrier::getBoardRevision};


MKRIoTCarrierQtouch Button0 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH0);
MKRIoTCarrierQtouch Button1 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH1);
MKRIoTCarrierQtouch Button2 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH2);
MKRIoTCarrierQtouch Button3 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH3);
MKRIoTCarrierQtouch Button4 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH4);
MKRIoTCarrierQtouch Button0 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH0,MKRIoTCarrier::getBoardRevision);
MKRIoTCarrierQtouch Button1 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH1,MKRIoTCarrier::getBoardRevision);
MKRIoTCarrierQtouch Button2 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH2,MKRIoTCarrier::getBoardRevision);
MKRIoTCarrierQtouch Button3 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH3,MKRIoTCarrier::getBoardRevision);
MKRIoTCarrierQtouch Button4 __attribute__((deprecated)) = MKRIoTCarrierQtouch(TOUCH4,MKRIoTCarrier::getBoardRevision);

//Display
Adafruit_ST7789 display = Adafruit_ST7789(TFT_CS, TFT_DC, -1);
Adafruit_ST7789 display = Adafruit_ST7789(-1, -1, -1);

//RGB LEDs
Adafruit_DotStar leds = Adafruit_DotStar(NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BGR);
private:
static int _revision;
int _relay1_pin;
int _relay2_pin;
};

#endif
26 changes: 25 additions & 1 deletion src/Arduino_MKRIoTCarrier_Qtouch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@ MKRIoTCarrierQtouch::MKRIoTCarrierQtouch() {
}

//Individual pad
MKRIoTCarrierQtouch::MKRIoTCarrierQtouch(touchButtons padIndex) {
MKRIoTCarrierQtouch::MKRIoTCarrierQtouch(touchButtons padIndex,getRev_t getRevision) {
_padID = padIndex;
board_revision = getRevision;
}

// sets function called on slave write
MKRIoTCarrierQtouch::MKRIoTCarrierQtouch(getRev_t getRevision)
{
//If board_revision = 0, IMU module is LSM6DSOX, otherwise is LSM6DS3
board_revision = getRevision;
}

bool MKRIoTCarrierQtouch::getTouch(touchButtons padIndex) {
Expand Down Expand Up @@ -93,6 +101,22 @@ void MKRIoTCarrierQtouch::updateConfig(int newSens, touchButtons padIndex) {

//Manager
bool MKRIoTCarrierQtouch::begin() {
// FIXME: TODO: check that passing revision makes sense
_revision = board_revision();
if (_revision == BOARD_REVISION_2){
TOUCH.setTouchPad(mkr_iot_carrier_rev2::Y0,
mkr_iot_carrier_rev2::Y1,
mkr_iot_carrier_rev2::Y2,
mkr_iot_carrier_rev2::Y3,
mkr_iot_carrier_rev2::Y4);

} else {
TOUCH.setTouchPad(mkr_iot_carrier_rev1::Y0,
mkr_iot_carrier_rev1::Y1,
mkr_iot_carrier_rev1::Y2,
mkr_iot_carrier_rev1::Y3,
mkr_iot_carrier_rev1::Y4);
}
return TOUCH.begin();
}

Expand Down
6 changes: 5 additions & 1 deletion src/Arduino_MKRIoTCarrier_Qtouch.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "Arduino.h"
#include "Arduino_MCHPTouch.h"
#include <MKRIoTCarrierDefines.h>

static bool _available = false;

Expand All @@ -37,7 +38,8 @@ typedef enum {
class MKRIoTCarrierQtouch{
public:
MKRIoTCarrierQtouch();
MKRIoTCarrierQtouch(touchButtons padIndex);
MKRIoTCarrierQtouch(int (*)(void));
MKRIoTCarrierQtouch(touchButtons padIndex,int (*)(void));
bool begin();
bool update();

Expand All @@ -59,6 +61,8 @@ class MKRIoTCarrierQtouch{
touchButtons _padID;
int _padIndex;

int (*board_revision)(void);
int _revision;

bool _touchesPrev[5] = {0, 0, 0, 0, 0}; //To know last touches

Expand Down
28 changes: 25 additions & 3 deletions src/Arduino_MKRIoTCarrier_Relay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,34 @@


#include "Arduino_MKRIoTCarrier_Relay.h"
#include "MKRIoTCarrierDefines.h"

MKRIoTCarrier_Relay::MKRIoTCarrier_Relay(int pin):_pin{pin}
MKRIoTCarrier_Relay::MKRIoTCarrier_Relay(int index, getRev_t getRev):_index{index}
{
board_revision = getRev;
}
void MKRIoTCarrier_Relay::begin(){

_revision = board_revision();

if(_revision == BOARD_REVISION_1)
{
if(_index == 1) {
_pin = mkr_iot_carrier_rev1::RELAY1;
}
else if(_index == 2) {
_pin = mkr_iot_carrier_rev1::RELAY2;
}
}
else {
/*carrier's revision 2 with pull down on AREF */
if(_index == 1) {
_pin = mkr_iot_carrier_rev2::RELAY1;
}
else if(_index == 2) {
_pin = mkr_iot_carrier_rev2::RELAY2;
}
}
pinMode(_pin ,OUTPUT);
close();
}
Expand All @@ -44,7 +67,6 @@ void MKRIoTCarrier_Relay::open(){
}

int MKRIoTCarrier_Relay::getStatus(){
//Serial.println("status");
//Serial.println(_status , BIN);

return (int)_status;
}
8 changes: 6 additions & 2 deletions src/Arduino_MKRIoTCarrier_Relay.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,23 @@
#define ARDUINO_MKRIoTCarrier_Relay

#include "Arduino.h"
using getRev_t = int (*)();

class MKRIoTCarrier_Relay{
public:
MKRIoTCarrier_Relay(int pin);
MKRIoTCarrier_Relay(int index, getRev_t getRev);
void begin();
void open();
void close();
int getPin();
int getStatus();

private:
const int _pin;
int _pin;
int _status;
int _index;
int (*board_revision)(void);
int _revision;
};

#endif
Loading

0 comments on commit d8e0105

Please sign in to comment.