Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Varindra KumarShalini Vaish
Published

Diabetes Diagnosis and Management

Diabetes diagnosis and management using Android over Bluetooth and NFC.

IntermediateWork in progress22,116
Diabetes Diagnosis and Management

Things used in this project

Story

Read more

Schematics

Partial schematics

Arduino connected with HC-05, SD card and TGS 826 gas sensor

Code

Partial code

Arduino
// This version uses the internal data queing so you can treat it like Serial (kinda)!

#include <SPI.h>
//#include "Adafruit_BLE_UART.h"
#include <Adafruit_GFX.h>      // include Adafruit graphics library
#include <Adafruit_ST7735.h>   // include Adafruit ST7735 TFT library
#include <Plotter.h>

#include <SoftwareSerial.h>

SoftwareSerial mySerial(4, 5); // RX, TX
 
#define TFT_RST   8      // TFT RST pin is connected to arduino pin 8
#define TFT_CS    9      // TFT CS  pin is connected to arduino pin 9
#define TFT_DC    10     // TFT DC  pin is connected to arduino pin 10
// initialize ST7735 TFT library
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);

 Plotter p;
double x;
// define Gas data pin connection
#define  Gas_pin  A0
// Connect CLK/MISO/MOSI to hardware SPI
// e.g. On UNO & compatible: CLK = 13, MISO = 12, MOSI = 11
#define ADAFRUITBLE_REQ 7
#define ADAFRUITBLE_RDY 2     // This should be an interrupt pin, on Uno thats #2 or #3
#define ADAFRUITBLE_RST 6

//Adafruit_BLE_UART BTLEserial = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST);
/**************************************************************************/
/*!
    Configure the Arduino and start advertising with the radio
*/
/**************************************************************************/
void setup(void)
{ 
  
  while(!Serial); // Leonardo/Micro should wait for serial init
  Serial.println(F("Bluetooth comm"));

  Serial.println("Enter AT commands:");
  mySerial.write("AT+ROLE=0");
  mySerial.begin(9600);

  p.Begin();
  p.AddTimeGraph( "BT plot", 1500, "sample", x ); // add any graphs you want
  // BTLEserial.setDeviceName("NEWNAME"); /* 7 characters max! */

//  BTLEserial.begin();
   analogReference(INTERNAL);     // set positive reference voltage to 1.1V
 
  tft.initR(INITR_BLACKTAB);     // initialize a ST7735S chip, black tab
  tft.fillScreen(ST7735_BLACK);  // fill screen with black color
  tft.drawFastHLine(0, 44,  tft.width(), ST7735_BLUE);    // draw horizontal blue line at position (0, 44)
 
  tft.setTextColor(ST7735_WHITE, ST7735_BLACK);     // set text color to white and black background
  tft.setTextSize(1);                 // text size = 1
  tft.setCursor(4, 10);               // move cursor to position (4, 10) pixel
  tft.print("ARDUINO + ST7735 TFT");
  tft.setCursor(15, 27);              // move cursor to position (25, 27) pixel
  tft.print("+ Diabetic SENSOR");
  tft.setTextColor(ST7735_GREEN, ST7735_BLACK);     // set text color to green and black background
  tft.setCursor(05, 55);              // move cursor to position (15, 55) pixel
  tft.print("Diabetic Value:");
  tft.setTextSize(2);                 // text size = 2
}

/**************************************************************************/
/*!
    Constantly checks for new events on the nRF8001
*/
/**************************************************************************/
//aci_evt_opcode_t laststatus = ACI_EVT_DISCONNECTED;

void loop()
{
    char _buffer[8];
    int Diabetic_value = analogRead(Gas_pin);
    float val;
    Diabetic_value = Diabetic_value/10;
    val = Diabetic_value; 

//Serial.print("Raw data : ");
//Serial.print(val);
if (mySerial.available()){
mySerial.print("Raw data : ");
mySerial.print(val);
Serial.print("Raw data : ");
Serial.print(val);
Serial.print('\n');}
else if (Serial.available()){
mySerial.print("Diabetes value : ");
//mySerial.write(Serial.read());
//mySerial.print(time1);
//mySerial.print(",");
mySerial.print(val);
mySerial.print(" PPM");
mySerial.print('\n');

}
  if (Diabetic_value >= 100)    // if Diabetes >= 100.0 
   {   tft.setCursor(13, 77);
       tft.setTextColor(ST7735_RED, ST7735_BLACK);  // set text color to red and black background
       tft.print(Diabetic_value);
       
     //  tft.print(_buffer);
       tft.setCursor(75, 77);
       tft.print("PPM"); }
  else
    {   tft.setCursor(05, 77);
        tft.setTextSize(2);                 // text size = 1
       tft.print("No Diabetes"); 
    }
  
  
  
  // Tell the nRF8001 to do whatever it should be working on.
/*  BTLEserial.pollACI();

  // Ask what is our current status
  aci_evt_opcode_t status = BTLEserial.getState();
  // If the status changed....
  if (status != laststatus) {
    // print it out!
    if (status == ACI_EVT_DEVICE_STARTED) {
        Serial.println(F("* Bluetooth starting to connect"));
    }
    if (status == ACI_EVT_CONNECTED) {
        Serial.println(F("* Connected!"));
    }
    if (status == ACI_EVT_DISCONNECTED) {
        Serial.println(F("* Disconnected or timed out"));
    }
    // OK set the last status change to this one
    laststatus = status;
  }

  if (status == ACI_EVT_CONNECTED) {
    // Lets see if there's any data for us!
    if (BTLEserial.available()) {
      Serial.print("* "); 
      Serial.print(BTLEserial.available()); 
      Serial.println(F(" bytes available from BTLE"));
    }
    // OK while we still have something to read, get a character and print it out
    while (BTLEserial.available()) {
      char c = BTLEserial.read();
  //    
      Serial.print(c);
    }

    // Next up, see if we have any data to get from the Serial console

    if (Serial.available()) {
      // Read a line from Serial
      Serial.setTimeout(100); // 100 millisecond timeout
      String s = Serial.readString();

      // We need to convert the line to bytes, no more than 20 at this time
     // uint8_t sendbuffer[20];
      uint8_t analog = Diabetic_value;
      //s.getBytes(sendbuffer, 20);
   //   s.getBytes(analog, 2);
    //  char sendbuffersize = min(20, s.length());
      char analogsize = min(2, s.length());

   //   Serial.print(F("\n* Sending -> \"")); 
  //    Serial.print((char *)sendbuffer); 
   //      Serial.print((char *)analog);
      Serial.println("\"");

      // write the data
     // BTLEserial.write(sendbuffer, sendbuffersize);
   //   analog = Diabetic_value;
   //   BTLEserial.write(analog, analogsize);
    }
  } */


 delay(1000);    // wait a second 
}

Credits

Varindra Kumar

Varindra Kumar

1 project • 10 followers
Shalini Vaish

Shalini Vaish

0 projects • 7 followers
I am a health professional and interested to create a quick and efficient way to detect and manage type 1 diabetes for bedside patients.
Thanks to shalini_v.

Comments