Show Posts
Pages: [1] 2 3 ... 9
1  Using Arduino / Programming Questions / Re: Debugging OBD II flow switching between queries on: August 04, 2014, 01:55:57 am
https://github.com/stirobot/arduinoModularTFTgauges/commit/d29fae5a3ed9c86136833c38ec6fd00e4247274e

Works, with the exception of the Coolant PID....which I put in right after all of the initializations and it works there.  So, I'm baffled as to why it doesn't work in the display code.

Thanks for the links and all.  There really is a lot of room for improvement in stuff like this.  Some of the pseudo multi-threading and non-blocking examples are pretty neat pieces of code. (I should have got that CS degree and not that Cognitive Science degree).
2  Using Arduino / Programming Questions / Debugging OBD II flow switching between queries on: August 02, 2014, 10:47:57 pm
I have a OBD II project the uses the sparkfun UART OBD II (https://www.sparkfun.com/products/9555) device, a 1.8" tft (similar to the one sold at by adafruit), a button and an accelerometer.  Everything is configured via a file in an SD card.  

A bit of warning, the code block is long and I don't like how it is organized (one large loop of reading through the config file), but that part works for the moment.

Here is the larger, graphical 1.8" tft version:  https://github.com/stirobot/arduinoModularTFTgauges/blob/master/modularTFTgauge.ino

I also have a smaller more readable version of this project that uses 3 buttons, the OBD II UART device and a serial 7 segment display (https://www.sparkfun.com/products/11442).

Here is the code for that: https://github.com/stirobot/arduinoModularTFTgauges/blob/master/brzclockgauge.ino

Some other notes:
-Both sketches use roughly the same OBD II code.  I've included the second one so you don't have to wade through the long project code listing of the first version.  It has a lot of graphics code and stuff for slogging through the config file (in an inefficient manner...it is like I did the whole thing forgetting to use arrays  smiley-eek).
-The BRZ (also called the FRS/GT86) is a car I own that use a special OBD II CAN header to access the 2101 pid that gives oil temperature.
-Even though some of the code applies the header right before getting an oil temp reading, it isn't necessary.  Resetting when switching back to standard PIDs is also not necessary.

So, what is my issue...
-I have something wrong with the OBD II serial flow of things.  I will oftentimes get no data or partial data from some PID calls.  And this is dependent on what PID I query for first
-I suspect this has something to do with stuff still left in the rxData[] array or maybe with how I initialized the connection to the UART device and make the first call.

There are two versions of getResponse() that are responsible for getting the serial stuff back from the UART device.  I've gotten them from others in other forums.  What are your thoughts on the two of them?

Code:
//from:  https://forum.sparkfun.com/viewtopic.php?f=14&t=32457&start=60 and https://forum.sparkfun.com/viewtopic.php?f=14&t=38253
/*void getResponse(void){
  char c;
 // int start=millis();
  //If nothing is currently available do nothing and break after 3 seconds
  //while(Serial1.available()==0){if(millis()-start>3000){break;}}
  do {
    if (Serial1.available() > 0)
    {
      c = Serial1.read();
      if ((c != '>') && (c != '\r') && (c != '\n')) //Keep these out of our buffer
      {
        rxData[rxIndex++] = c; //Add whatever we receive to the buffer
      }
    }
  }
  while (c != '>'); //The ELM327 ends its response with this char so when we get it we exit out.
  rxData[rxIndex++] = '\0';  //Converts the array into a string
  Serial.print("rxData(in getResponse): ");
  Serial.println(rxData);
  rxIndex = 0; //Set this to 0 so next time we call the read we get a "clean buffer
}

and

Code:
void getResponse(void){
  char obdIn=0;
  int i=0;
  int start=millis();
  //If nothing is currently available do nothing and break after 3 seconds
  while(Serial1.available()==0){if(millis()-start>3000){break;}}
  while(Serial1.available()){
    //check to see if end of line/message
    if (Serial1.peek()=='\r'){
      obdIn=Serial1.read();
      rxData[i]='\0';
      Serial.println(rxData);
      i=0;
    }
    // The prompt is sometimes the only thing recieved so this needs to be taken care of
    else if(Serial1.peek()=='>'){
      obdIn=Serial1.read();
      Serial.write(obdIn);
    }
    // Add next character to string
    else{
      obdIn=Serial1.read();
      rxData[i++]=obdIn;
    }
  }
  Serial.print("rxData(in getResponse): ");
  Serial.println(rxData);
  rxIndex=0;
}

Sorry for the word fort/wall of text.  It isn't the most straightforward question and I don't expect a silver bullet answer (though that would be pretty neat).  I would like to know what to try next.  I'm stumped.
3  Using Arduino / Displays / New arduino TFT vs adafruit 1.8" TFT vs eBay clone of adafruit TFT on: May 25, 2013, 08:56:31 am
All of these seem to be based on the ST7735R.
They have very similar wiring.  See this ref: http://webshed.org/wiki/18tftbreakout
The screens are all about the same size (might actually be the same)
Header arrangement on the arduino version seems to be much better for hooking onto arduino easier.
The adafruit one and the arduino one are actually probably lead free.  The eBay one not so much.
The arduino version and the adafruit version have a PWM dimable backlight...I don't think the others do this.
All three have a micro ad slot.

Will the new arduino TFT library work with the adafruit and the eBay device? 
What advantage does the arduino libs have over the adafruit ones? Is it just that they are more processing like?

(I ask all of this because I once had a project that used the liquid ware touchscreens.  Communicating with them was always an issue for me.  These screens are worlds cheaper and seem very straightforward to communicate with.)
4  Using Arduino / Displays / Re: issue with touschshield slide comms (showing reading then 0 then reading...etc) on: February 16, 2011, 09:47:56 pm
Ok, so i made the code much more simple and now the arduino just gets the values from the sensors via analog read sends those integers straight to the touchshield.

To debug I'm just displaying the those raw 0-1024 values and i'm getting the following behaviors:

-The values change rapidly between multiple values in a large(ish) range.
-That range seems to propogate through all the sensor with exactly the same values.
-They all show a peak of 912.

So, is addressing sensor values like this not working:
Code:
if (Sensor.available()){
    int value;
    value = Sensor.read();
    if (strcmp(Sensor.getName(), "x")) { 
        //accelx = getAccelerometerData(value)/100; //get the sensor value
        accelx = value;
        if ((accelx > x_peak_pos) && (accelx > 0)){
          x_peak_pos = accelx;
        }
        if ((accelx < x_peak_neg) && (accelx < 0)){
          x_peak_neg = accelx;
        }
        print_values_x();
        //draw_bars_x();
      }
      if (strcmp(Sensor.getName(), "y")) { 
        //accely = getAccelerometerData(value)/100; //get the sensor value
        accely = value;
        if ((accely > y_peak_pos) && (accely > 0)){
          y_peak_pos = accely;
        }
        if ((accely < y_peak_neg) && (accely < 0)){
          y_peak_neg = accely;
        }       
        print_values_y();
        //draw_bars_y();
      }
      if (strcmp(Sensor.getName(), "t1")) { 
        //temp1 = lookup_temp(value); //get the sensor value
        temp1 = value;
        if (temp1 > peak_temp1){
          peak_temp1 = temp1;
        }
        print_values_t1();
        //draw_bars_t1();
      }
      if (strcmp(Sensor.getName(), "t2")) { 
        //temp2 = lookup_temp(value); //get the sensor value
        temp2=value;
        if (temp2 > peak_temp2){
          peak_temp2 = temp2;
        }
        print_values_t2();
        //draw_bars_t2();
      }
      if (strcmp(Sensor.getName(), "bt")){
        //boost = lookup_boost(value);
        boost=value;
        if (boost > peak_boost){
          peak_boost = boost;
        }
        print_values_boost();
        //draw_bars_boost();
      } 
  }
5  Using Arduino / Displays / Re: issue with touschshield slide comms (showing reading then 0 then reading...etc) on: February 15, 2011, 10:58:50 pm
Wait... Small epiphany here.

Can I send a float through Sensor.print and expect it to reassembled the float on the other end or should I break it up into small chunks and reassemble them on the other end (ala the famous scooter computer)?
6  Using Arduino / Displays / Re: issue with touschshield slide comms (showing reading then 0 then reading...etc) on: February 15, 2011, 10:22:47 pm
Code:
#include <HardwareSensor.h>
//writen for the touchshield slide
//draws current/peak and a bar graph for:
//  x
//  y
//  bst
//  IC F
//  Turbo F

//debug notes:
//showing max then 0 then max then 0?? with no sensors plugged in and with sensors pluggedin
//shows value then 0 then value...
////comms issue - getting sent 0 and then getting sent real value (arduino code fix)
////comms issue - packing 0 into the var that is getting sent out (arduino code)
////comms error - between checking which sensor it is and then grabbing that value there is an error
////   but the buffer should aready have that value
//with sensors plugged in:
//boost 35 or 32 (not sure why...suspect missing something or other)
///boost also looks like it is matching the t2 output for some odd reason...even with no sensor present
//x and y both at 0
//t1 and t2 are working in their full range (warm hand test)

float boost = 0;
float temp1 = 0;
float temp2 = 0;
float accelx = 0, accely = 0;
float o_x = 160;
float o_y = 160;
float x_peak_neg = 0;
float x_peak_pos = 0;
float y_peak_neg = 0;
float y_peak_pos = 0;
float peak_boost = 0;
float peak_temp1 = 0;
float peak_temp2 = 0;
float o_boost = 0;
float o_temp1 = 0;
float o_temp2 = 0;

int maxBoost = 25;
int maxT1 = 300;
int maxT2 = 300;

int warnBoost = 21;
int warnT1 = 200;
int warnT2 = 200;

int severeBoost = 23;
int severeT1 = 300;
int severeT2 = 300;

void setup(){
  Sensor.begin(19200);
  background(0); //black background
 
  //draw the rectangles and labels
  //-spacing should be 40 pixels tall for each rectangle
  //-all rects start at 50 and go 2xx pixels widen
  //-all rects are 44 high
  fill(0,0,0);
  stroke(255,0,0);
  rect(50,4,220,42);
  rect(50,52,220,42);
  rect(50,100,220,42);
  rect(50,148,220,42);
  rect(50,196,220,42);
 
  //bar labels
  text("boost",8,22,8);
  text("x",20, 52+20,18);
  text("y",20,100+20,18);
  text("t1",14,148+20,18);
  text("t2",14,196+20,18);
 
}

//get the readings from the arduino
void loop(){
  gettouch(); //update the mouse coordinates
  //add section to reset peaks on touch per area

  //change the below section so that it updates in a nicer/more efficient manner
  if (Sensor.available()){
    int value;
    value = Sensor.read();
    if (strcmp(Sensor.getName(), "x")) { 
        accelx = value/100; //get the sensor value
        if ((accelx > x_peak_pos) && (accelx > 0)){
          x_peak_pos = accelx;
        }
        if ((accelx < x_peak_neg) && (accelx < 0)){
          x_peak_neg = accelx;
        }
        print_values_x();
        //draw_bars_x();
      }
      if (strcmp(Sensor.getName(), "y")) { 
        accely = value/100; //get the sensor value
        if ((accely > y_peak_pos) && (accely > 0)){
          y_peak_pos = accely;
        }
        if ((accely < y_peak_neg) && (accely < 0)){
          y_peak_neg = accely;
        }       
        print_values_y();
        //draw_bars_y();
      }
      if (strcmp(Sensor.getName(), "t1")) { 
        temp1 = value; //get the sensor value
        if (temp1 > peak_temp1){
          peak_temp1 = temp1;
        }
        print_values_t1();
        //draw_bars_t1();
      }
      if (strcmp(Sensor.getName(), "t2")) { 
        temp2 = value; //get the sensor value
        if (temp2 > peak_temp2){
          peak_temp2 = temp2;
        }
        print_values_t2();
        //draw_bars_t2();
      }
      if (strcmp(Sensor.getName(), "bt")){
        boost = value;
        if (boost > peak_boost){
          peak_boost = boost;
        }
        print_values_boost();
        //draw_bars_boost();
      } 
  }
    //for debuging the display without the comms stuff/without sensors
    /*boost = boost + random(2);
    accelx = accelx + .01;
    accely = accely + .01;
    temp1 = temp1 + random(2);
    temp2 = temp2 + random(2); */
   
    //avoid flicker as much as possible by only redrawing when there is a change
    //skip the accel readings because they will jump all over the place anyways?
    o_boost = boost;
    o_temp1 = temp1;
    o_temp2 = temp2;
    o_x = abs(accelx);
    o_y = abs(accely);
}


//TODO split this into many functions
void print_values_boost(){
  fill(0,0,0);
  stroke(0,255,255); //light blue
  //current
  text(boost,274,4+6);
  //peak
  text(peak_boost,274,30);
 }

 void print_values_x(){
  fill(0,0,0);
  stroke(0,255,255); //light blue
  text(accelx,274,52+6);
  text(x_peak_pos,274,52+20);
  text(x_peak_neg,274,52+30);
 }

 void print_values_y(){
  fill(0,0,0);
  stroke(0,255,255); //light blue
  text(accely,274,100+6);
  text(y_peak_pos,274,100+20);
  text(y_peak_neg,274,100+30);
 }

 void print_values_t1(){
  fill(0,0,0);
  stroke(0,255,255); //light blue
  text(temp1,274,148+6);
  text(peak_temp2,274,196+26);
 }

 void print_values_t2(){
  fill(0,0,0);
  stroke(0,255,255); //light blue
  text(temp2,274,196+6);
  text(peak_temp1,274,148+26); 
}

void draw_bars_boost(){
  float twidth=0;
  //boost
  if(boost != o_boost){
    fill(0,255,0); //green
    stroke(0,255,0);
    if (boost > warnBoost){
      fill(255,255,0);
      stroke(255,255,0);
    }
    if (boost > severeBoost){
      fill(255,0,0);
      stroke(255,0,0);
    }
    twidth=218/maxBoost*boost;
    rect(51,5,twidth,40);
    if (o_boost >= boost){
      stroke(0,0,0);
      fill(0,0,0);
      rect(twidth+1+51,5,218-twidth,40);
    }
  }
 }


  //x and y will be displayed as positive only (absolute value) in the bar graph
  //they will be light blue and have no warning/severe values

void draw_bars_x(){
  //x
  float twidth=0;
  fill(0,255,255); //light blue
  stroke(0,255,255);
  twidth = 218/200*abs(accelx*100);
  rect(51,53,twidth,40);
  if(o_x >= abs(accelx)){
    stroke(0,0,0);
    fill(0,0,0);
    rect(twidth+1+51,53,218-twidth-1,40);
  }
}
 
 void draw_bars_y(){
  //y
  float twidth=0;
  fill(0,255,255); //light blue
  stroke(0,255,255);
  twidth=218/200*abs(accely*100);
  rect(51,101,twidth,40);
  if (o_y >= abs(accely)){
    stroke(0,0,0);
    fill(0,0,0);
    rect(twidth+1+51,101,218-twidth-1,40);
  }
 }
 
void draw_bars_t1(){
  //t1
  float twidth=0;
  if (temp1 != o_temp1){
    fill(0,255,0); //green
    stroke(0,255,0);
    if (temp1 > warnT1){
      fill(255,255,0);
      stroke(255,255,0);
    }
    if (temp1 > severeT1){
      fill(255,0,0);
      stroke(255,0,0);
    }
    twidth = temp1;
    rect(51,149,twidth,40);
    if (o_temp1 >= temp1){
      stroke(0,0,0);
      fill(0,0,0);
      rect(twidth+1+51,149,218-twidth,40);
    }
  }
 }

  void draw_bars_t2(){
  //t2
  float twidth=0;
  if (temp2 != o_temp2){
    fill(0,255,0); //green
    stroke(0,255,0);
        if (temp2 > warnT2){
      fill(255,255,0);
      stroke(255,255,0);
    }
    if (temp2 > severeT2){
      fill(255,0,0);
      stroke(255,0,0);
    }
    twidth = temp2;
    rect(51,197,twidth,40);
    if (o_temp2 >= temp2){
      stroke(0,0,0);
      fill(0,0,0);
      rect(twidth+1+51,197,218-twidth,40);
    }
  }
}

7  Using Arduino / Displays / issue with touschshield slide comms (showing reading then 0 then reading...etc) on: February 15, 2011, 10:22:31 pm
I've been back and forth with this project and have "given up" a number of times...

Now I'm back and have a specific issue that is holding things up.  Communications between the arduino and the touchshield is unreliable with my code.  Currently the sensors that work flash between the current reading and 0.  I'm not sure why.

Here is the background info on the project: http://code.google.com/p/robotmeter/
This version of the code is a suite of bar graphs and print outs of the sensor readings.

Code:
//code for arduino to use with touchshield and other programs
//pulls data from sensors and reports it across serial based on a handshake

#include <HardwareSensor.h>
#include <Wire.h>

int xval = 4;
int yval = 5;
int zerogy = 512;
int zerogx = 512;

int t1pin = 2;
int t2pin = 3;
int boostPin = 1;

float boost;
float t1;
float t2;
float x;
float y;


void setup(){
  //setup connection to tsshield
  Sensor.begin(19200);
  zeroAccelerometer();
}

void zeroAccelerometer(){
  //zero the accelerometer on startup
  int tempreading = analogRead(yval);
  if ((tempreading < 800) && (tempreading > 200)){
    zerogy = tempreading;
  }
  else {
    zerogy = 512;
  }
  tempreading = analogRead(xval);
  if (true) {
    zerogx = tempreading;
  }
  else {
    zerogx = 512;
  }
}

void loop (){
  //listen for queries from tsshield

  //boost = lookup_boost(analogRead(boostPin));
  boost = lookup_boost(analogRead(boostPin));
  t1 = lookup_temp(analogRead(t1pin));
  t2 = lookup_temp(analogRead(t2pin));
  x = getAccelerometerData(xval);
  y = getAccelerometerData(yval);
  Sensor.print("x", x);
  Sensor.print("y", y);
  Sensor.print("t1", t1);
  Sensor.print("t2", t2);
  Sensor.print("bt", boost);
}


//correctly changed for float values
float lookup_boost(int boost){
  //boost = ( (boost-106000) / 259000 );
  // boost = ( (( boost * 398) / 1000) + 2); //2 is the y intercept
  //398 changed to 378 for slope...because slope was too steep
  float fboost = ( (( (float)boost * 378.0) / 1000.0) - 4.0)/10.0; //divide by 10.0 when adding decimals on the display code
  return fboost;
}

//correctly converted to float values
float lookup_temp(int tval){
  float ftval = (float)tval;
  if (tval < 89){
    return (999.9);
  }
  if (tval > 960){
    return (0.0);
  }
  if ((tval <= 960)&&(tval > 932)){
    return (((ftval-1015.77))/(-1.72));
  }
  if ((tval <= 932)&&(tval > 896)){
    return (((ftval-1042.01))/(-2.26));
  }
  if ((tval <= 896)&&(tval > 851)){
    return (((ftval-1077.38))/(-2.80));
  }
  if ((tval <= 851)&&(tval > 791)){
    return (((ftval-1122.64))/(-3.35));
  }
  if ((tval <= 791)&&(tval > 707)){
    return (((ftval-1175.88))/(-3.88));
  }
  if ((tval <= 707)&&(tval > 624)){
    return (((ftval-1214.41))/(-4.21));
  }
  if ((tval <= 624)&&(tval > 532)){
    return (((ftval-1223.67))/(-4.28));
  }
  if ((tval <= 532)&&(tval > 437)){
    return (((ftval-1186.51))/(-4.05));
  }
  if ((tval <= 437)&&(tval > 364)){
    return (((ftval-1113.49))/(-3.66));
  }
  if ((tval <= 364)&&(tval > 306)){
    return (((ftval-1022.32))/(-3.21));
  }
  if ((tval <= 306)&&(tval > 248)){
    return (((ftval-90.78))/(-2.70));
  }
  if ((tval <= 248)&&(tval > 200)){
    return (((ftval-785.75))/(-2.20));
  }
  if ((tval <= 200)&&(tval > 158)){
    return (((ftval-665.07))/(-1.75));
  }
  if ((tval <= 158)&&(tval > 123)){
    return (((ftval-553.00))/(-1.37));
  }
  if ((tval <= 123)&&(tval > 90)){
    return (((ftval-417.52))/(-.94));
  }
}

//correctly converted to use float values
float getAccelerometerData (int axis){
  int zerog = 512;
  if (axis == 4){
    zerog = zerogx;
  }  
  if (axis == 5){
    zerog = zerogy;
  }

  int rc = analogRead(axis);
  int top =( (zerog - rc) ) ;
  float frtrn = ((float)top/(float)158);  //158Vint jumps are 1g for the ADXL213AE (original accel)
  //154Vint jumps are 1g for the ADXL322 (updated one)
  return frtrn;
}


8  Forum 2005-2010 (read only) / Syntax & Programs / Re: Thermistor readings... use lookup table? on: July 19, 2007, 09:42:32 pm
openoffice calc doesn't have an equation solving function like excel does.  This is why I'm taking the stuff and importing it into the OS X grapher.  Its working but it's relatively slow.
9  Forum 2005-2010 (read only) / Syntax & Programs / Re: Thermistor readings... use lookup table? on: July 19, 2007, 09:22:33 pm
No clue why the poll was added.

I am recalculating everything right now.  I think a 470 Ohm resistor might be the best choice for temp range i selected.

I started calculating the lines i'll interpolate from.  Not having excel is a pain...this graphing program on os x is really basic and unwieldy.
10  Forum 2005-2010 (read only) / Syntax & Programs / Re: Thermistor readings... use lookup table? on: July 18, 2007, 08:07:11 am
So by adding:

#include <avr/pgmspace.h>
and "PROGMEM"

This person was able to use the flash as memory for a constant.  Cool.
I may have to do the same sort of thing for a oil temp sender/sensor as well so this works out nicely.

The only concern I have with this is how much space the pgmspace.h takes up.  I guess if it is an issue I could always modify pgmspace.h to be smaller.

Currently the sketch uses about 10k of 14k available.
11  Forum 2005-2010 (read only) / Syntax & Programs / Re: Thermistor readings... use lookup table? on: July 18, 2007, 07:08:51 am
I was all set to implement the interpolation style solution you suggested.  However, I figured out the y=mx+b line formula for the first segment and it comes out to something with m or b of 2.033e10 something or other that has to be expressed in scientific notation.  This is a non-starter as we all know that it is difficult to do decimal numbers...especially ones that require scientific notation to state, on the arduino.  

Maybe I'll try to fit some exponential curves or something.  Maybe the os x graphic program isn't all that good.  I also tried open office calc but that doesn't solve for equations.  
12  Forum 2005-2010 (read only) / Syntax & Programs / Re: Thermistor readings... use lookup table? on: July 17, 2007, 08:04:59 pm
Apparently there is an upper bound for array size.  Apparently, I've reached it ;D

I couldn't figure out why my sketch wasn't running.  Then I commented out the lookup table and voila it works.  I guess I'll use your interpolation idea.
13  Forum 2005-2010 (read only) / Syntax & Programs / Re: Thermistor readings... use lookup table? on: July 17, 2007, 06:47:13 pm
Oh, I wasn't doing interpolation.  I was doing thresholds.  So if the voltage read by analogRead is between a and b then the temp is c.  So you are taking, say, 30-40 degrees and mapping those to some linear equation then mapping 40-50 (or whatever it is) to another linear equation?
14  Forum 2005-2010 (read only) / Syntax & Programs / Re: Thermistor readings... use lookup table? on: July 17, 2007, 11:14:38 am
I went with almost exactly what you did.  Lookup table.  Its only 318 integers in an array.  

BTW I'm going to probably have to use your car power supply protection circuit from that other thread.

If anyone is interested in my project it's all document (all ramblings, etc....might want to read it back to front) here: http://www.iwsti.com/forums/showthread.php?t=84794
15  Forum 2005-2010 (read only) / Syntax & Programs / Re: Thermistor readings... use lookup table? on: July 15, 2007, 09:24:18 pm
No "mothership" in this project.  Everything is sent directly from the arduino to a 16x2 serial display.  It's a standalone unit.

All the temp values are to be read by human beings so they should show up a degC or degF values.  logarithmic arithmetic is way too difficult to do on the chip itself so I will be using lookup tables.
Pages: [1] 2 3 ... 9