Arduino programmable smart Watch

Anything not related to STM32
racemaniac
Posts: 261
Joined: Sat Nov 07, 2015 9:09 am

Re: Arduino programmable smart Watch

Postby racemaniac » Sun Oct 30, 2016 8:49 pm

RogerClark wrote:In terms using the smartwatch, the examples only worl with the first repo you linked to.

This is because those examples contain some function from mbed, and the old repo is a modified version of RedBearLabs repo, which its self is derived from mbed.

The second link is my fork of Sandeep Mistry's Arduino-nRF5 repo, which is a newer and better implemtation of an Arduino core for nRF51xxx and nRF52xxx devices, however at the moment, no one has had time to port the OLED display code etc to the new repo.

With the Blackmagic probe, the DFU device is to update the BMPs own internal firmware, its not used to upload to the target device.
You need to select the GDB com port, as the Com port in the IDE, otherwise it wont upload.

I normally open a separate terminal program to the other BMP com port, if I am using it for USB to serial ( or if I am using a separate USB to serial adaptor to view debug messages)

Also you need to pick the Smartwatch board, otherwise Serial will be on the wrong pins of the watch

Hmm so i did everything correct so far. Strange that i don't see anything working.
If i'm not mistaken, i'll have to connect the rx & tx of the smartwatch to the tx2 & rx2 of the bmp, and then i can see the serial output on a serial monitor?

User avatar
RogerClark
Posts: 5049
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Arduino programmable smart Watch

Postby RogerClark » Sun Oct 30, 2016 9:05 pm

From memory, the BMP uses tx2 and rx2 , ( this is the way Rick did his port of the BMP).

Its fixed at 9600 baud, so the sketch needs to use that speed.

Did you use the S130 SoftDevice version 1.0 which is part of the Nordic SDK V 10?

The SD 2.0 wont work as the application code offset is different

racemaniac
Posts: 261
Joined: Sat Nov 07, 2015 9:09 am

Re: Arduino programmable smart Watch

Postby racemaniac » Sun Oct 30, 2016 9:09 pm

RogerClark wrote:From memory, the BMP uses tx2 and rx2 , ( this is the way Rick did his port of the BMP).

Its fixed at 9600 baud, so the sketch needs to use that speed.

Did you use the S130 SoftDevice version 1.0 which is part of the Nordic SDK V 10?

The SD 2.0 wont work as the application code offset is different

yup, and i got the serial now working, and the code i upload is actually running :)
and i wrote some code that writes to the serial when i press the button, and that also works.
so my code is running, and at least the button is found :).

but neither the display nor the buzzer do anything at all.... glad to know i've got the programming and everything working. now to figure out why the display isn't doing anything at all. Maybe my ID107 is very different from yours?

User avatar
RogerClark
Posts: 5049
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Arduino programmable smart Watch

Postby RogerClark » Sun Oct 30, 2016 9:20 pm

Do you have the ID107 or the ID107HR ?

There are pinout differences between these watches

I had to visually trace and then confirm with my multimeter which pins went to the display on the ID107HR

If you have a github account, its probably worth logging into this gitter lobby , created by Goran, as there are a few other people who may be online to help

https://gitter.im/nRF51822-Arduino-Mbed ... ifications

User avatar
RogerClark
Posts: 5049
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Arduino programmable smart Watch

Postby RogerClark » Sun Oct 30, 2016 9:22 pm

Actually, I can't remember which example works with which watch

I'd need to double check

User avatar
RogerClark
Posts: 5049
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Arduino programmable smart Watch

Postby RogerClark » Sun Oct 30, 2016 9:23 pm

I have this version

Code: Select all

//#include <time.h>
#include <BLE_API.h>
#include "SFE_MicroOLED.h"
BLEDevice ble;

#define VIBRATE 7
#define BUTTON 4
#define DEVICE_NAME       "ArduWatch"

Ticker RTCTicker;

SPI my_spi(P0_2, NC, P0_1);// MOSI, MISIO, SCLK
MicroOLED my_oled(my_spi, P0_30, P0_0, P0_29);//SPI,Rst,DC,CS


#define alarmHours    14
#define alarmMinutes  33
#define alarmSeconds  0
volatile boolean showTime=true;
volatile boolean useAlarm = false;
volatile int alarmTime = alarmHours * 3600 + alarmMinutes * 60 + alarmSeconds;

// Use these variables to set the initial time
volatile int alarmOnCount=0;

#define UPLOAD_TIME_SECS 7
volatile int secsTime = ((__TIME__[0] - '0') * 10 + ( __TIME__[1] - '0')) * 3600 +
                ((__TIME__[3] - '0') * 10 + ( __TIME__[4] - '0') )* 60 +
                ((__TIME__[7] - '0') * 10 + ( __TIME__[7] - '0')) ;

volatile time_t theTime;

time_t cvt_date(char const *date, char const *time)
{
    char s_month[5];
    int year;
    struct tm t;
    static const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
    sscanf(date, "%s %d %d", s_month, &t.tm_mday, &year);
    sscanf(time, "%2d %*c %2d %*c %2d", &t.tm_hour, &t.tm_min, &t.tm_sec);
    // Find where is s_month in month_names. Deduce month value.
    t.tm_mon = (strstr(month_names, s_month) - month_names) / 3 + 1;   
    t.tm_year = year - 1900;   
    return mktime(&t);
}

// Simple function to increment seconds and then increment minutes
// and hours if necessary.
void updateTime()
{
 /*
  if (++secsTime> 24 * 3600)
  {
    secsTime=0;
  }
  */
  if (useAlarm == true && secsTime==alarmTime)
  {
    alarmOnCount=10;// on / off cycles
  }

  if (alarmOnCount>0)
  {
    alarmOnCount--;
    digitalWrite(VIBRATE, !digitalRead(VIBRATE));
  }
}

#define DISPLAY_ON_TIME_MS 5000
void displayTime()
{
unsigned long m=millis();
int lastSecs = 0;
int hours,remainder, minutes,seconds;
char txtBuf[9];


 //   y2k.tm_hour = 0;   y2k.tm_min = 0; y2k.tm_sec = 0;
#if 0
time_t     now;
      struct tm  *ts;
      char       buf[80];
     
      // Format time, "ddd yyyy-mm-dd hh:mm:ss zzz"
      ts = localtime((const time_t*)&theTime);
     
      Serial.println(ts->tm_hour);
     
      Serial.print("Again");
      while(1);
#endif

     


      my_oled.command(DISPLAYON);

      alarmOnCount=0;// if the alarm is buzzing, stop it.
      digitalWrite(VIBRATE, LOW);
     
      while(millis() - m <DISPLAY_ON_TIME_MS)
      {
        if (lastSecs!=secsTime)
        {
          hours = (secsTime% (24*3600)) / 3600;
          remainder = secsTime % 3600;
          minutes = remainder / 60;
          seconds = remainder % 60;
         
          my_oled.clear(PAGE);  // Clear the frame buffer
          sprintf(txtBuf, "%02d:%02d:%02d", hours, minutes, seconds);
          my_oled.setCursor(5, 5);
          my_oled.puts(txtBuf);
         // my_oled.setCursor(9, 20);
        //  my_oled.puts("Radiona");
          my_oled.display(); // Draw the memory buffer
          lastSecs=secsTime;
        }
        delay(1);
      }
      my_oled.command(DISPLAYOFF);
}

void buttonCheck(){
    showTime=true;
 
}

void disconnectionCallBack(const Gap::DisconnectionCallbackParams_t *params) {
//  Serial.println("Disconnected!");
//  Serial.println("Restarting the advertising process");
  ble.startAdvertising();
}

void initBLE(void)
{
  ble.init();
  ble.onDisconnection(disconnectionCallBack);

  // setup adv_data and srp_data
  ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
  ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));

  /*
  ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t*)uuid16_list, sizeof(uuid16_list));
  ble.accumulateAdvertisingPayload(GapAdvertisingData::HEART_RATE_SENSOR_HEART_RATE_BELT);
  */
 
 
  ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); // set adv_type
   
 // ble.addService(hrmService);// add service
   
  ble.setTxPower(0);// set tx power,valid values are -40, -20, -16, -12, -8, -4, 0, 4
  ble.setAdvertisingInterval(1600);// set adv_interval, 1000ms in multiples of 0.625ms.
  ble.setAdvertisingTimeout(0);  // set adv_timeout, in seconds

  ble.startAdvertising(); 
}

void setup() {
  //theTime=cvt_date(__DATE__,__TIME__);
  pinMode(VIBRATE, OUTPUT);
  pinMode(BUTTON, INPUT_PULLUP);

  Serial.begin(9600);
  Serial.print("HEllo");

#ifndef LOW_POWER
  NRF_POWER->DCDCEN = 0x00000001;
  NRF_TIMER2->POWER = 0;
  NRF_UART0->POWER = 0;
#endif
  initBLE();

  my_oled.init(0, 8000000);
  my_oled.setFontType(0);

  my_oled.clear(PAGE);
  my_oled.setCursor(4, 12);
  my_oled.puts("ArduWatch");
  my_oled.display();

  delay(2000);


  RTCTicker.attach_us(updateTime, 1000000);
  attachInterrupt(BUTTON, buttonCheck, FALLING);
}


void loop() {
  if (showTime==true)
  {
    showTime=false;
    displayTime();

  }
  else
  {
    ble.waitForEvent();// Go to low power mode until an event e.g. interrupt or BLE event
  }
}


User avatar
RogerClark
Posts: 5049
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Arduino programmable smart Watch

Postby RogerClark » Sun Oct 30, 2016 9:25 pm

You could also try this test for the motion sensor

Code: Select all

#include <Wire.h>

#define KX022_addr_w              0x3E
#define KX022_addr_r              0x3F
#define KX022_Accel_CNTL1_1       0x18
#define KX022_Accel_CNTL1_2       0x41
#define KX022_Accel_ODCNTL_1      0x1B
#define KX022_Accel_ODCNTL_2      0x02
#define KX022_Accel_CNTL3_1       0x1A
#define KX022_Accel_CNTL3_2       0xD8
#define KX022_Accel_TILT_TIMER_1  0x22
#define KX022_Accel_TILT_TIMER_2  0x01
#define KX022_Accel_CNTL2_1       0x18
#define KX022_Accel_CNTL2_2       0xC1 

#define DATA_OUT_BASE 0x06

void initSensor(){
    writeTwoBytes(KX022_Accel_CNTL1_1,KX022_Accel_CNTL1_2);
    writeTwoBytes(KX022_Accel_ODCNTL_1,KX022_Accel_ODCNTL_2);
    writeTwoBytes(KX022_Accel_CNTL3_1,KX022_Accel_CNTL3_2);
    writeTwoBytes(KX022_Accel_TILT_TIMER_1,KX022_Accel_TILT_TIMER_2);
    writeTwoBytes(KX022_Accel_CNTL2_1,KX022_Accel_CNTL2_2);
}

void writeTwoBytes (int one, int two)
{
    Wire.beginTransmission(KX022_addr_w);
    Wire.write(one);
    Wire.write(two);
    Wire.endTransmission();
}

int getByte (int address)
{
  int readedValue;
  Wire.beginTransmission(KX022_addr_w);
  Wire.write(address);
  Wire.endTransmission();
  Wire.requestFrom(KX022_addr_r , 1);  // Or-ed with "1" for read bit
  if(1 <= Wire.available())    // if two bytes were received
  {
    readedValue = Wire.read();
  }
  return readedValue;
}

float getAccel(int channelNum)
{
  return ((int16_t)((getByte(DATA_OUT_BASE+1 + 2*channelNum)<<8) | (getByte(DATA_OUT_BASE + 2*channelNum)))) / 16384.0; 
}

void setup()
{
  // put your setup code here, to run once:
    Wire.begin();
    Serial.begin(9600);

    initSensor();
}

void loop()
{

  Serial.print(getAccel(0)*10);
  Serial.print("\t");
  Serial.print(getAccel(1)*10);
  Serial.print("\t");
  Serial.println(getAccel(2)*10);
  delay(50);

}


Then use the serial plotter in the IDE

User avatar
RogerClark
Posts: 5049
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Arduino programmable smart Watch

Postby RogerClark » Sun Oct 30, 2016 9:27 pm

The OLED digital watch example in the repo is for the "DO 003" watch, which has a different display connection pinout

So probably doesnt work with your watch

So this code probably wont work for you


Code: Select all

#include "SFE_MicroOLED.h"

#define VIBRATE 7
#define BUTTON 4

SPI my_spi(P0_29, NC, P0_30);
MicroOLED my_oled(my_spi, P0_1, P0_0, P0_2);

const int CLOCK_SPEED = 1000;
// Use these variables to set the initial time
int hours = (__TIME__[0] -'0') *10 +( __TIME__[1] -'0') ;
int minutes = (__TIME__[3] -'0') *10 +( __TIME__[4] -'0') ;
int seconds = (__TIME__[7] -'0') *10 +( __TIME__[7] -'0') ;
unsigned long lastUpdate = 0;

// Simple function to increment seconds and then increment minutes
// and hours if necessary.
void updateTime()
{
  seconds++;  // Increment seconds
  if (seconds >= 60)  // If seconds overflows (>=60)
  {
    seconds = 0;  // Set seconds back to 0
    minutes++;    // Increment minutes
    if (minutes >= 60)  // If minutes overflows (>=60)
    {
      minutes = 0;  // Set minutes back to 0
      hours++;      // Increment hours
      if (hours >= 12)  // If hours overflows (>=12)
      {
        hours = 0;  // Set hours back to 0
      }
    }
  }
}

void setup() {
   // put your setup code here, to run once:
   my_oled.init(0, 8000000);
   my_oled.clear(PAGE);
   my_oled.setCursor(0,0);
   my_oled.puts("Its Alive");
   my_oled.display();
   pinMode(VIBRATE,OUTPUT);
   pinMode(BUTTON,INPUT_PULLUP);
   Serial.begin(9600);
   Serial.println("Smarty");
   delay(2000);
}

void loop()
{
digitalWrite(VIBRATE,!digitalRead(BUTTON));
char txtBuf[9];

  // Check if we need to update seconds, minutes, hours:
  if (lastUpdate + CLOCK_SPEED < millis())
  {
    lastUpdate = millis();
 
    updateTime();  // Add a second, update minutes/hours if necessary:

    my_oled.clear(PAGE);  // Clear the frame buffer

    sprintf(txtBuf,"%02d:%02d:%02d",hours,minutes,seconds);

    my_oled.setCursor(5,12);
    my_oled.puts(txtBuf);

    my_oled.display(); // Draw the memory buffer
  }
}

racemaniac
Posts: 261
Joined: Sat Nov 07, 2015 9:09 am

Re: Arduino programmable smart Watch

Postby racemaniac » Mon Oct 31, 2016 6:39 am

RogerClark wrote:I have this version


Awesome!!
your version works!!!!
I got this little watch working now :).

Thanks a lot :).

i think mine is just called ID107 (not HR), but our pinout seems to be the same!

the only thing that still doesn't work is the virbation. But maybe that is because i disconnected the battery? the battery is disconnected, and the board is getting power from its gnd & vdd pads. but maybe the motor draws power directly from the battery when enabled? to be tested :)
*edit*
i already pretty much confirmed it :). the + of the motor is directly connected to the + of battery :). So that's why my poor motor is silent :).

User avatar
RogerClark
Posts: 5049
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Arduino programmable smart Watch

Postby RogerClark » Mon Oct 31, 2016 7:00 am

Try this


Code: Select all

#include <SPI.h>

#define VIBRATE 6
#define TOUCH 7
#define BUTTON 4

int c=0;

void setup()
{
  Serial.begin(9600);
  delay(100);
 
  Serial.println("Hello ID107HR");
 
  pinMode(TOUCH,INPUT);
  pinMode(BUTTON,INPUT);
  pinMode(VIBRATE,OUTPUT);
}

void loop()
{
    Serial.print("Button state ...");
    Serial.println(digitalRead(TOUCH));
    delay(100);
    digitalWrite(VIBRATE,digitalRead(TOUCH)); 
}


Return to “Off topic”

Who is online

Users browsing this forum: No registered users and 2 guests