Skip to content

Commit

Permalink
update libraries to the latest x.x.1 variant. move examples to the li…
Browse files Browse the repository at this point in the history
…braries folder, plus a little formatting makes them visible as examples in the Arduino IDE. Add ID107 example that uses u8g2 for the OLED, and internal libraries for the heart rate sensor and accelerometer (Note: SoftwareI2C works with the heartrate sensor, but not the accelerometer). Add MPOW DS-D6 variant using pin mapping from @fanoush
  • Loading branch information
micooke committed Jan 31, 2019
1 parent 260859d commit 0801e12
Show file tree
Hide file tree
Showing 30 changed files with 979 additions and 16 deletions.
5 changes: 4 additions & 1 deletion README.md
Expand Up @@ -14,6 +14,7 @@ Included smartwatches:
3. [ID107HR](https://github.com/micooke/micooke.github.io/blob/master/arduino-nRF5-smartwatches/images/ID107HR_back.jpg)
4. [ID107HR Plus](https://github.com/micooke/micooke.github.io/blob/master/arduino-nRF5-smartwatches/images/ID107HRPlus_disected.jpg) (alpha) - dont expect this to work
5. [LEMDOIE T28](https://github.com/micooke/micooke.github.io/blob/master/nRF52832_Lemdoie_T28.md)
6. [MyPow DS-D6](https://github.com/fanoush/ds-d6)

Included Generic development boards:
6. [Taida Century nRF52 mini board / nRF52832 Gold Core](https://github.com/micooke/micooke.github.io/blob/master/nRF52832_TaidaCentury_GoldCore.md)
Expand Down Expand Up @@ -72,6 +73,7 @@ Progamming is via a SWD programmer (J-Link, ST-Link etc.) using sandeep's core.
### Pin allocation

The nRF52 based T28 is quite different. Its pin allocation table is located [here](https://github.com/micooke/micooke.github.io/blob/master/nRF52832_Lemdoie_T28.md)
@fanoush has done a great job on getting the DS-D6 pin allocation. It is hosted [here](https://github.com/fanoush/ds-d6)


| peripheral type | name | pin | IDO003 | ID100HR | ID107HR | ID107HR Plus
Expand Down Expand Up @@ -120,4 +122,5 @@ The nRF52 based T28 is quite different. Its pin allocation table is located [her
* (Modified) [IDO003 picture](https://espruino.microco.sm/api/v1/files/ba591802419c40145d825db2924360eb162cc026.JPG) is from Gordon, embedded in this [conversation](http://forum.espruino.com/conversations/280747/)
* ID107HR picture is my own
* [ID107HR Plus picture](http://www.rogerclark.net/wp-content/uploads/2017/06/id107plus-7-770x1024.jpg) is from Curt, embedded on Roger's website [article](http://www.rogerclark.net/new-nrf52832-based-smart-watch-available/)
* (Modified) [ID107HR Plus pads](http://www.rogerclark.net/wp-content/uploads/2017/06/id107plus-3.jpg) is from Curt, embedded on Roger's website [article](http://www.rogerclark.net/new-nrf52832-based-smart-watch-available/)
* (Modified) [ID107HR Plus pads](http://www.rogerclark.net/wp-content/uploads/2017/06/id107plus-3.jpg) is from Curt, embedded on Roger's website [article](http://www.rogerclark.net/new-nrf52832-based-smart-watch-available/)
* [DS-D6](https://github.com/fanoush/ds-d6) from [@fanoush](https://github.com/fanoush)
46 changes: 46 additions & 0 deletions boards.txt
Expand Up @@ -199,6 +199,52 @@ T28.menu.softdevice.none.softdeviceversion=
T28.menu.lfclk.lfrc=RC Oscillator
T28.menu.lfclk.lfrc.build.lfclk_flags=-DUSE_LFRC

T28.menu.board_variant.accel_hwi2c=I2C:Accel=HW, HeartRate=SW
T28.menu.board_variant.accel_hwi2c.build.lfclk_flags=-DUSE_LFXO -DACCEL_HWI2C

T28.menu.board_variant.heartrate_hwi2c=I2C:Accel=SW, HeartRate=HW
T28.menu.board_variant.heartrate_hwi2c.build.lfclk_flags=-DUSE_LFXO -DHEARTRATE_HWI2C

# -----------------------------------------------------------------------------
DS_D6.name=MPow DS-D6

DS_D6.upload.tool=sandeepmistry:openocd
DS_D6.upload.target=nrf52
DS_D6.upload.maximum_size=524288

DS_D6.bootloader.tool=sandeepmistry:openocd

DS_D6.build.mcu=cortex-m4
DS_D6.build.f_cpu=16000000
DS_D6.build.board=DS_D6
DS_D6.build.core=sandeepmistry:nRF5
DS_D6.build.variant=DS_D6
DS_D6.build.variant_system_lib=
DS_D6.build.extra_flags=-DCONFIG_NFCT_PINS_AS_GPIOS -DNRF52 -DDS_D6 -I{build.path}
DS_D6.build.float_flags=-mfloat-abi=hard -mfpu=fpv4-sp-d16
DS_D6.build.ldscript=nrf52_{build.chip}.ld
DS_D6.build.chip=xxaa

DS_D6.menu.softdevice.s132=S132
DS_D6.menu.softdevice.s132.softdevice=s132
DS_D6.menu.softdevice.s132.softdeviceversion=2.0.1
DS_D6.menu.softdevice.s132.upload.maximum_size=409600
DS_D6.menu.softdevice.s132.build.extra_flags=-DNRF52 -DS132 -DNRF52_S132
DS_D6.menu.softdevice.s132.build.ldscript=armgcc_s132_nrf52832_{build.chip}.ld

DS_D6.menu.softdevice.none=None
DS_D6.menu.softdevice.none.softdevice=none
DS_D6.menu.softdevice.none.softdeviceversion=

DS_D6.menu.lfclk.lfrc=RC Oscillator
DS_D6.menu.lfclk.lfrc.build.lfclk_flags=-DUSE_LFRC

DS_D6.menu.board_variant.accel_hwi2c=I2C:Accel=HW, HeartRate=SW
DS_D6.menu.board_variant.accel_hwi2c.build.lfclk_flags=-DUSE_LFXO -DACCEL_HWI2C

DS_D6.menu.board_variant.heartrate_hwi2c=I2C:Accel=SW, HeartRate=HW
DS_D6.menu.board_variant.heartrate_hwi2c.build.lfclk_flags=-DUSE_LFXO -DHEARTRATE_HWI2C

# -----------------------------------------------------------------------------
Waveshare_BLE400_HRM.name=Waveshare BLE400

Expand Down
115 changes: 115 additions & 0 deletions libraries/examples/Examples/ID107_u8g2_sensors_clock/ID107_OLED.h
@@ -0,0 +1,115 @@
#ifndef ID107_OLED_H
#define ID107_OLED_H

#include "ID107_sensors.h"

#include <U8g2lib.h>
#include <SPI.h>

U8G2_SH1106_64X32_1_4W_HW_SPI u8g2(U8G2_R0, OLED_CS, OLED_DC, OLED_RST);

class ID107_OLED{
private:
const uint8_t _numPages = 4;
uint32_t _splashTime;
uint8_t _pageNum;
time_t compileTime();

ID107_sensors _id107_sensors;

void splash(uint32_t splash_time_ms);
void draw();
public:
ID107_OLED(uint32_t splash_time_ms = 2000): _splashTime(splash_time_ms), _pageNum(0) {}
~ID107_OLED() {}
void begin();
void heartrate(uint8_t ambiant_sensor = 0);
void accelerometer();
void clock();
void nextPage();
uint8_t getPageCount() { return _numPages; }
void drawPage(uint8_t pageNum = 0);
};

void ID107_OLED::begin()
{
_id107_sensors.begin();

u8g2.begin();
u8g2.setFont(u8g2_font_6x10_tf);
u8g2.setFontRefHeightExtendedText();
u8g2.setDrawColor(1);
u8g2.setFontPosTop();
u8g2.setFontDirection(0);

splash(_splashTime);
}

void ID107_OLED::drawPage(uint8_t pageNum)
{
switch(pageNum) {
case 0:
heartrate(0); break;
case 1:
heartrate(1); break;
case 2:
accelerometer(); break;
default:
clock();
}
}

void ID107_OLED::draw()
{
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_6x10_tf);
u8g2.drawStr( 0, 0, _id107_sensors.row[0].c_str());
u8g2.drawStr(0, 10, _id107_sensors.row[1].c_str());
u8g2.drawStr(0, 20, _id107_sensors.row[2].c_str());
} while ( u8g2.nextPage() );
}

void ID107_OLED::nextPage()
{
// increment the page number
_pageNum = (_pageNum < _numPages - 1)?_pageNum + 1:0;

// draw the page
drawPage(_pageNum);
}


void ID107_OLED::heartrate(uint8_t ambiant_sensor)
{
_id107_sensors.get_heartrate(ambiant_sensor);

draw();
}

void ID107_OLED::accelerometer()
{
_id107_sensors.get_accelerometer();

draw();
}

void ID107_OLED::clock()
{
_id107_sensors.get_clock();

draw();
}

void ID107_OLED::splash(uint32_t splash_time_ms)
{
_id107_sensors.row[0] = "github.com";
_id107_sensors.row[1] = "/micooke";
_id107_sensors.row[2] = __TIME__;

draw();

delay(splash_time_ms);
}

#endif
169 changes: 169 additions & 0 deletions libraries/examples/Examples/ID107_u8g2_sensors_clock/ID107_sensors.h
@@ -0,0 +1,169 @@
#ifndef ID107_SENSORS_H
#define ID107_SENSORS_H

#include <SoftwareI2C.h>

#include <KX022.h>
#include <Si114.h>

#include <Timezone.h> // https://github.com/JChristensen/Timezone

TimeChangeRule ACST = {"ACST", First, Sun, Apr, 3, 570}; // Australian Central Daylight Time = UTC +9:30 hours
TimeChangeRule ACDT = {"ACDT", First, Sun, Oct, 2, 630}; // Australian Central Standard Time = UTC +10:30 hours
Timezone AdelaideTimezone(ACST, ACDT);
TimeChangeRule *tcr; // pointer to the time change rule, use to get TZ abbrev

#ifdef ACCEL_HWI2C
// Kx022 - Hardware I2C (Wire)
KX022<> acc(Wire);

// Si1143 - Software I2C
SoftwareI2C sWire(PIN_WIRE1_SDA, PIN_WIRE1_SCL);
PulsePlug<SoftwareI2C> pulse(sWire);
#else
// Kx022 - Software I2C (Wire)
SoftwareI2C sWire(PIN_WIRE1_SDA, PIN_WIRE1_SCL);
KX022<SoftwareI2C> acc(sWire);

// Si1143 - Hardware I2C
PulsePlug<> pulse(Wire);
#endif

class ID107_sensors{
private:
uint8_t _retries;
void float2chars(float &in, char (&out)[5]);
time_t compileTime();
public:
ID107_sensors(uint8_t retries = 5) : _retries(retries) {}
~ID107_sensors() {}
void begin();
void get_heartrate(uint8_t ambiant_sensor = 0);
void get_accelerometer();
void get_clock();
String row[3];
};

void ID107_sensors::begin()
{
// Clock
setTime(AdelaideTimezone.toUTC(compileTime()));

// Si1143 - Heartrate
uint8_t attempts = 0;
while ((pulse.isPresent() == false) & (attempts < _retries))
{
delay(100);
++attempts;
}
if (pulse.isPresent())
{
pulse.init();
}

// Kx022 - Accelerometer
acc.init();
}

void ID107_sensors::get_heartrate(uint8_t ambiant_sensor)
{
if (pulse.isPresent())
{
pulse.readSensor(ambiant_sensor + 1); // sensorIdx = 1(HeartRate),2(Ambiant),3(Both)
if (ambiant_sensor)
{

row[0] = "VIS " + String(pulse.als_vis);
row[1] = "IR " + String(pulse.als_ir);
row[2] = "";
}
else
{
row[0] = "RED " + String(pulse.led_red);
row[1] = "IR1 " + String(pulse.led_ir1);
row[2] = "IR2 " + String(pulse.led_ir2);
}
}
else
{
row[0] = "Si1143 (HRM)";
row[1] = "Not";
row[2] = "Present";
}
}

void ID107_sensors::get_accelerometer()
{
row[0] = "X ";
row[1] = "Y ";
row[2] = "Z ";

char fltBuf[5];
float xyz[3];
acc.getAccelXYZ(xyz);

float2chars(xyz[0],fltBuf); row[0] += String(fltBuf);
float2chars(xyz[1],fltBuf); row[1] += String(fltBuf);
float2chars(xyz[2],fltBuf); row[2] += String(fltBuf);
}

void ID107_sensors::get_clock()
{
time_t utc = now();
time_t local = AdelaideTimezone.toLocal(utc, &tcr);

char timeString[10];

sprintf(timeString, "%.2d:%.2d:%.2d", hour(local), minute(local), second(local));

char dateString[11];

sprintf(dateString, "%.2d/%.2d/%d", day(local), month(local), year(local));
/*
char dayString[7];
char monthYearString[9];
char m[4]; // temporary storage for month string (DateStrings.cpp uses shared buffer)
strcpy(m, monthShortStr(month(local)));
sprintf(dayString, "%s %.2d", dayShortStr(weekday(local)), day(local));
sprintf(buf, "%s %d", m, year(local));
*/
row[0] = timeString;
row[1] = dateString;
row[2] = "";
}

// Function to return the compile date and time as a time_t value
time_t ID107_sensors::compileTime()
{
const time_t FUDGE(4); // fudge factor to allow for compile time (seconds, YMMV)
const char *compDate = __DATE__, *compTime = __TIME__, *months = "JanFebMarAprMayJunJulAugSepOctNovDec";
char chMon[3], *m;
tmElements_t tm;

strncpy(chMon, compDate, 3);
chMon[3] = '\0';
m = strstr(months, chMon);
tm.Month = ((m - months) / 3 + 1);

tm.Day = atoi(compDate + 4);
tm.Year = atoi(compDate + 7) - 1970;
tm.Hour = atoi(compTime);
tm.Minute = atoi(compTime + 3);
tm.Second = atoi(compTime + 6);
time_t t = makeTime(tm);
return t + FUDGE; // add fudge factor to allow for compile time
}

void ID107_sensors::float2chars(float &in, char (&out)[5])
{
bool sign_bit = (in < 0);
uint16_t tmp = sign_bit?(-in * 10):(in * 10);
out[0] = (sign_bit)?'-':' ';
out[1] = char('0' + (tmp / 10));
out[2] = '.';
out[3] = char('0' + (tmp % 10));
out[4] = '\0';
}

#endif

0 comments on commit 0801e12

Please sign in to comment.