Tuesday, May 12, 2015

DIY - Jotiz CardioMachine with Arduino Due and TI MSP 432 and MSP 430

DIY - Jotiz CardioMachine with Arduino Due and TI MSP 432 and MSP 430


I present here a series of blogs that are intended to enable the use of ‘things’ in the Internet of Things IoT complementing Jotiz.

The idea of a Microcontroller based Cardiogram Reading machine was something I had planned on for quite a while. There is little to doubt that Panchanga and Kaala have a definite influence on a person’s mind, spirit and heart. Based on that key-note, I went about assembling a small machine that could fit into your palm, read EKG through electrodes on your body and correlate heart readings to the Panchanga and Kaala of time.

There were several architectural alternatives, which I went through and I present them all to you.

1. Arduino Mega (8 Bit) MCU with Olimex EKG/EMG front-end shield.
2. Arduino Due (32 Bit SAMX) MCU with Olimex EKG/EMG front end shield
3. TI MSP 430 (16 Bit) Launchpad with SparkFun EKG front end board
4. TI MSP 423 (32 Bit) Launchpad with SparkFun EKG front end board

The TI Launchpads were connected headless to the EKG front ends. The data was collected over the serial port through a program written in Java, which would plot and render the data on the cloud. To the Arduino boards, I added shields I had created which had LCD and OLEDs mounted additional to the EKG front ends.

Links and Bill of Material: 

1. Energia - http://energia.nu/
2. Arduino - http://www.arduino.cc/
3. Arduino Mega - http://www.arduino.cc/en/Main/arduinoBoardMega
4. Arduino Due - http://www.arduino.cc/en/Main/arduinoBoardDue
5. Sainsmart Due - http://www.sainsmart.com/sainsmart-due-atmel-sam3x8e-arm-cortex-m3-board.html
6. Sintron Mega 2560 R3 ATmega2560 with USB Cable
7. Olimex EKG Frontend - https://www.olimex.com/Products/Duino/Shields/SHIELD-EKG-EMG/
8. SparkFun AD8232 EKG - https://learn.sparkfun.com/tutorials/ad8232-heart-rate-monitor-hookup-guide
9. Hammond Manufacturing 1553BRDBKBAT Enclosure
10. Gikfun Prototype Shield DIY KIT for Arduino
11. Diymall 0.96" Inch I2c IIC Serial 128x64 OLED
12. SainSmart 1.8" TFT Color LCD Display Module with SPI Interface & MicroSD
13. Radioshack Enclosure Project Skeleton Kit (Two-Tray)
14. TI MSP 430 G2 series - http://www.ti.com/lsds/ti/microcontrollers_16-bit_32-bit/msp/ultra-low_power/msp430g2x_i2x/overview.page
15. Texas Instruments MSP432 Launchpad - http://www.ti.com/tool/MSP-EXP432P401R

Three layered Jotiz-Cardio machine on Arduino (Sintron) Mega
with Olimex EKG/EMG Shield and 0.96 inch OLED

Three layered Jotiz-Cardio machine on Arduino (Sainsmart) Due
with Olimex EKG/EMG shield and 0.96 inch OLED on top shield

MSP 432 Launchpad (32 Bit) with Sparkfun AD8232 EKG Board

MSP 430 Launchpad (16 Bit) with Sparkfun AD8232 EKG Board

MSP 430 Launchpad with Sparkfun EKG inside Hammond Enclosure
with three electrodes attached

How the program works:


Arduino 32 Bit (Single channel) with Olimex EKG Shield


  screen.firstPage();
  do {
    draw();
    screen.setColorIndex(1);
  } while ( screen.nextPage() );

  starttime = millis();
  Serial.begin(57600);
  Serial.setTimeout(2000);
  Serial.println("Vedic Heart Machine");
  Serial.println(">> Please input Time : Example \"21,53,0,25,4,2015,-4\"");
  if (!pTime) {
    processTime();
    pTime = true;
  }
  if (!pDone) {
    doPanchanga();
    pDone = true;
  }
}

void doPanchanga() {
  Serial.print("PCH, Date ");
  Serial.print(nYY);
  Serial.print("-");
  Serial.print(nMM);
  Serial.print("-");
  Serial.print(nDD);
  Serial.print(" Hour ");
  Serial.print(nHour);
  Serial.print(":");
  Serial.print(nMin);
  Serial.print(" TimeZone ");
  Serial.println(nTZ);

  pch.initialize_panchanga(nDD, nMM, nYY, nHour, nMin, nTZ);

  delay(200);
  pDone = true;

  // Set the timer for EKG Reading
  // TC1 : timer counter. Can be TC0, TC1 or TC2
  // 0   : channel. Can be 0, 1 or 2
  // TC3_IRQn: irq number.
  // 250 : frequency (in Hz)
  // The interrupt service routine is TC3_Handler.
  startTimer(TC1, 0, TC3_IRQn, 250);
}

void processTime() {
  nHour = Serial.parseInt();
  nMin = Serial.parseInt();
  nSec = Serial.parseInt();
  nDD = Serial.parseInt();
  nMM = Serial.parseInt();
  nYY = Serial.parseInt();
  nTZ = Serial.parseInt();
  if (nYY == 0) nYY = 2015;
  if (nDD == 0) nDD = 25;
  if (nMM == 0) nMM = 4;
  if (nHour == 0) nHour = 23;
  if (nMin == 0) nMin = 36;
  if (nTZ == 0) nTZ = -4;
  setTime(nHour, nMin, 0, nDD, nMM, nYY);
}

  activetime = millis() - starttime;
  if (timerInitiated) {
    inADC = analogRead(0);
    Serial.print("ADC,");
    Serial.print(inADC);
    Serial.print(",");
    Serial.println(activetime);
  }

Arduino 8-Bit Mega with Olimex EKG and OLED


#define SAMPFREQ 256                      // ADC sampling rate 256
#define TIMER2VAL (1024/(SAMPFREQ))       // Set 256Hz sampling frequency                   
volatile unsigned char CurrentCh = 0;     //Current channel being sampled.
volatile unsigned int ADC_Value = 0;             //ADC current value
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16

// Needed by Panchanga
uint8_t nDay = 6;
uint8_t nDD = 11;
uint8_t nMM = 4;
unsigned int nYY = 2015;
uint8_t nHour = 23;
uint8_t nMin = 18;
int nTZ = -4;
char buf[2];
char sbuf[15];
Panchanga pch;
  noInterrupts(); 
  FlexiTimer2::set(TIMER2VAL, Timer2_Overflow_ISR);
  FlexiTimer2::start();
  interrupts(); 
  doPanchanga();
  ADC_Value = analogRead(CurrentCh);
  // Spit out the values
  Serial.print("ADC, ");   
  Serial.println(ADC_Value);

MSP 432 with Sparkfun AD8232 EKG


int starttime;
int activetime;
int previoustime = 0;
int cnt = 0;
volatile unsigned int inADC = 0;
  pinMode(2, INPUT); // Setup for leads off detection LO +
  pinMode(3, INPUT); // Setup for leads off detection LO -
  if ((digitalRead(2) == 1) || (digitalRead(3) == 1)) {
    // Leads not connected
    // Serial.println('!');
  } else{
    // send the value of analog input 0:
    inADC = analogRead(A0);  // PIN_06
    // inADC = map(inADC, -4096, 4096, 1024, 1024);
    Serial.print("ADC,");
    Serial.print(inADC);
    Serial.print(",");
    Serial.println(activetime);
    ++cnt;
  }
  //Wait for a bit to keep serial data from saturating
  delay(1);

Based on the quality of time as determined by the Panchanga many health problems can be determined. Jotiz is being expanded to included uncharted medical astrology.

Read more about this in the upcoming book “Vedic Machine”

TI CC3200 LaunchPad IoT using Jotiz RESTful Services

TI CC3200 LaunchPad IoT with Sharp LCD using Jotiz RESTful Services

I present here a series of blogs that are intended to enable the use of ‘things’ in the Internet of Things IoT complementing Jotiz.

The CC3200 Launchpad from Texas Instruments is new generation 32 bit MCU with SoC and WiFi built it. In this article, I present the CC3200 micro-controller and its ability to read the Jotiz web service which gives the Panchanga. The development board is the size of a credit card and comes as an attractive red PCB. I also attached a Sharp 96x96 LCD booster pack on the MCU board to display the results. All this, I put into an acrylic enclosure with spacers and screws.

The Simplelink WiFi CC3200 Launchpad was connected to a Windows 7 laptop through the USB port. Remember to download the drivers for CC3200 from TI website. To develop the program, the Open Source Energia based on the Arduino IDE was used.


Links:

1.      Energia - http://energia.nu/
2.      Arduino - http://www.arduino.cc/
3.      Texas Instruments CC3200 Launchpad - http://www.ti.com/tool/cc3200-launchxl

How the program works:


It uses the WiFi library, JSON and the Sharp booster pack libraries. It fetches the Panchanga data from the Jotiz REST service, extracts the relevant information from the encoded JSON and displays on the LCD.

Based on the quality of time as determined by the Panchanga many common day to day decisions like attending an interview, choosing the right moment to discuss an idea or a raise, travelling, buying property, investing can be done with less negative consequences.

Excerpts from the code

  // Initializing the LCD and WiFi
  LCD_SharpBoosterPack_SPI myScreen;
  uint8_t k = 0;
  WiFiClient client;
  char server[] = "jotiz.com";
  boolean offline = false;
  
  #elif defined(__CC3200R1M1RGC__)
  SPI.begin();
  SPI.setClockDivider(SPI_CLOCK_DIV2); 
// for __CC3200R1M1RGC__ DIV2 = 4 MHz !
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);
  #endif

  if (WiFi.status() == WL_NO_SHIELD) {
    myScreen.text(10, 25, "FAIL");
    while(true);
  }

  while (wifiStatus != WL_CONNECTED) {
    wifiStatus = WiFi.begin(WIFI_SSID, WPA_PASSWORD);
    if (wifiStatus == WL_CONNECTED) {
      myScreen.text(10, 25, "Wifi: OK");
    } 
    delay(300);
  }

  if (!offline) {
    while (WiFi.localIP() == INADDR_NONE) {
      delay(300);
    }

    IPAddress ip = WiFi.localIP();

    if (client.connect(server, 80)) {
      client.println("GET /rest/resource.php?method=panch&format=json HTTP/1.1");
      client.println("Host: jotiz.com");
      client.println("Content-Type: application/json");
      client.println("Connection: close");
      client.println();
    } 

  if (!offline) {
    for (int i=0; i < 47; i++) {
      String jsonstr = "";
      while (client.available()) {
        char c = client.read();
        jsonstr += String(c);
      }
      String js = jsonstr.substring(jsonstr.indexOf("{"));
      char* jstr = strcpy((char*)malloc(js.length()+1), js.c_str());

      aJsonObject* root = aJson.parse((char *)jstr);
      aJsonObject* dd = aJson.getObjectItem(root, "dd");
      aJsonObject* mm = aJson.getObjectItem(root, "mm");
      aJsonObject* yy = aJson.getObjectItem(root, "yy");
      aJsonObject* hh = aJson.getObjectItem(root, "hh");
      aJsonObject* mt = aJson.getObjectItem(root, "mt");
      aJsonObject* dw = aJson.getObjectItem(root, "dw");

      aJsonObject* ui = aJson.getObjectItem(root, "unodeInausp");
      aJsonObject* si = aJson.getObjectItem(root, "saturnInausp");
      aJsonObject* di = aJson.getObjectItem(root, "deathBearing");
      aJsonObject* da = aJson.getObjectItem(root, "directionInausp");

      char buf1[10] = "";
      strcat(buf1, yy->valuestring);
      strcat(buf1, "-");
      strcat(buf1, mm->valuestring);
      strcat(buf1,  "-");
      strcat(buf1, dd->valuestring);

      myScreen.text(10, 25, buf1);
      char buf2[5] = "";

      strcat(buf2, hh->valuestring);
      strcat(buf2,  ":");
      strcat(buf2, mt->valuestring);
      myScreen.text(10, 35, buf2);

      myScreen.text(10, 45, "Rahu");
      myScreen.text(70, 45, ui->valuestring);
      blinkLed(LED1);
      myScreen.text(10, 55, "Saturn");
      myScreen.text(70, 55, si->valuestring);
      blinkLed(LED2);
      myScreen.text(10, 65, "Death");
      myScreen.text(70, 65, di->valuestring);
      blinkLed(LED3);
      myScreen.text(10, 75, "Direction");
      myScreen.text(70, 75, da->valuestring);
      myScreen.flush();

      free(dw);
      ..
      ..
      free (jstr);
      delay (500);

      free(mm);
      .. 
      ..
    }


MyScreen is the LCD screen - SHARP 96x96 pixels. The board on startup initializes the WiFi client, sends the SSID and Password to authenticate as an user and obtains an IP address. After getting the IP address, it uses the internet to connect to Jotiz and make a RESTful request. The JSON string received is broken up into its elements and displayed. 

Read more about this in the upcoming book “Vedic Machine

DIY - MSP430 Launchpad with BMP180 (A farmer's Almanac) complementing Jotiz

Do it Yourself - MSP430 Launchpad with BMP180 complementing Jotiz

I present here a series of blogs that are intended to enable the use of ‘things’ in the Internet of Things IoT complementing Jotiz.

To start with, I have used a MSP430FR5969(c) Launchpad(c)(r) from Texas Instruments. The development board is the size of a credit card and comes as an attractive red PCB. I also attached a Sharp 96x96 LCD booster pack on the MCU board to display the results and a Bosch BMP180 pressure and temperature sensor from Adafruit. All this, I put into an acrylic enclosure with hex spacers and M3 screws.


Links: 

1. Energia - http://energia.nu/
2. Guide to MSP430FR5969 - http://energia.nu/pin-maps/guide_msp430fr5969launchpad/
3. Arduino - http://www.arduino.cc/
4. Adafruit - https://www.adafruit.com/

How the program works:


It uses the wire library, the bmp085 and the Sharp booster pack libraries. It computes the Rahu Kaala, Gullika Kaala, Yamaghantaka and Shoola directions along with the sensors collecting pressure and temperature data from the ambient surroundings.

Based on the quality of time as determined by the Kaala and the pressure and temperature readings, house plants, green house plants and outdoor plants can be watered or checked for damages.

Excerpts from the code

  // Setting the pin modes of the pins connected to the BMP Sensor
  pinMode(P1_6, OUTPUT);
  pinMode(P1_7, OUTPUT);
  digitalWrite(P1_7, LOW);

  // Barometer Sensor
  digitalWrite(P1_7, HIGH);
  …
  …
  // After initializing the sensor, show the pressure and temperature
  showPressureTemp();
  …
  // display the results on the LCD
  myScreen.begin();
  myScreen.setFont(1);
  myScreen.text(10, 5, "Vedic");
  myScreen.setFont(0);
  myScreen.text(10, 30, "Jotiz Clock");
  myScreen.text(10, 40, "(c)devb inc");
  myScreen.flush();  

  delay(2000);
  myScreen.clearBuffer();

  // check for quality of time 
  doTime();
  …
  …

  // compute time
void doTime() {
  float h1;
  nMin++;
  if (nMin > 59) {
      nHour++;
      nMin = 0;
  }
  if (nHour > 23) {
      nDay++;
      nHour = 0;
  }
  if (nDay > 6) nDay = 0;
  h1 = nHour + (nMin / 60);

  switch (nDay) {
  case 0:
    if ((h1 >= 16.5) && (h1 <= 18)) showTime("Rahu  ","W","Sun");
    else if (h1 >= 15 && h1 < 16.5) showTime("Gulika","W","Sun");
    else if ((h1 >= 12 && h1 <= 13.5) || (h1 >= 18 && h1 <= 19.5)) 
showTime("Yama  ","W","Sun");
    else showTimeOnly("Sun");
    break;
  case 1:
    if (h1 >= 7.5 && h1 <= 9) showTime("Rahu  ","E","Mon");
    else if (h1 >= 13.5 && h1 < 15) showTime("Gulika","E","Mon");
    else if ((h1 >= 10.5 && h1 <= 12) || (h1 >= 3 && h1 <= 4.5)) 
showTime("Yama  ","E","Mon");
    else showTimeOnly("Mon");
    break;
  case 2:
    if (h1 >= 15 && h1 <= 16.5) showTime("Rahu  ","N","Tue");
    else if (h1 >= 12 && h1 < 13.5) showTime("Gulika","N","Tue");
    else if ((h1 >= 9 && h1 <= 10.5) || (h1 >= 1.5 && h1 <= 3)) 
showTime("Yama  ","N","Tue");
    else showTimeOnly("Tue");
    break;
  case 3:
    if (h1 >= 12 && h1 <= 13.5) showTime("Rahu  ","N","Wed");
    else if (h1 >= 10.5 && h1 < 12) showTime("Gulika","N","Wed");
    else if (h1 >= 7.5 && h1 <= 9) showTime("Yama  ","N","Wed");
    else showTimeOnly("Wed");
    break;
  case 4:
    if (h1 >= 13.5 && h1 <= 15) showTime("Rahu  ","S","Thu");
    else if (h1 >= 9 && h1 < 10.5) showTime("Gulika","S","Thu");
    else if ((h1 >= 6 && h1 <= 7.5) || (h1 >= 22 && h1 <= 24)) 
showTime("Yama  ","S","Thu");
    else showTimeOnly("Thu");
    break;
  case 5:
    if (h1 >= 10.5 && h1 <= 12) showTime("Rahu  ","W","Fri");
    else if (h1 >= 7.5 && h1 < 9) showTime("Gulika","W","Fri");
    else if ((h1 >= 15 && h1 <= 16.5) || (h1 >= 19.5 && h1 <= 21)) 
showTime("Yama  ","W","Fri");
    else showTimeOnly("Fri");
    break;
  case 6:
    if (h1 >= 9 && h1 <= 10.5) showTime("Rahu  ","E","Sat");
    else if (h1 >= 6 && h1 < 7.5) showTime("Gulika","E","Sat");
    else if ((h1 >= 13.5 && h1 <= 15) || (h1 >= 19.5 && h1 <= 21)) 
showTime("Yama  ","E","Sat");
    else showTimeOnly("Sat");
    break;
  default: 
    break;
  }
}

ShowTime has three parameters - the Kaala event, direction to avoid and the weekday.
Read more about this in the upcoming book “Vedic Machine