summaryrefslogtreecommitdiff
path: root/samples/dashboard_1602
diff options
context:
space:
mode:
authorStanley Huang <stanleyhuangyc@gmail.com>2015-05-17 23:29:58 +1000
committerStanley Huang <stanleyhuangyc@gmail.com>2015-05-17 23:29:58 +1000
commit06baa20150ece9b45d038234a04ed558ed2effab (patch)
tree08a689727d049ead87b5855adae8c9c5ded3c4f4 /samples/dashboard_1602
parente494891c8cb7a47279d5ce514850fa855e64ab0c (diff)
download2021-arduino-obd-06baa20150ece9b45d038234a04ed558ed2effab.tar.gz
2021-arduino-obd-06baa20150ece9b45d038234a04ed558ed2effab.tar.bz2
2021-arduino-obd-06baa20150ece9b45d038234a04ed558ed2effab.zip
Remove deprecated samples
Diffstat (limited to 'samples/dashboard_1602')
-rw-r--r--samples/dashboard_1602/LCD4Bit_mod.cpp233
-rw-r--r--samples/dashboard_1602/LCD4Bit_mod.h27
-rw-r--r--samples/dashboard_1602/dashboard_1602.ino173
3 files changed, 0 insertions, 433 deletions
diff --git a/samples/dashboard_1602/LCD4Bit_mod.cpp b/samples/dashboard_1602/LCD4Bit_mod.cpp
deleted file mode 100644
index ef93daa..0000000
--- a/samples/dashboard_1602/LCD4Bit_mod.cpp
+++ /dev/null
@@ -1,233 +0,0 @@
-/*
-LCD4Bit v0.1 16/Oct/2006 neillzero http://abstractplain.net
-
-What is this?
-An arduino library for comms with HD44780-compatible LCD, in 4-bit mode (saves pins)
-
-Sources:
-- The original "LiquidCrystal" 8-bit library and tutorial
- http://www.arduino.cc/en/uploads/Tutorial/LiquidCrystal.zip
- http://www.arduino.cc/en/Tutorial/LCDLibrary
-- DEM 16216 datasheet http://www.maplin.co.uk/Media/PDFs/N27AZ.pdf
-- Massimo's suggested 4-bit code (I took initialization from here) http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1144924220/8
-See also:
-- glasspusher's code (probably more correct): http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1160586800/0#0
-
-Tested only with a DEM 16216 (maplin "N27AZ" - http://www.maplin.co.uk/Search.aspx?criteria=N27AZ)
-If you use this successfully, consider feeding back to the arduino wiki with a note of which LCD it worked on.
-
-Usage:
-see the examples folder of this library distribution.
-
-*/
-
-#include "LCD4Bit_mod.h"
-
-#if defined(ARDUINO) && ARDUINO >= 100
-#include "Arduino.h"
-#else
-#include "WProgram.h"
-#endif
-
-//command bytes for LCD
-#define CMD_CLR 0x01
-#define CMD_RIGHT 0x1C
-#define CMD_LEFT 0x18
-#define CMD_HOME 0x02
-
-// --------- PINS -------------------------------------
-//is the RW pin of the LCD under our control? If we're only ever going to write to the LCD, we can use one less microcontroller pin, and just tie the LCD pin to the necessary signal, high or low.
-//this stops us sending signals to the RW pin if it isn't being used.
-int USING_RW = false;
-
-//RS, RW and Enable can be set to whatever you like
-int RS = 8;
-int RW = 11;
-int Enable = 9;
-//DB should be an unseparated group of pins - because of lazy coding in pushNibble()
-int DB[] = {4, 5, 6, 7}; //wire these to DB4~7 on LCD.
-
-//--------------------------------------------------------
-
-//how many lines has the LCD? (don't change here - specify on calling constructor)
-int g_num_lines = 2;
-
-//pulse the Enable pin high (for a microsecond).
-//This clocks whatever command or data is in DB4~7 into the LCD controller.
-void LCD4Bit_mod::pulseEnablePin(){
- digitalWrite(Enable,LOW);
- delayMicroseconds(1);
- // send a pulse to enable
- digitalWrite(Enable,HIGH);
- delayMicroseconds(1);
- digitalWrite(Enable,LOW);
- delay(1); // pause 1 ms. TODO: what delay, if any, is necessary here?
-}
-
-//push a nibble of data through the the LCD's DB4~7 pins, clocking with the Enable pin.
-//We don't care what RS and RW are, here.
-void LCD4Bit_mod::pushNibble(int value){
- int val_nibble= value & 0x0F; //clean the value. (unnecessary)
-
- for (int i=DB[0]; i <= DB[3]; i++) {
- digitalWrite(i,val_nibble & 01);
- val_nibble >>= 1;
- }
- pulseEnablePin();
-}
-
-//push a byte of data through the LCD's DB4~7 pins, in two steps, clocking each with the enable pin.
-void LCD4Bit_mod::pushByte(int value){
- int val_lower = value & 0x0F;
- int val_upper = value >> 4;
- pushNibble(val_upper);
- pushNibble(val_lower);
-}
-
-
-//stuff the library user might call---------------------------------
-//constructor. num_lines must be 1 or 2, currently.
-LCD4Bit_mod::LCD4Bit_mod (int num_lines) {
- g_num_lines = num_lines;
- if (g_num_lines < 1 || g_num_lines > 2)
- {
- g_num_lines = 1;
- }
-}
-
-void LCD4Bit_mod::commandWriteNibble(int nibble) {
- digitalWrite(RS, LOW);
- if (USING_RW) { digitalWrite(RW, LOW); }
- pushNibble(nibble);
-}
-
-
-void LCD4Bit_mod::commandWrite(int value) {
- digitalWrite(RS, LOW);
- if (USING_RW) { digitalWrite(RW, LOW); }
- pushByte(value);
- //TODO: perhaps better to add a delay after EVERY command, here. many need a delay, apparently.
-}
-
-
-
-
-//print the given character at the current cursor position. overwrites, doesn't insert.
-void LCD4Bit_mod::print(int value) {
- //set the RS and RW pins to show we're writing data
- digitalWrite(RS, HIGH);
- if (USING_RW) { digitalWrite(RW, LOW); }
-
- //let pushByte worry about the intricacies of Enable, nibble order.
- pushByte(value);
-}
-
-
-//print the given string to the LCD at the current cursor position. overwrites, doesn't insert.
-//While I don't understand why this was named printIn (PRINT IN?) in the original LiquidCrystal library, I've preserved it here to maintain the interchangeability of the two libraries.
-void LCD4Bit_mod::printIn(const char* msg) {
- uint8_t i; //fancy int. avoids compiler warning when comparing i with strlen()'s uint8_t
- uint8_t l = strlen(msg);
- for (i=0; i < l; i++){
- if (msg[i] >= 20) print(msg[i]);
- }
-}
-
-
-//send the clear screen command to the LCD
-void LCD4Bit_mod::clear(){
- commandWrite(CMD_CLR);
- delay(1);
-}
-
-
-// initiatize lcd after a short pause
-//while there are hard-coded details here of lines, cursor and blink settings, you can override these original settings after calling .init()
-void LCD4Bit_mod::init () {
- pinMode(Enable,OUTPUT);
- pinMode(RS,OUTPUT);
- if (USING_RW) { pinMode(RW,OUTPUT); }
- pinMode(DB[0],OUTPUT);
- pinMode(DB[1],OUTPUT);
- pinMode(DB[2],OUTPUT);
- pinMode(DB[3],OUTPUT);
-
- delay(50);
-
- //The first 4 nibbles and timings are not in my DEM16217 SYH datasheet, but apparently are HD44780 standard...
- commandWriteNibble(0x03);
- delay(5);
- commandWriteNibble(0x03);
- delayMicroseconds(100);
- commandWriteNibble(0x03);
- delay(5);
-
- // needed by the LCDs controller
- //this being 2 sets up 4-bit mode.
- commandWriteNibble(0x02);
- commandWriteNibble(0x02);
- //todo: make configurable by the user of this library.
- //NFXX where
- //N = num lines (0=1 line or 1=2 lines).
- //F= format (number of dots (0=5x7 or 1=5x10)).
- //X=don't care
-
- int num_lines_ptn = (g_num_lines - 1) << 3;
- int dot_format_ptn = 0x00; //5x7 dots. 0x04 is 5x10
-
- commandWriteNibble(num_lines_ptn | dot_format_ptn);
- delayMicroseconds(60);
-
- //The rest of the init is not specific to 4-bit mode.
- //NOTE: we're writing full bytes now, not nibbles.
-
- // display control:
- // turn display on, cursor off, no blinking
- commandWrite(0x0C);
- delayMicroseconds(60);
-
- //clear display
- commandWrite(0x01);
- delay(3);
-
- // entry mode set: 06
- // increment automatically, display shift, entire shift off
- commandWrite(0x06);
-
- delay(1);//TODO: remove unnecessary delays
-}
-
-
-//non-core stuff --------------------------------------
-//move the cursor to the given absolute position. line numbers start at 1.
-//if this is not a 2-line LCD4Bit_mod instance, will always position on first line.
-void LCD4Bit_mod::cursorTo(int line_num, int x){
- //first, put cursor home
- commandWrite(CMD_HOME);
-
- //if we are on a 1-line display, set line_num to 1st line, regardless of given
- if (g_num_lines==1){
- line_num = 1;
- }
- //offset 40 chars in if second line requested
- if (line_num == 2){
- x += 40;
- }
- //advance the cursor to the right according to position. (second line starts at position 40).
- for (int i=0; i<x; i++) {
- commandWrite(0x14);
- }
-}
-
-//scroll whole display to left
-void LCD4Bit_mod::leftScroll(int num_chars, int delay_time){
- for (int i=0; i<num_chars; i++) {
- commandWrite(CMD_LEFT);
- delay(delay_time);
- }
-}
-
-//Improvements ------------------------------------------------
-//Remove the unnecessary delays (e.g. from the end of pulseEnablePin()).
-//Allow the user to pass the pins to be used by the LCD in the constructor, and store them as member variables of the class instance.
-//-------------------------------------------------------------
diff --git a/samples/dashboard_1602/LCD4Bit_mod.h b/samples/dashboard_1602/LCD4Bit_mod.h
deleted file mode 100644
index 7318c32..0000000
--- a/samples/dashboard_1602/LCD4Bit_mod.h
+++ /dev/null
@@ -1,27 +0,0 @@
-#ifndef LCD4Bit_mod_h
-#define LCD4Bit_mod_h
-
-#include <inttypes.h>
-
-class LCD4Bit_mod {
-public:
- LCD4Bit_mod(int num_lines);
- void commandWrite(int value);
- void init();
- void print(int value);
- void printIn(const char* value);
- void clear();
- //non-core---------------
- void cursorTo(int line_num, int x);
- void leftScroll(int chars, int delay_time);
- //end of non-core--------
-
- //4bit only, therefore ideally private but may be needed by user
- void commandWriteNibble(int nibble);
-private:
- void pulseEnablePin();
- void pushNibble(int nibble);
- void pushByte(int value);
-};
-
-#endif
diff --git a/samples/dashboard_1602/dashboard_1602.ino b/samples/dashboard_1602/dashboard_1602.ino
deleted file mode 100644
index a357f4e..0000000
--- a/samples/dashboard_1602/dashboard_1602.ino
+++ /dev/null
@@ -1,173 +0,0 @@
-/*************************************************************************
-* Sample sketch based on OBD-II library for Arduino
-* Using a LCD1602 shield to display realtime vehicle data
-* Distributed under GPL v2.0
-* Copyright (c) 2012 Stanley Huang <stanleyhuangyc@gmail.com>
-* All rights reserved.
-*************************************************************************/
-
-#include <arduino.h>
-#include <Wire.h>
-#include <OBD.h>
-#include "LCD4Bit_mod.h"
-
-//create object to control an LCD.
-LCD4Bit_mod lcd = LCD4Bit_mod(2);
-
-COBD obd;
-
-//Key message
-unsigned int adc_key_val[5] ={30, 150, 360, 535, 760 };
-int NUM_KEYS = 5;
-int adc_key_in;
-char key=-1;
-char oldkey=-1;
-unsigned long lastTick = millis();
-uint8_t modes[2] = {0, 2};
-
-const char modePids[] = {PID_RPM, PID_SPEED, PID_THROTTLE, PID_ENGINE_LOAD,
- PID_COOLANT_TEMP, PID_INTAKE_TEMP, PID_AMBIENT_TEMP, PID_MAF_FLOW,
- PID_CONTROL_MODULE_VOLTAGE, PID_FUEL_PRESSURE, PID_INTAKE_MAP, PID_BAROMETRIC,
- PID_TIMING_ADVANCE, PID_FUEL_LEVEL, PID_RUNTIME, PID_DISTANCE};
-
-const char* modeLabels[] = {
- "Engine rpm", "Speed km/h", "Throttle %", "Engine Load %",
- "Coolant C", "Intake Air C", "Env. Temp C", "MAF Flow kpa",
- "Ctrl Voltage V", "Fuel kpa", "Intake kpa", "Barometer kpa",
- "Timing Adv. ", "Fuel Level %", "Run Time", "Distance km"};
-
-const char modePos[] = {8, 8, 11, 12,
- 11, 11, 11, 9,
- 11, 9, 9, 10,
- 12, 11, 8, 10};
-
-const char* modeFmts[] = {"%4u", "%3u", "%3u", "%u",
- "%3d", "%3d", "%3d", "%3u",
- "%3u", "%3u", "%3u", "%u",
- "%3d", "%3u", "%4u:%02u", "%04u"};
-
-#define TOTAL_PIDS (sizeof(modePids) / sizeof(modePids[0]))
-
-// Convert ADC value to key number
-char get_key(unsigned int input)
-{
- char k;
- for (k = 0; k < NUM_KEYS; k++) {
- if (input < adc_key_val[k])
- return k;
- }
- return -1;
-}
-
-void updateMode()
-{
- lcd.cursorTo(1, 0);
- lcd.printIn((char*)modeLabels[modes[0]]);
- lcd.cursorTo(2, 0);
- lcd.printIn((char*)modeLabels[modes[1]]);
-}
-
-bool showData(int index)
-{
- char buf[16];
- int value;
- uint8_t mode = modes[index];
- uint8_t pid = modePids[mode];
- digitalWrite(13, HIGH); // set the LED on
- if (!obd.read(pid, value)) {
- // display received data on error
- lcd.cursorTo(index + 1, 0);
- lcd.printIn("Error");
- delay(2000);
- updateMode();
- return false;
- }
- digitalWrite(13, LOW); // set the LED off
-
- if (pid == PID_RUNTIME) {
- sprintf(buf, modeFmts[mode], (unsigned int)value / 60, (unsigned int)value % 60);
- } else {
- sprintf(buf, modeFmts[mode], value);
- }
- lcd.cursorTo(index + 1, modePos[mode]);
- lcd.printIn(buf);
- return true;
-}
-
-bool setupConnection()
-{
- uint8_t errors = 0;
- char buf[16];
- lcd.clear();
- lcd.printIn("Connecting...");
- while (!obd.init()) {
- lcd.cursorTo(2, 0);
- sprintf(buf, "Attempts #%d", ++errors);
- lcd.printIn(buf);
- }
- lcd.clear();
- lcd.printIn("Connected!");
- delay(1000);
- updateMode();
- return true;
-}
-
-void setup()
-{
- pinMode(13, OUTPUT); //we'll use the debug LED to output a heartbeat
- lcd.init();
- obd.begin();
- setupConnection();
-}
-
-void loop()
-{
- adc_key_in = analogRead(0); // read the value from the sensor
- key = get_key(adc_key_in); // convert into key press
-
- if (key != oldkey) {
- delay(50); // wait for debounce time
- adc_key_in = analogRead(0); // read the value from the sensor
- key = get_key(adc_key_in); // convert into key press
- if (key != oldkey)
- {
- oldkey = key;
- if (key >=0){
- switch (key) {
- case 3: // left key
- do {
- modes[0] = modes[0] > 0 ? modes[0] - 1 : TOTAL_PIDS - 1;
- } while (modes[0] == modes[1]);
- break;
- case 0: // right key
- do {
- modes[0] = modes[0] < TOTAL_PIDS - 1 ? modes[0] + 1 : 0;
- } while (modes[0] == modes[1]);
- break;
- case 1: // up key
- do {
- modes[1] = modes[1] > 0 ? modes[1] - 1 : TOTAL_PIDS - 1;
- } while (modes[0] == modes[1]);
- break;
- case 2: // down key
- do {
- modes[1] = modes[1] < TOTAL_PIDS - 1 ? modes[1] + 1 : 0;
- } while (modes[0] == modes[1]);
- break;
- }
- updateMode();
- }
- }
- }
-
- unsigned long curTick = millis();
- if (curTick - lastTick > 500) {
- showData(0);
- showData(1);
- if (obd.errors > 10) {
- setupConnection();
- }
- lastTick = curTick;
- }
-}
-