Skip to content

Commit

Permalink
ADD: Analog Sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasmenares committed Apr 5, 2020
1 parent 9022ed8 commit 3860ae3
Show file tree
Hide file tree
Showing 24 changed files with 417 additions and 198 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VUE_APP_API_URL="http://localhost:5000/"
Binary file removed Skyline_data.hex
Binary file not shown.
155 changes: 0 additions & 155 deletions dash.py

This file was deleted.

Binary file added dashboard/Database.db
Binary file not shown.
114 changes: 114 additions & 0 deletions dashboard/arduino/analog.csv/analog/analog.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@

//Arduino pro micro, .93" I2C OLED use pin 2 for SDA and 3 for SCL ***Look up i2c pins for your controller

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define sensorPin A0

int OLED_RESET = 4;
Adafruit_SSD1306 display(OLED_RESET); //driver for the screen

// bar graph

float rawval = 0; // Setup raw sensor value
float barboost = 0; // Setup value for boost bar

// peak

int boostPeakReset = 4000; // time in milis to reset peak value
float boostPeak = 0.00;
float boostMax = 0.00;
unsigned long boostPeakTimer = 0;



// log

byte count;
byte sensorArray[128];
byte drawHeight;
boolean filled = 0; //decide either filled, or dot-display. 0==dot display.


//Send Data

String sender;
String peak;

void setup()
{
Serial.begin(9600); // start monitoring raw voltage for calibration
display.begin(SSD1306_SWITCHCAPVCC); // 3.3V power supply
display.clearDisplay(); // Clear the display and ram
display.display();
delay(2000); // display Adafruit logo for 2 seconds
for (count = 0; count <= 128; count++) //zero all elements
{
sensorArray[count] = 0;
}
}


void loop() // Start loop
{



int boostmbar = map(analogRead(sensorPin), 21, 961, 100, 2600);
rawval = analogRead(0); // Read MAP sensor raw value on analog port 0
barboost = (((rawval * 0.19) - 69.45) + 10); // Calculate boost value for the graph



if (boostPeak < boostmbar && boostmbar > 0.50) {
boostPeak = boostmbar;
boostPeakTimer = millis();
if (boostMax < boostPeak) {
boostMax = boostPeak;
}
}
else if (boostPeak > boostmbar && (millis() - boostPeakTimer) > boostPeakReset) {
boostPeak = 0.00;
}


// log

drawHeight = map(analogRead(A0), 0, 1023, 0, 25 );

sensorArray[0] = drawHeight;

for (count = 55; count <= 128; count++ )
{
if (filled == false)
{
display.drawPixel(count, 71 - sensorArray[count - 55], WHITE);
}
else
display.drawLine(count, 1, count, 71 - sensorArray[count - 55], WHITE);
}

for (count = 80; count >= 2; count--) // count down from 160 to 2
{
sensorArray[count - 1] = sensorArray[count - 2];
}
;

display.setTextSize(1); //Display peak boost
display.setCursor(97, 10);
peak = (((boostPeak * 0.001) - 0.865)*14); // 0.97 = 970mbar atmospheric pressure correction

if ((((boostmbar * 0.001) - 0.865)*14) < 0) {
display.println(((boostmbar * 0.001) - 0.865)*63.2);
sender = "{'psi': "+String(((boostmbar * 0.001) - 0.865)*63.2)+",'peak': "+String(peak)+", 'raw': "+ String(rawval) +"}";
}
else if ((((boostmbar * 0.001) - 0.865)*14) > 0) {
display.println(((boostmbar * 0.001) - 0.865)*14); // calibrated for a 2.5 bar sensor in Denver (+/- 1psi)
sender = "{'psi': "+String(((boostmbar * 0.001) - 0.865)*14)+", 'peak': "+String(peak)+",'raw': "+ String(rawval) +"}";
}

delay(1);
Serial.println(sender);
delay(10); // delay half second between numbers
}
32 changes: 32 additions & 0 deletions dashboard/core/analog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import pynmea2
import time
import json
from termcolor import colored
from core.serial import PortSerial

class Analog():

def __init__(self, socketio, arduino_path, serial_class):
self.socketio = socketio
self.port_serial = PortSerial(arduino_path, serial_class)
self.PORT = None

def start(self):
while self.port_serial.set_port():
print(colored("No Analog Devise connected in "+self.gps_path))
self.socketio.emit('gpsConnection', {'status': False})
time.sleep(2)
self.PORT = self.port_serial.PORT
# try:
while True:
self.parse_analog()
# except:
# self.port_serial.close()
# self.start()

def parse_analog(self):
ard = self.PORT.readline().decode().replace("\r\n","")
analog = eval(ard)
self.socketio.emit('analogConnection', {'status': True})
self.socketio.emit("analog", {'turbo': {'psi': { 'value': analog['psi'], 'peak': analog['peak'], 'raw': analog['raw'] }, 'bar': {'value': round((analog['psi'] * 0.0689475729317831), 2), 'peak': round((analog['peak'] * 0.0689475729317831), 2) } }})
time.sleep(0.001)
26 changes: 21 additions & 5 deletions dashboard/core/gps.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
import pynmea2
import time
from termcolor import colored
from core.serial import PortSerial

class Gps():

def __init__(self, socketio, gps_path, serial_class):
self.socketio = socketio
self.gps_path = gps_path
self.port_serial = PortSerial(gps_path, serial_class)
self.PORT = None

def start(self):
while self.port_serial.set_port():
print("No GPS Devise connected in "+self.gps_path)
self.socketio.emit('gps_conection', {'status': False})
while self.port_serial.set_port():
print(colored("No GPS Devise connected in "+self.gps_path))
self.socketio.emit('gpsConnection', {'status': False})
time.sleep(2)
self.PORT = self.port_serial.PORT
while True:
self.parse_gps()
try:
while True:
self.parse_gps()
except:
self.port_serial.close()
self.start()

def parse_gps(self):
gps = self.PORT.readline().decode()
if gps.find('GGA') > 0:
msg = pynmea2.parse(gps)
self.socketio.emit('gpsConnection', {'status': True, "signal": self.signal(msg.lat, msg.lon) })
self.socketio.emit("gps", {"lat": msg.lat, "lat_dir": msg.lat_dir, "lon": msg.lon, "lon_dir": msg.lon_dir, "altitude": msg.altitude, "altitude_long": msg.altitude_units, "sat_numbers": msg.num_sats})
print ("Timestamp: %s -- Lat: %s %s -- Lon: %s %s -- Altitude: %s %s -- Satellites: %s" % (msg.timestamp,msg.lat,msg.lat_dir,msg.lon,msg.lon_dir,msg.altitude,msg.altitude_units,msg.num_sats))

def signal(self, lat, lon):
if lat == "" or lon == "":
return False
else:
return True

1 change: 0 additions & 1 deletion dashboard/core/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def set_port(self):
self.PORT = self.serial.Serial(self.devise_path, 9600, timeout=None)
return False
except:
# traceback.print_exc()
self.PORT = None
return True
return False
Expand Down
Loading

0 comments on commit 3860ae3

Please sign in to comment.