Show Posts
Pages: [1] 2 3
1  Using Arduino / Programming Questions / Re: IDE update screwed up my libraries on: January 23, 2013, 12:50:24 am
Quote
Code:

void loop (){
if(CAN_Connect == true)
  {
      Get_CAN_Data( &RPM,  &SPEED,  &EngineTemp,  &TPS,  &Drivers_Torque_Demand,  &Actual_Torque,   &Engine_Torque_Reference, &Timing_Advance, &Caculated_Load, &Maf);// "&" passes the address of input to the function
      //Serial_CAN_Print(RPM,  SPEED, EngineTemp, TPS,  Drivers_Torque_Demand,  Actual_Torque, Engine_Torque_Reference, Timing_Advance, Caculated_Load, Maf); // doesnt need "&" not editing data **** comment out this line later ***
     
     Wire.beginTransmission(lcd_addr);Wire.write(0xFE); Wire.write(0x45); Wire.write(0x00+4);Wire.write(itoa(RPM,buffer2,10)); Wire.endTransmission();
      /*Wire.beginTransmission(lcd_addr);Wire.write(0xFE); Wire.write(0x45); Wire.write(0x00+14);Wire.write(itoa(TPS,buffer2,10)); Wire.endTransmission();
      Wire.beginTransmission(lcd_addr);Wire.write(0xFE); Wire.write(0x45); Wire.write(0x40+12);Wire.write(itoa(Engine_Torque_Reference,buffer2,10)); Wire.endTransmission();
      delay(100);*/
}
}

May I suggest more conventional formatting? This is almost impossible to read.

i can change it for the sake of making it more readable for you (and other), but the way it is laid out is easier to read for me as it follows strings of data that make up 1 line...
 i2c lines are like:  0x50, 0xFE,0x45,0x00,"data for that line", end... [address][CMD][CMD][parameter][data][end]


I think my problem may be my car... its a CAN car but it may be a special VW protocol where a 0x7DF address might not be the correct address for the ECU. This car has 21 nodes on the CAN bus..

Tomorrow i will test what i have on another CAN car/truck
2  Using Arduino / Programming Questions / Re: IDE update screwed up my libraries on: January 22, 2013, 11:08:16 pm
If data is being sent wrong, the devices may be unresponsive. Maybe the can lib or whatever handles the transmission has extra initialisation steps, or maybe endianness needs switching.

By wiggling do you mean transmitting digital bits, or is it just noise on a voltage ( no discernible voltage changes that would register a 0, or 1 )

the library i made use to work as is on version 0.22... on version 1.0.3 the same libraries, that use to work, don't work anymore..

by wiggling I mean changing state from high to low, low to high...
3  Using Arduino / Programming Questions / Re: IDE update screwed up my libraries on: January 22, 2013, 09:56:12 pm
This is a bad choice for a file name if it does exist ( not part of Arduino ) :
Quote
#include <FILENAME.h>

The IDE appears to give warnings/errors on some missing headers but not all, verify the file names are correct. Read the documentation for the new libraries you are using/switching too. Also search the forum for other people with upgrade problems using those libs, good chance by now someone else has encountered the error ( if it is not specific to your code ).


That's weird, now it complies with both of those commented out.... so i took it out the my car and fired it up still not working...
checked the data lines with an Oscope.. and they are wiggling..

here is the function code where i'm getting the data
Code:
void Get_CAN_Data(long *RPM, int *SPEED, int *EngineTemp, int *TPS, int *Drivers_Torque_Demand, int *Actual_Torque, int *Engine_Torque_Reference,int *Timing_Advance, int *Caculated_Load, int *Maf)
{
        //CAN Bus data collection
        if(Canbus.ecu_req(ENGINE_RPM,buffer) == 1){
          *RPM=atoi(buffer); //* changes what is stored
        }
        digitalWrite(A0, HIGH);// turns off LED
        if(Canbus.ecu_req(VEHICLE_SPEED,buffer) == 1){
            *SPEED=atoi(buffer); //* changes what is stored
        }
        if(Canbus.ecu_req(ENGINE_COOLANT_TEMP,buffer) == 1){
            *EngineTemp=atoi(buffer); //* changes what is stored
        }
        if(Canbus.ecu_req(THROTTLE,buffer) == 1){
            *TPS=atoi(buffer); //* changes what is stored
        } 
        if(Canbus.ecu_req(DRIVERS_TORQUE_DEMAND,buffer) == 1){ 
            *Drivers_Torque_Demand=atoi(buffer); //* changes what is stored
        }
         if(Canbus.ecu_req(ACTUAL_TORQUE,buffer) == 1){ 
             *Actual_Torque=atoi(buffer); //* changes what is stored
        }
        if(Canbus.ecu_req(ENGINE_TORQUE_REFERENCE,buffer) == 1){ 
            *Engine_Torque_Reference=atoi(buffer); //* changes what is stored
        }
        if(Canbus.ecu_req(TIMING_ADVANCE,buffer) == 1){ 
            *Timing_Advance=atoi(buffer); //* changes what is stored
        }
        if(Canbus.ecu_req(CALCULATED_ENGINE_LOAD,buffer) == 1){
            *Caculated_Load=atoi(buffer);
        }
        if(Canbus.ecu_req(MAF_SENSOR,buffer) == 1){
            *Maf=atoi(buffer);
        }
        digitalWrite(A0, LOW);// turns on LED

       
       
}

main
Code:

void loop (){
if(CAN_Connect == true)
  {
      Get_CAN_Data( &RPM,  &SPEED,  &EngineTemp,  &TPS,  &Drivers_Torque_Demand,  &Actual_Torque,   &Engine_Torque_Reference, &Timing_Advance, &Caculated_Load, &Maf);// "&" passes the address of input to the function
      //Serial_CAN_Print(RPM,  SPEED, EngineTemp, TPS,  Drivers_Torque_Demand,  Actual_Torque, Engine_Torque_Reference, Timing_Advance, Caculated_Load, Maf); // doesnt need "&" not editing data **** comment out this line later ***
     
     Wire.beginTransmission(lcd_addr);Wire.write(0xFE); Wire.write(0x45); Wire.write(0x00+4);Wire.write(itoa(RPM,buffer2,10)); Wire.endTransmission();
      /*Wire.beginTransmission(lcd_addr);Wire.write(0xFE); Wire.write(0x45); Wire.write(0x00+14);Wire.write(itoa(TPS,buffer2,10)); Wire.endTransmission();
      Wire.beginTransmission(lcd_addr);Wire.write(0xFE); Wire.write(0x45); Wire.write(0x40+12);Wire.write(itoa(Engine_Torque_Reference,buffer2,10)); Wire.endTransmission();
      delay(100);*/
}
}



 
4  Using Arduino / Programming Questions / IDE update screwed up my libraries on: January 22, 2013, 08:40:14 pm
this is the exact reason i did not want to update my IDE.... after updating form 0.22 to 1.0.3 my CAN bus library quit working and errored out, I'm getting sick of racking my brain on this...

My original Canbus.cpp had this
Code:
#include "WConstants.h" //for old IDE
#include <stdio.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "pins_arduino.h"
#include <inttypes.h>
#include "global.h"
#include "mcp2515.h"
#include "defaults.h"
#include "Canbus.h"


Error:
Quote
Canbus.cpp:6:38: error: WConstants.h: No such file or directory
after searching online I was told I needed this
Code:
//#include "WConstants.h" //for old IDE
#include "Arduino.h" //added for arduino 1.0+
#include <stdio.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "pins_arduino.h"
#include <inttypes.h>
#include "global.h"
#include "mcp2515.h"
#include "defaults.h"
#include "Canbus.h"
#include <FILENAME.h> // add this for 1.0+ IDE

the next error pointed to my mcp2515.c
Code:
mcp2515.c:31:34: error: WConstants.h: No such file or directory
original code
Code:
#include <avr/io.h>
#include <util/delay.h>
#include "WConstants.h" //old IDE
#include "global.h"
#include "mcp2515.h"
#include "mcp2515_defs.h"
#include "defaults.h"


changed to
Code:
#include <avr/io.h>
#include <util/delay.h>
//#include "WConstants.h" //old IDE
#include "Arduino.h" //added for arduino 1.0+
#include <FILENAME.h> // add this for 1.0+ IDE
#include "global.h"
#include "mcp2515.h"
#include "mcp2515_defs.h"
#include "defaults.h"

everything being called in my .pde
Code:
//#include <NewSoftSerial.h>
#include <SoftwareSerial.h>
#include <Canbus.h>  // my CAN needed.
#include <Wire.h>
//NewSoftSerial mDVRRec(6, 7);  //serial for unit that records ***correct
SoftwareSerial mDVRRec(6, 7);

everything use to work before I upgraded to 1.0.3

I'm using the SPI bus & SCK is connected to pin13 (LED pin) and I can see it blipping on and off so something is trying, but i'm not getting any data on my LCD or Serial port even though the print commands are there
5  Using Arduino / Programming Questions / Re: using Arduino to program the ATtiny167.. on: April 06, 2012, 03:56:39 am
This might be a bit unwanted, but if you need it in three weeks, isn't it better to just suffer through the pain of using the Uno as ISP?  Unless you need to program lots of ATtinies?

again i need to program 7 ATtinies...

Hello,

Current solutions is to use an Arduino UNO as a ISP and AVR studio & AVR dude to upload code via the ISP.

Does that work?  Are you able to program an ATtiny167 using the ArduinoISP sketch?


still working on a hello world program, our team has fallen apart/ dropped..... it is now down to the robotics & electrical engineering student(2 total/ out of the 22) to get us over the finish line. I need basic functionality, the 2 of us need to pass.


we both kinda know C++ from what we took in school.... we both have done extensive work using a arduino uno/demulva/mega 
6  Using Arduino / Programming Questions / using Arduino to program the ATtiny167.. on: April 06, 2012, 02:30:40 am
hey,

So I have to program 7 ATtiny167 and I would like to use  Arduino to do it.

Current solutions is to use an Arduino UNO as a ISP and AVR studio & AVR dude to upload code via the ISP.
AVR Studio does not recognize Arduino ISP as a programmer pod thus AVRdude to program :-(

lets face it, this way is a pain and suck...

how can i modify the arduino/arduino SDK to work with a attiny167?

how can i intercept the C code from arduino?

i'm willing to make the modifications/make files so the community can now use the ATtiny167. just need to know what to do and where to start...

also gotta program a ATmega2560 via ISP...

please help... 3 weeks left in the semester...
7  Using Arduino / Project Guidance / Re: HELP!, Arduino keeps rebooting on: December 16, 2011, 01:58:58 pm
Making a string of a single colon or slash is also sily.
What everyone said; cut down on the strings.

the "\r" is need for the mDVRs, that how they know the "enter" k\ey has been pressed, and the ":" is for for the time, lat or lon... is there a better way?
8  Using Arduino / Project Guidance / Re: HELP!, Arduino keeps rebooting on: December 16, 2011, 01:32:09 pm
Quote from: liudr

You save over 20 bytes on this instruction alone. UNO only has 2048 bytes and you have a ton of those long and nice printouts. For your 5pm deadline, trim down all the strings to see if it helps. For a future with nice long printouts WITHOUT wasting your RAM, you can come back over the weekend and have time to learn it.
we the system reboots with the serial prints at the bottom commented out

Quote from: liudr
Just curious, how frequently (in seconds) does the arduino reboot?
it varies between 8-20 seconds
9  Using Arduino / Project Guidance / Re: HELP!, Arduino keeps rebooting on: December 16, 2011, 01:28:01 pm
ok will do... so in my void OSD_setup would it help if i move those to a while loop as most of them are the same and where they differ just put an "i" and "++i" after each setup?


how do i find out how much sram i'm using?
10  Using Arduino / Project Guidance / Re: HELP!, Arduino keeps rebooting on: December 16, 2011, 12:39:06 pm
Serial log
Code:
booting....
Sofware build date: 12/16/2011
Booting Overlay Generator
Booting Recording unit
OSD start
OSD End
Booting Complete...
Acquired Data
-------------
Lat: 3338506    Lat: -11184308   
Lat/Long(float): 33.38506, -111.84308 Fix age: 145ms.
Date(ddmmyy): 161211 Time(hhmmsscc): 17372600 Fix age: 265ms.
Date: 12/16/2011  Time: 17:37:26.0  Fix age: 389ms.
Alt(cm): 999999999 Course(10^-2 deg): 9080 Speed(10^-2 knots): 0
Alt(float): 10000000.00 Course(float): 90.80
Speed(knots): 0.00 (mph): 0.00 (mps): 0.00 (kmph): 0.00
-------------

Acquired Data
-------------
Lat: 3338506    Lat: -11184308   
Lat/Long(float): 33.38506, -111.84308 Fix age: 165ms.
Date(ddmmyy): 161211 Time(hhmmsscc): 17372800 Fix age: 285ms.
Date: 12/16/2011  Time: 17:37:28.0  Fix age: 406ms.
Alt(cm): 999999999 Course(10^-2 deg): 9080 Speed(10^-2 knots): 0
Alt(float): 10000000.00 Course(float): 90.80
Speed(knots): 0.00 (mph): 0.00 (mps): 0.00 (kmph): 0.00
-------------
booting....
Sofware build date: 12/16/2011
Booting Overlay Generator
Booting Recording unit
OSD start
OSD End
Booting Complete...

Acquired Data
-------------
-------------

11  Using Arduino / Project Guidance / Re: HELP!, Arduino keeps rebooting on: December 16, 2011, 12:22:43 pm
stupid 9500 char limit  smiley-confuse
Code:
//===== Trigger section ===============================================
  if(analogRead(2)>800 &&Flag==0){
   
      mDVRRec.print("v1\r");
      digitalWrite(A0, LOW); // turns on LED
      Serial.println("Recording Started");
      Time_Check=Time_Alive; //captures current time
      Flag=1; // trigger
  }
 
    if( analogRead(2)>800 &&Flag==1 && ((Time_Alive - Time_Check) > 5)){
      mDVRRec.print("v2\r");
      Serial.println("Recording Stopped");
      digitalWrite(A0, HIGH); // turns off LED
   
      Flag=0;
     
    }
 
  if (analogRead(3) >400){
    mDVRRec.print("c1\r");  // take a still images
    Serial.println("Still Image Captured");
    delay(100);
  }
   
 /*
  if(((Time_Alive - Time_Check) > 5) && Flag ==1 && Rec_Flag==0){ // delta check
      //Flag=1;//do stuff Flag== something.... think
      Rec_Flag=1;
     
    }
  */
  Time_Alive=(millis()/1000); //how many seconds has this been running. overflow at 50 days
//=====================================================================
//====================LCD Pages====================================
  if((millis()%50)==0)
 {
 ++i;
 
 }
 switch(i%4)
{
case 0:
   
     lcd.setCursor(0, 0);
     lcd.print("Time: ");lcd.print(hour,DEC);lcd.print(":");lcd.print(minute,DEC);lcd.print(":");lcd.print(second,DEC);lcd.print(" Z    ");
     lcd.setCursor(0, 1);
     lcd.print("Date: ");lcd.print(month,DEC);lcd.print("/");lcd.print(day,DEC);lcd.print("/");lcd.print(year);
     
     break;
 
case 1:
   
     lcd.setCursor(0, 0);
     lcd.print("Lat: ");lcd.print(lat% 100L);lcd.print((char)228);lcd.print(lat% 1000L);lcd.print("'");lcd.print(lat% 10000L,1);
     lcd.setCursor(0, 1);
     lcd.print("long: ");lcd.print(lon);lcd.print((char)228);lcd.print(lon% 1000L);lcd.print("'");lcd.print(lon% 10000L,1);
     break;
 
   case 2:
   
     lcd.setCursor(0, 0);
     lcd.print("Speed(MPH): ");lcd.print(gps.f_speed_mph(),1);lcd.print("     ");
     lcd.setCursor(0, 1);
     lcd.print("Alt(ft): ");lcd.print((gps.altitude()*0.03281));lcd.print("     "); //centameters to feet
     break;
     
   case 3:
     lcd.setCursor(0, 0);
     lcd.print("# of sat: 7");//lcd.print(gps.get_sat);
     break;

  } 
} // end of main loop
//================================== this section runs no matter what===========================
void printFloat(double number, int digits)
{
  // Handle negative numbers
  if (number < 0.0)
  {
     Serial.print('-');
     number = -number;
  }

  // Round correctly so that print(1.999, 2) prints as "2.00"
  double rounding = 0.5;
  for (uint8_t i=0; i<digits; ++i)
    rounding /= 10.0;
 
  number += rounding;

  // Extract the integer part of the number and print it
  unsigned long int_part = (unsigned long)number;
  double remainder = number - (double)int_part;
  Serial.print(int_part);

  // Print the decimal point, but only if there are digits beyond
  if (digits > 0)
    Serial.print(".");

  // Extract digits from the remainder one at a time
  while (digits-- > 0)
  {
    remainder *= 10.0;
    int toPrint = int(remainder);
    Serial.print(toPrint);
    remainder -= toPrint;
  }
}


void gpsdump(TinyGPS &gps)
{/*
  long lat, lon;
  float flat, flon;
  unsigned long age, date, time, chars;
  int year;
  byte month, day, hour, minute, second, hundredths;
  unsigned short sentences, failed;
*/
  gps.get_position(&lat, &lon, &age);
  Serial.print("Lat: ");Serial.print(lat); Serial.print("    "); Serial.print("Lat: ");Serial.print(lon); Serial.print("    \n"); //embtxtload <index> <string>
         
  feedgps(); // If we don't feed the gps during this long routine, we may drop characters and get checksum errors

  gps.f_get_position(&flat, &flon, &age);
  Serial.print("Lat/Long(float): "); printFloat(flat, 5); Serial.print(", "); printFloat(flon, 5);
  Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms.");

  feedgps();

  gps.get_datetime(&date, &time, &age);
 Serial.print("Date(ddmmyy): "); Serial.print(date); Serial.print(" Time(hhmmsscc): "); Serial.print(time);
  Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms.");

  feedgps();

  gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);
Serial.print("Date: "); Serial.print(static_cast<int>(month)); Serial.print("/"); Serial.print(static_cast<int>(day)); Serial.print("/"); Serial.print(year);
  Serial.print("  Time: "); Serial.print(static_cast<int>(hour)); Serial.print(":"); Serial.print(static_cast<int>(minute)); Serial.print(":"); Serial.print(static_cast<int>(second)); Serial.print("."); Serial.print(static_cast<int>(hundredths));
  Serial.print("  Fix age: ");  Serial.print(age); Serial.println("ms.");

  feedgps();
 Serial.print("Alt(cm): "); Serial.print(gps.altitude()); Serial.print(" Course(10^-2 deg): "); Serial.print(gps.course()); Serial.print(" Speed(10^-2 knots): "); Serial.println(gps.speed());
  Serial.print("Alt(float): "); printFloat(gps.f_altitude()); Serial.print(" Course(float): "); printFloat(gps.f_course()); Serial.println();
  Serial.print("Speed(knots): "); printFloat(gps.f_speed_knots()); Serial.print(" (mph): ");  printFloat(gps.f_speed_mph());
  Serial.print(" (mps): "); printFloat(gps.f_speed_mps()); Serial.print(" (kmph): "); printFloat(gps.f_speed_kmph()); Serial.println();

  feedgps();

  gps.stats(&chars, &sentences, &failed);
 // Serial.print("Stats: characters: "); Serial.print(chars); Serial.print(" sentences: "); Serial.print(sentences); Serial.print(" failed checksum: "); Serial.println(failed);

}
 
bool feedgps()
{
  while (GPS.available())
  {
    if (gps.encode(GPS.read()))
      return true;
  }
  return false;
}
12  Using Arduino / Project Guidance / HELP!, Arduino keeps rebooting on: December 16, 2011, 12:21:41 pm
I'm trying to finish my a project for school (due at 5pm today)

My adruino UNO keeps rebooting for some unknow reason....
power supply is a lab supply 12v set to 1.1amps (DVRs need ~350mA ea) total running is 500-600mA

Binary sketch size: 15758 bytes (of a 32256 byte maximum)

Code:
#include <NewSoftSerial.h>
#include <TinyGPS.h>
#include <LiquidCrystal.h>


TinyGPS gps;
NewSoftSerial GPS(9, 8);
NewSoftSerial mDVRRec(12, 13);  //serial for unit that records ***correct
NewSoftSerial mDVROverlay(10, 11); //serial for unit that draws data on screen *** correct
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
 
  long lat, lon;
  float flat, flon;
  unsigned long age, date, time, chars;
  int year;
  byte month, day, hour, minute, second, hundredths;
  unsigned short sentences, failed;
  int Time_Zone = 7;
  
int timer;  
int i;
void gpsdump(TinyGPS &gps);
bool feedgps();
void printFloat(double f, int digits = 2);
int byteGPS=-1;
int k=0;

int Flag =0; //Rec triggering
long Time_Alive =0;
long Time_Check;
int SPEED=0;

int Altitude=0;



int incomingByte=0;  //for serial command passing
int serIn;;// for serial command passing
int j =0;
byte index = 0; // Index into array; where to store the character


//=========================================================================================
void setup() {
 // put your setup code here, to run once:
  Serial.begin(4800);  // Serial to PC
   GPS.begin(4800);
  mDVRRec.begin(115200);  // Serial to mDVR that records -rev 0.10
 // mDVRRec.begin(57600); // revs 0.20 +
  mDVROverlay.begin(57600);  // Serial to mDVR Overlay generator
 
  lcd.begin(16, 2);
  Serial.println("booting....");
  Serial.println("Sofware build date: 12/16/2011");

  pinMode(A0, OUTPUT);
  pinMode(A1, OUTPUT);
  pinMode(A4, OUTPUT);
  pinMode(A5, OUTPUT);
  
  Overlay_boot();
  RecBoot();
  delay(450); // need to get the mDVRs powered up in time to take commands
  OSD_Setup();
  Serial.println("Booting Complete...");
  digitalWrite(A0, HIGH); // turns off red LED
}
//=========================================================================================
void RecBoot(){
      Serial.println("Booting Recording unit");
      digitalWrite(A4,HIGH); //boot mdvr
      delay(1500);
      digitalWrite(A4,LOW); //boot mdvr
}
//=========================================================================================
void Overlay_boot(){
      Serial.println("Booting Overlay Generator");
      digitalWrite(A5,HIGH); //boot mdvr
      delay(1500);
      digitalWrite(A5,LOW); //boot mdvr
}
//=========================================================================================

void OSD_Setup(){
  int Delay=180; //200 was start, 150 works every time// will effect boot up time
    delay(Delay);
    Serial.println("OSD start");
    mDVROverlay.print(" \r"); // clears any invalid data in the input string
    delay(Delay);
    mDVROverlay.print(" \r");// clears any invalid data in the input string
    delay(Delay);
    mDVROverlay.print(" \r");// clears any invalid data in the input string
    delay(Delay);
    mDVROverlay.print("t4 4 42 00\r"); //
    delay (Delay);
    mDVROverlay.print("embtxtoffset 0 400 400\r"); // sets overlay top row (x,y) Real Time clock
    delay(Delay);
    mDVROverlay.print("embtxtoffset 0 400 400\r"); // sets overlay top row (x,y) Real Time clock
    delay(Delay);
    mDVROverlay.print("osdtxtoffset 1 30 25\r"); // sets overlay top row (x,y) Latitude
    delay(Delay);
    mDVROverlay.print("osdtxtoffset 2 30 50\r"); // sets overlay bottom row (x,y) longatude
    delay(Delay);
    mDVROverlay.print("osdtxtoffset 3 30 400\r");  // sets ovelay bottom row (x,y) speed
    delay(Delay);
    mDVROverlay.print("osdtxtoffset 4 30 75\r");  // sets ovelay bottom row (x,y) Alt
    delay(Delay);
    mDVROverlay.print("osdtxtenable 0 1\r"); // turns overlay string 0 on
    delay(Delay);
    mDVROverlay.print("osdtxtenable 1 1\r"); // turns overlay sting 1 on
    delay(Delay);  
    mDVROverlay.print("osdtxtenable 2 1\r"); // turns overlay sting 1 on
    delay(Delay);
    mDVROverlay.print("osdtxtenable 3 1\r"); // turns overlay sting 1 on
    delay(Delay);
    mDVROverlay.print("osdtxtenable 4 1\r"); // turns overlay sting 1 on
    delay(Delay);
    mDVROverlay.print("osdtxtsize 0 20 20 \r"); // turns overlay string 0 on
    delay(Delay);
    mDVROverlay.print("osdtxtsize 1 20 20 \r"); // turns overlay sting 1 on
    delay(Delay);
    mDVROverlay.print("osdtxtsize 2 20 20 \r"); // turns overlay sting 1 on
    delay(Delay);
    mDVROverlay.print("osdtxtsize 3 20 20 \r"); // turns overlay sting 1 on
    delay(Delay);
    mDVROverlay.print("osdtxtsize 4 20 20 \r"); // turns overlay sting 1 on
    delay(Delay);
    mDVROverlay.print("osdtxtcolor 0 3\r"); // sets sting 1  to blue
    delay (Delay);
    mDVROverlay.print("osdtxtcolor 1 3\r"); // set sting 0 on to blue
    delay (Delay);
    mDVROverlay.print("osdtxtcolor 2 3\r"); // set sting 0 on to blue
    delay (Delay);
    mDVROverlay.print("osdtxtcolor 3 3\r"); // set sting 0 on to blue
    delay (Delay);
    mDVROverlay.print("osdtxtcolor 4 3\r"); // set sting 0 on to blue
    delay (Delay);
    //mDVROverlay.print("vcallback 1\r"); //
    delay (Delay);
    mDVROverlay.print("embtxtrtcauto 1 \r"); //
    delay (Delay);
    mDVROverlay.print("t4 4 42 00\r"); //
    delay (Delay);
    mDVROverlay.print("embtxtenable 0 1\r"); //
    delay (Delay);
    mDVRRec.print(" \r");
    delay(Delay);
    mDVRRec.print(" \r");
    delay(Delay);
    mDVRRec.print("overlay \r");
   Serial.println("OSD End");
    delay(Delay);
}

//=========================================================================================
void mDVR_Print(long lat, long lon, int Altitude, int SPEED)
{
    int Delay=100;
   // int k =0;
    if (k == 0){
         mDVROverlay.print("osdtxtload 1 "); mDVROverlay.print("Latitude: ");mDVROverlay.print(lat);mDVROverlay.print("\r");//load DATA into string
         ++k;
    }
         //delay(Delay);
     else if(k==1){
       mDVROverlay.print("osdtxtload 2 ");mDVROverlay.print("Longatude: ");mDVROverlay.print(lon);mDVROverlay.print("\r");
       ++k;
     }
         //delay(Delay);
     else if (k==2){
       mDVROverlay.print("osdtxtload 3 "); mDVROverlay.print("Speed: "); mDVROverlay.print(SPEED); mDVROverlay.print(" MPH\r");
       ++k;
     }
        // delay(Delay);
      else if  (k==3){
        mDVROverlay.print("osdtxtload 4 "); mDVROverlay.print("Altitude: ");mDVROverlay.print(Altitude); mDVROverlay.print("Ft\r");
        ++k;
      }
      else
      {
        k=0;
      }
        // delay(Delay);
}

//=========================================================================================

void loop() {
     if (Serial.available()) { //direct to arduino
            incomingByte = Serial.read(); // wait a bit for the entire message to arrive
            delay(100); // read all the available characters
        
        if(incomingByte==49){ //1 command
            while (Serial.available() > 0) {
            serIn = Serial.read(); //read Serial
            Serial.print(serIn, BYTE); //eco commands
            mDVRRec.print(serIn, BYTE); //pass commands
          }
        }
        if (incomingByte==50){ //2comand
            while (Serial.available() > 0) {
            serIn = Serial.read(); //read Serial
            Serial.print(serIn, BYTE); //eco commands
            mDVROverlay.print(serIn, BYTE); //pass commands
          }
        }
        mDVRRec.print("\r");
        Serial.println("");
    }
    // end pass through

  digitalWrite(A1, HIGH); // turns orange LED off
  //digitalWrite(A0, HIGH); // turns red LED off
  byteGPS=GPS.read();
   if (byteGPS == -1) {       // See if the port is empty yet
     delay(100);
   }
  //ssdigitalWrite(A0, LOW); // turns redLED on
  
  bool newdata = false;
  unsigned long start = millis();

  // Every 5 seconds we print an update
  while (millis() - start < 20)
  {
    if (feedgps())
      newdata = true;
      
  }
  
  if (newdata)
  {
    Serial.print("Acquired Data \n");
    Serial.println("-------------");
    gpsdump(gps);
    digitalWrite(A1, LOW); // turns orangeLED on
    mDVR_Print(lat, lon, Altitude, SPEED);
    Serial.println("-------------");
    Serial.println();
  }
  Altitude=(gps.altitude()*0.03281);
  //SPEED=gps.f_speed_mph();
  SPEED = gps.speed()*1.1507;

//---------function ---------------------------------
//=====================================================================
//===== Trigger section ===============================================

13  Using Arduino / Programming Questions / Bitwise math/truncating on: December 12, 2011, 08:48:29 pm
hey guys I need some help with bitwise math for truncating variables, i know what i want to do but not sure of the implementation.

here is an example of what i'm getting
Lat=4807038
long=01131000

here is what i need to do with it:
Latitude: 48.07.038
Longitude: 11.31.000

i though if i did something like this is might work (lat & long are Longs)
 
Code:
serial.print("Latitude: ");serial.print((Lat&11100000)>>7;)serial.print(".");serial.print((Lat&00011000)>>3);serial.print(".");serial.print((Lat&0000111));serial.print("\r");
etc... whats the right way/ the easiest way
14  Using Arduino / Programming Questions / Re: Huge Compile Error after small additions/changes (CAN Bus) on: November 20, 2011, 07:10:20 pm
yeah that is my code. thought i posted it ...oops... the forum only allows for 9500characters per post.

i figured it out though, part of the problem was i did not copy the updated cpp & h file like i thought, as well as one type DRIVERS_TORQUE Vs
DRIVERS_TORQUE_DEMAND:
15  Using Arduino / Programming Questions / Re: Huge Compile Error after small additions/changes (CAN Bus) on: November 19, 2011, 10:18:45 pm
canbus.cpp
Code:
/**
 *
 *
 *
 */
#include "WConstants.h"
#include <stdio.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "pins_arduino.h"
#include <inttypes.h>
#include "global.h"
#include "mcp2515.h"
#include "defaults.h"
#include "Canbus.h"




/* C++ wrapper */
CanbusClass::CanbusClass() {

 
}
char CanbusClass::message_rx(unsigned char *buffer) {
tCAN message;

if (mcp2515_check_message()) {


// Lese die Nachricht aus dem Puffern des MCP2515
if (mcp2515_get_message(&message)) {
// print_can_message(&message);
// PRINT("\n");
buffer[0] = message.data[0];
buffer[1] = message.data[1];
buffer[2] = message.data[2];
buffer[3] = message.data[3];
buffer[4] = message.data[4];
buffer[5] = message.data[5];
buffer[6] = message.data[6];
buffer[7] = message.data[7];
// buffer[] = message[];
// buffer[] = message[];
// buffer[] = message[];
// buffer[] = message[];
}
else {
// PRINT("Kann die Nachricht nicht auslesen\n\n");
}
}

}

char CanbusClass::message_tx(void) {
tCAN message;


// einige Testwerte
message.id = 0x7DF;
message.header.rtr = 0;
message.header.length = 8;
message.data[0] = 0x02;
message.data[1] = 0x01;
message.data[2] = 0x05;
message.data[3] = 0x00;
message.data[4] = 0x00;
message.data[5] = 0x00;
message.data[6] = 0x00;
message.data[7] = 0x00;




// mcp2515_bit_modify(CANCTRL, (1<<REQOP2)|(1<<REQOP1)|(1<<REQOP0), (1<<REQOP1));
mcp2515_bit_modify(CANCTRL, (1<<REQOP2)|(1<<REQOP1)|(1<<REQOP0), 0);

if (mcp2515_send_message(&message)) {
// SET(LED2_HIGH);
return 1;

}
else {
// PRINT("Fehler: konnte die Nachricht nicht auslesen\n\n");
return 0;
}
return 1;
 
}

char CanbusClass::ecu_req(unsigned char pid,  char *buffer)
{
tCAN message;
float engine_data;
int timeout = 0;
char message_ok = 0;
// Prepair message
message.id = PID_REQUEST;
message.header.rtr = 0;
message.header.length = 8;
message.data[0] = 0x02;
message.data[1] = 0x01;
message.data[2] = pid;
message.data[3] = 0x00;
message.data[4] = 0x00;
message.data[5] = 0x00;
message.data[6] = 0x00;
message.data[7] = 0x00;


mcp2515_bit_modify(CANCTRL, (1<<REQOP2)|(1<<REQOP1)|(1<<REQOP0), 0);
// SET(LED2_HIGH);
if (mcp2515_send_message(&message)) {
}

while(timeout < 4000)
{
timeout++;
if (mcp2515_check_message())
{

if (mcp2515_get_message(&message))
{
if((message.id == PID_REPLY) && (message.data[2] == pid)) // Check message is the reply and its the right PID
{
switch(message.data[2])
{   /* Details from http://en.wikipedia.org/wiki/OBD-II_PIDs */
case ENGINE_RPM:  //Engine RPM 0x0C [0-16383.75]
engine_data =  ((message.data[3]*256) + message.data[4])/4; //((A*256)+B)/4
sprintf(buffer,"%d",(int) engine_data);
break;

case ENGINE_COOLANT_TEMP: // Engine coolant temperature 0x05 [-40-215 Deg C]
engine_data =  message.data[3] - 40; //A-40
sprintf(buffer,"%d",(int) engine_data);
break;

case VEHICLE_SPEED: // Vehicle speed 0x0D [km/h]
engine_data =  message.data[3]; //A
sprintf(buffer,"%d",(int) engine_data);
break;

case MAF_SENSOR:    // ((256*A)+B) / 100  [g/s]
engine_data =  ((message.data[3]*256) + message.data[4])/100;
sprintf(buffer,"%d",(int) engine_data);
break;

case O2_VOLTAGE:    // A * 0.005   (B-128) * 100/128 (if B==0xFF, sensor is not used in trim calc)
engine_data = message.data[3]*0.005;
sprintf(buffer,"%d",(int) engine_data);

case THROTTLE: // Throttle Position
engine_data = (message.data[3]*100)/255;
sprintf(buffer,"%d",(int) engine_data);
break;

case ABS_INTAKE_PRESSURE: // Intake manifold absolute pressure 0x0B [0-255 kPa]
engine_data = (message.data[3]); // A
sprintf(buffer,"%d",(int) engine_data); // "%d %% "
break;

case TIMING_ADVANCE:                     // Timing advance 0x0E [-64-63.5°]
engine_data = (message.data[3]/2)/-64; //A/2 - 64
sprintf(buffer,"%d",(int) engine_data); //" ° "
break;

case CALCULATED_ENGINE_LOAD: //Calculated engine load 0x04 [0-100%]
engine_data = (message.data[3]*100)/255; //A*100/255
sprintf(buffer,"%d",(int) engine_data);  //%%
break;

case DRIVERS_TORQUE_DEMAND: //  Driver's demand engine - percent torque 0x61 [-125-125%]
engine_data = (message.data[3]-125); //A-125
sprintf(buffer,"%d",(int) engine_data);  //%%
break;

case ACTUAL_TORQUE: // Actual engine - percent torque 0x62 [-125-125%]
engine_data = (message.data[3]-125); //A-125
sprintf(buffer,"%d",(int) engine_data); //%%
break;

case ENGINE_TORQUE: //  Engine reference torque 0x63 [Nm]
engine_data = (message.data[3]*256 + message.data[4]); //A*256+B
sprintf(buffer,"%d",(int) engine_data);
break;

case FUEL_RAIL_PRESSURE: //  Fuel Rail Pressure 0x23 [0-655,350 kPa]
engine_data = (((message.data[3]*256) + message.data[4]))*10; //((A*256)+B) * 10
sprintf(buffer,"%d",(int) engine_data); // kPa
break;

case COMMANDED_EGR: //  Commanded EGR 0x2C [0-100%]
engine_data = message.data[3]*100/255 ; //100*A/255
sprintf(buffer,"%d",(int) engine_data); //%%
break;

case OIL_TEMPATURE: //Engine oil temperature 0x5C [-40-210 DegC]
engine_data = message.data[3]-40 ; //A-40
sprintf(buffer,"%d",(int) engine_data); //%%
break;



}
message_ok = 1;
}

}
}
if(message_ok == 1) return 1;
}


  return 0;
}






char CanbusClass::init(unsigned char speed) {

  return mcp2515_init(speed);
 
}

CanbusClass Canbus;
Pages: [1] 2 3