Skip to content

Commit

Permalink
add Flip-n-Click Arduino example
Browse files Browse the repository at this point in the history
  • Loading branch information
moxondesign committed Aug 7, 2016
1 parent 2962e00 commit 3d07a14
Show file tree
Hide file tree
Showing 18 changed files with 391 additions and 0 deletions.
65 changes: 65 additions & 0 deletions examples/Flip_n_Click/Embedis_Due/Embedis_Due.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* Embedis - Embedded Dictionary Server
Copyright (C) 2015 PatternAgents, LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <Embedis.h>

// Embedis will run on the Serial port. Use the Arduino
// serial monitor and send "COMMANDS" to get started.
// Make sure "No line ending" is -not- selected. All others work.
Embedis embedis(Serial);

void setup()
{
Serial.begin(115200);
delay(50);
LOG( String() + F(" ") );
LOG( String() + F("[ Embedis Flip-n-Click (Arduino Due) Sketch ]") );

// "FLASH" is the internal Flash memory of the Arduino Due Processor
setup_FLASH();

// Add the SPI FRAM Click Board in Socket C
setup_SPI_FRAM();

// Add the I2C EEPROM Click Board in Socket D
setup_I2C_EEPROM();

// Add some useful commands
setup_commands();
LOG( String() + F("[ type 'commands' to get a list... ]") );
}

void loop()
{
embedis.process();
delay(20);
}

// This will log to an embedis channel called "log".
// Use SUBSCRIBE LOG to get these messages.
// Logs are also printed to Serial until an empty message is received.
void LOG(const String& message) {
static bool inSetup = true;
if (inSetup) {
if (!message.length()) {
inSetup = false;
return;
}
SERIAL_PORT_MONITOR.println(message);
}
Embedis::publish("log", message);
}
35 changes: 35 additions & 0 deletions examples/Flip_n_Click/Embedis_Due/FLASH.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* Embedis - Embedded Dictionary Server
Copyright (C) 2015 PatternAgents, LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* FLASH for Arduino Due */
#include <DueFlashStorage.h>
DueFlashStorage FlashDue;

void setup_FLASH()
{
setup_FLASH( F("FLASH") );
}

void setup_FLASH(const String& dict)
{
Embedis::dictionary( dict,
1024,
[](size_t pos) -> char { return FlashDue.read(pos); },
[](size_t pos, char value) { FlashDue.write(pos, value); },
[]() { }
);
}
46 changes: 46 additions & 0 deletions examples/Flip_n_Click/Embedis_Due/I2C_EEPROM.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* Embedis - Embedded Dictionary Server
Copyright (C) 2015 PatternAgents, LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* extEEPROM Library from: https://github.com/PaoloP74/extEEPROM */
#include <extEEPROM.h>

/* define the device size, number of devices, page size */
#define I2C_EEPROM_SIZE 8192
extEEPROM ext_i2c_eeprom(kbits_64, 1, 32);

void setup_I2C_EEPROM()
{
setup_I2C_EEPROM( F("I2C_EEPROM") );
}

void setup_I2C_EEPROM(const String& dict)
{
uint8_t ext_i2c_eepromStatus = ext_i2c_eeprom.begin(twiClock400kHz);
if (ext_i2c_eepromStatus) {
LOG( String() + F("[ No I2C_EEPROM found ... check your connections and address setting! ]") );
} else {
LOG( String() + F("[ Found I2C_EEPROM ]") );
}

Embedis::dictionary( dict,
(I2C_EEPROM_SIZE),
[](size_t pos) -> char { return ext_i2c_eeprom.read(pos); },
[](size_t pos, char value) { ext_i2c_eeprom.write(pos, value); },
[]() { }
);
}

72 changes: 72 additions & 0 deletions examples/Flip_n_Click/Embedis_Due/SPI_FRAM.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* Embedis - Embedded Dictionary Server
Copyright (C) 2015 PatternAgents, LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* FRAM_Click */

#include "flip_n_click_pins.h"

/* FRAM CLICK Pin Assignment
* FRAM installed in Socket "C" on the Flip-n-Click Board
*
* To install in Socket "A", just change the "C" suffix to "A"
* i.e. FRAM_CS = CSNA;
* FRAM_SCK = SCKA;
* FRAM_MISO = MISOA;
* FRAM_MOSI = MOSIA;
*/
uint8_t FRAM_CS = CSNC; /* FRAM Chip Select */
uint8_t FRAM_SCK = SCKC; /* FRAM Clock */
uint8_t FRAM_MISO = MISOC; /* FRAM Master Out */
uint8_t FRAM_MOSI = MOSIC; /* FRAM Mater In */
uint8_t FRAM_HOLD = RSTSC; /* FRAM HOLD */
uint8_t FRAM_WRTP = PWMC; /* FRAM Write Protect */
uint32_t FRAM_SIZE = 32768; /* MB85RS256 is 256K bits or 32768 x 8 bits*/

#include <SPI.h>
#include "Adafruit_FRAM_SPI.h"

/* Create the Adafruit_FRAM_SPI instance */
//Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_CS); /* use hardware SPI */
Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_SCK, FRAM_MISO, FRAM_MOSI, FRAM_CS); /* use software SPI */

void setup_SPI_FRAM()
{
setup_SPI_FRAM( F("SPI_FRAM") );
}

void setup_SPI_FRAM(const String& dict)
{
/* Configure the FRAM control pins correctly */
pinMode(FRAM_HOLD, OUTPUT);
digitalWrite(FRAM_HOLD, HIGH);
pinMode(FRAM_WRTP, OUTPUT);
digitalWrite(FRAM_WRTP, HIGH);
if (fram.begin()) {
LOG( String() + F("[ Found SPI_FRAM ]") );
fram.writeEnable(false);
} else {
LOG( String() + F("[ No SPI_FRAM found ... check your connections and address setting! ]") );
while (1);
}

Embedis::dictionary( dict,
(FRAM_SIZE),
[](size_t pos) -> char { return fram.read8(pos); },
[](size_t pos, char value) { fram.writeEnable(true); fram.write8(pos, value); fram.writeEnable(false); },
[]() { }
);
}
75 changes: 75 additions & 0 deletions examples/Flip_n_Click/Embedis_Due/commands.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* Embedis - Embedded Dictionary Server
Copyright (C) 2015, 2016 PatternAgents, LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

// Adds some useful commands to Embedis.
// We'll add some Arduino I/O commands for making it interpretive...
//
// Call setup_commands from your main setup() function.
// e.g. setup_commands();

//#include <StreamString.h>

void setup_commands()
{
/* create an interactive "pinMode" command */
Embedis::command( F("pinMode"), [](Embedis* e) {
if (e->argc != 3) return e->response(Embedis::ARGS_ERROR);
int pin = String(e->argv[1]).toInt();
String argv2(e->argv[2]);
argv2.toUpperCase();
int mode;
if (argv2 == "INPUT") mode = INPUT;
else if (argv2 == "OUTPUT") mode = OUTPUT;
else if (argv2 == "INPUT_PULLUP") mode = INPUT_PULLUP;
else return e->response(Embedis::ARGS_ERROR);
pinMode(pin, mode);
e->response(Embedis::OK);
});

/* create an interactive "digitalWrite" command */
Embedis::command( F("digitalWrite"), [](Embedis* e) {
if (e->argc != 3) return e->response(Embedis::ARGS_ERROR);
int pin = String(e->argv[1]).toInt();
String argv2(e->argv[2]);
argv2.toUpperCase();
int mode;
if (argv2 == "HIGH") mode = HIGH;
else if (argv2 == "LOW") mode = LOW;
else mode = argv2.toInt();
digitalWrite(pin, mode);
e->response(Embedis::OK);
});

/* create an interactive "digitalRead" command */
Embedis::command( F("digitalRead"), [](Embedis* e) {
if (e->argc != 2) return e->response(Embedis::ARGS_ERROR);
int pin = String(e->argv[1]).toInt();
if (digitalRead(pin)) {
e->response(F("HIGH"));
} else {
e->response(F("LOW"));
}
});

/* create an interactive "analogRead" command */
Embedis::command( F("analogRead"), [](Embedis* e) {
if (e->argc != 2) return e->response(Embedis::ARGS_ERROR);
int pin = String(e->argv[1]).toInt();
e->response(':', analogRead(pin));
});

}
98 changes: 98 additions & 0 deletions examples/Flip_n_Click/Embedis_Due/flip_n_click_pins.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Pin Out Definition for Mikroe Flip-n-Click
* ==========================================
*
* Pin Assignment for Mikroe Flip-n-Click Board Revision 1.0
*
* We'll use the schematic node names as our pin names where it makes sense.
* (this should really be put into a varient of arduino_pins.h after testing)
*
* http://www.mikroe.com/download/eng/documents/development-tools/accessory-boards/click/flip-n-click/flip-n-click-v100.manual.web.pdf
*
*/

/* Pin Out for Bottom Arduino Shield Connector
*/
#define RX_USB 0 /* PA8 : RX : Arduino Due D0 : FTDI USB Serial (Don't use for Input/Output) */
#define TX_USB 1 /* PA9 : TX: : Arduino Due D1 : FTDI USB Serial (Don't use for Input/Output) */
#define PWM2 2 /* PB25 : PWM2 : Arduino Due D2 : */
#define PWM3 3 /* PC28 : PWM3 : Arduino Due D3 : */
#define PWM4 4 /* PA29 : PWM4 : Arduino Due D4 : Due also connects PC26? test which one */
#define PWM5 5 /* PC25 : PWM5 : Arduino Due D5 : */
#define PWM6 6 /* PC24 : PWM6 : Arduino Due D6 : */
#define PWM7 7 /* PC23 : PWM7 : Arduino Due D7 : */
#define PWM8 8 /* PC22 : PWM8 : Arduino Due D8 : */
#define PWM9 9 /* PC21 : PWM9 : Arduino Due D9 : */
#define PWM10 10 /* PC29 : PWM10 : Arduino Due D10 : Due also connects PA28? */
#define PWM11 11 /* PD7 : PWM11 : Arduino Due D11 : */
#define PWM12 12 /* PD8 : PWM12 : Arduino Due D12 : */
#define PWM13 13 /* PB27 : PWM13 : Arduino Due D13 : LED_BULITIN */
#define SDA0 70 /* PA17 : I2C0_SDA : Arduino Due SDA : */
#define SCL0 71 /* PA18 : I2C0_SCL : Arduino Due SCL : */
#define AREF -1 /* NC : NC : Arduino Due AREF : AREF is floating? */
#define AD0 54 /* PA16 : AD0 : Arduino Due A0 : */
#define AD1 55 /* PA24 : AD1 : Arduino Due A1 : */
#define AD2 56 /* PA23 : AD2 : Arduino Due A2 : */
#define AD3 57 /* PA22 : AD3 : Arduino Due A3 : */
#define AD4 58 /* PA6 : AD4 : Arduino Due A4 : */
#define AD5 59 /* PA4 : AD5 : Arduino Due A5 : */

/* Pinout for Click Socket A
*/
#define LEDA 38 /* PC6 : LEDA : Arduino Due D38 : */
#define SDAA 70 /* PA17 : I2C0_SDA : Arduino Due SDA : */
#define SCLA 71 /* PA18 : I2C0_SCL : Arduino Due SCL : */
#define TXDA 18 /* PA11 : TXD0 : Arduino Due TX1 : Serial1 */
#define RXDA 19 /* PA10 : RXD0 : Arduino Due RX1 : Serial1 */
#define PWMA 6 /* PC24 : PWM6 : Arduino Due D6 : */
#define ANAA 54 /* PA16 : AD0 : Arduino Due A0 : */
#define RSTA 33 /* PC1 : RSTA : Arduino Due D33 : */
#define CSNA 77 /* PA28 : SPI0_CS0 : Arduino Due CS0 : */
#define SCKA 76 /* PA27 : SPI0_SCK : Arduino Due SCK : */
#define MISOA 74 /* PA25 : SPI0_MISO : Arduino Due MISO : */
#define MOSIA 75 /* PA26 : SPI0_MOSI : Arduino Due MOSI : */

/* Pinout for Click Socket B
*/
#define LEDB 37 /* PC5 : LEDB : Arduino Due D37 : */
#define SDAB 70 /* PA17 : I2C0_SDA : Arduino Due SDA : */
#define SCLB 71 /* PA18 : I2C0_SCL : Arduino Due SCL : */
#define TXDB 16 /* PA13 : TXD2 : Arduino Due TX2 : Serial2 */
#define RXDB 17 /* PA12 : RXD2 : Arduino Due RX2 : Serial2 */
#define PWMB 7 /* PC23 : PWM7 : Arduino Due D7 : */
#define ANAB 55 /* PA24 : AD1 : Arduino Due A1 : */
#define RSTB 34 /* PC2 : RSTB : Arduino Due D34 : */
#define CSNB 79 /* PA29 : SPI0_CS1 : Arduino Due ??? : N.B. this is not mapped for Due? */
#define SCKB 76 /* PA27 : SPI0_SCK : Arduino Due SCK : */
#define MISOB 74 /* PA25 : SPI0_MISO : Arduino Due MISO : */
#define MOSIB 75 /* PA26 : SPI0_MOSI : Arduino Due MOSI : */

/* Pinout for Click Socket C
*/
#define LEDC 39 /* PC7 : LEDC : Arduino Due D39 : */
#define SDAC 20 /* PB12 : I2C1_SDA : Arduino Due SDA1 : */
#define SCLC 21 /* PB13 : I2C1_SCL : Arduino Due SCL1 : */
#define TXDC 14 /* PD4 : TXD3 : Arduino Due TX3 : Serial3 */
#define RXDC 15 /* PD5 : RXD3 : Arduino Due RX3 : Serial3 */
#define PWMC 8 /* PC22 : PWM8 : Arduino Due D8 : */
#define ANA 56 /* PA23 : AD2 : Arduino Due A2 : */
#define RSTSC 35 /* PC3 : RSTC : Arduino Due D35 : */
#define CSNC 52 /* PB21 : SPI0_CS2 : Arduino Due D52 : */
#define SCKC 76 /* PA27 : SPI0_SCK : Arduino Due SCK : */
#define MISOC 74 /* PA25 : SPI0_MISO : Arduino Due MISO : */
#define MOSIC 75 /* PA26 : SPI0_MOSI : Arduino Due MOSI : */

/* Pinout for Click Socket D
*/
#define LEDD 40 /* PC8 : LEDD : Arduino Due D40 : */
#define SDAD 20 /* PB12 : I2C1_SDA : Arduino Due SDA1 : */
#define SCLD 21 /* PB13 : I2C1_SCL : Arduino Due SDA1 : */
#define TXDD 14 /* PD4 : TXD3 : Arduino Due TX3 : */
#define RXDD 15 /* PD5 : RXD3 : Arduino Due RX3 : */
#define PWMD 9 /* PC21 : PWM9 : Arduino Due D9 : */
#define ANAD 57 /* PA22 : AD3 : Arduino Due A3 : */
#define RSTD 36 /* PC4 : RSTD : Arduino Due D36 : */
#define CSND 78 /* PB23 : SPI0_CS3 : Arduino Due D78 : */
#define SCKD 76 /* PA27 : SPI0_SCK : Arduino Due SCK : */
#define MISOD 74 /* PA25 : SPI0_MISO : Arduino Due MISO : */
#define MOSID 75 /* PA26 : SPI0_MOSI : Arduino Due MOSI : */
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3d07a14

Please sign in to comment.