Got arduino to respond to bluetooth commands sent from android. Show values back on android and turn on and off load.
This commit is contained in:
@@ -9,6 +9,7 @@ Tue Jun 12 14:56:12 GMT 2018
|
||||
*********************************************************************/
|
||||
|
||||
// Libraries to be included, non native libraries need to be included in the Makefile
|
||||
#include <stdlib.h>
|
||||
#include <LiquidCrystal.h> // Handles the connection and communications with the LCD display
|
||||
#include <SPI.h> // Handles the SPI connection to the SD card
|
||||
#include <SD.h> // Handles communication routines with the SD card
|
||||
@@ -47,6 +48,7 @@ LiquidCrystal lcd(7, 6, 2, 3, 4, 5); // LCD screen pins, LiquidCrystal(rs, enabl
|
||||
#define no 0 // no is always zero
|
||||
#define yes 1 // yes is alyays one
|
||||
File myFile; // Initiate the object File to write in the SD card
|
||||
SoftwareSerial mySerial(BLUE_RX, BLUE_TX); // Start file descriptor and assign pins to bluetooth module
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -64,6 +66,7 @@ bool sd_inserted = no; // Holds the state if sd card is in or not
|
||||
int sd_status = sd_not_in; // Holds information about the sd card
|
||||
|
||||
int currentScreen = 0; // Current display menu
|
||||
char ble_data = 'Z';
|
||||
|
||||
// String with the menus to be displayed
|
||||
String screens[numOfScreens][2] = {{"Voltage 1","Volts"}, {"Voltage 2","Volts"},
|
||||
@@ -78,6 +81,7 @@ float parameters[4]; // Parameters of the several voltages and curre
|
||||
float denominator; // Denominator to calculate the voltage divider
|
||||
int resistor1 = 22000; // Resistor one of voltage divider
|
||||
int resistor2 = 2200; // Resistor two of voltage divider
|
||||
static char outstr[15];
|
||||
// -----------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -101,6 +105,9 @@ void setup()
|
||||
|
||||
lcd.begin(16, 2); // Start LCD display with 16 characters and 2 lines
|
||||
|
||||
mySerial.begin(9600); // Start serial connection to bluetooth module
|
||||
Serial.begin(9600); // For debug only
|
||||
|
||||
// Voltage divider --> Vout = Vin * R2 / R1 + R2
|
||||
denominator = (float)resistor2 / (resistor1 + resistor2);
|
||||
|
||||
@@ -139,6 +146,34 @@ ISR(TIMER1_COMPA_vect)
|
||||
load_status = off; // Turn off load
|
||||
}
|
||||
digitalWrite(load_line, load_status); // Turn load on or off depending on the load_status
|
||||
|
||||
if (mySerial.available()) {
|
||||
ble_data = mySerial.read();
|
||||
Serial.write(mySerial.read());
|
||||
if (ble_data == 'A') {
|
||||
dtostrf(parameters[battery_volt], 5, 2, outstr);
|
||||
mySerial.write(outstr);
|
||||
}
|
||||
if (ble_data == 'B') {
|
||||
dtostrf(parameters[voltage_1], 5, 2, outstr);
|
||||
mySerial.write(outstr);
|
||||
}
|
||||
if (ble_data == 'C') {
|
||||
dtostrf(parameters[voltage_2], 5, 2, outstr);
|
||||
mySerial.write(outstr);
|
||||
}
|
||||
if (ble_data == 'D') {
|
||||
dtostrf(parameters[curr], 5, 2, outstr);
|
||||
mySerial.write(outstr);
|
||||
}
|
||||
if (ble_data == 'E') {
|
||||
load_status = on;
|
||||
}
|
||||
if (ble_data == 'F') {
|
||||
load_status = off;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//-------------------------------------------
|
||||
|
||||
@@ -150,13 +185,19 @@ void loop()
|
||||
parameters[voltage_2] = volt_pin(volt_2); // Update voltage two value
|
||||
parameters[curr] = amp_pin(i_load); // Update current load
|
||||
|
||||
|
||||
|
||||
|
||||
Serial.write(ble_data); // For debug only
|
||||
|
||||
if (sd_inserted == no) // If sd_rw value is turned on
|
||||
{
|
||||
sd_status = sd_not_in;
|
||||
}
|
||||
else if (sd_rw == on)
|
||||
{
|
||||
myFile = SD.open(file_name + ".TXT", FILE_WRITE); // Open file name and add ".TXT", for writing
|
||||
myFile = SD.open(file_name + ".TXT", FILE_WRITE); // Open file name and add ".TXT",
|
||||
// for writing
|
||||
if (myFile) // if succeds
|
||||
{
|
||||
myFile.print("Batt voltage, ");
|
||||
|
Reference in New Issue
Block a user